mirror of
https://gitea.invidious.io/iv-org/shard-spectator.git
synced 2024-08-15 00:53:35 +00:00
Document and test MethodCall
This commit is contained in:
parent
13f185b801
commit
ced98778a4
2 changed files with 31 additions and 0 deletions
26
spec/spectator/mocks/method_call_spec.cr
Normal file
26
spec/spectator/mocks/method_call_spec.cr
Normal file
|
@ -0,0 +1,26 @@
|
||||||
|
require "../../spec_helper"
|
||||||
|
|
||||||
|
Spectator.describe Spectator::MethodCall do
|
||||||
|
let(arguments) { Spectator::Arguments.capture(42, "foobar", foo: :bar) }
|
||||||
|
subject(call) { Spectator::MethodCall.new(:foo, arguments) }
|
||||||
|
|
||||||
|
it "stores the method name" do
|
||||||
|
expect(&.method).to eq(:foo)
|
||||||
|
end
|
||||||
|
|
||||||
|
it "stores arguments" do
|
||||||
|
expect(&.arguments).to eq(arguments)
|
||||||
|
end
|
||||||
|
|
||||||
|
describe ".capture" do
|
||||||
|
subject(call) { Spectator::MethodCall.capture(:foo, 42, "foobar", foo: :bar) }
|
||||||
|
|
||||||
|
it "stores the method name" do
|
||||||
|
expect(&.method).to eq(:foo)
|
||||||
|
end
|
||||||
|
|
||||||
|
it "stores arguments" do
|
||||||
|
expect(&.arguments).to eq(arguments)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -2,14 +2,19 @@ require "./abstract_arguments"
|
||||||
require "./arguments"
|
require "./arguments"
|
||||||
|
|
||||||
module Spectator
|
module Spectator
|
||||||
|
# Stores information about a call to a method.
|
||||||
class MethodCall
|
class MethodCall
|
||||||
|
# Name of the method.
|
||||||
getter method : Symbol
|
getter method : Symbol
|
||||||
|
|
||||||
|
# Arguments passed to the method.
|
||||||
getter arguments : AbstractArguments
|
getter arguments : AbstractArguments
|
||||||
|
|
||||||
|
# Creates a method call.
|
||||||
def initialize(@method : Symbol, @arguments : Arguments = Arguments.empty)
|
def initialize(@method : Symbol, @arguments : Arguments = Arguments.empty)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Creates a method call by splatting its arguments.
|
||||||
def self.capture(method : Symbol, *args, **kwargs)
|
def self.capture(method : Symbol, *args, **kwargs)
|
||||||
arguments = Arguments.new(args, kwargs)
|
arguments = Arguments.new(args, kwargs)
|
||||||
new(method, arguments)
|
new(method, arguments)
|
||||||
|
|
Loading…
Reference in a new issue