jeudi 2 juillet 2015

Rspec: Expecting a module to receive a method

I've got a really simple module:

module Foo
  def self.quux
    begin
      # stuff here
    ensure
      Baz.print_stuff
    end
  end
end

And then I have a simple test that fails:

describe Foo
  describe '.quux' do
    it "should print stuff" do
      Foo.quux
      expect(Baz).to receive(:print_stuff)
    end
  end
end

I get the following error message when I run this:

Failures:

1) Foo.quux should should print stuff
   Failure/Error: expect(Baz).to receive(:print_stuff)
     (Baz).print_stuff(any args)
         expected: 1 time with any arguments
         received: 0 times with any arguments

What am I doing wrong? I know for a fact that the print_stuff method is being called.

Aucun commentaire:

Enregistrer un commentaire