I’m writing an integration test for a rails application using Capybara within Rspec. After filling out a form, the user presses submit.
If I run the test I get:
expected there to be content “Welcome to course builder” in “You are
being redirected.”
I am trying to test the resulted page content, here is the test:
describe PagesController do
describe "Quiz testing in chapter" do
def page_view
Capybara::Node::Simple.new(@response.body)
end
render_views
login_student
it "should fail if user chosen wrong answer" do
page= create_quiz_page_with_two_choices_first_correct
post :answer_quiz, :page_id=>page.id, :submitted_single_answer=>'2'
page_view.should have_content("Welcome to course builder")
end
end
end
in the PagesController
def answer_quiz
...
respond_to do |format|
format.html { redirect_to page }
format.json { head :ok }
end
end
I just started using Capybara, so am I missing something obvious here? Why am I stuck with the redirect response?
Thanks!
hopewise
login_studentneeds to go in abeforeblock:However even that probably won’t fix the problem. When using Capybara it is recommended to actually login by visiting the login page for each example, so:
It’s also helpful to write a special case to handle logins in the test environment, so you can avoid having to create a user for test logins.