rspec-expectations 2.11.3 → 3.11.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (152) hide show
  1. checksums.yaml +7 -0
  2. checksums.yaml.gz.sig +0 -0
  3. data/.document +1 -1
  4. data/.yardopts +1 -1
  5. data/Changelog.md +1026 -21
  6. data/{License.txt → LICENSE.md} +5 -3
  7. data/README.md +174 -78
  8. data/lib/rspec/expectations/block_snippet_extractor.rb +253 -0
  9. data/lib/rspec/expectations/configuration.rb +230 -0
  10. data/lib/rspec/expectations/expectation_target.rb +130 -55
  11. data/lib/rspec/expectations/fail_with.rb +17 -33
  12. data/lib/rspec/expectations/failure_aggregator.rb +212 -0
  13. data/lib/rspec/expectations/handler.rb +163 -29
  14. data/lib/rspec/expectations/minitest_integration.rb +58 -0
  15. data/lib/rspec/expectations/syntax.rb +68 -54
  16. data/lib/rspec/expectations/version.rb +1 -1
  17. data/lib/rspec/expectations.rb +59 -24
  18. data/lib/rspec/matchers/aliased_matcher.rb +116 -0
  19. data/lib/rspec/matchers/built_in/all.rb +86 -0
  20. data/lib/rspec/matchers/built_in/base_matcher.rb +150 -20
  21. data/lib/rspec/matchers/built_in/be.rb +115 -109
  22. data/lib/rspec/matchers/built_in/be_between.rb +77 -0
  23. data/lib/rspec/matchers/built_in/be_instance_of.rb +16 -1
  24. data/lib/rspec/matchers/built_in/be_kind_of.rb +10 -1
  25. data/lib/rspec/matchers/built_in/be_within.rb +43 -17
  26. data/lib/rspec/matchers/built_in/change.rb +392 -75
  27. data/lib/rspec/matchers/built_in/compound.rb +290 -0
  28. data/lib/rspec/matchers/built_in/contain_exactly.rb +302 -0
  29. data/lib/rspec/matchers/built_in/count_expectation.rb +169 -0
  30. data/lib/rspec/matchers/built_in/cover.rb +3 -0
  31. data/lib/rspec/matchers/built_in/eq.rb +26 -8
  32. data/lib/rspec/matchers/built_in/eql.rb +19 -8
  33. data/lib/rspec/matchers/built_in/equal.rb +56 -19
  34. data/lib/rspec/matchers/built_in/exist.rb +74 -10
  35. data/lib/rspec/matchers/built_in/has.rb +141 -22
  36. data/lib/rspec/matchers/built_in/have_attributes.rb +114 -0
  37. data/lib/rspec/matchers/built_in/include.rb +175 -20
  38. data/lib/rspec/matchers/built_in/match.rb +95 -1
  39. data/lib/rspec/matchers/built_in/operators.rb +128 -0
  40. data/lib/rspec/matchers/built_in/output.rb +207 -0
  41. data/lib/rspec/matchers/built_in/raise_error.rb +212 -38
  42. data/lib/rspec/matchers/built_in/respond_to.rb +155 -29
  43. data/lib/rspec/matchers/built_in/satisfy.rb +39 -9
  44. data/lib/rspec/matchers/built_in/start_or_end_with.rb +94 -0
  45. data/lib/rspec/matchers/built_in/throw_symbol.rb +58 -14
  46. data/lib/rspec/matchers/built_in/yield.rb +252 -98
  47. data/lib/rspec/matchers/built_in.rb +47 -33
  48. data/lib/rspec/matchers/composable.rb +171 -0
  49. data/lib/rspec/matchers/dsl.rb +530 -10
  50. data/lib/rspec/matchers/english_phrasing.rb +58 -0
  51. data/lib/rspec/matchers/expecteds_for_multiple_diffs.rb +82 -0
  52. data/lib/rspec/matchers/fail_matchers.rb +42 -0
  53. data/lib/rspec/matchers/generated_descriptions.rb +15 -10
  54. data/lib/rspec/matchers/matcher_delegator.rb +35 -0
  55. data/lib/rspec/matchers/matcher_protocol.rb +105 -0
  56. data/lib/rspec/matchers.rb +604 -252
  57. data.tar.gz.sig +0 -0
  58. metadata +178 -278
  59. metadata.gz.sig +0 -0
  60. data/features/README.md +0 -49
  61. data/features/Upgrade.md +0 -53
  62. data/features/built_in_matchers/README.md +0 -90
  63. data/features/built_in_matchers/be.feature +0 -173
  64. data/features/built_in_matchers/be_within.feature +0 -46
  65. data/features/built_in_matchers/cover.feature +0 -45
  66. data/features/built_in_matchers/end_with.feature +0 -46
  67. data/features/built_in_matchers/equality.feature +0 -145
  68. data/features/built_in_matchers/exist.feature +0 -43
  69. data/features/built_in_matchers/expect_change.feature +0 -59
  70. data/features/built_in_matchers/expect_error.feature +0 -138
  71. data/features/built_in_matchers/have.feature +0 -103
  72. data/features/built_in_matchers/include.feature +0 -121
  73. data/features/built_in_matchers/match.feature +0 -50
  74. data/features/built_in_matchers/operators.feature +0 -221
  75. data/features/built_in_matchers/predicates.feature +0 -128
  76. data/features/built_in_matchers/respond_to.feature +0 -78
  77. data/features/built_in_matchers/satisfy.feature +0 -31
  78. data/features/built_in_matchers/start_with.feature +0 -46
  79. data/features/built_in_matchers/throw_symbol.feature +0 -85
  80. data/features/built_in_matchers/types.feature +0 -114
  81. data/features/built_in_matchers/yield.feature +0 -146
  82. data/features/custom_matchers/access_running_example.feature +0 -53
  83. data/features/custom_matchers/define_diffable_matcher.feature +0 -27
  84. data/features/custom_matchers/define_matcher.feature +0 -340
  85. data/features/custom_matchers/define_matcher_outside_rspec.feature +0 -38
  86. data/features/custom_matchers/define_matcher_with_fluent_interface.feature +0 -24
  87. data/features/customized_message.feature +0 -22
  88. data/features/diffing.feature +0 -85
  89. data/features/implicit_docstrings.feature +0 -52
  90. data/features/step_definitions/additional_cli_steps.rb +0 -22
  91. data/features/support/env.rb +0 -5
  92. data/features/syntax_configuration.feature +0 -68
  93. data/features/test_frameworks/test_unit.feature +0 -46
  94. data/lib/rspec/expectations/deprecation.rb +0 -38
  95. data/lib/rspec/expectations/differ.rb +0 -81
  96. data/lib/rspec/expectations/errors.rb +0 -9
  97. data/lib/rspec/expectations/extensions/array.rb +0 -9
  98. data/lib/rspec/expectations/extensions/object.rb +0 -39
  99. data/lib/rspec/expectations/extensions.rb +0 -2
  100. data/lib/rspec/matchers/be_close.rb +0 -9
  101. data/lib/rspec/matchers/built_in/have.rb +0 -108
  102. data/lib/rspec/matchers/built_in/match_array.rb +0 -45
  103. data/lib/rspec/matchers/built_in/start_and_end_with.rb +0 -48
  104. data/lib/rspec/matchers/compatibility.rb +0 -14
  105. data/lib/rspec/matchers/configuration.rb +0 -66
  106. data/lib/rspec/matchers/extensions/instance_eval_with_args.rb +0 -39
  107. data/lib/rspec/matchers/matcher.rb +0 -299
  108. data/lib/rspec/matchers/method_missing.rb +0 -12
  109. data/lib/rspec/matchers/operator_matcher.rb +0 -84
  110. data/lib/rspec/matchers/pretty.rb +0 -60
  111. data/lib/rspec-expectations.rb +0 -1
  112. data/spec/rspec/expectations/differ_spec.rb +0 -153
  113. data/spec/rspec/expectations/expectation_target_spec.rb +0 -65
  114. data/spec/rspec/expectations/extensions/kernel_spec.rb +0 -67
  115. data/spec/rspec/expectations/fail_with_spec.rb +0 -70
  116. data/spec/rspec/expectations/handler_spec.rb +0 -206
  117. data/spec/rspec/matchers/base_matcher_spec.rb +0 -60
  118. data/spec/rspec/matchers/be_close_spec.rb +0 -22
  119. data/spec/rspec/matchers/be_instance_of_spec.rb +0 -40
  120. data/spec/rspec/matchers/be_kind_of_spec.rb +0 -37
  121. data/spec/rspec/matchers/be_spec.rb +0 -452
  122. data/spec/rspec/matchers/be_within_spec.rb +0 -80
  123. data/spec/rspec/matchers/change_spec.rb +0 -528
  124. data/spec/rspec/matchers/configuration_spec.rb +0 -202
  125. data/spec/rspec/matchers/cover_spec.rb +0 -69
  126. data/spec/rspec/matchers/description_generation_spec.rb +0 -176
  127. data/spec/rspec/matchers/dsl_spec.rb +0 -57
  128. data/spec/rspec/matchers/eq_spec.rb +0 -54
  129. data/spec/rspec/matchers/eql_spec.rb +0 -41
  130. data/spec/rspec/matchers/equal_spec.rb +0 -60
  131. data/spec/rspec/matchers/exist_spec.rb +0 -110
  132. data/spec/rspec/matchers/has_spec.rb +0 -118
  133. data/spec/rspec/matchers/have_spec.rb +0 -461
  134. data/spec/rspec/matchers/include_spec.rb +0 -367
  135. data/spec/rspec/matchers/match_array_spec.rb +0 -124
  136. data/spec/rspec/matchers/match_spec.rb +0 -61
  137. data/spec/rspec/matchers/matcher_spec.rb +0 -434
  138. data/spec/rspec/matchers/matchers_spec.rb +0 -31
  139. data/spec/rspec/matchers/method_missing_spec.rb +0 -24
  140. data/spec/rspec/matchers/operator_matcher_spec.rb +0 -221
  141. data/spec/rspec/matchers/raise_error_spec.rb +0 -344
  142. data/spec/rspec/matchers/respond_to_spec.rb +0 -295
  143. data/spec/rspec/matchers/satisfy_spec.rb +0 -44
  144. data/spec/rspec/matchers/start_with_end_with_spec.rb +0 -182
  145. data/spec/rspec/matchers/throw_symbol_spec.rb +0 -116
  146. data/spec/rspec/matchers/yield_spec.rb +0 -402
  147. data/spec/spec_helper.rb +0 -27
  148. data/spec/support/classes.rb +0 -56
  149. data/spec/support/in_sub_process.rb +0 -31
  150. data/spec/support/matchers.rb +0 -22
  151. data/spec/support/ruby_version.rb +0 -10
  152. data/spec/support/shared_examples.rb +0 -13
@@ -1,528 +0,0 @@
1
- #Based on patch from Wilson Bilkovich
2
-
3
- require 'spec_helper'
4
-
5
- class SomethingExpected
6
- attr_accessor :some_value
7
- end
8
-
9
- describe "should change(actual, message)" do
10
- context "with a numeric value" do
11
- before(:each) do
12
- @instance = SomethingExpected.new
13
- @instance.some_value = 5
14
- end
15
-
16
- it "passes when actual is modified by the block" do
17
- expect {@instance.some_value = 6.0}.to change(@instance, :some_value)
18
- end
19
-
20
- it "fails when actual is not modified by the block" do
21
- expect do
22
- expect {}.to change(@instance, :some_value)
23
- end.to fail_with("some_value should have changed, but is still 5")
24
- end
25
-
26
- it "provides a #description" do
27
- change(@instance, :some_value).description.should == "change #some_value"
28
- end
29
- end
30
-
31
- context "with boolean values" do
32
- before(:each) do
33
- @instance = SomethingExpected.new
34
- @instance.some_value = true
35
- end
36
-
37
- it "passes when actual is modified by the block" do
38
- expect {@instance.some_value = false}.to change(@instance, :some_value)
39
- end
40
-
41
- it "fails when actual is not modified by the block" do
42
- expect do
43
- expect {}.to change(@instance, :some_value)
44
- end.to fail_with("some_value should have changed, but is still true")
45
- end
46
- end
47
-
48
- context "with nil value" do
49
- before(:each) do
50
- @instance = SomethingExpected.new
51
- @instance.some_value = nil
52
- end
53
-
54
- it "passes when actual is modified by the block" do
55
- expect {@instance.some_value = false}.to change(@instance, :some_value)
56
- end
57
-
58
- it "fails when actual is not modified by the block" do
59
- expect do
60
- expect {}.to change(@instance, :some_value)
61
- end.to fail_with("some_value should have changed, but is still nil")
62
- end
63
- end
64
-
65
- context "with an array" do
66
- before(:each) do
67
- @instance = SomethingExpected.new
68
- @instance.some_value = []
69
- end
70
-
71
- it "passes when actual is modified by the block" do
72
- expect {@instance.some_value << 1}.to change(@instance, :some_value)
73
- end
74
-
75
- it "fails when actual is not modified by the block" do
76
- expect do
77
- expect {}.to change(@instance, :some_value)
78
- end.to fail_with("some_value should have changed, but is still []")
79
- end
80
- end
81
-
82
- context "with a hash" do
83
- before(:each) do
84
- @instance = SomethingExpected.new
85
- @instance.some_value = {:a => 'a'}
86
- end
87
-
88
- it "passes when actual is modified by the block" do
89
- expect {@instance.some_value[:a] = 'A'}.to change(@instance, :some_value)
90
- end
91
-
92
- it "fails when actual is not modified by the block" do
93
- expect do
94
- expect {}.to change(@instance, :some_value)
95
- end.to fail
96
- end
97
- end
98
-
99
- context "with an arbitrary enumerable" do
100
- before(:each) do
101
- @instance = SomethingExpected.new
102
- @instance.some_value = Class.new do
103
- include Enumerable
104
-
105
- attr_reader :elements
106
-
107
- def initialize(*elements)
108
- @elements = elements.dup
109
- end
110
-
111
- def <<(element)
112
- elements << element
113
- end
114
-
115
- def dup
116
- self.class.new(*elements)
117
- end
118
-
119
- def ==(other)
120
- elements == other.elements
121
- end
122
- end.new
123
- end
124
-
125
- it "passes when actual is modified by the block" do
126
- expect {@instance.some_value << 1}.to change(@instance, :some_value)
127
- end
128
-
129
- it "fails when actual is not modified by the block" do
130
- expect do
131
- expect {}.to change(@instance, :some_value)
132
- end.to fail_with(/^some_value should have changed, but is still/)
133
- end
134
-
135
- end
136
- end
137
-
138
- describe "should_not change(actual, message)" do
139
- before(:each) do
140
- @instance = SomethingExpected.new
141
- @instance.some_value = 5
142
- end
143
-
144
- it "passes when actual is not modified by the block" do
145
- expect { }.to_not change(@instance, :some_value)
146
- end
147
-
148
- it "fails when actual is not modified by the block" do
149
- expect do
150
- expect {@instance.some_value = 6}.to_not change(@instance, :some_value)
151
- end.to fail_with("some_value should not have changed, but did change from 5 to 6")
152
- end
153
- end
154
-
155
- describe "should change { block }" do
156
- o = SomethingExpected.new
157
- it_behaves_like "an RSpec matcher", :valid_value => lambda { o.some_value = 5 },
158
- :invalid_value => lambda { } do
159
- let(:matcher) { change { o.some_value } }
160
- end
161
-
162
- before(:each) do
163
- @instance = SomethingExpected.new
164
- @instance.some_value = 5
165
- end
166
-
167
- it "passes when actual is modified by the block" do
168
- expect {@instance.some_value = 6}.to change { @instance.some_value }
169
- end
170
-
171
- it "fails when actual is not modified by the block" do
172
- expect do
173
- expect {}.to change{ @instance.some_value }
174
- end.to fail_with("result should have changed, but is still 5")
175
- end
176
-
177
- it "warns if passed a block using do/end instead of {}" do
178
- expect do
179
- expect {}.to change do; end
180
- end.to raise_error(SyntaxError, /block passed to should or should_not/)
181
- end
182
-
183
- it "provides a #description" do
184
- change { @instance.some_value }.description.should == "change #result"
185
- end
186
- end
187
-
188
- describe "should_not change { block }" do
189
- before(:each) do
190
- @instance = SomethingExpected.new
191
- @instance.some_value = 5
192
- end
193
-
194
- it "passes when actual is modified by the block" do
195
- expect {}.to_not change{ @instance.some_value }
196
- end
197
-
198
- it "fails when actual is not modified by the block" do
199
- expect do
200
- expect {@instance.some_value = 6}.to_not change { @instance.some_value }
201
- end.to fail_with("result should not have changed, but did change from 5 to 6")
202
- end
203
-
204
- it "warns if passed a block using do/end instead of {}" do
205
- expect do
206
- expect {}.to_not change do; end
207
- end.to raise_error(SyntaxError, /block passed to should or should_not/)
208
- end
209
- end
210
-
211
- describe "should change(actual, message).by(expected)" do
212
- before(:each) do
213
- @instance = SomethingExpected.new
214
- @instance.some_value = 5
215
- end
216
-
217
- it "passes when attribute is changed by expected amount" do
218
- expect { @instance.some_value += 1 }.to change(@instance, :some_value).by(1)
219
- end
220
-
221
- it "passes when attribute is not changed and expected amount is 0" do
222
- expect { @instance.some_value += 0 }.to change(@instance, :some_value).by(0)
223
- end
224
-
225
- it "fails when the attribute is changed by unexpected amount" do
226
- expect do
227
- expect { @instance.some_value += 2 }.to change(@instance, :some_value).by(1)
228
- end.to fail_with("some_value should have been changed by 1, but was changed by 2")
229
- end
230
-
231
- it "fails when the attribute is changed by unexpected amount in the opposite direction" do
232
- expect do
233
- expect { @instance.some_value -= 1 }.to change(@instance, :some_value).by(1)
234
- end.to fail_with("some_value should have been changed by 1, but was changed by -1")
235
- end
236
- end
237
-
238
- describe "should change{ block }.by(expected)" do
239
- before(:each) do
240
- @instance = SomethingExpected.new
241
- @instance.some_value = 5
242
- end
243
-
244
- it "passes when attribute is changed by expected amount" do
245
- expect { @instance.some_value += 1 }.to change{@instance.some_value}.by(1)
246
- end
247
-
248
- it "fails when the attribute is changed by unexpected amount" do
249
- expect do
250
- expect { @instance.some_value += 2 }.to change{@instance.some_value}.by(1)
251
- end.to fail_with("result should have been changed by 1, but was changed by 2")
252
- end
253
-
254
- it "fails when the attribute is changed by unexpected amount in the opposite direction" do
255
- expect do
256
- expect { @instance.some_value -= 1 }.to change{@instance.some_value}.by(1)
257
- end.to fail_with("result should have been changed by 1, but was changed by -1")
258
- end
259
- end
260
-
261
- describe "should change(actual, message).by_at_least(expected)" do
262
- before(:each) do
263
- @instance = SomethingExpected.new
264
- @instance.some_value = 5
265
- end
266
-
267
- it "passes when attribute is changed by greater than the expected amount" do
268
- expect { @instance.some_value += 2 }.to change(@instance, :some_value).by_at_least(1)
269
- end
270
-
271
- it "passes when attribute is changed by the expected amount" do
272
- expect { @instance.some_value += 2 }.to change(@instance, :some_value).by_at_least(2)
273
- end
274
-
275
- it "fails when the attribute is changed by less than the expected amount" do
276
- expect do
277
- expect { @instance.some_value += 1 }.to change(@instance, :some_value).by_at_least(2)
278
- end.to fail_with("some_value should have been changed by at least 2, but was changed by 1")
279
- end
280
-
281
- end
282
-
283
- describe "should change{ block }.by_at_least(expected)" do
284
- before(:each) do
285
- @instance = SomethingExpected.new
286
- @instance.some_value = 5
287
- end
288
-
289
- it "passes when attribute is changed by greater than expected amount" do
290
- expect { @instance.some_value += 2 }.to change{@instance.some_value}.by_at_least(1)
291
- end
292
-
293
- it "passes when attribute is changed by the expected amount" do
294
- expect { @instance.some_value += 2 }.to change{@instance.some_value}.by_at_least(2)
295
- end
296
-
297
- it "fails when the attribute is changed by less than the unexpected amount" do
298
- expect do
299
- expect { @instance.some_value += 1 }.to change{@instance.some_value}.by_at_least(2)
300
- end.to fail_with("result should have been changed by at least 2, but was changed by 1")
301
- end
302
- end
303
-
304
-
305
- describe "should change(actual, message).by_at_most(expected)" do
306
- before(:each) do
307
- @instance = SomethingExpected.new
308
- @instance.some_value = 5
309
- end
310
-
311
- it "passes when attribute is changed by less than the expected amount" do
312
- expect { @instance.some_value += 2 }.to change(@instance, :some_value).by_at_most(3)
313
- end
314
-
315
- it "passes when attribute is changed by the expected amount" do
316
- expect { @instance.some_value += 2 }.to change(@instance, :some_value).by_at_most(2)
317
- end
318
-
319
- it "fails when the attribute is changed by greater than the expected amount" do
320
- expect do
321
- expect { @instance.some_value += 2 }.to change(@instance, :some_value).by_at_most(1)
322
- end.to fail_with("some_value should have been changed by at most 1, but was changed by 2")
323
- end
324
-
325
- end
326
-
327
- describe "should change{ block }.by_at_most(expected)" do
328
- before(:each) do
329
- @instance = SomethingExpected.new
330
- @instance.some_value = 5
331
- end
332
-
333
- it "passes when attribute is changed by less than expected amount" do
334
- expect { @instance.some_value += 2 }.to change{@instance.some_value}.by_at_most(3)
335
- end
336
-
337
- it "passes when attribute is changed by the expected amount" do
338
- expect { @instance.some_value += 2 }.to change{@instance.some_value}.by_at_most(2)
339
- end
340
-
341
- it "fails when the attribute is changed by greater than the unexpected amount" do
342
- expect do
343
- expect { @instance.some_value += 2 }.to change{@instance.some_value}.by_at_most(1)
344
- end.to fail_with("result should have been changed by at most 1, but was changed by 2")
345
- end
346
- end
347
-
348
- describe "should change(actual, message).from(old)" do
349
- context "with boolean values" do
350
- before(:each) do
351
- @instance = SomethingExpected.new
352
- @instance.some_value = true
353
- end
354
-
355
- it "passes when attribute is == to expected value before executing block" do
356
- expect { @instance.some_value = false }.to change(@instance, :some_value).from(true)
357
- end
358
-
359
- it "fails when attribute is not == to expected value before executing block" do
360
- expect do
361
- expect { @instance.some_value = 'foo' }.to change(@instance, :some_value).from(false)
362
- end.to fail_with("some_value should have initially been false, but was true")
363
- end
364
- end
365
- context "with non-boolean values" do
366
- before(:each) do
367
- @instance = SomethingExpected.new
368
- @instance.some_value = 'string'
369
- end
370
-
371
- it "passes when attribute is === to expected value before executing block" do
372
- expect { @instance.some_value = "astring" }.to change(@instance, :some_value).from("string")
373
- end
374
-
375
- it "compares the expected and actual values with ===" do
376
- expected = "string"
377
- expected.should_receive(:===).and_return true
378
- expect { @instance.some_value = "astring" }.to change(@instance, :some_value).from(expected)
379
- end
380
-
381
- it "fails when attribute is not === to expected value before executing block" do
382
- expect do
383
- expect { @instance.some_value = "knot" }.to change(@instance, :some_value).from("cat")
384
- end.to fail_with("some_value should have initially been \"cat\", but was \"string\"")
385
- end
386
- end
387
- end
388
-
389
- describe "should change{ block }.from(old)" do
390
- before(:each) do
391
- @instance = SomethingExpected.new
392
- @instance.some_value = 'string'
393
- end
394
-
395
- it "passes when attribute is === to expected value before executing block" do
396
- expect { @instance.some_value = "astring" }.to change{@instance.some_value}.from("string")
397
- end
398
-
399
- it "compares the expected and actual values with ===" do
400
- expected = "string"
401
- expected.should_receive(:===).and_return true
402
- expect { @instance.some_value = "astring" }.to change{@instance.some_value}.from(expected)
403
- end
404
-
405
- it "fails when attribute is not === to expected value before executing block" do
406
- expect do
407
- expect { @instance.some_value = "knot" }.to change{@instance.some_value}.from("cat")
408
- end.to fail_with("result should have initially been \"cat\", but was \"string\"")
409
- end
410
- end
411
-
412
- describe "should change(actual, message).to(new)" do
413
- context "with boolean values" do
414
- before(:each) do
415
- @instance = SomethingExpected.new
416
- @instance.some_value = true
417
- end
418
-
419
- it "passes when attribute is == to expected value after executing block" do
420
- expect { @instance.some_value = false }.to change(@instance, :some_value).to(false)
421
- end
422
-
423
- it "fails when attribute is not == to expected value after executing block" do
424
- expect do
425
- expect { @instance.some_value = 1 }.to change(@instance, :some_value).from(true).to(false)
426
- end.to fail_with("some_value should have been changed to false, but is now 1")
427
- end
428
- end
429
- context "with non-boolean values" do
430
- before(:each) do
431
- @instance = SomethingExpected.new
432
- @instance.some_value = 'string'
433
- end
434
-
435
- it "passes when attribute is === to expected value after executing block" do
436
- expect { @instance.some_value = "cat" }.to change(@instance, :some_value).to("cat")
437
- end
438
-
439
- it "compares the expected and actual values with ===" do
440
- expected = "cat"
441
- expected.should_receive(:===).and_return true
442
- expect { @instance.some_value = "cat" }.to change(@instance, :some_value).to(expected)
443
- end
444
-
445
- it "fails when attribute is not === to expected value after executing block" do
446
- expect do
447
- expect { @instance.some_value = "cat" }.to change(@instance, :some_value).from("string").to("dog")
448
- end.to fail_with("some_value should have been changed to \"dog\", but is now \"cat\"")
449
- end
450
- end
451
- end
452
-
453
- describe "should change{ block }.to(new)" do
454
- before(:each) do
455
- @instance = SomethingExpected.new
456
- @instance.some_value = 'string'
457
- end
458
-
459
- it "passes when attribute is === to expected value after executing block" do
460
- expect { @instance.some_value = "cat" }.to change{@instance.some_value}.to("cat")
461
- end
462
-
463
- it "compares the expected and actual values with ===" do
464
- expected = "cat"
465
- expected.should_receive(:===).and_return true
466
- expect { @instance.some_value = "cat" }.to change{@instance.some_value}.to(expected)
467
- end
468
-
469
- it "fails when attribute is not === to expected value after executing block" do
470
- expect do
471
- expect { @instance.some_value = "cat" }.to change{@instance.some_value}.from("string").to("dog")
472
- end.to fail_with("result should have been changed to \"dog\", but is now \"cat\"")
473
- end
474
- end
475
-
476
- describe "should change(actual, message).from(old).to(new)" do
477
- before(:each) do
478
- @instance = SomethingExpected.new
479
- @instance.some_value = 'string'
480
- end
481
-
482
- it "passes when #to comes before #from" do
483
- expect { @instance.some_value = "cat" }.to change(@instance, :some_value).to("cat").from("string")
484
- end
485
-
486
- it "passes when #from comes before #to" do
487
- expect { @instance.some_value = "cat" }.to change(@instance, :some_value).from("string").to("cat")
488
- end
489
-
490
- it "shows the correct messaging when #after and #to are different" do
491
- expect do
492
- expect { @instance.some_value = "cat" }.to change(@instance, :some_value).from("string").to("dog")
493
- end.to fail_with("some_value should have been changed to \"dog\", but is now \"cat\"")
494
- end
495
-
496
- it "shows the correct messaging when #before and #from are different" do
497
- expect do
498
- expect { @instance.some_value = "cat" }.to change(@instance, :some_value).from("not_string").to("cat")
499
- end.to fail_with("some_value should have initially been \"not_string\", but was \"string\"")
500
- end
501
- end
502
-
503
- describe "should change{ block }.from(old).to(new)" do
504
- before(:each) do
505
- @instance = SomethingExpected.new
506
- @instance.some_value = 'string'
507
- end
508
-
509
- it "passes when #to comes before #from" do
510
- expect { @instance.some_value = "cat" }.to change{@instance.some_value}.to("cat").from("string")
511
- end
512
-
513
- it "passes when #from comes before #to" do
514
- expect { @instance.some_value = "cat" }.to change{@instance.some_value}.from("string").to("cat")
515
- end
516
- end
517
-
518
- describe RSpec::Matchers::BuiltIn::Change do
519
- it "works when the receiver has implemented #send" do
520
- @instance = SomethingExpected.new
521
- @instance.some_value = "string"
522
- def @instance.send(*args); raise "DOH! Library developers shouldn't use #send!" end
523
-
524
- expect {
525
- expect { @instance.some_value = "cat" }.to change(@instance, :some_value)
526
- }.to_not raise_error
527
- end
528
- end