Expect A Method To Be Called And Actually Call It
class Greeting
def self.say_hello
raise "Don't actually execute this"
puts "Hello"
end
end
class GreetingService
def self.run
Greeting.say_hello
end
enddescribe "expect and call original" do
it "expect the message is received" do
expect(Greeting).to receive(:say_hello)
GreetingService.run
# passes
end
it "expect and call original" do
expect(Greeting).to receive(:say_hello).and_call_original
GreetingService.run
# fails, RuntimeError
end
endLast updated