2022-04-11 02:01:54 +00:00
|
|
|
require "../../spec_helper"
|
|
|
|
|
|
|
|
Spectator.describe Spectator::Mock do
|
2022-05-15 21:56:32 +00:00
|
|
|
let(stub1) { Spectator::ValueStub.new(:method1, 777) }
|
|
|
|
let(stub2) { Spectator::ValueStub.new(:method2, :override) }
|
|
|
|
let(stub3) { Spectator::ValueStub.new(:method3, "stubbed") }
|
|
|
|
|
2022-05-19 02:56:04 +00:00
|
|
|
describe "#define_subtype" do
|
2022-05-25 01:25:22 +00:00
|
|
|
context "with a concrete class" do
|
|
|
|
class Thing
|
2022-05-28 15:18:03 +00:00
|
|
|
getter _spectator_calls = [] of Symbol
|
|
|
|
|
2022-05-25 01:25:22 +00:00
|
|
|
def method1
|
2022-05-28 15:18:03 +00:00
|
|
|
@_spectator_calls << :method1
|
2022-05-25 01:25:22 +00:00
|
|
|
42
|
|
|
|
end
|
|
|
|
|
|
|
|
def method2
|
2022-05-28 15:18:03 +00:00
|
|
|
@_spectator_calls << :method2
|
2022-05-25 01:25:22 +00:00
|
|
|
:original
|
|
|
|
end
|
|
|
|
|
|
|
|
def method3
|
2022-05-28 15:18:03 +00:00
|
|
|
@_spectator_calls << :method3
|
2022-05-25 01:25:22 +00:00
|
|
|
"original"
|
|
|
|
end
|
2022-05-15 16:59:44 +00:00
|
|
|
end
|
2022-04-11 02:01:54 +00:00
|
|
|
|
2022-05-25 01:25:22 +00:00
|
|
|
Spectator::Mock.define_subtype(:class, Thing, MockThing, :mock_name, method1: 123) do
|
|
|
|
stub def method2
|
|
|
|
:stubbed
|
|
|
|
end
|
2022-05-15 16:59:44 +00:00
|
|
|
end
|
2022-04-11 02:01:54 +00:00
|
|
|
|
2022-05-25 01:25:22 +00:00
|
|
|
let(mock) { MockThing.new }
|
|
|
|
|
|
|
|
it "defines a subclass of the mocked type" do
|
2022-05-26 00:00:05 +00:00
|
|
|
expect(mock).to be_a(Thing)
|
2022-05-25 01:29:42 +00:00
|
|
|
end
|
|
|
|
|
2022-05-25 01:25:22 +00:00
|
|
|
it "overrides responses from methods with keyword arguments" do
|
|
|
|
expect(mock.method1).to eq(123)
|
2022-05-15 16:59:44 +00:00
|
|
|
end
|
2022-04-11 02:01:54 +00:00
|
|
|
|
2022-05-25 01:25:22 +00:00
|
|
|
it "overrides responses from methods defined in the block" do
|
|
|
|
expect(mock.method2).to eq(:stubbed)
|
|
|
|
end
|
2022-04-11 02:01:54 +00:00
|
|
|
|
2022-05-25 01:25:22 +00:00
|
|
|
it "allows methods to be stubbed" do
|
|
|
|
aggregate_failures do
|
|
|
|
expect { mock._spectator_define_stub(stub1) }.to change { mock.method1 }.to(777)
|
|
|
|
expect { mock._spectator_define_stub(stub2) }.to change { mock.method2 }.to(:override)
|
|
|
|
expect { mock._spectator_define_stub(stub3) }.to change { mock.method3 }.from("original").to("stubbed")
|
|
|
|
end
|
|
|
|
end
|
2022-04-11 02:01:54 +00:00
|
|
|
|
2022-05-25 01:25:22 +00:00
|
|
|
it "can clear stubs" do
|
|
|
|
mock._spectator_define_stub(stub1)
|
|
|
|
mock._spectator_define_stub(stub2)
|
|
|
|
mock._spectator_define_stub(stub3)
|
2022-04-11 02:01:54 +00:00
|
|
|
|
2022-05-25 01:25:22 +00:00
|
|
|
mock._spectator_clear_stubs
|
|
|
|
aggregate_failures do
|
|
|
|
expect(mock.method1).to eq(123)
|
|
|
|
expect(mock.method2).to eq(:stubbed)
|
|
|
|
expect(mock.method3).to eq("original")
|
|
|
|
end
|
|
|
|
end
|
2022-04-30 17:40:54 +00:00
|
|
|
|
2022-05-25 01:25:22 +00:00
|
|
|
it "sets the mock name" do
|
|
|
|
args = Spectator::Arguments.capture("foo")
|
|
|
|
stub = Spectator::ValueStub.new(:method3, 0, args)
|
|
|
|
mock._spectator_define_stub(stub)
|
|
|
|
expect { mock.method3 }.to raise_error(Spectator::UnexpectedMessage, /mock_name/), "Raised error doesn't contain the mocked name."
|
2022-05-15 16:59:44 +00:00
|
|
|
end
|
2022-05-28 15:18:03 +00:00
|
|
|
|
|
|
|
def restricted(thing : Thing)
|
|
|
|
thing.method1
|
|
|
|
end
|
|
|
|
|
|
|
|
it "can be used in type restricted methods" do
|
|
|
|
expect(restricted(mock)).to eq(123)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "does not call the original method when stubbed" do
|
|
|
|
mock.method1
|
|
|
|
mock.method2
|
|
|
|
mock.method3
|
|
|
|
expect(mock._spectator_calls).to contain_exactly(:method3)
|
|
|
|
end
|
2022-05-15 16:59:44 +00:00
|
|
|
end
|
2022-05-15 21:56:32 +00:00
|
|
|
|
2022-05-25 01:25:22 +00:00
|
|
|
context "with an abstract class" do
|
|
|
|
abstract class Thing
|
2022-05-28 15:18:03 +00:00
|
|
|
getter _spectator_calls = [] of Symbol
|
|
|
|
|
2022-05-25 01:25:22 +00:00
|
|
|
abstract def method1
|
|
|
|
|
|
|
|
abstract def method2 : Symbol
|
|
|
|
|
|
|
|
def method3
|
2022-05-28 15:18:03 +00:00
|
|
|
@_spectator_calls << :method3
|
2022-05-25 01:25:22 +00:00
|
|
|
"original"
|
|
|
|
end
|
|
|
|
|
|
|
|
abstract def method4
|
|
|
|
end
|
2022-05-15 21:56:32 +00:00
|
|
|
|
2022-05-25 01:25:22 +00:00
|
|
|
Spectator::Mock.define_subtype(:class, Thing, MockThing, :mock_name, method2: :stubbed) do
|
|
|
|
stub def method1 : Int32 # NOTE: Return type is required since one wasn't provided in the parent.
|
|
|
|
123
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
let(mock) { MockThing.new }
|
|
|
|
|
|
|
|
it "defines a subclass of the mocked type" do
|
2022-05-26 00:00:05 +00:00
|
|
|
expect(mock).to be_a(Thing)
|
2022-05-25 01:29:42 +00:00
|
|
|
end
|
|
|
|
|
2022-05-25 01:25:22 +00:00
|
|
|
it "overrides responses from methods defined in the block" do
|
2022-05-15 21:56:32 +00:00
|
|
|
expect(mock.method1).to eq(123)
|
2022-05-25 01:25:22 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it "overrides responses from methods with keyword arguments" do
|
2022-05-15 21:56:32 +00:00
|
|
|
expect(mock.method2).to eq(:stubbed)
|
|
|
|
end
|
2022-05-15 21:59:08 +00:00
|
|
|
|
2022-05-25 01:30:42 +00:00
|
|
|
it "allows methods to be stubbed" do
|
|
|
|
aggregate_failures do
|
|
|
|
expect { mock._spectator_define_stub(stub1) }.to change { mock.method1 }.to(777)
|
|
|
|
expect { mock._spectator_define_stub(stub2) }.to change { mock.method2 }.to(:override)
|
|
|
|
expect { mock._spectator_define_stub(stub3) }.to change { mock.method3 }.from("original").to("stubbed")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
it "can clear stubs" do
|
|
|
|
mock._spectator_define_stub(stub1)
|
|
|
|
mock._spectator_define_stub(stub2)
|
|
|
|
mock._spectator_define_stub(stub3)
|
|
|
|
|
|
|
|
mock._spectator_clear_stubs
|
|
|
|
aggregate_failures do
|
|
|
|
expect(mock.method1).to eq(123)
|
|
|
|
expect(mock.method2).to eq(:stubbed)
|
|
|
|
expect(mock.method3).to eq("original")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
it "raises when calling an abstract method that isn't stubbed" do
|
|
|
|
expect { mock.method4 }.to raise_error(Spectator::UnexpectedMessage, /method4/)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "sets the mock name" do
|
|
|
|
args = Spectator::Arguments.capture("foo")
|
|
|
|
stub = Spectator::ValueStub.new(:method3, 0, args)
|
|
|
|
mock._spectator_define_stub(stub)
|
|
|
|
expect { mock.method3 }.to raise_error(Spectator::UnexpectedMessage, /mock_name/), "Raised error doesn't contain the mocked name."
|
|
|
|
end
|
2022-05-28 15:18:03 +00:00
|
|
|
|
|
|
|
def restricted(thing : Thing)
|
|
|
|
thing.method1
|
|
|
|
end
|
|
|
|
|
|
|
|
it "can be used in type restricted methods" do
|
|
|
|
expect(restricted(mock)).to eq(123)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "does not call the original method when stubbed" do
|
|
|
|
mock.method1
|
|
|
|
mock.method2
|
|
|
|
mock.method3
|
|
|
|
expect(mock._spectator_calls).to contain_exactly(:method3)
|
|
|
|
end
|
2022-05-25 01:30:42 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
context "with an abstract struct" do
|
|
|
|
abstract struct Thing
|
2022-05-28 15:18:03 +00:00
|
|
|
getter _spectator_calls = [] of Symbol
|
|
|
|
|
2022-05-25 01:30:42 +00:00
|
|
|
abstract def method1
|
|
|
|
|
|
|
|
abstract def method2 : Symbol
|
|
|
|
|
|
|
|
def method3
|
2022-05-28 15:18:03 +00:00
|
|
|
@_spectator_calls << :method3
|
2022-05-25 01:30:42 +00:00
|
|
|
"original"
|
|
|
|
end
|
|
|
|
|
|
|
|
abstract def method4
|
|
|
|
end
|
|
|
|
|
|
|
|
Spectator::Mock.define_subtype(:struct, Thing, MockThing, :mock_name, method2: :stubbed) do
|
|
|
|
stub def method1 : Int32 # NOTE: Return type is required since one wasn't provided in the parent.
|
|
|
|
123
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
let(mock) { MockThing.new }
|
|
|
|
|
|
|
|
it "defines a sub-type of the mocked type" do
|
2022-05-28 03:45:01 +00:00
|
|
|
expect(mock).to be_a(Thing)
|
2022-05-25 01:30:42 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it "overrides responses from methods defined in the block" do
|
|
|
|
expect(mock.method1).to eq(123)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "overrides responses from methods with keyword arguments" do
|
|
|
|
expect(mock.method2).to eq(:stubbed)
|
|
|
|
end
|
|
|
|
|
2022-05-25 01:25:22 +00:00
|
|
|
it "allows methods to be stubbed" do
|
2022-05-25 01:41:16 +00:00
|
|
|
mock = self.mock # FIXME: Workaround for passing by value messing with stubs.
|
2022-05-25 01:25:22 +00:00
|
|
|
aggregate_failures do
|
|
|
|
expect { mock._spectator_define_stub(stub1) }.to change { mock.method1 }.to(777)
|
|
|
|
expect { mock._spectator_define_stub(stub2) }.to change { mock.method2 }.to(:override)
|
|
|
|
expect { mock._spectator_define_stub(stub3) }.to change { mock.method3 }.from("original").to("stubbed")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
it "can clear stubs" do
|
|
|
|
mock._spectator_define_stub(stub1)
|
|
|
|
mock._spectator_define_stub(stub2)
|
|
|
|
mock._spectator_define_stub(stub3)
|
|
|
|
|
|
|
|
mock._spectator_clear_stubs
|
|
|
|
aggregate_failures do
|
|
|
|
expect(mock.method1).to eq(123)
|
|
|
|
expect(mock.method2).to eq(:stubbed)
|
|
|
|
expect(mock.method3).to eq("original")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
it "raises when calling an abstract method that isn't stubbed" do
|
|
|
|
expect { mock.method4 }.to raise_error(Spectator::UnexpectedMessage, /method4/)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "sets the mock name" do
|
2022-05-25 01:41:16 +00:00
|
|
|
mock = self.mock # FIXME: Workaround for passing by value messing with stubs.
|
2022-05-25 01:25:22 +00:00
|
|
|
args = Spectator::Arguments.capture("foo")
|
|
|
|
stub = Spectator::ValueStub.new(:method3, 0, args)
|
|
|
|
mock._spectator_define_stub(stub)
|
|
|
|
expect { mock.method3 }.to raise_error(Spectator::UnexpectedMessage, /mock_name/), "Raised error doesn't contain the mocked name."
|
|
|
|
end
|
2022-05-28 15:18:03 +00:00
|
|
|
|
|
|
|
def restricted(thing : Thing)
|
|
|
|
thing.method1
|
|
|
|
end
|
|
|
|
|
|
|
|
it "can be used in type restricted methods" do
|
|
|
|
expect(restricted(mock)).to eq(123)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "does not call the original method when stubbed" do
|
|
|
|
mock = self.mock # FIXME: Workaround for passing by value messing with stubs.
|
|
|
|
mock.method1
|
|
|
|
mock.method2
|
|
|
|
mock.method3
|
|
|
|
expect(mock._spectator_calls).to contain_exactly(:method3)
|
|
|
|
end
|
2022-05-15 21:59:08 +00:00
|
|
|
end
|
2022-05-15 16:59:44 +00:00
|
|
|
end
|
2022-04-30 17:40:54 +00:00
|
|
|
|
|
|
|
describe "#inject" do
|
|
|
|
context "with a class" do
|
2022-05-19 02:56:04 +00:00
|
|
|
class MockedClass
|
2022-05-28 15:18:03 +00:00
|
|
|
getter _spectator_calls = [] of Symbol
|
|
|
|
|
|
|
|
getter method1 do
|
|
|
|
@_spectator_calls << :method1
|
|
|
|
42
|
|
|
|
end
|
2022-05-19 02:56:04 +00:00
|
|
|
|
|
|
|
def method2
|
2022-05-28 15:18:03 +00:00
|
|
|
@_spectator_calls << :method2
|
2022-05-19 02:56:04 +00:00
|
|
|
:original
|
|
|
|
end
|
|
|
|
|
|
|
|
def method3
|
2022-05-28 15:18:03 +00:00
|
|
|
@_spectator_calls << :method3
|
2022-05-19 02:56:04 +00:00
|
|
|
"original"
|
|
|
|
end
|
|
|
|
|
|
|
|
def instance_variables
|
2022-05-28 15:18:03 +00:00
|
|
|
{% begin %}[{{@type.instance_vars.map(&.name.symbolize).splat}}]{% end %}
|
2022-05-19 02:56:04 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
Spectator::Mock.inject(:class, MockedClass, :mock_name, method1: 123) do
|
2022-04-30 17:40:54 +00:00
|
|
|
stub def method2
|
|
|
|
:stubbed
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2022-05-15 17:27:58 +00:00
|
|
|
let(mock) { MockedClass.new }
|
2022-04-30 17:40:54 +00:00
|
|
|
|
2022-05-15 21:56:32 +00:00
|
|
|
# Necessary to clear stubs to prevent leakages between tests.
|
|
|
|
after_each { mock._spectator_clear_stubs }
|
|
|
|
|
2022-04-30 17:40:54 +00:00
|
|
|
it "overrides responses from methods with keyword arguments" do
|
2022-05-15 17:27:58 +00:00
|
|
|
expect(mock.method1).to eq(123)
|
2022-04-30 17:40:54 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it "overrides responses from methods defined in the block" do
|
2022-05-15 17:27:58 +00:00
|
|
|
expect(mock.method2).to eq(:stubbed)
|
2022-04-30 17:40:54 +00:00
|
|
|
end
|
2022-04-11 02:01:54 +00:00
|
|
|
|
2022-04-30 17:40:54 +00:00
|
|
|
it "allows methods to be stubbed" do
|
|
|
|
aggregate_failures do
|
2022-05-15 17:27:58 +00:00
|
|
|
expect { mock._spectator_define_stub(stub1) }.to change { mock.method1 }.to(777)
|
|
|
|
expect { mock._spectator_define_stub(stub2) }.to change { mock.method2 }.to(:override)
|
|
|
|
expect { mock._spectator_define_stub(stub3) }.to change { mock.method3 }.from("original").to("stubbed")
|
2022-04-30 17:40:54 +00:00
|
|
|
end
|
2022-04-29 04:32:34 +00:00
|
|
|
end
|
2022-05-15 17:27:58 +00:00
|
|
|
|
2022-05-15 21:56:32 +00:00
|
|
|
it "can clear stubs" do
|
|
|
|
mock._spectator_define_stub(stub1)
|
|
|
|
mock._spectator_define_stub(stub2)
|
|
|
|
mock._spectator_define_stub(stub3)
|
|
|
|
|
|
|
|
mock._spectator_clear_stubs
|
|
|
|
aggregate_failures do
|
|
|
|
expect(mock.method1).to eq(123)
|
|
|
|
expect(mock.method2).to eq(:stubbed)
|
|
|
|
expect(mock.method3).to eq("original")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2022-05-15 17:27:58 +00:00
|
|
|
it "doesn't change the size of an instance" do
|
2022-05-28 15:18:03 +00:00
|
|
|
size = sizeof(Int64) + sizeof(Int32?) + sizeof(Array(Symbol)) # TypeID + Int32? + _spectator_calls
|
|
|
|
expect(instance_sizeof(MockedClass)).to eq(size)
|
2022-05-15 17:27:58 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it "doesn't affect instance variables" do
|
2022-05-28 15:18:03 +00:00
|
|
|
expect(mock.instance_variables).to contain_exactly(:method1, :_spectator_calls)
|
2022-05-15 17:27:58 +00:00
|
|
|
end
|
2022-05-15 21:59:08 +00:00
|
|
|
|
|
|
|
it "sets the mock name" do
|
|
|
|
args = Spectator::Arguments.capture("foo")
|
|
|
|
stub = Spectator::ValueStub.new(:method3, 0, args)
|
|
|
|
mock._spectator_define_stub(stub)
|
|
|
|
expect { mock.method3 }.to raise_error(Spectator::UnexpectedMessage, /mock_name/), "Raised error doesn't contain the mocked name."
|
|
|
|
end
|
2022-05-28 15:18:03 +00:00
|
|
|
|
|
|
|
def restricted(thing : MockedClass)
|
|
|
|
thing.method1
|
|
|
|
end
|
|
|
|
|
|
|
|
it "can be used in type restricted methods" do
|
|
|
|
expect(restricted(mock)).to eq(123)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "does not call the original method when stubbed" do
|
|
|
|
mock.method1
|
|
|
|
mock.method2
|
|
|
|
mock.method3
|
|
|
|
expect(mock._spectator_calls).to contain_exactly(:method3)
|
|
|
|
end
|
2022-04-11 02:01:54 +00:00
|
|
|
end
|
2022-05-15 18:34:50 +00:00
|
|
|
|
|
|
|
context "with a struct" do
|
2022-05-19 02:56:04 +00:00
|
|
|
struct MockedStruct
|
2022-05-28 15:18:03 +00:00
|
|
|
# Using a class variable instead of an instance variable to prevent mutability problems with stub lookup.
|
|
|
|
class_getter _spectator_calls = [] of Symbol
|
|
|
|
|
|
|
|
@method1 = 42
|
|
|
|
|
|
|
|
def method1
|
|
|
|
@@_spectator_calls << :method1
|
|
|
|
@method1
|
|
|
|
end
|
2022-05-19 02:56:04 +00:00
|
|
|
|
|
|
|
def method2
|
2022-05-28 15:18:03 +00:00
|
|
|
@@_spectator_calls << :method2
|
2022-05-19 02:56:04 +00:00
|
|
|
:original
|
|
|
|
end
|
|
|
|
|
|
|
|
def method3
|
2022-05-28 15:18:03 +00:00
|
|
|
@@_spectator_calls << :method3
|
2022-05-19 02:56:04 +00:00
|
|
|
"original"
|
|
|
|
end
|
|
|
|
|
|
|
|
def instance_variables
|
2022-05-28 15:18:03 +00:00
|
|
|
{% begin %}[{{@type.instance_vars.map(&.name.symbolize).splat}}]{% end %}
|
2022-05-19 02:56:04 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
Spectator::Mock.inject(:struct, MockedStruct, :mock_name, method1: 123) do
|
2022-05-15 18:34:50 +00:00
|
|
|
stub def method2
|
|
|
|
:stubbed
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
let(mock) { MockedStruct.new }
|
|
|
|
|
2022-05-15 21:56:32 +00:00
|
|
|
# Necessary to clear stubs to prevent leakages between tests.
|
|
|
|
after_each { mock._spectator_clear_stubs }
|
2022-05-28 15:18:03 +00:00
|
|
|
after_each { MockedStruct._spectator_calls.clear }
|
2022-05-15 21:56:32 +00:00
|
|
|
|
2022-05-15 18:34:50 +00:00
|
|
|
it "overrides responses from methods with keyword arguments" do
|
|
|
|
expect(mock.method1).to eq(123)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "overrides responses from methods defined in the block" do
|
|
|
|
expect(mock.method2).to eq(:stubbed)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "allows methods to be stubbed" do
|
|
|
|
aggregate_failures do
|
|
|
|
expect { mock._spectator_define_stub(stub1) }.to change { mock.method1 }.to(777)
|
|
|
|
expect { mock._spectator_define_stub(stub2) }.to change { mock.method2 }.to(:override)
|
|
|
|
expect { mock._spectator_define_stub(stub3) }.to change { mock.method3 }.from("original").to("stubbed")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
it "doesn't change the size of an instance" do
|
2022-05-28 15:18:03 +00:00
|
|
|
expect(sizeof(MockedStruct)).to eq(sizeof(Int32))
|
2022-05-15 18:34:50 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it "doesn't affect instance variables" do
|
2022-05-28 15:18:03 +00:00
|
|
|
expect(mock.instance_variables).to contain_exactly(:method1)
|
2022-05-15 18:34:50 +00:00
|
|
|
end
|
2022-05-15 21:59:08 +00:00
|
|
|
|
|
|
|
it "sets the mock name" do
|
|
|
|
args = Spectator::Arguments.capture("foo")
|
|
|
|
stub = Spectator::ValueStub.new(:method3, 0, args)
|
|
|
|
mock._spectator_define_stub(stub)
|
|
|
|
expect { mock.method3 }.to raise_error(Spectator::UnexpectedMessage, /mock_name/), "Raised error doesn't contain the mocked name."
|
|
|
|
end
|
2022-05-28 15:18:03 +00:00
|
|
|
|
|
|
|
def restricted(thing : MockedStruct)
|
|
|
|
thing.method1
|
|
|
|
end
|
|
|
|
|
|
|
|
it "can be used in type restricted methods" do
|
|
|
|
expect(restricted(mock)).to eq(123)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "does not call the original method when stubbed" do
|
|
|
|
mock.method1
|
|
|
|
mock.method2
|
|
|
|
mock.method3
|
|
|
|
expect(MockedStruct._spectator_calls).to contain_exactly(:method3)
|
|
|
|
end
|
2022-05-15 18:34:50 +00:00
|
|
|
end
|
2022-04-11 02:01:54 +00:00
|
|
|
end
|
|
|
|
end
|