bogus 0.1.5 → 0.1.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.rspec +1 -0
- data/.travis.yml +6 -3
- data/Gemfile +0 -2
- data/Guardfile +1 -1
- data/bogus.gemspec +2 -4
- data/features/authors.md +2 -1
- data/features/changelog.md +8 -0
- data/features/contract_tests/contract_tests_mocks.feature +4 -4
- data/features/contract_tests/contract_tests_stubs.feature +4 -4
- data/features/contract_tests/custom_overwritten_class.feature +3 -3
- data/features/fakes/fake_objects.feature +2 -2
- data/lib/bogus/core_ext.rb +5 -1
- data/lib/bogus/fakes/method_stringifier.rb +2 -2
- data/lib/bogus/minitest/syntax.rb +2 -2
- data/lib/bogus/minitest.rb +2 -2
- data/lib/bogus/rspec/syntax.rb +3 -0
- data/lib/bogus/stubbing/verifies_stub_definition.rb +10 -1
- data/lib/bogus/version.rb +1 -1
- data/license.md +1 -0
- data/spec/bogus/bugs/rbx_instance_eval_bug_spec.rb +20 -0
- data/spec/bogus/bugs/rbx_jruby_stub_on_class_spec.rb +45 -0
- data/spec/bogus/contracts/adds_contract_verification_spec.rb +10 -10
- data/spec/bogus/contracts/adds_recording_spec.rb +9 -9
- data/spec/bogus/contracts/interactions_repository_spec.rb +13 -13
- data/spec/bogus/contracts/records_double_interactions_spec.rb +9 -7
- data/spec/bogus/contracts/verifies_contracts_spec.rb +9 -9
- data/spec/bogus/fakes/copies_classes_spec.rb +5 -5
- data/spec/bogus/fakes/creates_fakes_spec.rb +13 -13
- data/spec/bogus/fakes/creates_fakes_with_stubbed_methods_spec.rb +21 -19
- data/spec/bogus/fakes/fake_ar_attributes_spec.rb +3 -1
- data/spec/bogus/fakes/fake_configuration_spec.rb +4 -4
- data/spec/bogus/fakes/fakes_classes_spec.rb +6 -6
- data/spec/bogus/fakes/faking_factories_spec.rb +3 -1
- data/spec/bogus/fakes/frozen_fakes_spec.rb +3 -1
- data/spec/bogus/fakes/registers_created_fakes_spec.rb +8 -8
- data/spec/bogus/fakes/resets_overwritten_classes_spec.rb +8 -8
- data/spec/bogus/fakes/stubbing_new_method_on_fake_class_spec.rb +3 -1
- data/spec/bogus/mocking_dsl_spec.rb +3 -1
- data/spec/bogus/rspec/syntax_spec.rb +16 -0
- data/spec/bogus/ruby_2_1_support_spec.rb +4 -2
- data/spec/bogus/ruby_2_support_spec.rb +4 -2
- data/spec/bogus/stubbing/double_spec.rb +19 -19
- data/spec/bogus/stubbing/have_received_matcher_spec.rb +13 -14
- data/spec/bogus/stubbing/interaction_spec.rb +7 -7
- data/spec/bogus/stubbing/multi_stubber_spec.rb +5 -5
- data/spec/bogus/stubbing/record_interactions_spec.rb +2 -2
- data/spec/bogus/stubbing/resets_stubbed_methods_spec.rb +5 -5
- data/spec/bogus/stubbing/shadow_spec.rb +6 -6
- data/spec/bogus/stubbing/stubbing_existing_methods_on_fakes_spec.rb +1 -1
- data/spec/bogus/stubbing/verifies_stub_definition_spec.rb +14 -1
- data/spec/spec_helper.rb +6 -13
- data/spec/support/ruby_features.rb +19 -0
- metadata +13 -9
- data/license.md +0 -9
@@ -125,15 +125,15 @@ describe Bogus::CopiesClasses do
|
|
125
125
|
end
|
126
126
|
|
127
127
|
it "should override kind_of?" do
|
128
|
-
expect(fake.kind_of?(SomeModule::SomeClass)).to
|
128
|
+
expect(fake.kind_of?(SomeModule::SomeClass)).to be(true)
|
129
129
|
end
|
130
130
|
|
131
131
|
it "should override instance_of?" do
|
132
|
-
expect(fake.instance_of?(SomeModule::SomeClass)).to
|
132
|
+
expect(fake.instance_of?(SomeModule::SomeClass)).to be(true)
|
133
133
|
end
|
134
134
|
|
135
135
|
it "should override is_a?" do
|
136
|
-
expect(fake.is_a?(SomeModule::SomeClass)).to
|
136
|
+
expect(fake.is_a?(SomeModule::SomeClass)).to be(true)
|
137
137
|
end
|
138
138
|
|
139
139
|
it "should include class name in the output of fake's class #to_s" do
|
@@ -145,13 +145,13 @@ describe Bogus::CopiesClasses do
|
|
145
145
|
end
|
146
146
|
|
147
147
|
it 'should override ===' do
|
148
|
-
expect(SomeModule::SomeClass === fake).to
|
148
|
+
expect(SomeModule::SomeClass === fake).to be(true)
|
149
149
|
end
|
150
150
|
end
|
151
151
|
|
152
152
|
shared_examples_for 'spying' do
|
153
153
|
def should_record(method, *args)
|
154
|
-
|
154
|
+
expect(subject).to receive(:__record__).with(method, *args)
|
155
155
|
|
156
156
|
subject.send(method, *args)
|
157
157
|
end
|
@@ -1,11 +1,11 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Bogus::CreatesFakes do
|
4
|
-
let(:fake_class) {
|
5
|
-
let(:fake_instance) {
|
6
|
-
let(:converts_name_to_class) {
|
7
|
-
let(:copies_classes) {
|
8
|
-
let(:makes_ducks) {
|
4
|
+
let(:fake_class) { double }
|
5
|
+
let(:fake_instance) { double }
|
6
|
+
let(:converts_name_to_class) { double }
|
7
|
+
let(:copies_classes) { double }
|
8
|
+
let(:makes_ducks) { double }
|
9
9
|
let(:creates_fakes) { isolate(Bogus::CreatesFakes) }
|
10
10
|
|
11
11
|
module Foo
|
@@ -14,12 +14,12 @@ describe Bogus::CreatesFakes do
|
|
14
14
|
module Bar
|
15
15
|
end
|
16
16
|
|
17
|
-
before {
|
17
|
+
before { allow(fake_class).to receive(:__create__){fake_instance} }
|
18
18
|
|
19
19
|
context "without block" do
|
20
20
|
before do
|
21
|
-
|
22
|
-
|
21
|
+
expect(converts_name_to_class).to receive(:convert).with(:foo) { Foo }
|
22
|
+
expect(copies_classes).to receive(:copy).with(Foo) { fake_class }
|
23
23
|
end
|
24
24
|
|
25
25
|
it "creates a new instance of copied class by default" do
|
@@ -43,8 +43,8 @@ describe Bogus::CreatesFakes do
|
|
43
43
|
|
44
44
|
context "with block" do
|
45
45
|
before do
|
46
|
-
|
47
|
-
|
46
|
+
allow(converts_name_to_class).to receive(:convert)
|
47
|
+
expect(copies_classes).to receive(:copy).with(Bar) { fake_class }
|
48
48
|
end
|
49
49
|
|
50
50
|
it "uses the class provided" do
|
@@ -54,7 +54,7 @@ describe Bogus::CreatesFakes do
|
|
54
54
|
it "does not convert the class name" do
|
55
55
|
creates_fakes.create(:foo) { Bar}
|
56
56
|
|
57
|
-
expect(
|
57
|
+
expect(converts_name_to_class).not_to have_received(:convert)
|
58
58
|
end
|
59
59
|
end
|
60
60
|
|
@@ -63,8 +63,8 @@ describe Bogus::CreatesFakes do
|
|
63
63
|
|
64
64
|
context "with multiple classes" do
|
65
65
|
it "creates a duck type out of those classes and fakes it" do
|
66
|
-
|
67
|
-
|
66
|
+
allow(makes_ducks).to receive(:make).with(Foo, Bar) { FooBarDuck }
|
67
|
+
allow(copies_classes).to receive(:copy).with(FooBarDuck) { :the_fake }
|
68
68
|
|
69
69
|
fake = creates_fakes.create(:role, as: :class) { [Foo, Bar] }
|
70
70
|
|
@@ -3,15 +3,15 @@ require 'spec_helper'
|
|
3
3
|
module Bogus
|
4
4
|
describe CreatesFakesWithStubbedMethods do
|
5
5
|
let(:creates_fakes) { FakeCreatorOfFakes.new }
|
6
|
-
let(:fake_configuration) {
|
7
|
-
let(:responds_to_everything) {
|
8
|
-
let(:multi_stubber) {
|
6
|
+
let(:fake_configuration) { double }
|
7
|
+
let(:responds_to_everything) { double }
|
8
|
+
let(:multi_stubber) { double }
|
9
9
|
|
10
10
|
let(:creates_anonymous_stubs) { isolate(CreatesFakesWithStubbedMethods) }
|
11
11
|
|
12
12
|
before do
|
13
|
-
|
14
|
-
|
13
|
+
allow(fake_configuration).to receive(:include?) { false }
|
14
|
+
allow(multi_stubber).to receive(:stub_all) { :stubbed_object }
|
15
15
|
end
|
16
16
|
|
17
17
|
context "given symbol as first parameter" do
|
@@ -26,7 +26,7 @@ module Bogus
|
|
26
26
|
end
|
27
27
|
|
28
28
|
it "stubs all the given methods" do
|
29
|
-
expect(multi_stubber).to have_received.
|
29
|
+
expect(multi_stubber).to have_received(:stub_all).with(fake, bar: 1)
|
30
30
|
end
|
31
31
|
end
|
32
32
|
|
@@ -40,7 +40,7 @@ module Bogus
|
|
40
40
|
end
|
41
41
|
|
42
42
|
it "stubs all the given methods" do
|
43
|
-
expect(multi_stubber).to have_received.
|
43
|
+
expect(multi_stubber).to have_received(:stub_all).with(responds_to_everything, bar: 1)
|
44
44
|
end
|
45
45
|
end
|
46
46
|
|
@@ -56,7 +56,7 @@ module Bogus
|
|
56
56
|
end
|
57
57
|
|
58
58
|
it "stubs all the given methods" do
|
59
|
-
expect(multi_stubber).to have_received.
|
59
|
+
expect(multi_stubber).to have_received(:stub_all).with(fake, {})
|
60
60
|
end
|
61
61
|
end
|
62
62
|
|
@@ -70,7 +70,7 @@ module Bogus
|
|
70
70
|
end
|
71
71
|
|
72
72
|
it "stubs all the given methods" do
|
73
|
-
expect(multi_stubber).to have_received.
|
73
|
+
expect(multi_stubber).to have_received(:stub_all).with(responds_to_everything, {})
|
74
74
|
end
|
75
75
|
end
|
76
76
|
|
@@ -78,8 +78,8 @@ module Bogus
|
|
78
78
|
let(:fake) { [:foo, {as: :class}, "SomeClass"] }
|
79
79
|
|
80
80
|
before do
|
81
|
-
|
82
|
-
|
81
|
+
allow(fake_configuration).to receive(:include?).with(:foo) { true }
|
82
|
+
allow(fake_configuration).to receive(:get).with(:foo) { FakeDefinition.new(opts: {as: :class},
|
83
83
|
stubs: {xyz: "abc"},
|
84
84
|
class_block: proc{"SomeClass"}) }
|
85
85
|
|
@@ -89,12 +89,12 @@ module Bogus
|
|
89
89
|
it "uses the configuration to create fake" do
|
90
90
|
expect(creates_fakes.fakes).to eq [fake]
|
91
91
|
|
92
|
-
expect(fake_configuration).to have_received
|
93
|
-
expect(fake_configuration).to have_received.
|
92
|
+
expect(fake_configuration).to have_received(:include?).with(:foo)
|
93
|
+
expect(fake_configuration).to have_received(:get).with(:foo)
|
94
94
|
end
|
95
95
|
|
96
96
|
it "stubs the methods defined in configuration" do
|
97
|
-
expect(multi_stubber).to have_received.
|
97
|
+
expect(multi_stubber).to have_received(:stub_all).with(fake, xyz: "abc")
|
98
98
|
end
|
99
99
|
end
|
100
100
|
|
@@ -102,10 +102,12 @@ module Bogus
|
|
102
102
|
let(:fake) { [:foo, {as: :instance}, "SomeOtherClass"] }
|
103
103
|
|
104
104
|
before do
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
105
|
+
allow(fake_configuration).to receive(:include?).with(:foo) { true }
|
106
|
+
allow(fake_configuration).to receive(:get).with(:foo) {
|
107
|
+
FakeDefinition.new(opts: {as: :class},
|
108
|
+
stubs: {a: "b", b: "c"},
|
109
|
+
class_block: proc{"SomeClass"})
|
110
|
+
}
|
109
111
|
|
110
112
|
creates_anonymous_stubs.create(:foo, as: :instance, b: "d", c: "e") { "SomeOtherClass" }
|
111
113
|
end
|
@@ -115,7 +117,7 @@ module Bogus
|
|
115
117
|
end
|
116
118
|
|
117
119
|
it "overrides the stubbed methods" do
|
118
|
-
expect(multi_stubber).to have_received.
|
120
|
+
expect(multi_stubber).to have_received(:stub_all).with(fake, a: "b", b: "d", c: "e")
|
119
121
|
end
|
120
122
|
end
|
121
123
|
end
|
@@ -4,7 +4,7 @@ describe Bogus::FakeConfiguration do
|
|
4
4
|
let(:config) { Bogus::FakeConfiguration.new }
|
5
5
|
|
6
6
|
it "does not contain not configured fakes" do
|
7
|
-
expect(config.include?(:foo)).to
|
7
|
+
expect(config.include?(:foo)).to be(false)
|
8
8
|
end
|
9
9
|
|
10
10
|
def class_block(name)
|
@@ -26,8 +26,8 @@ describe Bogus::FakeConfiguration do
|
|
26
26
|
end
|
27
27
|
end
|
28
28
|
|
29
|
-
expect(config.include?(:foo)).to
|
30
|
-
expect(config.include?(:bar)).to
|
29
|
+
expect(config.include?(:foo)).to be(true)
|
30
|
+
expect(config.include?(:bar)).to be(false)
|
31
31
|
end
|
32
32
|
|
33
33
|
it "returns the configuration for a fake" do
|
@@ -81,7 +81,7 @@ describe Bogus::FakeConfiguration do
|
|
81
81
|
end
|
82
82
|
|
83
83
|
block = stubs(:foo)[:bar]
|
84
|
-
expect{ block.call }.to raise_error
|
84
|
+
expect{ block.call }.to raise_error RuntimeError
|
85
85
|
end
|
86
86
|
end
|
87
87
|
|
@@ -2,8 +2,8 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe Bogus::FakesClasses do
|
4
4
|
let(:creates_fakes_with_stubbed_methods) { FakeCreatorOfFakes.new }
|
5
|
-
let(:overwrites_classes) {
|
6
|
-
let(:overwritten_classes) {
|
5
|
+
let(:overwrites_classes) { double }
|
6
|
+
let(:overwritten_classes) { double }
|
7
7
|
|
8
8
|
let(:fakes_classes) { isolate(Bogus::FakesClasses) }
|
9
9
|
|
@@ -13,8 +13,8 @@ describe Bogus::FakesClasses do
|
|
13
13
|
end
|
14
14
|
|
15
15
|
before do
|
16
|
-
|
17
|
-
|
16
|
+
allow(overwrites_classes).to receive(:overwrite)
|
17
|
+
allow(overwritten_classes).to receive(:add)
|
18
18
|
end
|
19
19
|
|
20
20
|
it "creates a fake named after the class" do
|
@@ -29,13 +29,13 @@ describe Bogus::FakesClasses do
|
|
29
29
|
|
30
30
|
fakes_classes.fake(Samples::WillBeOverwritten)
|
31
31
|
|
32
|
-
expect(overwrites_classes).to have_received.
|
32
|
+
expect(overwrites_classes).to have_received(:overwrite).with("Samples::WillBeOverwritten", fake)
|
33
33
|
end
|
34
34
|
|
35
35
|
it "stores the overwritten class so that it can be replaced back later" do
|
36
36
|
fakes_classes.fake(Samples::WillBeOverwritten)
|
37
37
|
|
38
|
-
expect(overwritten_classes).to have_received.
|
38
|
+
expect(overwritten_classes).to have_received(:add).with("Samples::WillBeOverwritten", Samples::WillBeOverwritten)
|
39
39
|
end
|
40
40
|
|
41
41
|
it "uses the passed fake name if provided" do
|
@@ -1,28 +1,28 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Bogus::RegistersCreatedFakes do
|
4
|
-
let(:fake_registry) {
|
5
|
-
let(:creates_fakes) {
|
6
|
-
let(:double_tracker) {
|
4
|
+
let(:fake_registry) { double }
|
5
|
+
let(:creates_fakes) { double }
|
6
|
+
let(:double_tracker) { double }
|
7
7
|
|
8
8
|
let(:registers_created_fakes) { isolate(Bogus::RegistersCreatedFakes) }
|
9
9
|
|
10
10
|
before do
|
11
|
-
|
12
|
-
|
13
|
-
|
11
|
+
allow(fake_registry).to receive(:store)
|
12
|
+
allow(creates_fakes).to receive(:create) { :the_fake }
|
13
|
+
allow(double_tracker).to receive(:track).with(:the_fake)
|
14
14
|
end
|
15
15
|
|
16
16
|
it "registers the fakes created by creates_fakes" do
|
17
17
|
registers_created_fakes.create(:foo, as: :instance) { Object }
|
18
18
|
|
19
|
-
expect(fake_registry).to have_received.
|
19
|
+
expect(fake_registry).to have_received(:store).with(:foo, :the_fake)
|
20
20
|
end
|
21
21
|
|
22
22
|
it "tracks the created fakes for purposes of mock expectations" do
|
23
23
|
registers_created_fakes.create(:foo, as: :instance) { Object }
|
24
24
|
|
25
|
-
expect(double_tracker).to have_received.
|
25
|
+
expect(double_tracker).to have_received(:track).with(:the_fake)
|
26
26
|
end
|
27
27
|
|
28
28
|
it "returns the created fake" do
|
@@ -2,25 +2,25 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe Bogus::ResetsOverwrittenClasses do
|
4
4
|
let(:classes) { [['Foo', :foo], ['Bar', :bar]] }
|
5
|
-
let(:overwritten_classes) {
|
6
|
-
let(:overwrites_classes) {
|
5
|
+
let(:overwritten_classes) { double }
|
6
|
+
let(:overwrites_classes) { double }
|
7
7
|
|
8
8
|
let(:resets_overwritten_classes) { isolate(Bogus::ResetsOverwrittenClasses) }
|
9
9
|
|
10
10
|
before do
|
11
|
-
|
12
|
-
|
13
|
-
|
11
|
+
allow(overwritten_classes).to receive(:classes) { classes }
|
12
|
+
allow(overwritten_classes).to receive(:clear)
|
13
|
+
allow(overwrites_classes).to receive(:overwrite)
|
14
14
|
|
15
15
|
resets_overwritten_classes.reset
|
16
16
|
end
|
17
17
|
|
18
18
|
it "overwrites back all of the overwritten classes" do
|
19
|
-
expect(overwrites_classes).to have_received.
|
20
|
-
expect(overwrites_classes).to have_received.
|
19
|
+
expect(overwrites_classes).to have_received(:overwrite).with('Foo', :foo)
|
20
|
+
expect(overwrites_classes).to have_received(:overwrite).with('Bar', :bar)
|
21
21
|
end
|
22
22
|
|
23
23
|
it "clears the overwritten classes" do
|
24
|
-
expect(overwritten_classes).to have_received
|
24
|
+
expect(overwritten_classes).to have_received(:clear)
|
25
25
|
end
|
26
26
|
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Bogus::RSpecSyntax do
|
4
|
+
context = self
|
5
|
+
let(:syntax) { Bogus::RSpecSyntax.new(context) }
|
6
|
+
|
7
|
+
it "gets the described class" do
|
8
|
+
expect(syntax.described_class).to eq(Bogus::RSpecSyntax)
|
9
|
+
end
|
10
|
+
|
11
|
+
it "can set the described class" do
|
12
|
+
syntax.described_class = Object
|
13
|
+
|
14
|
+
expect(described_class).to eq(Object)
|
15
|
+
end
|
16
|
+
end
|
@@ -1,13 +1,15 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
if
|
3
|
+
if RubyFeatures.required_keyword_arguments?
|
4
4
|
describe "Ruby 2.1 required keyword arguments" do
|
5
5
|
class ExampleForRequiredKeywordArgs
|
6
6
|
eval "def foo(x:); end"
|
7
7
|
eval "def bar(x:, **rest); end"
|
8
8
|
end
|
9
9
|
|
10
|
-
|
10
|
+
before do
|
11
|
+
extend Bogus::MockingDSL
|
12
|
+
end
|
11
13
|
|
12
14
|
context "with regular objects" do
|
13
15
|
subject { ExampleForRequiredKeywordArgs.new }
|
@@ -1,13 +1,15 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
if
|
3
|
+
if RubyFeatures.keyword_arguments?
|
4
4
|
describe "Ruby 2.0 keyword arguments" do
|
5
5
|
class ExampleForKeywordArgs
|
6
6
|
eval "def foo(x: 1); end"
|
7
7
|
eval "def bar(x: 1, **rest); end"
|
8
8
|
end
|
9
9
|
|
10
|
-
|
10
|
+
before do
|
11
|
+
extend Bogus::MockingDSL
|
12
|
+
end
|
11
13
|
|
12
14
|
context "with regular objects" do
|
13
15
|
subject { ExampleForKeywordArgs.new }
|
@@ -4,59 +4,59 @@ module Bogus
|
|
4
4
|
describe Double do
|
5
5
|
shared_examples_for "double behavior" do
|
6
6
|
it "tracks existence of test doubles" do
|
7
|
-
|
7
|
+
expect(double_tracker).to receive(:track).with(object)
|
8
8
|
|
9
|
-
|
9
|
+
double_instance.stub.foo("a", "b") { "the result" }
|
10
10
|
end
|
11
11
|
|
12
12
|
it "does not track existence of the double if verify fails" do
|
13
|
-
|
13
|
+
allow(verifies_stub_definition).to receive(:verify!).with(object, :foo, ["a", "b"]) { raise NameError }
|
14
14
|
|
15
15
|
expect {
|
16
|
-
|
17
|
-
}.to raise_error
|
16
|
+
double_instance.stub.foo("a", "b") { "the result" }
|
17
|
+
}.to raise_error NameError
|
18
18
|
|
19
|
-
expect(double_tracker).not_to have_received.
|
19
|
+
expect(double_tracker).not_to have_received(:track).with(object)
|
20
20
|
end
|
21
21
|
|
22
22
|
it "verifies stub definition" do
|
23
|
-
|
23
|
+
expect(verifies_stub_definition).to receive(:verify!).with(object, :foo, ["a", "b"])
|
24
24
|
|
25
|
-
|
25
|
+
double_instance.stub.foo("a", "b") { "the result" }
|
26
26
|
end
|
27
27
|
|
28
28
|
it "stubs shadow methods" do
|
29
29
|
object.extend RecordInteractions
|
30
|
-
|
30
|
+
expect(object.__shadow__).to receive(:stubs).with(:foo, "a", "b")
|
31
31
|
|
32
|
-
|
32
|
+
double_instance.stub.foo("a", "b") { "the result" }
|
33
33
|
end
|
34
34
|
|
35
35
|
it "mocks shadow methods" do
|
36
36
|
object.extend RecordInteractions
|
37
|
-
|
37
|
+
expect(object.__shadow__).to receive(:mocks).with(:foo, "a", "b")
|
38
38
|
|
39
|
-
|
39
|
+
double_instance.mock.foo("a", "b") { "the result" }
|
40
40
|
end
|
41
41
|
|
42
42
|
it "adds method overwriting" do
|
43
|
-
|
43
|
+
double_instance.stub.foo("a", "b") { "the result" }
|
44
44
|
|
45
45
|
expect(overwrites_methods.overwrites).to eq([[object, :foo]])
|
46
46
|
end
|
47
47
|
|
48
48
|
it "records double interactions" do
|
49
|
-
|
49
|
+
expect(records_double_interactions).to receive(:record).with(object, :foo, ["a", "b"])
|
50
50
|
|
51
|
-
|
51
|
+
double_instance.stub.foo("a", "b") { "the result" }
|
52
52
|
end
|
53
53
|
end
|
54
54
|
|
55
|
-
let(:double_tracker) {
|
56
|
-
let(:verifies_stub_definition) {
|
57
|
-
let(:records_double_interactions) {
|
55
|
+
let(:double_tracker) { double(:double_tracker, track: nil) }
|
56
|
+
let(:verifies_stub_definition) { double(:verifies_stub_definition, verify!: nil) }
|
57
|
+
let(:records_double_interactions) { double(:records_double_interactions, record: nil) }
|
58
58
|
let(:overwrites_methods) { FakeMethodOverwriter.new }
|
59
|
-
let(:
|
59
|
+
let(:double_instance) { isolate(Double) }
|
60
60
|
|
61
61
|
context "with regular objects" do
|
62
62
|
let(:object) { Samples::Foo.new }
|
@@ -1,10 +1,9 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Bogus::HaveReceivedMatcher do
|
4
|
-
let(:verifies_stub_definition) {
|
5
|
-
let(:records_double_interactions) {
|
4
|
+
let(:verifies_stub_definition) { double(:verifies_stub_definition, verify!: nil) }
|
5
|
+
let(:records_double_interactions) { double(:records_double_interactions, record: nil) }
|
6
6
|
let(:have_received_matcher) { isolate(Bogus::HaveReceivedMatcher) }
|
7
|
-
let(:have_received) { have_received_matcher.method_call }
|
8
7
|
let(:fake) { Samples::FooFake.new }
|
9
8
|
|
10
9
|
before do
|
@@ -13,33 +12,33 @@ describe Bogus::HaveReceivedMatcher do
|
|
13
12
|
|
14
13
|
shared_examples_for "have_received_matcher" do
|
15
14
|
it "matches when the spy has received the message" do
|
16
|
-
expect(fake).to
|
15
|
+
expect(fake).to bogus_have_received(:foo, "a", "b")
|
17
16
|
end
|
18
17
|
|
19
18
|
it "does not match if the spy hasn't received the message" do
|
20
|
-
expect(fake).not_to
|
19
|
+
expect(fake).not_to bogus_have_received(:foo, "a", "c")
|
21
20
|
end
|
22
21
|
|
23
22
|
it "verifies that the method call has the right signature" do
|
24
|
-
|
23
|
+
expect(verifies_stub_definition).to receive(:verify!).with(fake, :foo, ["a", "b"])
|
25
24
|
|
26
|
-
|
25
|
+
bogus_have_received(:foo, "a", "b")
|
27
26
|
|
28
27
|
have_received_matcher.matches?(fake)
|
29
28
|
end
|
30
29
|
|
31
30
|
it "records the interaction so that it can be checked by contract tests" do
|
32
|
-
|
31
|
+
expect(records_double_interactions).to receive(:record).with(fake, :foo, ["a", "b"])
|
33
32
|
|
34
|
-
|
33
|
+
bogus_have_received(:foo, "a", "b")
|
35
34
|
|
36
35
|
have_received_matcher.matches?(fake)
|
37
36
|
end
|
38
37
|
|
39
38
|
it "returns a readable error message for object with no shadow" do
|
40
|
-
|
39
|
+
bogus_have_received(:upcase)
|
41
40
|
|
42
|
-
expect(have_received_matcher.matches?("foo")).to
|
41
|
+
expect(have_received_matcher.matches?("foo")).to be(false)
|
43
42
|
expect(have_received_matcher.failure_message_for_should).to eq(Bogus::HaveReceivedMatcher::NO_SHADOW)
|
44
43
|
expect(have_received_matcher.failure_message).to eq(Bogus::HaveReceivedMatcher::NO_SHADOW)
|
45
44
|
expect(have_received_matcher.failure_message_for_should_not).to eq(Bogus::HaveReceivedMatcher::NO_SHADOW)
|
@@ -47,7 +46,7 @@ describe Bogus::HaveReceivedMatcher do
|
|
47
46
|
end
|
48
47
|
|
49
48
|
it "returns a readable error message for fakes" do
|
50
|
-
|
49
|
+
bogus_have_received(:foo, "a", "c")
|
51
50
|
|
52
51
|
have_received_matcher.matches?(fake)
|
53
52
|
|
@@ -62,7 +61,7 @@ describe Bogus::HaveReceivedMatcher do
|
|
62
61
|
end
|
63
62
|
|
64
63
|
context "with method_missing builder" do
|
65
|
-
def
|
64
|
+
def bogus_have_received(method, *args)
|
66
65
|
have_received_matcher.build.__send__(method, *args)
|
67
66
|
end
|
68
67
|
|
@@ -70,7 +69,7 @@ describe Bogus::HaveReceivedMatcher do
|
|
70
69
|
end
|
71
70
|
|
72
71
|
context "with method call builder" do
|
73
|
-
def
|
72
|
+
def bogus_have_received(*args)
|
74
73
|
have_received_matcher.build(*args)
|
75
74
|
end
|
76
75
|
|