Created
March 2, 2016 00:47
-
-
Save nownabe/a49bc755d3dc565c0a92 to your computer and use it in GitHub Desktop.
Defference between allow_any_instance_of and expect_any_instance_of
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
class SomeClass | |
def greet | |
"Hello." | |
end | |
end | |
describe "allow_any_instance_of" do | |
before { allow_any_instance_of(SomeClass).to receive(:greet).and_call_original } | |
context "when calling Command#greet" do | |
it "pass the test" do | |
expect(SomeClass.new.greet).to eq "Hello." | |
end | |
end | |
context "when not calling Command#greet" do | |
it "pass the test" do | |
end | |
end | |
end | |
describe "expect_any_instance_of" do | |
context "when calling Command#greet" do | |
it "pass the test" do | |
expect_any_instance_of(SomeClass).to receive(:greet).and_call_original | |
SomeClass.new.greet | |
end | |
end | |
context "when calling Command#greet" do | |
it "fail the test" do | |
expect_any_instance_of(SomeClass).to receive(:greet).and_call_original | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment