-
-
Save alindeman/89ec035c97d161c89183 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Original mock syntax, straight forward example | |
Object.any_instance.should_receive(:foo) | |
Object.new.foo # satisfies mock | |
# Original mock syntax, confusing example b/c of "any" term | |
Object.any_instance.should_receive(:foo) | |
Object.new.foo # satisfies mock | |
Object.new.foo # error, "another instance has already received the :foo message" | |
# Proposed syntaxes | |
expect_any_instance_of(Object).to receive(:foo) | |
# ... or something like ... | |
expect_an_instance_of(Object).to receive(:foo) | |
expect_one_instance_of(Object).to receive(:foo) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Original stub syntax, straight forward example | |
Object.any_instance.stub(:foo).and_return(:bar) | |
Object.new.foo # => :bar | |
# Original stub syntax, confusing example b/c of "any" term | |
Object.any_instance.stub(:foo).and_return(1, 2, 3) | |
o = Object.new | |
o.foo # => 1 | |
o.foo # => 2 | |
Object.new.foo # => 1 (NOT 3) | |
# Proposed syntaxes | |
allow_any_instance_of(Object).to receive(:foo).and_return(:bar) | |
# ... or something like ... | |
allow_every_instance_of(Object).to receive(:foo).and_return(:bar) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Though the
an_instance
is still confusing in the case that you create multiple instances.