rspec + capybara未定义的局部变量或方法 [英] rspec+capybara undefined local variable or method
本文介绍了rspec + capybara未定义的局部变量或方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
#gemfile
...
gem 'rspec-rails'
gem 'capybara'
我在spec_helper.rb中根据官方文档。
i已生成测试:
i have add require 'capybara/rails' in spec_helper.rb according with official docs. i have generate a test:
$rails generate integration_test authentication_pages
我已经编写了一个测试:
i have write a test:
#spec/features/authentication_pages_spec.rb
describe "Authentication" do
subject { page }
describe "signin" do
before { visit new_user_session_path }
describe "with invalid information" do
before { click_button "Sign in" }
it { should have_title('Sign in') }
end
end
end
运行测试我出现了错误:
running the test i had an error:
$rspec spec/features/authentication_pages_spec.rb
F
Failures:
1) Authentication signin with invalid information
Failure/Error: before { visit new_user_session_path }
NameError:
undefined local variable or method `new_user_session_path' for #<RSpec::Core::ExampleGroup::Nested_1::Nested_1::Nested_1:0x000000010f9618>
# ./spec/features/authentication_pages_spec.rb:6:in `block (3 levels) in <top (required)>'
Finished in 0.0007 seconds
1 example, 1 failure
Failed examples:
rspec ./spec/features/authentication_pages_spec.rb:11 # Authentication signin with invalid information
new_user_session_path是有效路径,我在我的应用程序中使用了它并且有效。
new_user_session_path is a valid path, i'm using it in my app and it works.
我没有解决方案,我尊重官方文档。
您能帮我吗?
i have no solution, i have respected the official docs. Can you help me?
推荐答案
我发现了错误:
缺少,需要输入 spec_helper spec / features / authentication_pages_spec.rb
i have found the error: missing require 'spec_helper' in spec/features/authentication_pages_spec.rb
正确的文件是这样的:
#spec/features/authentication_pages_spec.rb
require 'spec_helper'
describe "Authentication" do
subject { page }
describe "signin" do
before { visit new_user_session_path }
describe "with invalid information" do
before { click_button "Sign in" }
it { should have_title('Sign in') }
end
end
end
这篇关于rspec + capybara未定义的局部变量或方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文