Wincent Colaiuta wrote:
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
Hi Wincent,
Thanks for the input. I like the idea of the shared behavior so it gets
tested at all points of execution. [And I really enjoyed David's "Yay!",
too. :) ] I am going to keep that in mind as I go forward. In this
particular case, my dilemma was how to test the behavior in the
base_controller to begin with. The problem stemmed from the fact that
there were no actions in the controller to call so I couldn't do a get
on it. With Matt and David's help, I have achieved what I was originally
after. The gist is updated if you are interested:
http://gist.github.com/269544
I'm not sure how to share the behavior now, though. As I look at the
context that implements the testing of the before_filter, sharing it
doesn't seem to make sense since it creates a bogus derived class to do
the testing. If I share the behavior to real derived controllers, it
doesn't seem to me that they will, in fact, be tested.
Do you have any thoughts on that?
Peace,
Phillip
_______________________________________________
rspec-users mailing list
[email protected]
http://rubyforge.org/mailman/listinfo/rspec-users