bogus 0.1.4 → 0.1.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (85) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +1 -0
  3. data/.travis.yml +1 -1
  4. data/Guardfile +1 -3
  5. data/Guardfile.cucumber +0 -2
  6. data/README.md +1 -1
  7. data/bogus.gemspec +3 -1
  8. data/features/changelog.md +11 -0
  9. data/features/configuration/fake_ar_attributes.feature +2 -2
  10. data/features/contract_tests/contract_tests_mocks.feature +5 -5
  11. data/features/contract_tests/contract_tests_spies.feature +1 -1
  12. data/features/contract_tests/contract_tests_stubs.feature +6 -6
  13. data/features/contract_tests/custom_overwritten_class.feature +4 -4
  14. data/features/contract_tests/return_value_contracts.feature +2 -2
  15. data/features/fakes/anonymous_doubles.feature +5 -5
  16. data/features/fakes/duck_types.feature +9 -9
  17. data/features/fakes/fake_objects.feature +31 -8
  18. data/features/fakes/global_fake_configuration.feature +5 -5
  19. data/features/fakes/replacing_classes.feature +5 -5
  20. data/features/readme.md +5 -5
  21. data/features/safe_stubbing/argument_matchers.feature +23 -10
  22. data/features/safe_stubbing/safe_mocking.feature +1 -1
  23. data/features/safe_stubbing/safe_stubbing.feature +1 -1
  24. data/features/safe_stubbing/spies.feature +7 -7
  25. data/lib/bogus.rb +1 -0
  26. data/lib/bogus/core_ext.rb +22 -0
  27. data/lib/bogus/fakes/fake.rb +2 -1
  28. data/lib/bogus/fakes/method_stringifier.rb +1 -0
  29. data/lib/bogus/mocking_dsl.rb +4 -0
  30. data/lib/bogus/stubbing/has_overwritten_methods.rb +28 -10
  31. data/lib/bogus/stubbing/have_received_matcher.rb +4 -2
  32. data/lib/bogus/stubbing/matchers/any_args.rb +9 -0
  33. data/lib/bogus/stubbing/matchers/matches_argument.rb +11 -0
  34. data/lib/bogus/stubbing/{any_args.rb → matchers/with_arguments.rb} +0 -6
  35. data/lib/bogus/stubbing/overwrites_methods.rb +6 -1
  36. data/lib/bogus/stubbing/undefined_return_value.rb +4 -0
  37. data/lib/bogus/support.rb +11 -0
  38. data/lib/bogus/version.rb +1 -1
  39. data/spec/bogus/clean_ruby_spec.rb +1 -1
  40. data/spec/bogus/configuration_spec.rb +2 -2
  41. data/spec/bogus/contracts/adds_contract_verification_spec.rb +10 -10
  42. data/spec/bogus/contracts/adds_recording_spec.rb +4 -4
  43. data/spec/bogus/contracts/interactions_repository_spec.rb +15 -15
  44. data/spec/bogus/contracts/proxy_class_spec.rb +7 -7
  45. data/spec/bogus/contracts/records_double_interactions_spec.rb +1 -1
  46. data/spec/bogus/contracts/verifies_contracts_spec.rb +3 -3
  47. data/spec/bogus/fakes/base_class_identifier_spec.rb +1 -1
  48. data/spec/bogus/fakes/class_methods_spec.rb +4 -5
  49. data/spec/bogus/fakes/converts_name_to_class_spec.rb +3 -3
  50. data/spec/bogus/fakes/copies_classes_spec.rb +20 -16
  51. data/spec/bogus/fakes/creates_fakes_spec.rb +6 -6
  52. data/spec/bogus/fakes/creates_fakes_with_stubbed_methods_spec.rb +16 -15
  53. data/spec/bogus/fakes/fake_ar_attributes_spec.rb +3 -3
  54. data/spec/bogus/fakes/fake_configuration_spec.rb +16 -16
  55. data/spec/bogus/fakes/fake_registry_spec.rb +2 -2
  56. data/spec/bogus/fakes/fake_spec.rb +1 -1
  57. data/spec/bogus/fakes/fakes_classes_spec.rb +4 -4
  58. data/spec/bogus/fakes/faking_factories_spec.rb +4 -4
  59. data/spec/bogus/fakes/frozen_fakes_spec.rb +4 -4
  60. data/spec/bogus/fakes/instance_methods_spec.rb +5 -5
  61. data/spec/bogus/fakes/makes_ducks_spec.rb +3 -3
  62. data/spec/bogus/fakes/makes_substitute_methods_spec.rb +1 -1
  63. data/spec/bogus/fakes/overwriten_classes_spec.rb +3 -3
  64. data/spec/bogus/fakes/overwrites_classes_spec.rb +2 -2
  65. data/spec/bogus/fakes/registers_created_fakes_spec.rb +3 -3
  66. data/spec/bogus/fakes/resets_overwritten_classes_spec.rb +3 -3
  67. data/spec/bogus/fakes/stubbing_new_method_on_fake_class_spec.rb +25 -0
  68. data/spec/bogus/mocking_dsl_spec.rb +36 -36
  69. data/spec/bogus/ruby_2_1_support_spec.rb +38 -0
  70. data/spec/bogus/ruby_2_support_spec.rb +14 -64
  71. data/spec/bogus/stubbing/anything_spec.rb +5 -5
  72. data/spec/bogus/stubbing/double_spec.rb +2 -2
  73. data/spec/bogus/stubbing/have_received_matcher_spec.rb +11 -6
  74. data/spec/bogus/stubbing/interaction_spec.rb +7 -7
  75. data/spec/bogus/stubbing/multi_stubber_spec.rb +2 -2
  76. data/spec/bogus/stubbing/overwrites_methods_spec.rb +8 -8
  77. data/spec/bogus/stubbing/record_interactions_spec.rb +3 -3
  78. data/spec/bogus/stubbing/shadow_spec.rb +28 -28
  79. data/spec/bogus/stubbing/stubbing_existing_methods_on_fakes_spec.rb +50 -0
  80. data/spec/bogus/stubbing/tracks_existence_of_test_doubles_spec.rb +2 -2
  81. data/spec/bogus/stubbing/undefined_return_value_spec.rb +2 -2
  82. data/spec/spec_helper.rb +6 -1
  83. data/spec/support/shared_examples_for_keyword_arguments.rb +63 -0
  84. metadata +160 -160
  85. data/Gemfile.lock +0 -146
@@ -4,10 +4,10 @@ describe Bogus::Anything do
4
4
  it "is equal to everything" do
5
5
  anything = Bogus::Anything
6
6
 
7
- anything.should == "foo"
8
- anything.should == "bar"
9
- anything.should == 1
10
- anything.should == Object.new
11
- anything.should == anything
7
+ expect(anything).to eq("foo")
8
+ expect(anything).to eq("bar")
9
+ expect(anything).to eq(1)
10
+ expect(anything).to eq(Object.new)
11
+ expect(anything).to eq(anything)
12
12
  end
13
13
  end
@@ -16,7 +16,7 @@ module Bogus
16
16
  double.stub.foo("a", "b") { "the result" }
17
17
  }.to raise_error
18
18
 
19
- double_tracker.should_not have_received.track(object)
19
+ expect(double_tracker).not_to have_received.track(object)
20
20
  end
21
21
 
22
22
  it "verifies stub definition" do
@@ -42,7 +42,7 @@ module Bogus
42
42
  it "adds method overwriting" do
43
43
  double.stub.foo("a", "b") { "the result" }
44
44
 
45
- overwrites_methods.overwrites.should == [[object, :foo]]
45
+ expect(overwrites_methods.overwrites).to eq([[object, :foo]])
46
46
  end
47
47
 
48
48
  it "records double interactions" do
@@ -13,11 +13,11 @@ describe Bogus::HaveReceivedMatcher do
13
13
 
14
14
  shared_examples_for "have_received_matcher" do
15
15
  it "matches when the spy has received the message" do
16
- fake.should have_received(:foo, "a", "b")
16
+ expect(fake).to have_received(:foo, "a", "b")
17
17
  end
18
18
 
19
19
  it "does not match if the spy hasn't received the message" do
20
- fake.should_not have_received(:foo, "a", "c")
20
+ expect(fake).not_to have_received(:foo, "a", "c")
21
21
  end
22
22
 
23
23
  it "verifies that the method call has the right signature" do
@@ -39,9 +39,11 @@ describe Bogus::HaveReceivedMatcher do
39
39
  it "returns a readable error message for object with no shadow" do
40
40
  have_received(:upcase)
41
41
 
42
- have_received_matcher.matches?("foo").should be_false
43
- have_received_matcher.failure_message_for_should.should == Bogus::HaveReceivedMatcher::NO_SHADOW
44
- have_received_matcher.failure_message_for_should_not.should == Bogus::HaveReceivedMatcher::NO_SHADOW
42
+ expect(have_received_matcher.matches?("foo")).to be_false
43
+ expect(have_received_matcher.failure_message_for_should).to eq(Bogus::HaveReceivedMatcher::NO_SHADOW)
44
+ expect(have_received_matcher.failure_message).to eq(Bogus::HaveReceivedMatcher::NO_SHADOW)
45
+ expect(have_received_matcher.failure_message_for_should_not).to eq(Bogus::HaveReceivedMatcher::NO_SHADOW)
46
+ expect(have_received_matcher.failure_message_when_negated).to eq(Bogus::HaveReceivedMatcher::NO_SHADOW)
45
47
  end
46
48
 
47
49
  it "returns a readable error message for fakes" do
@@ -49,10 +51,13 @@ describe Bogus::HaveReceivedMatcher do
49
51
 
50
52
  have_received_matcher.matches?(fake)
51
53
 
52
- have_received_matcher.failure_message_for_should.should ==
54
+ message =
53
55
  %Q{Expected #{fake.inspect} to have received foo("a", "c"), but it didn't.\n\n}+
54
56
  %Q{The recorded interactions were:\n} +
55
57
  %Q{ - foo("a", "b")\n}
58
+
59
+ expect(have_received_matcher.failure_message_for_should).to eq(message)
60
+ expect(have_received_matcher.failure_message).to eq(message)
56
61
  end
57
62
  end
58
63
 
@@ -52,7 +52,7 @@ module Bogus
52
52
  first = create_interaction(first_interaction)
53
53
  second = create_interaction(second_interaction)
54
54
 
55
- Interaction.same?(recorded: first, stubbed: second).should be_true
55
+ expect(Interaction.same?(recorded: first, stubbed: second)).to be_true
56
56
  end
57
57
  end
58
58
 
@@ -61,7 +61,7 @@ module Bogus
61
61
  first = create_interaction(first_interaction)
62
62
  second = create_interaction(second_interaction)
63
63
 
64
- Interaction.same?(recorded: first, stubbed: second).should be_false
64
+ expect(Interaction.same?(recorded: first, stubbed: second)).to be_false
65
65
  end
66
66
  end
67
67
 
@@ -69,21 +69,21 @@ module Bogus
69
69
  first = Interaction.new(:foo, [:bar]) { raise SomeError }
70
70
  second = Interaction.new(:foo, [:bar]) { nil }
71
71
 
72
- Interaction.same?(recorded: first, stubbed: second).should be_false
72
+ expect(Interaction.same?(recorded: first, stubbed: second)).to be_false
73
73
  end
74
74
 
75
75
  it "differs raised exceptions from ones just returned from the block" do
76
76
  first = Interaction.new(:foo, [:bar]) { raise SomeError }
77
77
  second = Interaction.new(:foo, [:bar]) { SomeError }
78
78
 
79
- Interaction.same?(recorded: first, stubbed: second).should be_false
79
+ expect(Interaction.same?(recorded: first, stubbed: second)).to be_false
80
80
  end
81
81
 
82
82
  it "considers exceptions of the same type as equal" do
83
83
  first = Interaction.new(:foo, [:bar]) { raise SomeError }
84
84
  second = Interaction.new(:foo, [:bar]) { raise SomeError }
85
85
 
86
- Interaction.same?(recorded: first, stubbed: second).should be_true
86
+ expect(Interaction.same?(recorded: first, stubbed: second)).to be_true
87
87
  end
88
88
 
89
89
  context 'when comparing arguments with custom #== implementations' do
@@ -97,14 +97,14 @@ module Bogus
97
97
  first = Interaction.new(:with, [Dev.new(:psyho)])
98
98
  second = Interaction.new(:with, [Dev.new(:psyho)])
99
99
 
100
- Interaction.same?(recorded: first, stubbed: second).should be_true
100
+ expect(Interaction.same?(recorded: first, stubbed: second)).to be_true
101
101
  end
102
102
 
103
103
  it "considers two interactions != when the arguments are !=" do
104
104
  first = Interaction.new(:with, [Dev.new(:wrozka)])
105
105
  second = Interaction.new(:with, [Dev.new(:yundt)])
106
106
 
107
- Interaction.same?(recorded: first, stubbed: second).should be_false
107
+ expect(Interaction.same?(recorded: first, stubbed: second)).to be_false
108
108
  end
109
109
  end
110
110
  end
@@ -10,13 +10,13 @@ describe Bogus::MultiStubber do
10
10
  it "stubs all the given methods with any args returning the given value" do
11
11
  multi_stubber.stub_all(Object.new, foo: 1, bar: 2)
12
12
 
13
- double.stubbed.should == [[:foo, [any_args], 1], [:bar, [any_args], 2]]
13
+ expect(double.stubbed).to eq([[:foo, [any_args], 1], [:bar, [any_args], 2]])
14
14
  end
15
15
 
16
16
  it "uses passed procs as the return value block" do
17
17
  multi_stubber.stub_all(Object.new, foo: proc{ 1 })
18
18
 
19
- double.stubbed.should == [[:foo, [any_args], 1]]
19
+ expect(double.stubbed).to eq([[:foo, [any_args], 1]])
20
20
  end
21
21
 
22
22
  class FakeDouble
@@ -24,7 +24,7 @@ module Bogus
24
24
  end
25
25
 
26
26
  it "does not change the method signature" do
27
- object.method(:greet).arity.should == 1
27
+ expect(object.method(:greet).arity).to eq(1)
28
28
  end
29
29
 
30
30
  it "does not change the method signature" do
@@ -36,14 +36,14 @@ module Bogus
36
36
  it "adds interaction recording to the overwritten object" do
37
37
  object.greet("John")
38
38
 
39
- object.should Bogus.have_received.greet("John")
40
- object.should_not Bogus.have_received.greet("Paul")
39
+ expect(object).to Bogus.have_received.greet("John")
40
+ expect(object).not_to Bogus.have_received.greet("Paul")
41
41
  end
42
42
 
43
43
  it "can reset the overwritten methods" do
44
44
  overwriter.reset(object)
45
45
 
46
- object.greet("John").should == "Hello John"
46
+ expect(object.greet("John")).to eq("Hello John")
47
47
  end
48
48
 
49
49
  it "is imdepotent when overwriting" do
@@ -53,7 +53,7 @@ module Bogus
53
53
 
54
54
  overwriter.reset(object)
55
55
 
56
- object.greet("John").should == "Hello John"
56
+ expect(object.greet("John")).to eq("Hello John")
57
57
  end
58
58
  end
59
59
 
@@ -75,7 +75,7 @@ module Bogus
75
75
  end
76
76
 
77
77
  it "can overwrite the non-existent methods" do
78
- object.methods.should include(:greet)
78
+ expect(object.methods).to include(:greet)
79
79
  end
80
80
 
81
81
  it "can be reset back to the original state" do
@@ -84,7 +84,7 @@ module Bogus
84
84
 
85
85
  overwriter.reset(object)
86
86
 
87
- object.greet.should == "the original return value"
87
+ expect(object.greet).to eq("the original return value")
88
88
  end
89
89
  end
90
90
 
@@ -94,7 +94,7 @@ module Bogus
94
94
  it "does nothing because fakes methods already work as we need" do
95
95
  overwriter.overwrite(fake, :foo_bar)
96
96
 
97
- fake.should_not respond_to(:foo_bar)
97
+ expect(fake).not_to respond_to(:foo_bar)
98
98
  end
99
99
 
100
100
  it "does not reset fakes, because there is nothing to reset" do
@@ -11,16 +11,16 @@ describe Bogus::RecordInteractions do
11
11
  it "allows verifying that interactions happened" do
12
12
  sample.__record__(:foo, 1, 2, 3)
13
13
 
14
- sample.__shadow__.has_received(:foo, [1,2,3]).should be_true
14
+ expect(sample.__shadow__.has_received(:foo, [1,2,3])).to be_true
15
15
  end
16
16
 
17
17
  it "allows verifying that interactions didn't happen" do
18
18
  sample.__record__(:bar)
19
19
 
20
- sample.__shadow__.has_received(:foo, [1,2,3]).should be_false
20
+ expect(sample.__shadow__.has_received(:foo, [1,2,3])).to be_false
21
21
  end
22
22
 
23
23
  it "returns self from record by default" do
24
- sample.__record__(:foo).should be_a_default_return_value
24
+ expect(sample.__record__(:foo)).to be_a_default_return_value
25
25
  end
26
26
  end
@@ -11,12 +11,12 @@ describe Bogus::Shadow do
11
11
  end
12
12
 
13
13
  it "returns the called methods" do
14
- shadow.has_received(:foo, ["a", "b"]).should be_true
14
+ expect(shadow.has_received(:foo, ["a", "b"])).to be_true
15
15
  end
16
16
 
17
17
  it "does not return true for interactions that did not happen" do
18
- shadow.has_received(:foo, ["a", "c"]).should be_false
19
- shadow.has_received(:bar, ["a", "c"]).should be_false
18
+ expect(shadow.has_received(:foo, ["a", "c"])).to be_false
19
+ expect(shadow.has_received(:bar, ["a", "c"])).to be_false
20
20
  end
21
21
  end
22
22
  end
@@ -25,7 +25,7 @@ describe Bogus::Shadow do
25
25
  it "returns an unstubbed value" do
26
26
  return_value = shadow.run(:foo, "a", "b")
27
27
 
28
- return_value.should be_a_default_return_value
28
+ expect(return_value).to be_a_default_return_value
29
29
  end
30
30
 
31
31
  include_examples "spying on shadows"
@@ -53,7 +53,7 @@ describe Bogus::Shadow do
53
53
  end
54
54
 
55
55
  it "returns the default value" do
56
- shadow.run(:foo, ["a", "b"]).should be_a_default_return_value
56
+ expect(shadow.run(:foo, ["a", "b"])).to be_a_default_return_value
57
57
  end
58
58
 
59
59
  include_examples "spying on shadows"
@@ -67,21 +67,21 @@ describe Bogus::Shadow do
67
67
  end
68
68
 
69
69
  it "changes the default value returned from method" do
70
- shadow.run(:foo, "b", "c").should == "default value"
70
+ expect(shadow.run(:foo, "b", "c")).to eq("default value")
71
71
  end
72
72
 
73
73
  it "overwrites the old specific stubbed values" do
74
- shadow.run(:foo, "a", "b").should == "default value"
74
+ expect(shadow.run(:foo, "a", "b")).to eq("default value")
75
75
  end
76
76
 
77
77
  it "does not affect the new specific stubbed values" do
78
- shadow.run(:foo, "a", "d").should == "new specific value"
78
+ expect(shadow.run(:foo, "a", "d")).to eq("new specific value")
79
79
  end
80
80
 
81
81
  it "allows spying on calls using any args" do
82
82
  shadow.run(:foo, "a", "c")
83
83
 
84
- shadow.has_received(:foo, [Bogus::AnyArgs]).should be_true
84
+ expect(shadow.has_received(:foo, [Bogus::AnyArgs])).to be_true
85
85
  end
86
86
  end
87
87
 
@@ -91,19 +91,19 @@ describe Bogus::Shadow do
91
91
  end
92
92
 
93
93
  it "changes the return value for calls that match" do
94
- shadow.run(:foo, "a", "c").should == "return value"
94
+ expect(shadow.run(:foo, "a", "c")).to eq("return value")
95
95
  end
96
96
 
97
97
  it "does not affect the return value for other calls" do
98
98
  shadow.stubs(:foo, "a", "b") { "specific value" }
99
99
 
100
- shadow.run(:foo, "a", "b").should == "specific value"
100
+ expect(shadow.run(:foo, "a", "b")).to eq("specific value")
101
101
  end
102
102
 
103
103
  it "allows spying on calls using anything in args" do
104
104
  shadow.run(:foo, "a", "b")
105
105
 
106
- shadow.has_received(:foo, [Bogus::Anything, "b"]).should be_true
106
+ expect(shadow.has_received(:foo, [Bogus::Anything, "b"])).to be_true
107
107
  end
108
108
  end
109
109
 
@@ -113,30 +113,30 @@ describe Bogus::Shadow do
113
113
  end
114
114
 
115
115
  it "returns the stubbed value" do
116
- shadow.run(:foo, "a", "b").should == "stubbed value"
116
+ expect(shadow.run(:foo, "a", "b")).to eq("stubbed value")
117
117
  end
118
118
 
119
119
  it "returns the latest stubbed value" do
120
120
  shadow.stubs(:foo, "a", "b") { "stubbed twice" }
121
121
  shadow.stubs(:foo, "b", "c") { "different params" }
122
122
 
123
- shadow.run(:foo, "a", "b").should == "stubbed twice"
124
- shadow.run(:foo, "b", "c").should == "different params"
123
+ expect(shadow.run(:foo, "a", "b")).to eq("stubbed twice")
124
+ expect(shadow.run(:foo, "b", "c")).to eq("different params")
125
125
  end
126
126
 
127
127
  it "returns the default value for non-stubbed calls" do
128
- shadow.run(:foo, "c", "d").should be_a_default_return_value
129
- shadow.run(:bar).should be_a_default_return_value
128
+ expect(shadow.run(:foo, "c", "d")).to be_a_default_return_value
129
+ expect(shadow.run(:bar)).to be_a_default_return_value
130
130
  end
131
131
 
132
132
  it "does not contribute towards unsatisfied interactions" do
133
- shadow.unsatisfied_interactions.should be_empty
133
+ expect(shadow.unsatisfied_interactions).to be_empty
134
134
  end
135
135
 
136
136
  it "adds required interaction when mocking over stubbing" do
137
137
  shadow.mocks(:foo, "a", "b") { "stubbed value" }
138
138
 
139
- shadow.unsatisfied_interactions.should_not be_empty
139
+ expect(shadow.unsatisfied_interactions).not_to be_empty
140
140
  end
141
141
 
142
142
  include_examples "spying on shadows"
@@ -148,38 +148,38 @@ describe Bogus::Shadow do
148
148
  end
149
149
 
150
150
  it "returns the mocked value" do
151
- shadow.run(:foo, "a", "b").should == "mocked value"
151
+ expect(shadow.run(:foo, "a", "b")).to eq("mocked value")
152
152
  end
153
153
 
154
154
  it "overwrites the stubbed value" do
155
155
  shadow.stubs(:foo, "a", "c") { "stubbed value" }
156
156
  shadow.mocks(:foo, "a", "c") { "mocked value" }
157
157
 
158
- shadow.run(:foo, "a", "c").should == "mocked value"
158
+ expect(shadow.run(:foo, "a", "c")).to eq("mocked value")
159
159
  end
160
160
 
161
161
  it "is overwritten by stubbing" do
162
162
  shadow.mocks(:foo, "a", "c") { "mocked value" }
163
163
  shadow.stubs(:foo, "a", "c") { "stubbed value" }
164
164
 
165
- shadow.run(:foo, "a", "c").should == "stubbed value"
165
+ expect(shadow.run(:foo, "a", "c")).to eq("stubbed value")
166
166
  end
167
167
 
168
168
  it "removes the required interaction when stubbing over mocking" do
169
169
  shadow.stubs(:foo, "a", "b") { "stubbed value" }
170
170
 
171
- shadow.unsatisfied_interactions.should be_empty
171
+ expect(shadow.unsatisfied_interactions).to be_empty
172
172
  end
173
173
 
174
174
  it "returns the default value for non-stubbed calls" do
175
- shadow.run(:foo, "a", "c").should be_a_default_return_value
175
+ expect(shadow.run(:foo, "a", "c")).to be_a_default_return_value
176
176
  end
177
177
 
178
178
  it "contributes towards unsatisfied interactions" do
179
179
  interactions = shadow.unsatisfied_interactions
180
- interactions.should have(1).item
181
- interactions.first.method.should == :foo
182
- interactions.first.args.should == ["a", "b"]
180
+ expect(interactions).to have(1).item
181
+ expect(interactions.first.method).to eq(:foo)
182
+ expect(interactions.first.args).to eq(["a", "b"])
183
183
  end
184
184
 
185
185
  it "removes the staisfied expectations from unsatisfied interactions" do
@@ -187,7 +187,7 @@ describe Bogus::Shadow do
187
187
  shadow.run(:with_optional_args, 'a', Bogus::DefaultValue)
188
188
  shadow.run(:foo, "a", "b")
189
189
 
190
- shadow.unsatisfied_interactions.should be_empty
190
+ expect(shadow.unsatisfied_interactions).to be_empty
191
191
  end
192
192
 
193
193
  include_examples "spying on shadows"
@@ -0,0 +1,50 @@
1
+ require 'spec_helper'
2
+
3
+ describe "Stubbing existing methods on fakes" do
4
+ include Bogus::MockingDSL
5
+
6
+ before do
7
+ Bogus.clear
8
+ end
9
+
10
+ it "should be possible to stub to_s" do
11
+ foo = fake(:foo) { Samples::Foo }
12
+
13
+ stub(foo).to_s { "I'm a foo" }
14
+
15
+ expect(foo.to_s).to eq("I'm a foo")
16
+ end
17
+
18
+ it "should be possible to mock to_s" do
19
+ foo = fake(:foo) { Samples::Foo }
20
+
21
+ mock(foo).to_s { "I'm a foo" }
22
+
23
+ expect {
24
+ Bogus.after_each_test
25
+ }.to raise_exception(Bogus::NotAllExpectationsSatisfied)
26
+ end
27
+
28
+
29
+ it "should be possible to stub to_s on anonymous fake" do
30
+ foo = fake(to_s: "I'm a foo")
31
+
32
+ expect(foo.to_s).to eq("I'm a foo")
33
+ end
34
+
35
+ class Object
36
+ def sample_method_for_stubbing_existing_methods
37
+ end
38
+ end
39
+
40
+ class SampleForStubbingExistingMethods
41
+ end
42
+
43
+ it "should be possible to stub arbitrary methods that were defined on Object" do
44
+ foo = fake(:foo) { SampleForStubbingExistingMethods }
45
+
46
+ stub(foo).sample_method_for_stubbing_existing_methods { :bar }
47
+
48
+ expect(foo.sample_method_for_stubbing_existing_methods).to eq(:bar)
49
+ end
50
+ end