Posts [ 16 ]

Topic: Rspec redirect issues - (on Ruby 1.9.1 and Rails 2.3.5)

I'm developing in Rails 2.3.5 on Ruby 1.9.1 and using Cucumber 0.4.4, Rspec 1.2.9 and Webrat 0.6.0 to steer the way. I'm also using restful_authentication and am having issues getting the preconfigured features to work. There were some scenarios that were failing that have been easily fixed, but I'm now getting to a point where I'm starting to think something must be broken in Rspec for these latest versions of Rails and Ruby.

The first issue is that there are instances where redirects will work just fine in the browser but show up as not working in the tests. Other times, the steps defined will pass the redirects without issues.

# This one fails at the should be redirected
Scenario: Anonymous user can log in
Given an anonymous user
And an activated user named 'reggie'
When she creates a singular sessions with login: 'reggie', password: 'monkey', remember me: ''
Then she should be redirected to the home page
...
# This one does get through the redirect
Scenario: Anonymous (logged out) user can log out.
Given an anonymous user
When she goes to /logout
Then she should be redirected to the home page
...

Can anyone make sense of why this should be failing in some cases and not others? It seems totally bizarre - even within the first scenario mentioned (which failed at should redirect) it goes through a should redirect call in the 'Given an anonymous user' step.

The other bit is even stranger. Somehow, flash[:notice] seems to be broken in rspec (possibly just cucumber+..). When I put a flash[:notice] in my code that shows up fine on my browser, the step

Then I should see "You are now logged in"

fails. The weirdest part is that if I test for a flash[:error] message, it works fine! This one is SO bizarre I have a hard time believing that I didn't muddle something up somewhere, but I've have checked and checked again and rechecked everything that would seems obvious to check (to see if there are any assignments of flash[:notice] in the cucumber code, making sure things are spelled correctly and so on). I'm happy to put code up relating to that, but I'll leave it at this for now.

I should mention that I have been getting these strange deprecation messages every time I run rspec or cucumber and I decided to check into these as a possible source but as of yet have found nothing related to them. I started a separate post on this as I can't say for sure that it is related - http://railsforum.com/viewtopic.php?pid=114577#p114577.

Have other people been having experiences like these? Any ideas on what might be malfunctioning - things to check?

Re: Rspec redirect issues - (on Ruby 1.9.1 and Rails 2.3.5)

Re: Rspec redirect issues - (on Ruby 1.9.1 and Rails 2.3.5)

I went ahead and installed the ZenTest gem so that I could use mulitruby to start managing my ruby versions (see http://blog.robseaman.com/2008/12/20/sw ultiruby). I can now say that this happens when using ruby 1.8.7 as well as ruby 1.9.1 so the ruby version is not the issue. I have several apps that have this bug - it ONLY shows up in the cucumber tests. The flash[:notice] messages render just fine in the browser. Still haven't figured out why this is happening, but want keep things up to date on this topic in case any one else comes across this issue.

Re: Rspec redirect issues - (on Ruby 1.9.1 and Rails 2.3.5)

I can verify this behavior with Rails 2.3.4, Ruby 1.8.7, webrat 0.5.3, and cucumber 0.4.4. The flash shows up in my browser, but it's not getting rendered in the page within the cucumber test. The only plugins I'm using are haml and restful-authentication.

Re: Rspec redirect issues - (on Ruby 1.9.1 and Rails 2.3.5)

Hey there. I'm starting to think that restful_authentication might be at fault here. I thought for a sec that it might be haml, so I wrote a quick test with haml_index and erb_index actions within a simple welcome controller. There were no other plugins or gems or anything (other than webrat and cucumber) - just one controller with two actions, each of which assigned a flash[:notice]. To my surprise both actions tested out just fine! Didn't look at things for a while, but just now I started another project that wasn't set up with restful_auth but rather with Ryan Bates' nifty_authentication. To my surprise once again, the errors didn't crop up.

Now, before I can say that my money is on restful_auth being at fault there is something I still have to test. There is another application I wrote with super simple authentication along the lines of one of Ryan's early screencasts. I seem to remember having the flash errors with this one too, but I'll have to go back and take a look to be sure. I'll post results once I have them.

Re: Rspec redirect issues - (on Ruby 1.9.1 and Rails 2.3.5)

Hi,everyoneI have the *flas[:notice]* problem. I tried to hack the rest_auth_features_helper.rb, yet I still got a empty flash object.So i add the following code to the rest_auth_features_helper.rb:

puts "Session[#{session.object_id}] : #{@_flash.to_s}"

finding that session was reset after every redirect.

#
# Account Creation
#
Scenario: Anonymous user can create an account # features\accounts.feature:24
Session[52452552] : noticeYou have been logged out.
Session[52435044] :
Given an anonymous user # features/step_definitions/user_steps.rb:8
And no user with login: 'Oona' exists # features/step_definitions/ra_resource_steps.rb:40
Session[52367928] : noticeThanks for signing up!
When she registers an account as the preloaded 'Oona' # features/step_definitions/user_steps.rb:42
Then she should be redirected to the home page # features/step_definitions/ra_response_steps.rb:19
Session[53901624] :
When she follows that redirect! # features/step_definitions/ra_navigation_steps.rb:46
Then she should see a notice message 'Thanks for signing up!' # features/step_definitions/ra_response_steps.rb:112
</Thanks for signing up!/> expected but was
<"">.
<false> is not true. (Spec::Expectations::ExpectationNotMetError)
./features/step_definitions/ra_response_steps.rb:113:in `/^she should +see an? (\w+) message '([\w !]+)'$/'
features\accounts.feature:30:in `Then she should see a notice message 'Thanks for signing up!''
And a user with login: 'oona' should exist # features/step_definitions/ra_resource_steps.rb:53
And the user should have login: 'oona', and email: 'unactivated@example.com' # features/step_definitions/ra_resource_steps.rb:65
And oona should be logged in # features/step_definitions/user_steps.rb:68

Re: Rspec redirect issues - (on Ruby 1.9.1 and Rails 2.3.5)

One option (possibly a little more involved) is to use authlogic instead. Supposedly they have some helpers that let you easily migrate restful_auth over to authlogic, but I haven't tried it myself, so I can't really testify. Authlogic has been way easier for me to use personally. I use it for all my user models now, and plan on converting the old restful_auth apps over as I go back to them and refactor/build upon. Let me know how it goes for you.

Re: Rspec redirect issues - (on Ruby 1.9.1 and Rails 2.3.5)

metasoarous wrote:

One option (possibly a little more involved) is to use authlogic instead. Supposedly they have some helpers that let you easily migrate restful_auth over to authlogic, but I haven't tried it myself, so I can't really testify. Authlogic has been way easier for me to use personally. I use it for all my user models now, and plan on converting the old restful_auth apps over as I go back to them and refactor/build upon. Let me know how it goes for you.

I'll be shifting to authlogic as I just started prototyping my app.thank you