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
40
spec/docs/mocks/overview_spec.cr
Normal file
40
spec/docs/mocks/overview_spec.cr
Normal file
|
@ -0,0 +1,40 @@
|
|||
require "../../spec_helper"
|
||||
|
||||
Spectator.describe "Doubles" do
|
||||
double :my_double do
|
||||
stub answer { 42 }
|
||||
end
|
||||
|
||||
specify "the answer to everything" do
|
||||
dbl = double(:my_double)
|
||||
expect(dbl.answer).to eq(42)
|
||||
end
|
||||
end
|
||||
|
||||
class MyType
|
||||
def answer
|
||||
123
|
||||
end
|
||||
end
|
||||
|
||||
Spectator.describe "Mocks" do
|
||||
mock MyType do
|
||||
stub answer { 42 }
|
||||
end
|
||||
|
||||
specify "the answer to everything" do
|
||||
m = MyType.new
|
||||
expect(m.answer).to eq(42)
|
||||
end
|
||||
end
|
||||
Spectator.describe "Mocks and doubles" do
|
||||
double :my_double do
|
||||
stub answer : Int32 # Return type required, otherwise nil is assumed.
|
||||
end
|
||||
|
||||
specify "the answer to everything" do
|
||||
dbl = double(:my_double)
|
||||
allow(dbl).to receive(:answer).and_return(42)
|
||||
expect(dbl.answer).to eq(42)
|
||||
end
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue