Reputation: 1027
I have three pages:
I set a file upload feature in the index page. I check whether the file is a good file when user attach a file and click submit button.
Then show the validate messages in the confirm page.
If there isn't any errors, it will go to finish page and show success message.
Now I am using rspec/capybara to do the feature test. I can test whether user attach a good file or a bad file in the index page. So I can think what messages will been shown in the confirm page.
But I can't visit
the confirm page or finish page first, because I used a http post method in both of them.
So how to do the feature test on the confirm page and the finish page?
Upvotes: 1
Views: 923
Reputation: 4649
You should controller test the post method, not feature test it. Something like this
describe SomeController, type: :controller do
it "uses post method to ..." do
post :index
expect(response.status).to eq 200
expect(response.body).to have_content('Hello World')
end
end
Upvotes: 1
Reputation: 49950
In a feature test you wouldn't test the three pages separately, you would test it as one feature using something along these lines (with button names, messages, changed to match your pages)
visit index_page_path # go to your index page
page.attach_file ... # select a file
page.click_button 'Submit' # submit the file
expect(page).to have_text 'Whatever message shows on the confirm page'
page.click_button 'Yes I want to save that file' # click the button on the confirm page to do whatever you're doing
expect(page).to have_text 'Whatever message shows on the finish page'
You could also test current_path after the have_text methods if the URL the page is shown on is important to you. You would test the current_path after the have_text because the have_text matcher will wait for the submits to finish and the new page with the text to be loaded. If you test the current_path before the browser could still be on the previous page finishing up the submit and the test would fail
Upvotes: 3