mirror of
https://gitea.invidious.io/iv-org/shard-spectator.git
synced 2024-08-15 00:53:35 +00:00
Add example usage of double
This commit is contained in:
parent
5ad1277bdd
commit
ce4fefaab2
1 changed files with 24 additions and 1 deletions
25
README.md
25
README.md
|
@ -239,7 +239,7 @@ Spectator supports multiple options for running tests.
|
||||||
Tests can be filtered by their location and name.
|
Tests can be filtered by their location and name.
|
||||||
Additionally, tests can be randomized.
|
Additionally, tests can be randomized.
|
||||||
Spectator can be configured with command-line arguments,
|
Spectator can be configured with command-line arguments,
|
||||||
a config block in a `spec_helper.cr` file, and `.spectator` config file.
|
a configure block in a `spec_helper.cr` file, and `.spectator` configuration file.
|
||||||
|
|
||||||
```crystal
|
```crystal
|
||||||
Spectator.configure do |config|
|
Spectator.configure do |config|
|
||||||
|
@ -249,6 +249,29 @@ Spectator.configure do |config|
|
||||||
end
|
end
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### Mocks and Doubles
|
||||||
|
|
||||||
|
Spectator supports an extensive mocking feature set via two types - mocks and doubles.
|
||||||
|
Mocks are used to override behavior in existing types.
|
||||||
|
Doubles are objects that stand-in when there are no type restrictions.
|
||||||
|
Stubs can be defined on both that control how methods behave.
|
||||||
|
|
||||||
|
```crystal
|
||||||
|
double :my_double do
|
||||||
|
stub foo : Int32
|
||||||
|
stub bar(arg) { arg.to_s }
|
||||||
|
end
|
||||||
|
|
||||||
|
it "does a thing" do
|
||||||
|
dbl = double(:my_double)
|
||||||
|
allow(dbl).to receive(:foo).and_return(42)
|
||||||
|
expect(dbl.foo).to eq(42)
|
||||||
|
expect(dbl.bar(42)).to eq("42")
|
||||||
|
end
|
||||||
|
```
|
||||||
|
|
||||||
|
For details on mocks and doubles, see the [wiki](https://gitlab.com/arctic-fox/spectator/-/wikis/Mocks-and-Doubles).
|
||||||
|
|
||||||
### Output
|
### Output
|
||||||
|
|
||||||
Spectator matches Crystal's default Spec output with some minor changes.
|
Spectator matches Crystal's default Spec output with some minor changes.
|
||||||
|
|
Loading…
Reference in a new issue