Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails 3 Capybara error

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...

like image 733
errorhandler Avatar asked Apr 01 '11 23:04

errorhandler


People also ask

How to install RSpec in rails with Capybara?

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 .

How to use RSpec-Rails instead of Minitest in rails?

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.

How do I access the created bookmarks in capybara?

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.

What is the difference between click_link and reload method in capybara?

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).


1 Answers

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.

like image 187
ipd Avatar answered Sep 25 '22 13:09

ipd