Skip to content

Instantly share code, notes, and snippets.

@nownabe
Created March 2, 2016 00:47
Show Gist options
  • Save nownabe/a49bc755d3dc565c0a92 to your computer and use it in GitHub Desktop.
Save nownabe/a49bc755d3dc565c0a92 to your computer and use it in GitHub Desktop.
Defference between allow_any_instance_of and expect_any_instance_of
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