to test the create method of the sites controller?
If i’ve understood what you want, something like
Site.expects(:new).with( :name => ‘foo’, :location => ‘bar’)
will do the job.
Fred
That I’ve already tried, but does not work:
NoMethodError: You have a nil object when you didn’t expect it!
You might have expected an instance of Array.
The error occurred while evaluating nil.[]
NoMethodError: You have a nil object when you didn’t expect it!
You might have expected an instance of Array.
The error occurred while evaluating nil.[]
Where does that error occur ? You are aware that setting an
expectation completely replaces the original method ? (ie Site.new
will now return nil, unless you do Site.expects(:new).returns(x) in
which case it returns x)
Fred
That’s what I though, but the behaviour is different. The error happens
in the line when the method new is called:
def create @site = Site.new(params[:site]) <— here
NoMethodError: You have a nil object when you didn’t expect it!
You might have expected an instance of Array.
The error occurred while evaluating nil.[]
Where does that error occur ? You are aware that setting an
expectation completely replaces the original method ? (ie Site.new
will now return nil, unless you do Site.expects(:new).returns(x) in
which case it returns x)