[rspec-users] undefined local variable or method `params' for #<Spec

Fernando Perez lists at ruby-forum.com
Tue Apr 14 09:01:50 EDT 2009

> it "should be active if controller is same" do
>     params = {:controller => 'royalty_statement'}
>     tab_class('royalty_statement').should include('active')
>   end
> but it doesn't work out. it gives me same error as previous.

Nah it doesn't work that way, because remember that RSpec is just Ruby
code. 'it' is just a method, "should be active ..." is just an argument,
and then you specify a block of code.

So when you define params = ..., you are actually defining a local
variable, but that variable is not available inside the controller when
the spec is run. That's why I find controllers so painful to spec. I
prefer to use cucumber and webrat for that purpose.

Anyway, I thought that setting controller.params would do the trick but

Maybe you'll have to force a get request then?  so it would be:
get :action_name

We need to wait for rspec-rails experts advice.

By the way the same problem applies to session, so you might be luckier
looking for info about simulating session in rspec and then apply the
same technique to params.
Posted via http://www.ruby-forum.com/.

More information about the rspec-users mailing list