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