shard-spectator/spec/docs/mocks/mocks_spec.cr

33 lines
565 B
Crystal
Raw Normal View History

2020-05-09 20:12:40 +00:00
require "../../spec_helper"
2020-03-28 16:50:58 +00:00
class Phonebook
def find(name)
# Some expensive lookup call.
"+18005554321"
end
end
class Resolver
def initialize(@phonebook : Phonebook)
end
def find(name)
@phonebook.find(name)
end
end
Spectator.describe Resolver do
mock Phonebook do
stub find(name)
end
describe "#find" do
it "can find number" do
pb = Phonebook.new
allow(pb).to receive(find).and_return("+18005551234")
resolver = Resolver.new(pb)
expect(resolver.find("Bob")).to eq("+18005551234")
end
end
end