[rspec-users] Specs for ApplicationController, where to put them?
anthony at digitalphenom.com
Thu May 24 15:16:41 EDT 2007
I'm sorry, but I'm a newbie and I don't fully understand. Could you
please give me more details?
1. Is the slightly dodgy way completely separate from using a shared
2. What is the appropriate file path and name for your first example
regarding a shared spec? Is it RAILS_ROOT/spec/controllers/
3. Does the event controller spec belong in RAILS_ROOT/spec/
4. How do you actually fire off the test? Do I have to call get or
post inside a do-end block that is attached to it_should_behave_like
describe EventController do
it_should_behave_like "All controllers" do
get 'event1' # just an example action
5. Is there any further documentation on it_should_behave_like other
than the RDoc? It doesn't really say too much.
Thanks for your help!
On May 24, 2007, at 3:18 AM, Tim Lucas wrote:
> 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
>> 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/
> 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
> and then:
> describe EventController do
> it_should_behave_like "All controllers"
> Not sure how you'd deal with something like skip_before_filter
> -- tim
> rspec-users mailing list
> rspec-users at rubyforge.org
More information about the rspec-users