mirror of
https://gitea.invidious.io/iv-org/shard-spectator.git
synced 2024-08-15 00:53:35 +00:00
Add no_args
This commit is contained in:
parent
b9eaefb424
commit
32a9bfd356
8 changed files with 29 additions and 11 deletions
|
@ -93,4 +93,14 @@ Spectator.describe "Stub DSL", :smoke do
|
|||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "#no_args" do
|
||||
it "defines a stub with a no arguments constraint" do
|
||||
allow(dbl).to receive(:foo).with(no_args).and_return(5)
|
||||
aggregate_failures do
|
||||
expect(dbl.foo).to eq(5)
|
||||
expect(dbl.foo(0)).to eq(42)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -432,5 +432,10 @@ module Spectator::DSL
|
|||
::Spectator::NullStub.new({{method.id.symbolize}}, location: ::Spectator::Location.new({{_file}}, {{_line}}))
|
||||
{% end %}
|
||||
end
|
||||
|
||||
# Returns empty arguments.
|
||||
def no_args
|
||||
::Spectator::Arguments.empty
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -12,8 +12,7 @@ module Spectator
|
|||
end
|
||||
|
||||
# Returns a new stub with constrained arguments.
|
||||
def with(*args, **kwargs)
|
||||
constraint = Arguments.new(args, kwargs)
|
||||
def with(constraint : AbstractArguments)
|
||||
self.class.new(method, @exception, constraint, location)
|
||||
end
|
||||
|
||||
|
|
|
@ -16,8 +16,7 @@ module Spectator
|
|||
end
|
||||
|
||||
# Returns a new stub with constrained arguments.
|
||||
def with(*args, **kwargs)
|
||||
constraint = Arguments.new(args, kwargs)
|
||||
def with(constraint : AbstractArguments)
|
||||
self.class.new(method, @values, constraint, location)
|
||||
end
|
||||
|
||||
|
|
|
@ -9,8 +9,7 @@ module Spectator
|
|||
end
|
||||
|
||||
# Returns a new stub with constrained arguments.
|
||||
def with(*args, **kwargs)
|
||||
constraint = Arguments.new(args, kwargs)
|
||||
def with(constraint : AbstractArguments)
|
||||
self.class.new(method, constraint, location)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -11,8 +11,7 @@ module Spectator
|
|||
end
|
||||
|
||||
# Returns a new stub with constrained arguments.
|
||||
def with(*args, **kwargs)
|
||||
constraint = Arguments.new(args, kwargs)
|
||||
def with(constraint : AbstractArguments)
|
||||
self.class.new(method, @proc, constraint, location)
|
||||
end
|
||||
|
||||
|
|
|
@ -1,7 +1,15 @@
|
|||
require "./arguments"
|
||||
|
||||
module Spectator
|
||||
# Mixin intended for `Stub` to return new, modified stubs.
|
||||
module StubModifiers
|
||||
# Returns a new stub of the same type with constrained arguments.
|
||||
abstract def with(*args, **kwargs)
|
||||
abstract def with(constraint : AbstractArguments)
|
||||
|
||||
# :ditto:
|
||||
def with(*args, **kwargs)
|
||||
constraint = Arguments.new(args, kwargs)
|
||||
self.with(constraint)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -12,8 +12,7 @@ module Spectator
|
|||
end
|
||||
|
||||
# Returns a new stub with constrained arguments.
|
||||
def with(*args, **kwargs)
|
||||
constraint = Arguments.new(args, kwargs)
|
||||
def with(constraint : AbstractArguments)
|
||||
self.class.new(method, @value, constraint, location)
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in a new issue