Rails 路由在 rspec before(:all) 过滤器中未定义?
我正在使用 capybara 和 rspec 设置一些集成测试。
在单个测试中,这是有效的:
describe "SIGN IN, POST post" do
it "redirects to /posts after creating a new post" do
visit new_artist_session_path
fill_in 'Email', :with => '[email protected]'
fill_in 'Password', :with => 'password'
click_link_or_button 'artist_submit'
visit "/artists/vargas/posts"
page.should have_content("Upload")
click_button 'Upload'
URI.parse(current_url).path.should == "/artists/vargas/posts"
end
end
但是,我想将“sign_in”部分移动到 before(:all) 过滤器块,以便我可以干燥我的测试。然而,在 before(:all) 块中,相同的代码似乎给出了此错误:
Failure/Error: visit new_artist_session_path
NameError:
undefined local variable or method `new_artist_session_path' for #<RSpec::Core::ExampleGroup::Nested_1:0x0000010399e388>
似乎在 before 块中无法使用路由 url 帮助程序?我该如何补救?
I'm setting up some integration tests using capybara and rspec.
In a single test, this works:
describe "SIGN IN, POST post" do
it "redirects to /posts after creating a new post" do
visit new_artist_session_path
fill_in 'Email', :with => '[email protected]'
fill_in 'Password', :with => 'password'
click_link_or_button 'artist_submit'
visit "/artists/vargas/posts"
page.should have_content("Upload")
click_button 'Upload'
URI.parse(current_url).path.should == "/artists/vargas/posts"
end
end
However, I want to move the "sign_in" portion to a before(:all) filter block so that I can DRY up my tests. However it seems that within the before(:all) block, the same code gives this error:
Failure/Error: visit new_artist_session_path
NameError:
undefined local variable or method `new_artist_session_path' for #<RSpec::Core::ExampleGroup::Nested_1:0x0000010399e388>
It seems that the routes url helpers are not available from within the before block? How do I remedy this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
看来路径助手仅在“it”和“do”之间可用。只是不在 before(:all) 方法中。因此,我最终只是创建了一种登录方法,并将其包含在每个需要它的测试中。
it appears that the paths helpers are available only between the "it" and "do". Just not in the before(:all) method. So I ended up just creating a method for signing in and included it in each test that needed it.