Skip to content

Instantly share code, notes, and snippets.

@psyho
Created May 11, 2013 08:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save psyho/5559365 to your computer and use it in GitHub Desktop.
Save psyho/5559365 to your computer and use it in GitHub Desktop.
Bogus.have_received in minispec
require 'minitest/autorun'
require 'set' # bummer, I forgot to require set in Bogus
require 'bogus'
class Foo
def bar(x, y)
end
end
module Bogus
def self.have_received_matcher(method, args)
Bogus.have_received.__send__(method, *args)
end
end
module MiniTest::Assertions
def assert_has_received(subject, method, args)
matcher = Bogus.have_received_matcher(method, args)
assert matcher.matches?(subject), matcher.failure_message_for_should
end
def refute_has_received(subject, method, args)
matcher = Bogus.have_received_matcher(method, args)
refute matcher.matches?(subject), matcher.failure_message_for_should_not
end
end
module MiniTest::Expectations
infect_an_assertion :assert_has_received, :must_have_received, true
infect_an_assertion :refute_has_received, :wont_have_received, true
end
describe "bogus + minitest" do
let(:foo) { Bogus.fake_for(:foo) }
describe "with assertions" do
it "can spy" do
foo.bar(2,3)
assert_has_received(foo, :bar, [1, 2])
end
it "can have negative expectations" do
foo.bar(1,2)
refute_has_received(foo, :bar, [1, 2])
end
end
describe "with matchers" do
it "can spy" do
foo.bar(2,3)
foo.must_have_received(:bar, [1, 2])
end
it "can have negative expectations" do
foo.bar(1,2)
foo.wont_have_received(:bar, [1, 2])
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment