[rspec-users] RSpec mock question

Christopher Voltz cjunk at voltz.ws
Mon Jan 9 10:33:20 EST 2012


How can I mock the XMLRPC::Client.new3 class method using rspec's mock?
I expected this spec:

        describe Foo do
          it 'should call new3' do
            options = {}
            XMLRPC::Client.any_instance.should_receive(:new3).with(options)
            Foo.new(options)
          end
        end

with this class definition:

        class Foo
          def new(options)
            @server = XMLRPC::Client.new3(options)
          end
        end

to pass but instead I got the error:

          1) Foo should call new 3
             Failure/Error: Unable to find matching line from backtrace
               Exactly one instance should have received the following
message(s) but didn't: new3

How can I change the spec to make this pass (while verifying that new3
was called)?

Thanks,
Christopher


More information about the rspec-users mailing list