mirror of
https://gitea.invidious.io/iv-org/shard-spectator.git
synced 2024-08-15 00:53:35 +00:00
Show new mock and double system in README
This commit is contained in:
parent
754bfd6939
commit
e52f187eb7
2 changed files with 64 additions and 9 deletions
34
spec/docs/readme_spec.cr
Normal file
34
spec/docs/readme_spec.cr
Normal file
|
@ -0,0 +1,34 @@
|
|||
require "../spec_helper"
|
||||
|
||||
private abstract class Interface
|
||||
abstract def invoke(thing) : String
|
||||
end
|
||||
|
||||
# Type being tested.
|
||||
private class Driver
|
||||
def do_something(interface : Interface, thing)
|
||||
interface.invoke(thing)
|
||||
end
|
||||
end
|
||||
|
||||
Spectator.describe Driver do
|
||||
# Define a mock for Interface.
|
||||
mock Interface
|
||||
|
||||
# Define a double that the interface will use.
|
||||
double(:my_double, foo: 42)
|
||||
|
||||
it "does a thing" do
|
||||
# Create an instance of the mock interface.
|
||||
interface = mock(Interface)
|
||||
# Indicate that `#invoke` should return "test" when called.
|
||||
allow(interface).to receive(:invoke).and_return("test")
|
||||
|
||||
# Create an instance of the double.
|
||||
dbl = double(:my_double)
|
||||
# Call the mock method.
|
||||
subject.do_something(interface, dbl)
|
||||
# Verify everything went okay.
|
||||
expect(interface).to have_received(:invoke).with(dbl)
|
||||
end
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue