[rspec-users] Specs for ApplicationController, where to put them?
Tim Lucas
t.lucas at toolmantim.com
Thu May 24 03:18:23 EDT 2007
On 24/05/2007, at 5:00 PM, Wincent Colaiuta wrote:
> The Rails ApplicationController (app/controllers/application.rb)
> serves as an abstract superclass for all other controllers in a Rails
> application and is a good place to put methods and filters which you
> want all of your controllers to use. In my case I'm using it to
> provide methods such as "current_user" and "logged_in?" etc.
>
> By default, RSpec doesn't produce a corresponding spec file for this
> controller.
>
> I've made a spec file (spec/controllers/application_spec.rb) so that
> I can test these methods, but I'm not sure if this is the right thing
> to do. Should I be testing only the non-abstract subclasses instead?
I did it a slighty dodgy way (spec/controllers/
application_controller_spec.rb):
http://pastie.caboo.se/64123
but nowadays you can probably use a shared spec, like so (require'd
from your spec helper):
describe "All controllers", :shared => true do
it "should redirect to HQ if no subdomains specified" do
...
end
end
and then:
describe EventController do
it_should_behave_like "All controllers"
...
end
Not sure how you'd deal with something like skip_before_filter though...
-- tim
More information about the rspec-users
mailing list