【问题标题】:Rails 3 Capybara errorRails 3 水豚错误
【发布时间】:2011-04-01 23:08:43
【问题描述】:

我正在尝试让 Capybara 使用 rails 3(和测试单元),但是当我尝试运行 rake test:integration 时出现错误:ArgumentError: @request must be an ActionDispatch::Request

测试

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

我不太确定出了什么问题...

【问题讨论】:

    标签: ruby-on-rails ruby-on-rails-3 testing testunit


    【解决方案1】:

    这是水豚在visit 之后没有为@request 变量分配任何东西的问题。

    一种解决方案是使用 rails 内置方法,即

    get '/login'
    assert_response :success
    

    在 rspec 中,我在 page 而不是 @request 上使用断言。

    some discussion here.

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-12-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多