2022-07-13 17:17:10 +00:00
|
|
|
require "../spec_helper"
|
|
|
|
|
|
|
|
class Person
|
|
|
|
def initialize(@dog = Dog.new)
|
|
|
|
end
|
|
|
|
|
|
|
|
def pet
|
|
|
|
@dog.pet
|
|
|
|
end
|
|
|
|
|
|
|
|
def pet_more
|
|
|
|
@dog.pet(5)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
class Dog
|
|
|
|
def initialize
|
|
|
|
end
|
|
|
|
|
|
|
|
def pet(times = 2)
|
|
|
|
"woof" * times
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
Spectator.describe Person do
|
|
|
|
mock Dog
|
|
|
|
|
|
|
|
describe "#pet" do
|
|
|
|
it "pets the persons dog" do
|
|
|
|
dog = mock(Dog)
|
|
|
|
person = Person.new(dog)
|
|
|
|
allow(dog).to receive(pet()).and_return("woof")
|
|
|
|
|
2022-07-13 19:42:44 +00:00
|
|
|
person.pet
|
2022-07-13 17:17:10 +00:00
|
|
|
|
|
|
|
expect(dog).to have_received(pet()).with(2)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "#pet_more" do
|
|
|
|
it "pets the persons dog alot" do
|
|
|
|
dog = mock(Dog)
|
|
|
|
person = Person.new(dog)
|
|
|
|
allow(dog).to receive(pet()).and_return("woof")
|
|
|
|
|
2022-07-13 19:42:44 +00:00
|
|
|
person.pet_more
|
2022-07-13 17:17:10 +00:00
|
|
|
|
|
|
|
expect(dog).to have_received(pet()).with(5)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|