I'm trying to get Capybara to work with rails 3 (and test unit) but when I try to run rake test:integration
I get an error:ArgumentError: @request must be an ActionDispatch::Request
The test:
require 'integration_test_helper'
class UserNotesTest < ActionDispatch::IntegrationTest
test "User should login" do
user = Factory.create(:user)
visit '/login'
assert_response :success
fill_in 'user_email', :with => user.email
fill_in 'user_password', :with => user.password
click_button 'Sign in'
assert_redirect_to notes_path
end
end
integration_test_helper:
require 'test_helper'
require 'capybara/rails'
module ActionDispatch
class IntegrationTest
include Capybara
end
end
I'm not really sure whats going wrong...
If you are using an existing Rails app, the capybara and webdrivers gem might be already included in the :test group, then you only need to add rspec-rails to the :development, :test group. Then run bundle install to install them. After installing these gems, we still need to install Rspec into our app using rails generate rspec:install .
By default, Rails will use a test framework called ‘MiniTest’ if we didn’t specify -T flag, we want to use Rspec as the test framework instead of MiniTest. Next, create the database of the Rails app so that we can run the app later : Now, we will install the rspec-rails, capybara and webdrivers gems into our Rails app.
then you can use bookmark method in your test code to access the created bookmark record. Jason Swett’s article on let, let! and instance variables has explained this in more detail. The click_link is also a method from Capybara, it will tell the browser to click a link that has the text will specify.
The click_link is also a method from Capybara, it will tell the browser to click a link that has the text will specify. The reload method will ask the bookmark (object) to query the database and get its latest value, instead of using the values stored in memory (which we did it in the let! helper method).
This has been a problem with capybara not assigning anything to the @request
variable after visit
.
One solution is to use the rails built-in methods, i.e.
get '/login'
assert_response :success
In rspec, i use assertions on page
rather than @request
.
There is some discussion here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With