mirror of
https://gitea.invidious.io/iv-org/shard-spectator.git
synced 2024-08-15 00:53:35 +00:00
Allow creation of doubles without a definition
Utilizes anonymous doubles to implement this. Fixes https://github.com/icy-arctic-fox/spectator/issues/30
This commit is contained in:
parent
d4e2954725
commit
a0537484f4
3 changed files with 32 additions and 14 deletions
|
@ -7,6 +7,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||
## [Unreleased]
|
||||
### Added
|
||||
- Added support for `with(no_args)` for method stubs. [#28](https://github.com/icy-arctic-fox/spectator/issues/28)
|
||||
- Allow creation of doubles without definition block. [#30](https://github.com/icy-arctic-fox/spectator/issues/30)
|
||||
|
||||
## [0.9.38] - 2021-05-27
|
||||
### Fixed
|
||||
|
|
9
spec/issues/github_issue_30_spec.cr
Normal file
9
spec/issues/github_issue_30_spec.cr
Normal file
|
@ -0,0 +1,9 @@
|
|||
require "../spec_helper"
|
||||
|
||||
Spectator.describe "GitHub Issue #30" do
|
||||
let(dbl) { double(:foo) }
|
||||
|
||||
it "supports block-less symbol doubles" do
|
||||
expect(dbl).to_not be_nil
|
||||
end
|
||||
end
|
|
@ -19,13 +19,17 @@ module Spectator::DSL
|
|||
end
|
||||
|
||||
macro create_double(type_name, name, **stubs)
|
||||
{% type_name.resolve? || raise("Could not find a double labeled #{name}") %}
|
||||
|
||||
{% if type_name.resolve? %}
|
||||
{{type_name}}.new.tap do |%double|
|
||||
{% for name, value in stubs %}
|
||||
allow(%double).to receive({{name.id}}).and_return({{value}})
|
||||
{% end %}
|
||||
end
|
||||
{% elsif @def %}
|
||||
anonymous_double({{name ? name.stringify : "Anonymous"}}, {{stubs.double_splat}})
|
||||
{% else %}
|
||||
{% raise "Block required for double definition" %}
|
||||
{% end %}
|
||||
end
|
||||
|
||||
macro define_double(type_name, name, **stubs, &block)
|
||||
|
@ -73,13 +77,17 @@ module Spectator::DSL
|
|||
end
|
||||
|
||||
macro create_null_double(type_name, name, **stubs)
|
||||
{% type_name.resolve? || raise("Could not find a double labeled #{name}") %}
|
||||
|
||||
{% if type_name.resolve? %}
|
||||
{{type_name}}.new(true).tap do |%double|
|
||||
{% for name, value in stubs %}
|
||||
allow(%double).to receive({{name.id}}).and_return({{value}})
|
||||
{% end %}
|
||||
end
|
||||
{% elsif @def %}
|
||||
anonymous_null_double({{name ? name.stringify : "Anonymous"}}, {{stubs.double_splat}})
|
||||
{% else %}
|
||||
{% raise "Block required for double definition" %}
|
||||
{% end %}
|
||||
end
|
||||
|
||||
macro define_null_double(type_name, name, **stubs, &block)
|
||||
|
|
Loading…
Reference in a new issue