mirror of
https://gitea.invidious.io/iv-org/shard-spectator.git
synced 2024-08-15 00:53:35 +00:00
Add support for any_args in DSL
This commit is contained in:
parent
4aaa8db5e2
commit
3d7655a5d1
9 changed files with 32 additions and 12 deletions
|
@ -103,4 +103,14 @@ Spectator.describe "Stub DSL", :smoke do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe "#any_args" do
|
||||||
|
it "defines a stub with no arguments constraint" do
|
||||||
|
allow(dbl).to receive(:foo).with(any_args).and_return(5)
|
||||||
|
aggregate_failures do
|
||||||
|
expect(dbl.foo).to eq(5)
|
||||||
|
expect(dbl.foo(0)).to eq(5)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -437,5 +437,10 @@ module Spectator::DSL
|
||||||
def no_args
|
def no_args
|
||||||
::Spectator::Arguments.none
|
::Spectator::Arguments.none
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Indicates any arguments can be used (no constraint).
|
||||||
|
def any_args
|
||||||
|
::Spectator::Arguments.any
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -25,6 +25,11 @@ module Spectator
|
||||||
# Instance of empty arguments.
|
# Instance of empty arguments.
|
||||||
class_getter none : AbstractArguments = capture
|
class_getter none : AbstractArguments = capture
|
||||||
|
|
||||||
|
# Returns unconstrained arguments.
|
||||||
|
def self.any : AbstractArguments?
|
||||||
|
nil.as(AbstractArguments?)
|
||||||
|
end
|
||||||
|
|
||||||
# Returns the positional argument at the specified index.
|
# Returns the positional argument at the specified index.
|
||||||
def [](index : Int)
|
def [](index : Int)
|
||||||
@args[index]
|
@args[index]
|
||||||
|
|
|
@ -12,7 +12,7 @@ module Spectator
|
||||||
end
|
end
|
||||||
|
|
||||||
# Returns a new stub with constrained arguments.
|
# Returns a new stub with constrained arguments.
|
||||||
def with_constraint(constraint : AbstractArguments)
|
def with_constraint(constraint : AbstractArguments?)
|
||||||
self.class.new(method, @exception, constraint, location)
|
self.class.new(method, @exception, constraint, location)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -16,7 +16,7 @@ module Spectator
|
||||||
end
|
end
|
||||||
|
|
||||||
# Returns a new stub with constrained arguments.
|
# Returns a new stub with constrained arguments.
|
||||||
def with_constraint(constraint : AbstractArguments)
|
def with_constraint(constraint : AbstractArguments?)
|
||||||
self.class.new(method, @values, constraint, location)
|
self.class.new(method, @values, constraint, location)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -9,7 +9,7 @@ module Spectator
|
||||||
end
|
end
|
||||||
|
|
||||||
# Returns a new stub with constrained arguments.
|
# Returns a new stub with constrained arguments.
|
||||||
def with_constraint(constraint : AbstractArguments)
|
def with_constraint(constraint : AbstractArguments?)
|
||||||
self.class.new(method, constraint, location)
|
self.class.new(method, constraint, location)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -11,7 +11,7 @@ module Spectator
|
||||||
end
|
end
|
||||||
|
|
||||||
# Returns a new stub with constrained arguments.
|
# Returns a new stub with constrained arguments.
|
||||||
def with_constraint(constraint : AbstractArguments)
|
def with_constraint(constraint : AbstractArguments?)
|
||||||
self.class.new(method, @proc, constraint, location)
|
self.class.new(method, @proc, constraint, location)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -4,18 +4,18 @@ module Spectator
|
||||||
# Mixin intended for `Stub` to return new, modified stubs.
|
# Mixin intended for `Stub` to return new, modified stubs.
|
||||||
module StubModifiers
|
module StubModifiers
|
||||||
# Returns a new stub of the same type with constrained arguments.
|
# Returns a new stub of the same type with constrained arguments.
|
||||||
abstract def with_constraint(constraint : AbstractArguments)
|
abstract def with_constraint(constraint : AbstractArguments?)
|
||||||
|
|
||||||
|
# :ditto:
|
||||||
|
@[AlwaysInline]
|
||||||
|
def with(constraint : AbstractArguments?)
|
||||||
|
with_constraint(constraint)
|
||||||
|
end
|
||||||
|
|
||||||
# :ditto:
|
# :ditto:
|
||||||
def with(*args, **kwargs)
|
def with(*args, **kwargs)
|
||||||
constraint = Arguments.new(args, kwargs).as(AbstractArguments)
|
constraint = Arguments.new(args, kwargs).as(AbstractArguments)
|
||||||
self.with_constraint(constraint)
|
self.with_constraint(constraint)
|
||||||
end
|
end
|
||||||
|
|
||||||
# :ditto:
|
|
||||||
@[AlwaysInline]
|
|
||||||
def with(constraint : AbstractArguments)
|
|
||||||
with_constraint(constraint)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -12,7 +12,7 @@ module Spectator
|
||||||
end
|
end
|
||||||
|
|
||||||
# Returns a new stub with constrained arguments.
|
# Returns a new stub with constrained arguments.
|
||||||
def with_constraint(constraint : AbstractArguments)
|
def with_constraint(constraint : AbstractArguments?)
|
||||||
self.class.new(method, @value, constraint, location)
|
self.class.new(method, @value, constraint, location)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue