why can't I use root_path and other *_path methods?

92 views
Skip to first unread message

Barnabas

unread,
Jul 30, 2010, 2:43:45 PM7/30/10
to shoulda
Hi there everyone,

I am new on this list and I'm a new shoulda user too.

I am writing my first tests and found out that I can't use root_path
for some reason in my tests - but I've seen this in a few examples...

an example test:

context "test basic redirect" do
setup do
get :show
end
should redirect_to(root_path)
end


$ ruby test/functional/application_controller_test.rb -v
/Library/Ruby/Gems/1.8/gems/shoulda-2.11.1/lib/shoulda/context.rb:
429:in `send': undefined method `root_path' for
ApplicationControllerTest:Class (NoMethodError)

I tried a few routes, but none of them were working.

I am using shoulda-2.11.1, rails-2.3.8 and hobo-1.0.1

Thanks for your help!

Dan Croak

unread,
Aug 4, 2010, 12:54:59 PM8/4/10
to sho...@googlegroups.com
Barnabas,

You need to wrap the matcher in a lambda:

should { redirect_to(root_path) }

That should do it.

Dan

> --
> Individuals over processes. Interactions over tools.
>
> Agile Rails training from thoughtbot, the makers of Clearance, Shoulda, & Factory Girl:
> http://thoughtbot.com/services/training
>
> The Shoulda group:
> http://groups.google.com/group/shoulda
>
> To post to this group, send email to
> sho...@googlegroups.com
>
> To unsubscribe from this group, send email to
> shoulda+u...@googlegroups.com
>

yannis_

unread,
Aug 20, 2010, 9:28:12 AM8/20/10
to shoulda
Hi,
I'm running a Rails 3.0.0.rc, Shoulda 2.11.2 application and I'm
facing the same problem...
When I a try

should redirect_to(root_path)

I get

usr/local/lib/ruby/gems/1.8/gems/shoulda-2.11.2/lib/shoulda/context.rb:
429:in `send': undefined method `root_path' for
Admin::RoomsControllerTest:Class (NoMethodError)

and if I wrap the matcher in a lambda (should
{ redirect_to(root_path) }) I get a

./test/functional/admin/rooms_controller_test.rb:67:in `should': wrong
number of arguments (0 for 1) (ArgumentError)

Any idea?
Thanks,
Yannis

On Aug 4, 6:54 pm, Dan Croak <dcr...@thoughtbot.com> wrote:
> Barnabas,
>
> You need to wrap the matcher in a lambda:
>
> should { redirect_to(root_path) }
>
> That should do it.
>
> Dan
>
>
>
> On Fri, Jul 30, 2010 at 2:43 PM, Barnabas <k...@goa.hu> wrote:
> > Hi there everyone,
>
> > I am new on this list and I'm a new shoulda user too.
>
> > I am writing my first tests and found out that I can't use root_path
> > for some reason in my tests - but I've seen this in a few examples...
>
> > an example test:
>
> >  context "test basic redirect" do
> >    setup do
> >      get :show
> >    end
> >    should redirect_to(root_path)
> >  end
>
> > $ ruby test/functional/application_controller_test.rb -v
> > /Library/Ruby/Gems/1.8/gems/shoulda-2.11.1/lib/shoulda/context.rb:
> > 429:in `send': undefined method `root_path' for
> > ApplicationControllerTest:Class (NoMethodError)
>
> > I tried a fewroutes, but none of them were working.

yannis_

unread,
Aug 20, 2010, 10:41:31 AM8/20/10
to shoulda
Ok, I got it!
It should be

should ("redirect to the root url" ){ redirect_to root_url }

Best,
Yannis
Reply all
Reply to author
Forward
0 new messages