[rspec-users] authentication, controller specs. I think I'm missing something simple ....
Rick Tessner
rick.tessner at gmail.com
Sat Jun 9 16:05:29 EDT 2007
Hi all,
I feel like I'm missing something really easy and I'm just not seeing
it.
I'm using the restful_authentication plugin and have a User model. Uesr
has_many :things and Thing belongs_to :user.
That's it.
I did a "script/generate rspec_scaffold thing" to generate all the
necessary bits. The "rake db:migrate" to create the db.
At this point, a "rake spec" works just fine. All specs pass.
I add in the "include AuthenticatedSystem" in the ThingsController and
add a line to the "before" section in each of the describe stanzas that
reads:
controller.should_receive(:login_required).with(no_args).once.and_return(true)
All tests pass just fine at this point as well.
It's this next part where I get really confused about how the spec
should be written.
What I change in the controller itself (and at this point, all methods
are the default generated by the scaffold) is to add scoping of the
current user to the finds:
For example, the "index" method becomes (to find all things for the
current user)
@things = current_user.things.find(:all)
rather than
@things = Thing.find(:all)
I run "rake spec" and of course it fails. So, I try to mock/stub the
current_user and add a stub for the things method on it and it's at this
point that I feel like I'm missing something fundamental since I get
many many failures of various types.
LocalJumpError in 'ThingsController handling GET /things should
render index template'
no block given
is the major error. If I remove the "find(:all)" a number of these
LocalJumpErrors disappear. I am interested in how to resolve the
LocalJumpError issue tho since I'm sure it will be a use-case that crops
up in my application.
The basic issue I'm struggling with is how does define mocks/stubs for a
controller method that does something of the form:
method_a.method_b.find
Pasted code/spec/errors here
* things_controller http://pastie.caboo.se/69136
* things_controller_spec http://pastie.caboo.se/69137
* Errors w/ find(:all) http://pastie.caboo.se/69138
--
Rick
rick.tessner at gmail.com
More information about the rspec-users
mailing list