bogus 0.1.5 → 0.1.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rspec +1 -0
- data/.travis.yml +1 -0
- data/Gemfile +0 -2
- data/Guardfile +1 -1
- data/bogus.gemspec +1 -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/rspec/syntax.rb +3 -0
- data/lib/bogus/version.rb +1 -1
- 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 +3 -3
- 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 +18 -18
- 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/spec_helper.rb +6 -13
- data/spec/support/ruby_features.rb +19 -0
- metadata +10 -5
@@ -1,25 +1,27 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Bogus::RecordsDoubleInteractions do
|
4
|
-
let(:fake_registry) {
|
5
|
-
let(:doubled_interactions) {
|
4
|
+
let(:fake_registry) { double }
|
5
|
+
let(:doubled_interactions) { double }
|
6
6
|
let(:object) { Object.new }
|
7
7
|
|
8
8
|
let(:records_double_interactions) { isolate(Bogus::RecordsDoubleInteractions) }
|
9
9
|
|
10
10
|
it "records the call in double interaction repository" do
|
11
|
-
|
12
|
-
|
11
|
+
allow(fake_registry).to receive(:name).with(object) { :object_name }
|
12
|
+
allow(doubled_interactions).to receive(:record)
|
13
13
|
|
14
14
|
records_double_interactions.record(object, :method_name, [:foo, 1])
|
15
15
|
|
16
|
-
expect(doubled_interactions).to have_received.
|
16
|
+
expect(doubled_interactions).to have_received(:record).with(:object_name, :method_name, :foo, 1)
|
17
17
|
end
|
18
18
|
|
19
19
|
it "does not record the interaction if object is not a fake" do
|
20
|
-
|
21
|
-
|
20
|
+
allow(fake_registry).to receive(:name).with(object) { nil }
|
21
|
+
allow(doubled_interactions).to receive(:record)
|
22
22
|
|
23
23
|
records_double_interactions.record(object, :method_name, [:foo, 1])
|
24
|
+
|
25
|
+
expect(doubled_interactions).not_to have_received(:record)
|
24
26
|
end
|
25
27
|
end
|
@@ -1,8 +1,8 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Bogus::VerifiesContracts do
|
4
|
-
let(:real_interactions) {
|
5
|
-
let(:doubled_interactions) {
|
4
|
+
let(:real_interactions) { double }
|
5
|
+
let(:doubled_interactions) { double }
|
6
6
|
let(:verifies_contracts) { isolate(Bogus::VerifiesContracts) }
|
7
7
|
|
8
8
|
let(:matched_interaction) { interaction("matched") }
|
@@ -12,12 +12,12 @@ describe Bogus::VerifiesContracts do
|
|
12
12
|
second_interaction = interaction("second")
|
13
13
|
other_interaction = interaction("other")
|
14
14
|
|
15
|
-
|
16
|
-
|
15
|
+
allow(doubled_interactions).to receive(:for_fake).with(:fake_name){[first_interaction, matched_interaction, second_interaction]}
|
16
|
+
allow(real_interactions).to receive(:for_fake).with(:fake_name){[matched_interaction, other_interaction]}
|
17
17
|
|
18
|
-
|
19
|
-
|
20
|
-
|
18
|
+
allow(real_interactions).to receive(:recorded?).with(:fake_name, first_interaction) { false }
|
19
|
+
allow(real_interactions).to receive(:recorded?).with(:fake_name, second_interaction) { false }
|
20
|
+
allow(real_interactions).to receive(:recorded?).with(:fake_name, matched_interaction) { true }
|
21
21
|
|
22
22
|
expect_verify_to_raise_error_with_interactions(:fake_name,
|
23
23
|
[first_interaction, second_interaction],
|
@@ -25,8 +25,8 @@ describe Bogus::VerifiesContracts do
|
|
25
25
|
end
|
26
26
|
|
27
27
|
it "passes with all calls matched" do
|
28
|
-
|
29
|
-
|
28
|
+
allow(doubled_interactions).to receive(:for_fake).with(:fake_name) { [matched_interaction] }
|
29
|
+
allow(real_interactions).to receive(:recorded?).with(:fake_name, matched_interaction) { true }
|
30
30
|
|
31
31
|
expect {
|
32
32
|
verifies_contracts.verify(:fake_name)
|
@@ -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
|
@@ -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
|