[rspec-users] Mocking MiddleMan

Shane Mingins smingins at elctech.com
Mon Jun 23 20:01:05 EDT 2008


This is what worked for me back then:

In our spec_helper I did:

class Object;  remove_const :MiddleMan; end
MiddleMan = Object.new

And then the spec looked like:

   it "should call the admin email worker" do
     MiddleMan.should_receive(:new_worker).with(:class  
=> :admin_email_worker, :args => @email_params)
     post_with_successful_send
   end

and often MiddleMan.stub!(:new_worker)

HTH
Shane


On 24/06/2008, at 6:08 AM, s.ross wrote:

> I'm trying to verify (using expectations) that a backgroundrb job is  
> being started. I ran across this thread: http://rubyforge.org/pipermail/rspec-users/2007-October/004115.html 
> , in which Pat Maddox conditionally loads backgroundrb. However, I  
> don't see why the original construct that started the thread doesn't  
> work:
>
> MiddleMan 
> .should_receive(:new_worker).with(whateveryourparticularargumentsare)
>
> What I'm observing is a failure connecting to dRuby, which makes  
> sense if MiddleMan is not mocked but (to me) does not make sense  
> when it is mocked.
>
> I'd prefer not to change the actual init code for the plugin as Pat  
> suggests.
>
> What am I missing about how this expectation should work?
>
> Thanks
> _______________________________________________
> rspec-users mailing list
> rspec-users at rubyforge.org
> http://rubyforge.org/mailman/listinfo/rspec-users




More information about the rspec-users mailing list