rspec-expectations 3.0.0.beta1 → 3.0.0.beta2

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 (122) hide show
  1. data.tar.gz.sig +2 -2
  2. data/.yardopts +1 -0
  3. data/Changelog.md +138 -0
  4. data/README.md +75 -8
  5. data/features/README.md +2 -2
  6. data/features/built_in_matchers/README.md +12 -9
  7. data/features/built_in_matchers/comparisons.feature +2 -2
  8. data/features/built_in_matchers/contain_exactly.feature +46 -0
  9. data/features/built_in_matchers/expect_change.feature +2 -2
  10. data/features/built_in_matchers/include.feature +0 -48
  11. data/features/built_in_matchers/output.feature +70 -0
  12. data/features/composing_matchers.feature +250 -0
  13. data/features/compound_expectations.feature +45 -0
  14. data/features/custom_matchers/access_running_example.feature +1 -1
  15. data/features/custom_matchers/define_matcher.feature +6 -6
  16. data/features/custom_matchers/define_matcher_outside_rspec.feature +4 -8
  17. data/features/test_frameworks/{test_unit.feature → minitest.feature} +11 -11
  18. data/lib/rspec/expectations.rb +31 -42
  19. data/lib/rspec/expectations/diff_presenter.rb +141 -0
  20. data/lib/rspec/expectations/differ.rb +22 -132
  21. data/lib/rspec/expectations/encoded_string.rb +56 -0
  22. data/lib/rspec/expectations/expectation_target.rb +0 -30
  23. data/lib/rspec/expectations/fail_with.rb +2 -2
  24. data/lib/rspec/expectations/handler.rb +128 -31
  25. data/lib/rspec/expectations/minitest_integration.rb +16 -0
  26. data/lib/rspec/expectations/syntax.rb +4 -58
  27. data/lib/rspec/expectations/version.rb +1 -1
  28. data/lib/rspec/matchers.rb +298 -60
  29. data/lib/rspec/matchers/aliased_matcher.rb +35 -0
  30. data/lib/rspec/matchers/built_in.rb +37 -33
  31. data/lib/rspec/matchers/built_in/base_matcher.rb +25 -15
  32. data/lib/rspec/matchers/built_in/be.rb +23 -31
  33. data/lib/rspec/matchers/built_in/be_between.rb +55 -0
  34. data/lib/rspec/matchers/built_in/be_within.rb +15 -11
  35. data/lib/rspec/matchers/built_in/change.rb +198 -81
  36. data/lib/rspec/matchers/built_in/compound.rb +106 -0
  37. data/lib/rspec/matchers/built_in/contain_exactly.rb +245 -0
  38. data/lib/rspec/matchers/built_in/eq.rb +43 -4
  39. data/lib/rspec/matchers/built_in/eql.rb +2 -2
  40. data/lib/rspec/matchers/built_in/equal.rb +35 -18
  41. data/lib/rspec/matchers/built_in/has.rb +16 -15
  42. data/lib/rspec/matchers/built_in/include.rb +45 -23
  43. data/lib/rspec/matchers/built_in/match.rb +6 -3
  44. data/lib/rspec/matchers/built_in/operators.rb +103 -0
  45. data/lib/rspec/matchers/built_in/output.rb +108 -0
  46. data/lib/rspec/matchers/built_in/raise_error.rb +9 -15
  47. data/lib/rspec/matchers/built_in/respond_to.rb +5 -4
  48. data/lib/rspec/matchers/built_in/satisfy.rb +4 -3
  49. data/lib/rspec/matchers/built_in/start_and_end_with.rb +37 -16
  50. data/lib/rspec/matchers/built_in/throw_symbol.rb +6 -5
  51. data/lib/rspec/matchers/built_in/yield.rb +31 -29
  52. data/lib/rspec/matchers/composable.rb +138 -0
  53. data/lib/rspec/matchers/dsl.rb +330 -0
  54. data/lib/rspec/matchers/generated_descriptions.rb +6 -6
  55. data/lib/rspec/matchers/matcher_delegator.rb +33 -0
  56. data/lib/rspec/matchers/pretty.rb +13 -2
  57. data/spec/rspec/expectations/{differ_spec.rb → diff_presenter_spec.rb} +56 -36
  58. data/spec/rspec/expectations/encoded_string_spec.rb +74 -0
  59. data/spec/rspec/expectations/extensions/kernel_spec.rb +11 -11
  60. data/spec/rspec/expectations/fail_with_spec.rb +8 -8
  61. data/spec/rspec/expectations/handler_spec.rb +27 -49
  62. data/spec/rspec/expectations/minitest_integration_spec.rb +27 -0
  63. data/spec/rspec/expectations/syntax_spec.rb +17 -67
  64. data/spec/rspec/expectations_spec.rb +7 -52
  65. data/spec/rspec/matchers/aliased_matcher_spec.rb +48 -0
  66. data/spec/rspec/matchers/aliases_spec.rb +449 -0
  67. data/spec/rspec/matchers/{base_matcher_spec.rb → built_in/base_matcher_spec.rb} +24 -3
  68. data/spec/rspec/matchers/built_in/be_between_spec.rb +159 -0
  69. data/spec/rspec/matchers/{be_instance_of_spec.rb → built_in/be_instance_of_spec.rb} +0 -0
  70. data/spec/rspec/matchers/{be_kind_of_spec.rb → built_in/be_kind_of_spec.rb} +0 -0
  71. data/spec/rspec/matchers/{be_spec.rb → built_in/be_spec.rb} +76 -32
  72. data/spec/rspec/matchers/{be_within_spec.rb → built_in/be_within_spec.rb} +6 -2
  73. data/spec/rspec/matchers/{change_spec.rb → built_in/change_spec.rb} +310 -69
  74. data/spec/rspec/matchers/built_in/compound_spec.rb +292 -0
  75. data/spec/rspec/matchers/built_in/contain_exactly_spec.rb +441 -0
  76. data/spec/rspec/matchers/{cover_spec.rb → built_in/cover_spec.rb} +0 -0
  77. data/spec/rspec/matchers/built_in/eq_spec.rb +156 -0
  78. data/spec/rspec/matchers/{eql_spec.rb → built_in/eql_spec.rb} +2 -2
  79. data/spec/rspec/matchers/built_in/equal_spec.rb +106 -0
  80. data/spec/rspec/matchers/{exist_spec.rb → built_in/exist_spec.rb} +1 -1
  81. data/spec/rspec/matchers/{has_spec.rb → built_in/has_spec.rb} +39 -0
  82. data/spec/rspec/matchers/{include_spec.rb → built_in/include_spec.rb} +118 -109
  83. data/spec/rspec/matchers/{match_spec.rb → built_in/match_spec.rb} +30 -2
  84. data/spec/rspec/matchers/{operator_matcher_spec.rb → built_in/operators_spec.rb} +26 -26
  85. data/spec/rspec/matchers/built_in/output_spec.rb +165 -0
  86. data/spec/rspec/matchers/{raise_error_spec.rb → built_in/raise_error_spec.rb} +81 -11
  87. data/spec/rspec/matchers/{respond_to_spec.rb → built_in/respond_to_spec.rb} +0 -0
  88. data/spec/rspec/matchers/{satisfy_spec.rb → built_in/satisfy_spec.rb} +0 -0
  89. data/spec/rspec/matchers/{start_with_end_with_spec.rb → built_in/start_and_end_with_spec.rb} +82 -15
  90. data/spec/rspec/matchers/{throw_symbol_spec.rb → built_in/throw_symbol_spec.rb} +29 -10
  91. data/spec/rspec/matchers/{yield_spec.rb → built_in/yield_spec.rb} +90 -0
  92. data/spec/rspec/matchers/configuration_spec.rb +7 -39
  93. data/spec/rspec/matchers/description_generation_spec.rb +22 -6
  94. data/spec/rspec/matchers/dsl_spec.rb +838 -0
  95. data/spec/rspec/matchers/legacy_spec.rb +101 -0
  96. data/spec/rspec/matchers_spec.rb +74 -0
  97. data/spec/spec_helper.rb +35 -21
  98. data/spec/support/shared_examples.rb +26 -4
  99. metadata +172 -116
  100. metadata.gz.sig +3 -4
  101. checksums.yaml +0 -15
  102. checksums.yaml.gz.sig +0 -0
  103. data/features/built_in_matchers/match_array.feature +0 -37
  104. data/lib/rspec/expectations/errors.rb +0 -9
  105. data/lib/rspec/expectations/extensions.rb +0 -1
  106. data/lib/rspec/expectations/extensions/object.rb +0 -29
  107. data/lib/rspec/matchers/built_in/match_array.rb +0 -51
  108. data/lib/rspec/matchers/compatibility.rb +0 -14
  109. data/lib/rspec/matchers/matcher.rb +0 -301
  110. data/lib/rspec/matchers/method_missing.rb +0 -12
  111. data/lib/rspec/matchers/operator_matcher.rb +0 -99
  112. data/lib/rspec/matchers/test_unit_integration.rb +0 -11
  113. data/spec/rspec/matchers/eq_spec.rb +0 -60
  114. data/spec/rspec/matchers/equal_spec.rb +0 -78
  115. data/spec/rspec/matchers/include_matcher_integration_spec.rb +0 -30
  116. data/spec/rspec/matchers/match_array_spec.rb +0 -194
  117. data/spec/rspec/matchers/matcher_spec.rb +0 -706
  118. data/spec/rspec/matchers/matchers_spec.rb +0 -36
  119. data/spec/rspec/matchers/method_missing_spec.rb +0 -28
  120. data/spec/support/classes.rb +0 -56
  121. data/spec/support/in_sub_process.rb +0 -37
  122. data/spec/support/ruby_version.rb +0 -10
@@ -39,7 +39,28 @@ module RSpec::Matchers::BuiltIn
39
39
 
40
40
  end
41
41
 
42
- describe "#==" do
42
+ describe "#failure_message" do
43
+ context "when the parameter to .new is omitted" do
44
+ it "describes what was expected" do
45
+ matcher_class = Class.new(BaseMatcher) do
46
+ def name=(name)
47
+ @name = name
48
+ end
49
+
50
+ def match(expected, actual)
51
+ false
52
+ end
53
+ end
54
+
55
+ matcher = matcher_class.new
56
+ matcher.name = "be something"
57
+ matcher.matches?("foo")
58
+ expect(matcher.failure_message).to eq('expected "foo" to be something')
59
+ end
60
+ end
61
+ end
62
+
63
+ describe "#===" do
43
64
  it "responds the same way as matches?" do
44
65
  matcher = Class.new(BaseMatcher) do
45
66
  def initialize(expected)
@@ -52,10 +73,10 @@ module RSpec::Matchers::BuiltIn
52
73
  end
53
74
 
54
75
  expect(matcher.new(3).matches?(3)).to be_truthy
55
- expect(matcher.new(3)).to eq(3)
76
+ expect(matcher.new(3)).to be === 3
56
77
 
57
78
  expect(matcher.new(3).matches?(4)).to be_falsey
58
- expect(matcher.new(3)).not_to eq(4)
79
+ expect(matcher.new(3)).not_to be === 4
59
80
  end
60
81
  end
61
82
  end
@@ -0,0 +1,159 @@
1
+ require 'spec_helper'
2
+
3
+ module RSpec::Matchers::BuiltIn
4
+ describe BeBetween do
5
+ class SizeMatters
6
+ include Comparable
7
+ attr :str
8
+ def <=>(other)
9
+ str.size <=> other.str.size
10
+ end
11
+ def initialize(str)
12
+ @str = str
13
+ end
14
+ def inspect
15
+ @str
16
+ end
17
+ end
18
+
19
+ shared_examples_for "be_between" do |mode|
20
+ it "passes if target is between min and max" do
21
+ expect(5).to matcher(1, 10)
22
+ end
23
+
24
+ it "fails if target is not between min and max" do
25
+ expect {
26
+ # It does not go to 11
27
+ expect(11).to matcher(1, 10)
28
+ }.to fail_with("expected 11 to be between 1 and 10 (#{mode})")
29
+ end
30
+
31
+ it "works with strings" do
32
+ expect("baz").to matcher("bar", "foo")
33
+
34
+ expect {
35
+ expect("foo").to matcher("bar", "baz")
36
+ }.to fail_with("expected \"foo\" to be between \"bar\" and \"baz\" (#{mode})")
37
+ end
38
+
39
+ it "works with other Comparable objects" do
40
+ expect(SizeMatters.new("--")).to matcher(SizeMatters.new("-"), SizeMatters.new("---"))
41
+
42
+ expect {
43
+ expect(SizeMatters.new("---")).to matcher(SizeMatters.new("-"), SizeMatters.new("--"))
44
+ }.to fail_with("expected --- to be between - and -- (#{mode})")
45
+ end
46
+ end
47
+
48
+ shared_examples_for "not_to be_between" do |mode|
49
+ it "passes if target is not between min and max" do
50
+ expect(11).not_to matcher(1, 10)
51
+ end
52
+
53
+ it "fails if target is between min and max" do
54
+ expect {
55
+ expect(5).not_to matcher(1, 10)
56
+ }.to fail_with("expected 5 not to be between 1 and 10 (#{mode})")
57
+ end
58
+ end
59
+
60
+ shared_examples_for "composing with other matchers" do |mode|
61
+ it "passes when the matchers both match" do
62
+ expect([nil, 3]).to include(matcher(2, 4), a_nil_value)
63
+ end
64
+
65
+ it "works with mixed types" do
66
+ expect(["baz", Math::PI]).to include(matcher(3.1, 3.2), matcher("bar", "foo"))
67
+
68
+ expect {
69
+ expect(["baz", 2.14]).to include(matcher(3.1, 3.2), matcher("bar", "foo") )
70
+ }.to fail_with("expected [\"baz\", 2.14] to include (a value between 3.1 and 3.2 (#{mode})) and (a value between \"bar\" and \"foo\" (#{mode}))")
71
+ end
72
+
73
+ it "provides a description" do
74
+ description = include(matcher(2, 4), an_instance_of(Float)).description
75
+ expect(description).to eq("include (a value between 2 and 4 (#{mode})) and (an instance of Float)")
76
+ end
77
+
78
+ it "fails with a clear error message when the matchers do not match" do
79
+ expect {
80
+ expect([nil, 1]).to include(matcher(2, 4), a_nil_value)
81
+ }.to fail_with("expected [nil, 1] to include (a value between 2 and 4 (#{mode})) and (a nil value)")
82
+ end
83
+ end
84
+
85
+ it_behaves_like "an RSpec matcher", :valid_value => (10), :invalid_value => (11) do
86
+ let(:matcher) { be_between(1, 10) }
87
+ end
88
+
89
+ describe "expect(...).to be_between(min, max) (inclusive)" do
90
+ it_behaves_like "be_between", :inclusive do
91
+ def matcher(min, max)
92
+ be_between(min, max)
93
+ end
94
+ end
95
+
96
+ it "is inclusive" do
97
+ expect(1).to be_between(1, 10)
98
+ expect(10).to be_between(1, 10)
99
+ end
100
+
101
+ it "indicates it was not comparable if it does not respond to `<=` and `>=`" do
102
+ expect {
103
+ expect(nil).to be_between(0, 10)
104
+ }.to fail_with("expected nil to be between 0 and 10 (inclusive), but it does not respond to `<=` and `>=`")
105
+ end
106
+ end
107
+
108
+ describe "expect(...).to be_between(min, max) (exclusive)" do
109
+ it_behaves_like "be_between", :exclusive do
110
+ def matcher(min, max)
111
+ be_between(min, max).exclusive
112
+ end
113
+ end
114
+
115
+ it "indicates it was not comparable if it does not respond to `<` and `>`" do
116
+ expect {
117
+ expect(nil).to be_between(0, 10).exclusive
118
+ }.to fail_with("expected nil to be between 0 and 10 (exclusive), but it does not respond to `<` and `>`")
119
+ end
120
+
121
+ it "is exclusive" do
122
+ expect { expect(1).to be_between(1, 10).exclusive }.to fail
123
+ expect { expect(10).to be_between(1, 10).exclusive }.to fail
124
+ end
125
+ end
126
+
127
+ describe "expect(...).not_to be_between(min, max) (inclusive)" do
128
+ it_behaves_like "not_to be_between", :inclusive do
129
+ def matcher(min, max)
130
+ be_between(min, max)
131
+ end
132
+ end
133
+ end
134
+
135
+ describe "expect(...).not_to be_between(min, max) (exclusive)" do
136
+ it_behaves_like "not_to be_between", :exclusive do
137
+ def matcher(min, max)
138
+ be_between(min, max).exclusive
139
+ end
140
+ end
141
+ end
142
+
143
+ describe "composing with other matchers (inclusive)" do
144
+ it_behaves_like "composing with other matchers", :inclusive do
145
+ def matcher(min, max)
146
+ a_value_between(min, max)
147
+ end
148
+ end
149
+ end
150
+
151
+ describe "composing with other matchers (exclusive)" do
152
+ it_behaves_like "composing with other matchers", :exclusive do
153
+ def matcher(min, max)
154
+ a_value_between(min, max).exclusive
155
+ end
156
+ end
157
+ end
158
+ end
159
+ end
@@ -6,6 +6,23 @@ describe "expect(...).to be_predicate" do
6
6
  expect(actual).to be_happy
7
7
  end
8
8
 
9
+ it 'allows composable aliases to be defined' do
10
+ RSpec::Matchers.alias_matcher :a_user_who_is_happy, :be_happy
11
+ actual = double("actual", :happy? => true)
12
+ expect(actual).to a_user_who_is_happy
13
+ expect(a_user_who_is_happy.description).to eq("a user who is happy")
14
+
15
+ RSpec::Matchers.alias_matcher :a_user_who_is_an_admin, :be_an_admin
16
+ actual = double("actual", :admin? => true)
17
+ expect(actual).to a_user_who_is_an_admin
18
+ expect(a_user_who_is_an_admin.description).to eq("a user who is an admin")
19
+
20
+ RSpec::Matchers.alias_matcher :an_animal_that_is_a_canine, :be_a_canine
21
+ actual = double("actual", :canine? => true)
22
+ expect(actual).to an_animal_that_is_a_canine
23
+ expect(an_animal_that_is_a_canine.description).to eq("an animal that is a canine")
24
+ end
25
+
9
26
  it "passes when actual returns true for :predicates? (present tense)" do
10
27
  actual = double("actual", :exists? => true, :exist? => true)
11
28
  expect(actual).to be_exist
@@ -43,7 +60,7 @@ describe "expect(...).to be_predicate" do
43
60
 
44
61
  it "fails on error other than NameError" do
45
62
  actual = double("actual")
46
- actual.should_receive(:foo?).and_raise("aaaah")
63
+ expect(actual).to receive(:foo?).and_raise("aaaah")
47
64
  expect {
48
65
  expect(actual).to be_foo
49
66
  }.to raise_error(/aaaah/)
@@ -51,7 +68,7 @@ describe "expect(...).to be_predicate" do
51
68
 
52
69
  it "fails on error other than NameError (with the present tense predicate)" do
53
70
  actual = Object.new
54
- actual.should_receive(:foos?).and_raise("aaaah")
71
+ expect(actual).to receive(:foos?).and_raise("aaaah")
55
72
  expect {
56
73
  expect(actual).to be_foo
57
74
  }.to raise_error(/aaaah/)
@@ -92,13 +109,13 @@ end
92
109
  describe "expect(...).to be_predicate(*args)" do
93
110
  it "passes when actual returns true for :predicate?(*args)" do
94
111
  actual = double("actual")
95
- actual.should_receive(:older_than?).with(3).and_return(true)
112
+ expect(actual).to receive(:older_than?).with(3).and_return(true)
96
113
  expect(actual).to be_older_than(3)
97
114
  end
98
115
 
99
116
  it "fails when actual returns false for :predicate?(*args)" do
100
117
  actual = double("actual")
101
- actual.should_receive(:older_than?).with(3).and_return(false)
118
+ expect(actual).to receive(:older_than?).with(3).and_return(false)
102
119
  expect {
103
120
  expect(actual).to be_older_than(3)
104
121
  }.to fail_with("expected older_than?(3) to return true, got false")
@@ -114,13 +131,13 @@ end
114
131
  describe "expect(...).not_to be_predicate(*args)" do
115
132
  it "passes when actual returns false for :predicate?(*args)" do
116
133
  actual = double("actual")
117
- actual.should_receive(:older_than?).with(3).and_return(false)
134
+ expect(actual).to receive(:older_than?).with(3).and_return(false)
118
135
  expect(actual).not_to be_older_than(3)
119
136
  end
120
137
 
121
138
  it "fails when actual returns true for :predicate?(*args)" do
122
139
  actual = double("actual")
123
- actual.should_receive(:older_than?).with(3).and_return(true)
140
+ expect(actual).to receive(:older_than?).with(3).and_return(true)
124
141
  expect {
125
142
  expect(actual).not_to be_older_than(3)
126
143
  }.to fail_with("expected older_than?(3) to return false, got true")
@@ -137,16 +154,16 @@ describe "expect(...).to be_predicate(&block)" do
137
154
  it "passes when actual returns true for :predicate?(&block)" do
138
155
  actual = double("actual")
139
156
  delegate = double("delegate")
140
- actual.should_receive(:happy?).and_yield
141
- delegate.should_receive(:check_happy).and_return(true)
157
+ expect(actual).to receive(:happy?).and_yield
158
+ expect(delegate).to receive(:check_happy).and_return(true)
142
159
  expect(actual).to be_happy { delegate.check_happy }
143
160
  end
144
161
 
145
162
  it "fails when actual returns false for :predicate?(&block)" do
146
163
  actual = double("actual")
147
164
  delegate = double("delegate")
148
- actual.should_receive(:happy?).and_yield
149
- delegate.should_receive(:check_happy).and_return(false)
165
+ expect(actual).to receive(:happy?).and_yield
166
+ expect(delegate).to receive(:check_happy).and_return(false)
150
167
  expect {
151
168
  expect(actual).to be_happy { delegate.check_happy }
152
169
  }.to fail_with("expected happy? to return true, got false")
@@ -164,16 +181,16 @@ describe "expect(...).not_to be_predicate(&block)" do
164
181
  it "passes when actual returns false for :predicate?(&block)" do
165
182
  actual = double("actual")
166
183
  delegate = double("delegate")
167
- actual.should_receive(:happy?).and_yield
168
- delegate.should_receive(:check_happy).and_return(false)
184
+ expect(actual).to receive(:happy?).and_yield
185
+ expect(delegate).to receive(:check_happy).and_return(false)
169
186
  expect(actual).not_to be_happy { delegate.check_happy }
170
187
  end
171
188
 
172
189
  it "fails when actual returns true for :predicate?(&block)" do
173
190
  actual = double("actual")
174
191
  delegate = double("delegate")
175
- actual.should_receive(:happy?).and_yield
176
- delegate.should_receive(:check_happy).and_return(true)
192
+ expect(actual).to receive(:happy?).and_yield
193
+ expect(delegate).to receive(:check_happy).and_return(true)
177
194
  expect {
178
195
  expect(actual).not_to be_happy { delegate.check_happy }
179
196
  }.to fail_with("expected happy? to return false, got true")
@@ -191,16 +208,16 @@ describe "expect(...).to be_predicate(*args, &block)" do
191
208
  it "passes when actual returns true for :predicate?(*args, &block)" do
192
209
  actual = double("actual")
193
210
  delegate = double("delegate")
194
- actual.should_receive(:older_than?).with(3).and_yield(3)
195
- delegate.should_receive(:check_older_than).with(3).and_return(true)
211
+ expect(actual).to receive(:older_than?).with(3).and_yield(3)
212
+ expect(delegate).to receive(:check_older_than).with(3).and_return(true)
196
213
  expect(actual).to be_older_than(3) { |age| delegate.check_older_than(age) }
197
214
  end
198
215
 
199
216
  it "fails when actual returns false for :predicate?(*args, &block)" do
200
217
  actual = double("actual")
201
218
  delegate = double("delegate")
202
- actual.should_receive(:older_than?).with(3).and_yield(3)
203
- delegate.should_receive(:check_older_than).with(3).and_return(false)
219
+ expect(actual).to receive(:older_than?).with(3).and_yield(3)
220
+ expect(delegate).to receive(:check_older_than).with(3).and_return(false)
204
221
  expect {
205
222
  expect(actual).to be_older_than(3) { |age| delegate.check_older_than(age) }
206
223
  }.to fail_with("expected older_than?(3) to return true, got false")
@@ -218,16 +235,16 @@ describe "expect(...).not_to be_predicate(*args, &block)" do
218
235
  it "passes when actual returns false for :predicate?(*args, &block)" do
219
236
  actual = double("actual")
220
237
  delegate = double("delegate")
221
- actual.should_receive(:older_than?).with(3).and_yield(3)
222
- delegate.should_receive(:check_older_than).with(3).and_return(false)
238
+ expect(actual).to receive(:older_than?).with(3).and_yield(3)
239
+ expect(delegate).to receive(:check_older_than).with(3).and_return(false)
223
240
  expect(actual).not_to be_older_than(3) { |age| delegate.check_older_than(age) }
224
241
  end
225
242
 
226
243
  it "fails when actual returns true for :predicate?(*args, &block)" do
227
244
  actual = double("actual")
228
245
  delegate = double("delegate")
229
- actual.should_receive(:older_than?).with(3).and_yield(3)
230
- delegate.should_receive(:check_older_than).with(3).and_return(true)
246
+ expect(actual).to receive(:older_than?).with(3).and_yield(3)
247
+ expect(delegate).to receive(:check_older_than).with(3).and_return(true)
231
248
  expect {
232
249
  expect(actual).not_to be_older_than(3) { |age| delegate.check_older_than(age) }
233
250
  }.to fail_with("expected older_than?(3) to return false, got true")
@@ -327,6 +344,11 @@ describe "expect(...).to be <" do
327
344
  it "describes itself" do
328
345
  expect(be.<(4).description).to eq "be < 4"
329
346
  end
347
+
348
+ it 'does not lie and say that it is equal to a number' do
349
+ matcher = (be < 3)
350
+ expect(5 == matcher).to be false
351
+ end
330
352
  end
331
353
 
332
354
  describe "expect(...).to be <=" do
@@ -427,19 +449,41 @@ describe "expect(...).to be ===" do
427
449
  end
428
450
  end
429
451
 
430
- describe "expect(...).not_to with operators" do
431
- it "coaches user to stop using operators with expect().not_to" do
452
+ describe "expect(...).not_to with comparison operators" do
453
+ it "coaches user to stop using operators with expect().not_to with numerical comparison operators" do
432
454
  expect {
433
455
  expect(5).not_to be < 6
434
- }.to raise_error(/`expect\(actual\).not_to be < 6` not only FAILED,\nit is a bit confusing./m)
456
+ }.to fail_with("`expect(5).not_to be < 6` not only FAILED, it is a bit confusing.")
457
+
458
+ expect {
459
+ expect(5).not_to be <= 6
460
+ }.to fail_with("`expect(5).not_to be <= 6` not only FAILED, it is a bit confusing.")
461
+
462
+ expect {
463
+ expect(6).not_to be > 5
464
+ }.to fail_with("`expect(6).not_to be > 5` not only FAILED, it is a bit confusing.")
465
+
466
+ expect {
467
+ expect(6).not_to be >= 5
468
+ }.to fail_with("`expect(6).not_to be >= 5` not only FAILED, it is a bit confusing.")
469
+ end
470
+
471
+ it "coaches users to stop using negation with string comparison operators" do
472
+ expect {
473
+ expect("foo").not_to be > "bar"
474
+ }.to fail_with('`expect("foo").not_to be > "bar"` not only FAILED, it is a bit confusing.')
435
475
  end
436
476
  end
437
477
 
438
- describe "should_not with operators", :uses_only_should do
439
- it "coaches user to stop using operators with should_not" do
440
- lambda {
441
- 5.should_not be < 6
442
- }.should raise_error(/`actual.should_not be < 6` not only FAILED,\nit is a bit confusing./m)
478
+ describe "expect(...).not_to with equality operators" do
479
+ it "raises normal error with expect().not_to with equality operators" do
480
+ expect {
481
+ expect(6).not_to be == 6
482
+ }.to fail_with("`expect(6).not_to be == 6`")
483
+
484
+ expect {
485
+ expect(String).not_to be === "Hello"
486
+ }.to fail_with('`expect(String).not_to be === "Hello"`')
443
487
  end
444
488
  end
445
489
 
@@ -482,7 +526,7 @@ end
482
526
  describe "expect(...).to be(value)" do
483
527
  it "delegates to equal" do
484
528
  matcher = equal(5)
485
- self.should_receive(:equal).with(5).and_return(matcher)
529
+ expect(self).to receive(:equal).with(5).and_return(matcher)
486
530
  expect(5).to be(5)
487
531
  end
488
532
  end
@@ -490,7 +534,7 @@ end
490
534
  describe "expect(...).not_to be(value)" do
491
535
  it "delegates to equal" do
492
536
  matcher = equal(4)
493
- self.should_receive(:equal).with(4).and_return(matcher)
537
+ expect(self).to receive(:equal).with(4).and_return(matcher)
494
538
  expect(5).not_to be(4)
495
539
  end
496
540
  end
@@ -63,10 +63,10 @@ module RSpec
63
63
  }.to raise_error(ArgumentError, /must set an expected value using #of/)
64
64
  end
65
65
 
66
- it "raises an error if the actual does not respond to :-" do
66
+ it "fails if the actual is not numeric" do
67
67
  expect {
68
68
  expect(nil).to be_within(0.1).of(0)
69
- }.to raise_error(ArgumentError, /The actual value \(nil\) must respond to `-`/)
69
+ }.to fail_with("expected nil to be within 0.1 of 0, but it could not be treated as a numeric value")
70
70
  end
71
71
  end
72
72
 
@@ -132,6 +132,10 @@ module RSpec
132
132
  expect(5.5).not_to be_within(0.5).of(5.0)
133
133
  }.to fail_with("expected 5.5 not to be within 0.5 of 5.0")
134
134
  end
135
+
136
+ it "passes if the actual is not numeric" do
137
+ expect(nil).not_to be_within(0.1).of(0)
138
+ end
135
139
  end
136
140
  end
137
141
  end