Re: [rspec] "Undefined method assigns" in my API controller

318 views
Skip to first unread message

David Chelimsky

unread,
Feb 21, 2013, 4:45:27 PM2/21/13
to rs...@googlegroups.com
On Wed, Feb 20, 2013 at 4:34 PM, Bruce <bruce...@gmail.com> wrote:
> Hi,
>
> So I'm writing an api controller for my app's api and I'm getting an error
> in my spec: Failure/Error: assigns(:some_response).should_not be_empty
> NoMethodError: undefined method `assigns'.... I am checking to see that
> @some_response got set in a before filter called before the create action of
> the api - I know the filter is getting called and @some_response is getting
> set in the before_filter in the controller. I don't know why the "assigns"
> method is not being found though. My guess is I need to define a path other
> than the rspec defaults, but I'm not sure if this is the issue or how to go
> about doing it. Any help would be greatly appreciated.
>
> Here is a link to the setup/code: http://pastie.org/6260383

Two problems:

1. rspec doesn't know about the apis directory. Try api instead (e.g.
spec/api/v1/some_spec.rb)
2. even if that works, assigns is really a controller spec concept. I
wouldn't recommend it for an api spec, which should (IMO) be more
black-boxy.

HTH,
David

>
> Thank you in advance,
>
> --
> You received this message because you are subscribed to the Google Groups
> "rspec" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to rspec+un...@googlegroups.com.
> To post to this group, send email to rs...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/rspec/-/EJZ0JIgDvv4J.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>

Bruce

unread,
Feb 26, 2013, 2:20:56 PM2/26/13
to rs...@googlegroups.com
Thank you David.  Still couldn't find the assigns, but I read your comment and decided to try it a different way.  So then rspec infers the "spec/api/v1/some_spec.rb" path from "app/controllers/api/v1/some_controller.rb" path?  Is there a way to configure how rspec maps this path? 

David Chelimsky

unread,
Feb 26, 2013, 3:08:56 PM2/26/13
to rs...@googlegroups.com
Reply all
Reply to author
Forward
0 new messages