Topic: Speccing a mixin under controllers folder

Hi!

I have some functionality that is used by many different controllers. I extracted it into a module and put it under my app/controllers folder, and I include it in controllers. I also want to spec it in separation. The problem is that if I create a spec under spec/controllers folder, I get the error telling me that I must specify the controller which I describe:

Controller specs need to know what controller is being specified. You can
indicate this by passing the controller to describe():

  describe MyController do
    
or by declaring the controller's name

  describe "a MyController" do
    controller_name :my #invokes the MyController
end

Have anybody run into this before. How can I solve this?

Re: Speccing a mixin under controllers folder

Hi,

Do you have something like this at the beginning of your controller spec?

  require 'spec_helper'

  describe MyModuleName do

Re: Speccing a mixin under controllers folder

Nope, I have describe MyCoolController in the controller spec. But I have a separate spec for my module and there is describe MyModuleName do

I have solved the issue for now by making a parallel mixin for specs, but I'd like to solve it more straigth anyway.

Re: Speccing a mixin under controllers folder

Sorry I meant "at the beginning of your helper spec?".

Trying to do what you want I faced the same error. Maybe RSpec allows only controller specs in the spec/controllers directory. Might worth asking it in the rspec mailing list.

I could make it work by putting the helper in RAILS_ROOT/lib/controllers and its spec in RAILS_ROOT/spec/lib/controllers (had to add RAILS_ROOT/lib/controllers to the load path). Would that be acceptable for you?

Re: Speccing a mixin under controllers folder

Well, thats acceptable, but not preferable smile Thanks