rails routes undefined in rspec before(:all) filter?
I'm setting up some integration tests using capybara and rspec.
In a single test, this works:
describe "SIGN IN, POST post"开发者_JAVA技巧 do
it "redirects to /posts after creating a new post" do
visit new_artist_session_path
fill_in 'Email', :with => 'vargas@vargas.com'
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?
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.
精彩评论