gpt4 book ai didi

ruby-on-rails - Rails 3 capybara 错误

转载 作者:行者123 更新时间:2023-11-28 19:47:27 24 4
gpt4 key购买 nike

我试图让 Capybara 与 rails 3(和测试单元)一起工作,但是当我尝试运行 rake test:integration 时,我收到一个错误:ArgumentError: @request must是一个 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

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

最佳答案

这是 capybara 在 visit 之后没有给 @request 变量赋值的问题。

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

get '/login'
assert_response :success

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

some discussion here.

关于ruby-on-rails - Rails 3 capybara 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5519797/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com