I’ve been using Rspec for a while and for some reason am receiving errors on a controller called ReferencesController.
The error says that I have to specify the controller name by either using:
describe MyController do
or
describe 'aoeuaoeu' do
controller_name :my
I’ve tried both variations:
describe ReferencesController do
and
describe 'refs controller' do
controller_name :references
But I get an error for both! Any Idea what could be going on wrong?
Berns
EDIT: Due to the nature of the solution, I’ve reworded the title and added relevant code. Here’s the erroneous code:
#references_controller.rb
class ReferencesController < ApplicationController
def initialize(*args)
#do stuff
super(args) # <= this is the problem line
end
def index
end
end
And the error:
1)
'ReferencesController GET index should take parameters for a company and return the references' FAILED
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
If you call
super(args), you’re passing in a single argument – the array referenced byargs. Using the “splat operator” –super(*args)– turns the array in to a list and passes along each element ofargsas an individual argument.As Wayne has pointed out, there’s also a little syntactic sugar in Ruby that lets you just say
superand it will automatically pass on the arguments for you, treating it likesuper(*args)instead of justsuper().In your particular case, I would guess that your Controller’s superclass’s
initializemethod doesn’t accept an array, so when RSpec tried to instantiate your Controller it failed, which ultimately resulted in the error message you saw.