mirror of
https://gitea.invidious.io/iv-org/shard-spectator.git
synced 2024-08-15 00:53:35 +00:00
Add specs of snippets from docs
This commit is contained in:
parent
0322d5bd28
commit
5c24d606dd
7 changed files with 382 additions and 0 deletions
30
spec/docs/mocks/mocks_spec.cr
Normal file
30
spec/docs/mocks/mocks_spec.cr
Normal file
|
@ -0,0 +1,30 @@
|
|||
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
|
Loading…
Add table
Add a link
Reference in a new issue