Testing Redirect in Cucumber with response.should contain()

745 views
Skip to first unread message

Daniel Dyba

unread,
Jun 11, 2011, 1:45:18 PM6/11/11
to cu...@googlegroups.com
The problem at hand involves a testing a redirect with Cucumber. After having read a post on this Google Group, I decided not to test the implementation of a redirect (i.e., response.should redirect_to(root_url). Rather, I wrote a test that a user would be able to understand that checked if I made it to the redirected page. When the test ran, I got a message saying I am being redirected. I thought that by the time Webrat simulates the clicking of the submit button of the form, the next Cucumber step (i.e. the Then) would response would contain the redirected page.

Any idea why I'm getting this error message?

(::) failed steps (::)

expected the following element's content to include "Sign in":
You are being redirected. (RSpec::Expectations::ExpectationNotMetError)
./features/step_definitions/signing_up/user_signs_up_steps.rb:10:in `/^I am taken to the sign in page$/'
features/signing_up/user_signs_up.feature:10:in `Then I am taken to the sign in page'

Failing Scenarios:
cucumber features/signing_up/user_signs_up.feature:7 # Scenario: User signs up

1 scenario (1 failed)
3 steps (1 failed, 2 passed)
0m4.147s

>_ cat -n features/step_definitions/signing_up/user_signs_up_steps.rb 
     1 When /^I fill in the sign up form$/ do
     2  fill_in "Username", :with => "user"
     3  fill_in "Email", :with => "us...@test.com"
     4  fill_in "Password", :with => "password"
     5  fill_in "Password Confirmation", :with => "password"
     6  click_button "Sign up!"
     7 end
     8
     9 Then /^I am taken to the sign in page$/ do
    10  response.should contain("Sign in")
    11 end

Daniel Dyba

unread,
Jun 11, 2011, 2:46:36 PM6/11/11
to cu...@googlegroups.com
I updated my rspec-rails gem to 2.6.1 and cucumber-rails gem to 0.5.2. That gets rid of my error, but raises another error. I've only partially solved it.

Andrew Premdas

unread,
Jun 11, 2011, 7:38:17 PM6/11/11
to cu...@googlegroups.com
On 11 June 2011 18:45, Daniel Dyba <danie...@gmail.com> wrote:
The problem at hand involves a testing a redirect with Cucumber. After having read a post on this Google Group, I decided not to test the implementation of a redirect (i.e., response.should redirect_to(root_url). Rather, I wrote a test that a user would be able to understand that checked if I made it to the redirected page. When the test ran, I got a message saying I am being redirected. I thought that by the time Webrat simulates the clicking of the submit button of the form, the next Cucumber step (i.e. the Then) would response would contain the redirected page.


redirects have no place in cucumber features as far as webrat (and capybara) are concerned, so you are correct not to put them in your features. However if your application renders a page as part of being redirected (i.e. you are being redirected) then maybe this won't work, as the rendering of the page might disrupt webrat following the redirect. You can always debug and see where you go.

HTH

Andrew

 
Any idea why I'm getting this error message?

(::) failed steps (::)

expected the following element's content to include "Sign in":
You are being redirected. (RSpec::Expectations::ExpectationNotMetError)
./features/step_definitions/signing_up/user_signs_up_steps.rb:10:in `/^I am taken to the sign in page$/'
features/signing_up/user_signs_up.feature:10:in `Then I am taken to the sign in page'

Failing Scenarios:
cucumber features/signing_up/user_signs_up.feature:7 # Scenario: User signs up

1 scenario (1 failed)
3 steps (1 failed, 2 passed)
0m4.147s

>_ cat -n features/step_definitions/signing_up/user_signs_up_steps.rb 
     1 When /^I fill in the sign up form$/ do
     2  fill_in "Username", :with => "user"
     3  fill_in "Email", :with => "us...@test.com"
     4  fill_in "Password", :with => "password"
     5  fill_in "Password Confirmation", :with => "password"
     6  click_button "Sign up!"
     7 end
     8
     9 Then /^I am taken to the sign in page$/ do
    10  response.should contain("Sign in")
    11 end

--
You received this message because you are subscribed to the Google Groups "Cukes" group.
To view this discussion on the web visit https://groups.google.com/d/msg/cukes/-/vBi-zJiH_G0J.
To post to this group, send email to cu...@googlegroups.com.
To unsubscribe from this group, send email to cukes+un...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/cukes?hl=en.



--
------------------------
Andrew Premdas

Matt Wynne

unread,
Jun 12, 2011, 3:15:23 AM6/12/11
to cu...@googlegroups.com
On 11 Jun 2011, at 18:45, Daniel Dyba wrote:

The problem at hand involves a testing a redirect with Cucumber. After having read a post on this Google Group, I decided not to test the implementation of a redirect (i.e., response.should redirect_to(root_url). Rather, I wrote a test that a user would be able to understand that checked if I made it to the redirected page. When the test ran, I got a message saying I am being redirected. I thought that by the time Webrat simulates the clicking of the submit button of the form, the next Cucumber step (i.e. the Then) would response would contain the redirected page.

Any idea why I'm getting this error message?

(::) failed steps (::)

expected the following element's content to include "Sign in":
You are being redirected. (RSpec::Expectations::ExpectationNotMetError)

Just a guess, but do you use a meta-refresh on the page where this "You are being redirected" is displayed? I wouldn't be surprised if webrat doesn't understand those. In any case, something about how that message page redirects to the sign in page is not working with webrat. 

./features/step_definitions/signing_up/user_signs_up_steps.rb:10:in `/^I am taken to the sign in page$/'
features/signing_up/user_signs_up.feature:10:in `Then I am taken to the sign in page'

Failing Scenarios:
cucumber features/signing_up/user_signs_up.feature:7 # Scenario: User signs up

1 scenario (1 failed)
3 steps (1 failed, 2 passed)
0m4.147s

>_ cat -n features/step_definitions/signing_up/user_signs_up_steps.rb 
     1 When /^I fill in the sign up form$/ do
     2  fill_in "Username", :with => "user"
     3  fill_in "Email", :with => "us...@test.com"
     4  fill_in "Password", :with => "password"
     5  fill_in "Password Confirmation", :with => "password"
     6  click_button "Sign up!"
     7 end
     8
     9 Then /^I am taken to the sign in page$/ do
    10  response.should contain("Sign in")
    11 end

--
You received this message because you are subscribed to the Google Groups "Cukes" group.
To view this discussion on the web visit https://groups.google.com/d/msg/cukes/-/vBi-zJiH_G0J.
To post to this group, send email to cu...@googlegroups.com.
To unsubscribe from this group, send email to cukes+un...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/cukes?hl=en.

cheers,
Matt

07974 430184

Reply all
Reply to author
Forward
0 new messages