How to mock parameters with Mocha

Hi folks,

I want to test the following:

In sites controller:

  def create     @site = Site.new(params[:site])     ...

In the functional test:

class SitesControllerTest < Test::Unit::TestCase   def setup     @controller = SitesController.new     @request = ActionController::TestRequest.new     @response = ActionController::TestResponse.new   end

  ...

  def test_create   ...

How can I mock the parameters passed to the new method of the Site model to test the create method of the sites controller?

Thank you!

Hi folks,

...

def test_create ...

How can I mock the parameters passed to the new method of the Site
model 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

Frederick Cheung wrote:

Frederick Cheung wrote:

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.

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

Frederick Cheung wrote:

post :create, :site => ...