views:

1545

answers:

7

After cloning the latest stable versions of

into a clean rails application, and following (what I believe are) all the instructions for each plugin, cucumber stories still are failing :-(. Here's a summary of the problems:

  1. redirects are not working right off the bat despite having created the 'map.root :controller => "my_controller"' route :
    expected redirect to "/", got no redirect (Spec::Expectations::ExpectationNotMetError)
    /cygdrive/c/development/test/vendor/plugins/rspec/lib/spec/expectations.rb:57:in fail_with'
    /cygdrive/c/development/test/vendor/plugins/rspec/lib/spec/expectations/handler.rb:14:in handle_matcher'
    /cygdrive/c/development/test/vendor/plugins/rspec/lib/spec/expectations/extensions/object.rb:31:in should'.
    /features/step_definitions/user_steps.rb:111:in /^an? (.) user named '(.)'$/'
    features/sessions.feature:25:in `And an activated user named 'reggie''
    
  2. the story says the logged_in? method is protected despite the features/step_definitions/ra_env.rb file calling:
    ApplicationController.send(:public, :logged_in?, :current_user, :authorized?)
    Doesn't that call make those methods available without needing stubbing?

Oh, and I'm trying to run autospec, so I've done the following commands to get it started:

export AUTOFEATURE=true
rake spec:server:start
ruby script/autospec
A: 

I don't have a lot of guidance to offer, just sympathy - I've spent a few hours recently dealing with the same problem. On the up side, it's how I learned RSpec.

One thing I did find is that a lot of the failures were things I wanted to change anyway - e.g., I didn't want to redirect to '/' on login, but someplace else.

In the end, most of the failures were simple to fix, once I'd figured out where to look.

bradheintz
Haha...thanks for the sympathy. Unfortunately I'm a slower learner than you, and I've spent the past three days trying to figure it all out...maybe a full night's sleep wouldn't hurt. :-)
btelles
A: 

I am working through the same issues. I am not there yet, but I think that ApplicationController.send(:public, :logged_in?, :current_user, :authorized?) needs to go in support/env.rb instead.

+1  A: 

I had to change the definition of the logout function in user_steps.rb to:

def log_out
  get '/logout'
end

Before it was trying to get '/session/destroy' which only exists if you don't remove the default routes.

Also, make sure you "include AuthenticatedSystem" in application_controller.

Still fighting through some of the other issues though...

+2  A: 
hugo.corbucci
Excellent Hugo! Thank you! This solved the redirect part of the problem.
btelles
+1  A: 

As for the "Protected method" problem, I figured out that if I don't use autospec and leave config.cache_classes=true, then the tests pass.

Turning config.cache_classes=false introduces the error again.

It appears that the the problem is either with how class caching is implemented in rails, or how rspec manages classes that have been created. Unfortunately I don't have the resources to investigate this a whole log more, and it appears there is a good discussion about it taking place at: http://groups.google.com/group/rspec/browse_thread/thread/500ede090bd08996/25a3d9a7d283696b?lnk=gst&q=cache_classes#25a3d9a7d283696b

btelles
A: 

I get some of the mentioned errors, too. But the first problem occuring in my app is this:

Multiple step definitions have the same Regexp:

features/step_definitions/user_steps.rb:16:in /^(.*) (.*) user named '(.*)'$/' features/step_definitions/user_steps.rb:29:in /^there is no (.*) user named '(. *)'$/'

(Cucumber::Redundant)

Sure, I can fix this, but many more errors will follow (including the protected logged_in? method on the controller, the failing RSpecs and so on).

Does anyone know, whether we all do somthing fundamentally wrong here? Or is it just that restful_authentication is broken in its current release?

morgler
+1  A: 

I found this blog post that explains the crux of the issue well:

http://blog.andrew.premdas.org/articles/2008/10/15/webrat-visits-and-redirects

basically, restful authentication tests are trying to test something that shouldn't be tested using webrat. So, the change recommended above is the opposite of what I think probably should be changed.

I've changed the Restful Authentication Tests so that they don't test redirects but just test what page you end up on. However, there still seems to be a problem with certain redirects that I don't understand:

Then she should be at the new session page                     # features/step_definitions/ra_response_steps.rb:15
  expected "session/new", got redirected to "http://www.example.com/session/new" (Spec::Expectations::ExpectationNotMetError)

I don't understand where this example.com is coming from. anybody else have a similar error?

Gabe S.