El 05/01/2010, a las 21:52, Phillip Koebbe escribió:
Pat Maddox wrote:
The spec has Admin::BaseController as the described type. So of
course it's going to test against that. If you want to test a
different class, you need to describe that instead!
Hi Pat,
Right. But, I'm not really wanting to test a different class. My
intention is to put the require_admin in the base_controller and
have all the admin controllers descend from it, so I don't have to
duplicate the before_filter. I was trying to be simple and make a
request to a controller that descends from base_controller, thinking
that if it got through and didn't redirect to the error page, it
worked. How would you suggest I test that
I test inherited stuff with shared behaviors. It might be something
you could use here.
Basically, I have a bunch of behavior in my ApplicationController, for
example, and in my spec/controllers/application_controller_spec.rb
file I have a bunch of blocks like this:
describe ApplicationController, 'protected methods', :shared =>
true do
...
end
describe ApplicationController, 'parameter filtering', :shared =>
true do
...
end
And I then group them all together in one more shared behavior:
describe ApplicationController, :shared => true do
it_should_behave_like 'ApplicationController protected methods'
it_should_behave_like 'ApplicationController parameter filtering'
...
end
And finally in all subclasses which inherit I can now just do:
describe ArticlesController do
it_should_behave_like 'ApplicationController'
...
end
So the behavior inherited from the superclass is specified, but it is
also tested independently by the inheriting subclasses.
I imagine the same idea might be adaptable in some way for your use
case.
Cheers,
Wincent
_______________________________________________
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users