[rspec-users] mocking does not work

Leon Du leondu at gmail.com
Thu Oct 30 02:47:54 EDT 2008


The spec
--------------------------------------------------------------------------------------------------------------------------------------------------------
it "should expose a newly created logo as @logo" do
  Logo.should_receive(:new).with({'these' =>
'params'}).and_return(mock_logo(:save => true))
  Logo.should_receive(:company=).with(mock_model(Company))
  post :create, :logo => {:these => 'params'}
  assigns(:logo).should equal(mock_logo)
end


The code:
--------------------------------------------------------------------------------------------------------------------------------------------------------
def create
  @logo = Logo.new(params[:logo])
  @logo.company = current_user.company
  puts current_user.full_name
  if @logo.save
    flash[:notice] = 'You logo was successfully uploaded.'
    redirect_to logo_setting_path
  else
    render :action => logo_setting_path
  end
end

And the error:
--------------------------------------------------------------------------------------------------------------------------------------------------------
Spec::Mocks::MockExpectationError in 'LogosController responding to POST
create
with valid params should expose a newly created logo as @logo'
Mock 'Logo_1001' received unexpected message :company= with
(#<Company:0x219a800
 @name="Company_1">)



Question:
How could I mock a company= methond on Logo?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://rubyforge.org/pipermail/rspec-users/attachments/20081030/529ae69c/attachment.html>


More information about the rspec-users mailing list