rspec-expectations 2.13.0 → 2.99.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 (96) hide show
  1. checksums.yaml +15 -0
  2. data/Changelog.md +204 -23
  3. data/README.md +43 -87
  4. data/features/README.md +10 -10
  5. data/features/built_in_matchers/README.md +41 -41
  6. data/features/built_in_matchers/be.feature +40 -40
  7. data/features/built_in_matchers/be_within.feature +3 -3
  8. data/features/built_in_matchers/expect_change.feature +6 -6
  9. data/features/built_in_matchers/expect_error.feature +2 -2
  10. data/features/built_in_matchers/start_with.feature +1 -1
  11. data/features/built_in_matchers/throw_symbol.feature +11 -11
  12. data/features/built_in_matchers/yield.feature +18 -3
  13. data/features/custom_matchers/define_diffable_matcher.feature +1 -1
  14. data/features/custom_matchers/define_matcher_outside_rspec.feature +6 -6
  15. data/features/custom_matchers/define_matcher_with_fluent_interface.feature +1 -1
  16. data/features/customized_message.feature +1 -1
  17. data/features/diffing.feature +1 -1
  18. data/features/step_definitions/additional_cli_steps.rb +10 -0
  19. data/features/support/env.rb +10 -1
  20. data/features/support/rubinius.rb +6 -0
  21. data/features/syntax_configuration.feature +3 -0
  22. data/features/test_frameworks/test_unit.feature +55 -17
  23. data/lib/rspec/expectations/caller_filter.rb +60 -0
  24. data/lib/rspec/{matchers → expectations}/configuration.rb +5 -3
  25. data/lib/rspec/expectations/deprecation.rb +20 -31
  26. data/lib/rspec/expectations/differ.rb +48 -9
  27. data/lib/rspec/expectations/expectation_target.rb +81 -15
  28. data/lib/rspec/expectations/extensions/object.rb +2 -12
  29. data/lib/rspec/expectations/fail_with.rb +11 -1
  30. data/lib/rspec/expectations/handler.rb +16 -7
  31. data/lib/rspec/expectations/syntax.rb +5 -7
  32. data/lib/rspec/expectations/version.rb +1 -1
  33. data/lib/rspec/expectations.rb +28 -2
  34. data/lib/rspec/matchers/be_close.rb +4 -1
  35. data/lib/rspec/matchers/built_in/base_matcher.rb +17 -10
  36. data/lib/rspec/matchers/built_in/be.rb +69 -32
  37. data/lib/rspec/matchers/built_in/be_within.rb +9 -3
  38. data/lib/rspec/matchers/built_in/change.rb +49 -3
  39. data/lib/rspec/matchers/built_in/has.rb +40 -7
  40. data/lib/rspec/matchers/built_in/have.rb +170 -5
  41. data/lib/rspec/matchers/built_in/include.rb +3 -11
  42. data/lib/rspec/matchers/built_in/match.rb +5 -0
  43. data/lib/rspec/matchers/built_in/match_array.rb +1 -1
  44. data/lib/rspec/matchers/built_in/raise_error.rb +34 -8
  45. data/lib/rspec/matchers/built_in/respond_to.rb +7 -1
  46. data/lib/rspec/matchers/built_in/satisfy.rb +7 -1
  47. data/lib/rspec/matchers/built_in/throw_symbol.rb +10 -2
  48. data/lib/rspec/matchers/built_in/yield.rb +102 -5
  49. data/lib/rspec/matchers/built_in.rb +2 -2
  50. data/lib/rspec/matchers/differentiate_block_method_types.rb +55 -0
  51. data/lib/rspec/matchers/dsl.rb +2 -1
  52. data/lib/rspec/matchers/match_aliases.rb +22 -0
  53. data/lib/rspec/matchers/matcher.rb +131 -10
  54. data/lib/rspec/matchers/operator_matcher.rb +70 -66
  55. data/lib/rspec/matchers/pretty.rb +11 -1
  56. data/lib/rspec/matchers/test_unit_integration.rb +28 -0
  57. data/lib/rspec/matchers.rb +175 -146
  58. data/lib/rspec-expectations.rb +5 -0
  59. data/spec/rspec/{matchers → expectations}/configuration_spec.rb +78 -91
  60. data/spec/rspec/expectations/differ_spec.rb +65 -6
  61. data/spec/rspec/expectations/expectation_target_spec.rb +72 -3
  62. data/spec/rspec/expectations/extensions/kernel_spec.rb +9 -5
  63. data/spec/rspec/expectations/fail_with_spec.rb +19 -0
  64. data/spec/rspec/expectations/handler_spec.rb +43 -22
  65. data/spec/rspec/expectations/syntax_spec.rb +51 -9
  66. data/spec/rspec/expectations_spec.rb +71 -0
  67. data/spec/rspec/matchers/base_matcher_spec.rb +33 -18
  68. data/spec/rspec/matchers/be_close_spec.rb +9 -6
  69. data/spec/rspec/matchers/be_spec.rb +146 -45
  70. data/spec/rspec/matchers/be_within_spec.rb +8 -0
  71. data/spec/rspec/matchers/change_spec.rb +107 -7
  72. data/spec/rspec/matchers/description_generation_spec.rb +38 -20
  73. data/spec/rspec/matchers/differentiate_block_method_types_spec.rb +39 -0
  74. data/spec/rspec/matchers/eq_spec.rb +1 -1
  75. data/spec/rspec/matchers/equal_spec.rb +26 -0
  76. data/spec/rspec/matchers/exist_spec.rb +9 -9
  77. data/spec/rspec/matchers/has_spec.rb +25 -1
  78. data/spec/rspec/matchers/have_spec.rb +411 -3
  79. data/spec/rspec/matchers/include_matcher_integration_spec.rb +2 -2
  80. data/spec/rspec/matchers/include_spec.rb +4 -4
  81. data/spec/rspec/matchers/match_array_spec.rb +1 -1
  82. data/spec/rspec/matchers/match_spec.rb +14 -1
  83. data/spec/rspec/matchers/matcher_spec.rb +213 -24
  84. data/spec/rspec/matchers/operator_matcher_spec.rb +56 -8
  85. data/spec/rspec/matchers/pretty_spec.rb +23 -0
  86. data/spec/rspec/matchers/raise_error_spec.rb +242 -102
  87. data/spec/rspec/matchers/respond_to_spec.rb +4 -4
  88. data/spec/rspec/matchers/satisfy_spec.rb +1 -1
  89. data/spec/rspec/matchers/start_with_end_with_spec.rb +2 -2
  90. data/spec/rspec/matchers/throw_symbol_spec.rb +14 -14
  91. data/spec/rspec/matchers/yield_spec.rb +81 -4
  92. data/spec/spec_helper.rb +5 -3
  93. data/spec/support/helper_methods.rb +42 -0
  94. data/spec/support/shared_examples.rb +42 -0
  95. metadata +40 -44
  96. data/spec/rspec/matchers/matchers_spec.rb +0 -37
@@ -49,21 +49,21 @@ module RSpec
49
49
  describe PositiveExpectationHandler do
50
50
  describe "#handle_matcher" do
51
51
  it "asks the matcher if it matches" do
52
- matcher = mock("matcher")
52
+ matcher = double("matcher")
53
53
  actual = Object.new
54
54
  matcher.should_receive(:matches?).with(actual).and_return(true)
55
55
  RSpec::Expectations::PositiveExpectationHandler.handle_matcher(actual, matcher)
56
56
  end
57
57
 
58
58
  it "returns the match value" do
59
- matcher = mock("matcher")
59
+ matcher = double("matcher")
60
60
  actual = Object.new
61
61
  matcher.should_receive(:matches?).with(actual).and_return(:this_value)
62
62
  expect(RSpec::Expectations::PositiveExpectationHandler.handle_matcher(actual, matcher)).to eq :this_value
63
63
  end
64
64
 
65
65
  it "calls failure_message_for_should if the matcher implements it" do
66
- matcher = mock("matcher", :failure_message_for_should => "message", :matches? => false)
66
+ matcher = double("matcher", :failure_message_for_should => "message", :matches? => false)
67
67
  actual = Object.new
68
68
 
69
69
  ::RSpec::Expectations.should_receive(:fail_with).with("message")
@@ -72,7 +72,7 @@ module RSpec
72
72
  end
73
73
 
74
74
  it "calls fail if matcher.diffable?" do
75
- matcher = mock("matcher",
75
+ matcher = double("matcher",
76
76
  :diffable? => true,
77
77
  :failure_message_for_should => "message",
78
78
  :matches? => false,
@@ -87,7 +87,7 @@ module RSpec
87
87
  end
88
88
 
89
89
  it "calls failure_message if the matcher does not implement failure_message_for_should" do
90
- matcher = mock("matcher", :failure_message => "message", :matches? => false)
90
+ matcher = double("matcher", :failure_message => "message", :matches? => false)
91
91
  actual = Object.new
92
92
 
93
93
  ::RSpec::Expectations.should_receive(:fail_with).with("message")
@@ -96,45 +96,56 @@ module RSpec
96
96
 
97
97
  end
98
98
 
99
- it "appends the :or message in the options hash passed to should" do
100
- matcher = mock("matcher", :failure_message_for_should => "message", :matches? => false)
99
+ it "uses the custom failure message when one is provided" do
100
+ matcher = double("matcher", :failure_message_for_should => "message", :matches? => false)
101
101
  actual = Object.new
102
102
 
103
103
  ::RSpec::Expectations.should_receive(:fail_with).with("custom")
104
104
 
105
105
  RSpec::Expectations::PositiveExpectationHandler.handle_matcher(actual, matcher, "custom")
106
106
  end
107
+
108
+ it "uses the custom failure message when one is provided as a callable object" do
109
+ matcher = double("matcher", :failure_message_for_should => "message", :matches? => false)
110
+ actual = Object.new
111
+
112
+ failure_message = double("failure message", :call => "custom")
113
+
114
+ ::RSpec::Expectations.should_receive(:fail_with).with("custom")
115
+
116
+ RSpec::Expectations::PositiveExpectationHandler.handle_matcher(actual, matcher, failure_message)
117
+ end
107
118
  end
108
119
  end
109
120
 
110
121
  describe NegativeExpectationHandler do
111
122
  describe "#handle_matcher" do
112
123
  it "asks the matcher if it doesn't match when the matcher responds to #does_not_match?" do
113
- matcher = mock("matcher", :does_not_match? => true, :negative_failure_message => nil)
124
+ matcher = double("matcher", :does_not_match? => true, :negative_failure_message => nil)
114
125
  actual = Object.new
115
126
  matcher.should_receive(:does_not_match?).with(actual).and_return(true)
116
127
  RSpec::Expectations::NegativeExpectationHandler.handle_matcher(actual, matcher)
117
128
  end
118
129
 
119
130
  it "asks the matcher if it matches when the matcher doesn't respond to #does_not_match?" do
120
- matcher = mock("matcher")
131
+ matcher = double("matcher")
121
132
  actual = Object.new
122
- matcher.stub!(:negative_failure_message)
133
+ matcher.stub(:negative_failure_message)
123
134
  matcher.should_receive(:matches?).with(actual).and_return(false)
124
135
  RSpec::Expectations::NegativeExpectationHandler.handle_matcher(actual, matcher)
125
136
  end
126
137
 
127
138
  it "returns the match value" do
128
- matcher = mock("matcher")
139
+ matcher = double("matcher")
129
140
  actual = Object.new
130
141
  matcher.should_receive(:matches?).with(actual).and_return(false)
131
- matcher.stub!(:negative_failure_message).and_return("ignore")
132
- expect(RSpec::Expectations::NegativeExpectationHandler.handle_matcher(actual, matcher)).to be_false
142
+ matcher.stub(:negative_failure_message).and_return("ignore")
143
+ expect(RSpec::Expectations::NegativeExpectationHandler.handle_matcher(actual, matcher)).to be_falsey
133
144
  end
134
145
 
135
146
 
136
147
  it "calls failure_message_for_should_not if the matcher implements it" do
137
- matcher = mock("matcher", :failure_message_for_should_not => "message", :matches? => true)
148
+ matcher = double("matcher", :failure_message_for_should_not => "message", :matches? => true)
138
149
  actual = Object.new
139
150
 
140
151
  ::RSpec::Expectations.should_receive(:fail_with).with("message")
@@ -144,7 +155,7 @@ module RSpec
144
155
  end
145
156
 
146
157
  it "calls negative_failure_message if the matcher does not implement failure_message_for_should_not" do
147
- matcher = mock("matcher", :negative_failure_message => "message", :matches? => true)
158
+ matcher = double("matcher", :negative_failure_message => "message", :matches? => true)
148
159
  actual = Object.new
149
160
 
150
161
  ::RSpec::Expectations.should_receive(:fail_with).with("message")
@@ -155,7 +166,7 @@ module RSpec
155
166
 
156
167
 
157
168
  it "calls fail if matcher.diffable?" do
158
- matcher = mock("matcher",
169
+ matcher = double("matcher",
159
170
  :diffable? => true,
160
171
  :failure_message_for_should_not => "message",
161
172
  :matches? => true,
@@ -169,8 +180,8 @@ module RSpec
169
180
  RSpec::Expectations::NegativeExpectationHandler.handle_matcher(actual, matcher)
170
181
  end
171
182
 
172
- it "appends the :or message in the options hash passed to should" do
173
- matcher = mock("matcher", :failure_message_for_should_not => "message", :matches? => true)
183
+ it "uses the custom failure message when one is provided" do
184
+ matcher = double("matcher", :failure_message_for_should_not => "message", :matches? => true)
174
185
  actual = Object.new
175
186
 
176
187
  ::RSpec::Expectations.should_receive(:fail_with).with("custom")
@@ -178,6 +189,16 @@ module RSpec
178
189
  RSpec::Expectations::NegativeExpectationHandler.handle_matcher(actual, matcher, "custom")
179
190
  end
180
191
 
192
+ it "uses the custom failure message when one is provided as a callable object" do
193
+ matcher = double("matcher", :failure_message_for_should_not => "message", :matches? => true)
194
+ actual = Object.new
195
+
196
+ failure_message = double("failure message", :call => "custom")
197
+
198
+ ::RSpec::Expectations.should_receive(:fail_with).with("custom")
199
+
200
+ RSpec::Expectations::NegativeExpectationHandler.handle_matcher(actual, matcher, failure_message)
201
+ end
181
202
  end
182
203
  end
183
204
 
@@ -189,10 +210,10 @@ module RSpec
189
210
  expect(5).to arbitrary_matcher(:expected => "wrong").with(5)
190
211
  expect { expect(5).to arbitrary_matcher(:expected => 4) }.to fail_with("expected 4, got 5")
191
212
  expect { expect(5).to arbitrary_matcher(:expected => 5).with(4) }.to fail_with("expected 4, got 5")
192
- expect(5).to_not arbitrary_matcher(:expected => 4)
193
- expect(5).to_not arbitrary_matcher(:expected => 5).with(4)
194
- expect { expect(5).to_not arbitrary_matcher(:expected => 5) }.to fail_with("expected not 5, got 5")
195
- expect { expect(5).to_not arbitrary_matcher(:expected => 4).with(5) }.to fail_with("expected not 5, got 5")
213
+ expect(5).not_to arbitrary_matcher(:expected => 4)
214
+ expect(5).not_to arbitrary_matcher(:expected => 5).with(4)
215
+ expect { expect(5).not_to arbitrary_matcher(:expected => 5) }.to fail_with("expected not 5, got 5")
216
+ expect { expect(5).not_to arbitrary_matcher(:expected => 4).with(5) }.to fail_with("expected not 5, got 5")
196
217
  end
197
218
 
198
219
  it "handles the submitted block" do
@@ -6,9 +6,21 @@ module RSpec
6
6
  context "when passing a message to an expectation" do
7
7
  let(:warner) { ::Kernel }
8
8
 
9
+ let(:string_like_object) do
10
+ Struct.new(:to_str, :to_s).new(*(["Ceci n'est pas une Chaine."]*2))
11
+ end
12
+
13
+ let(:insufficiently_string_like_object) do
14
+ Struct.new(:to_s).new("Ceci n'est pas une Chaine.")
15
+ end
16
+
17
+ let(:callable_object) do
18
+ Struct.new(:call).new("Ceci n'est pas une Chaine.")
19
+ end
20
+
9
21
  describe "expect(...).to" do
10
22
  it "prints a warning when the message object isn't a String" do
11
- warner.should_receive(:warn).with /ignoring.*message/
23
+ warner.should_receive(:warn).with(/ignoring.*message/)
12
24
  expect(3).to eq(3), :not_a_string
13
25
  end
14
26
 
@@ -16,11 +28,26 @@ module RSpec
16
28
  warner.should_not_receive(:warn)
17
29
  expect(3).to eq(3), "a string"
18
30
  end
31
+
32
+ it "doesn't print a warning when message responds to to_str" do
33
+ warner.should_not_receive(:warn)
34
+ expect(3).to eq(3), string_like_object
35
+ end
36
+
37
+ it "prints a warning when the message object handles to_s but not to_str" do
38
+ warner.should_receive(:warn).with(/ignoring.*message/)
39
+ expect(3).to eq(3), insufficiently_string_like_object
40
+ end
41
+
42
+ it "doesn't print a warning when message responds to call" do
43
+ warner.should_not_receive(:warn)
44
+ expect(3).to eq(3), callable_object
45
+ end
19
46
  end
20
47
 
21
- describe "expect(...).to_not" do
48
+ describe "expect(...).not_to" do
22
49
  it "prints a warning when the message object isn't a String" do
23
- warner.should_receive(:warn).with /ignoring.*message/
50
+ warner.should_receive(:warn).with(/ignoring.*message/)
24
51
  expect(3).not_to eq(4), :not_a_string
25
52
  end
26
53
 
@@ -28,6 +55,21 @@ module RSpec
28
55
  warner.should_not_receive(:warn)
29
56
  expect(3).not_to eq(4), "a string"
30
57
  end
58
+
59
+ it "doesn't print a warning when message responds to to_str" do
60
+ warner.should_not_receive(:warn)
61
+ expect(3).not_to eq(4), string_like_object
62
+ end
63
+
64
+ it "prints a warning when the message object handles to_s but not to_str" do
65
+ warner.should_receive(:warn).with(/ignoring.*message/)
66
+ expect(3).not_to eq(4), insufficiently_string_like_object
67
+ end
68
+
69
+ it "doesn't print a warning when message responds to call" do
70
+ warner.should_not_receive(:warn)
71
+ expect(3).not_to eq(4), callable_object
72
+ end
31
73
  end
32
74
  end
33
75
 
@@ -49,8 +91,8 @@ module RSpec
49
91
 
50
92
  context "when only :expect is enabled" do
51
93
  before do
52
- expect(Syntax.should_enabled?).to be_false
53
- expect(Syntax.expect_enabled?).to be_true
94
+ expect(Syntax.should_enabled?).to be_falsey
95
+ expect(Syntax.expect_enabled?).to be_truthy
54
96
  end
55
97
 
56
98
  it 'generates a positive expression using the expect syntax' do
@@ -64,8 +106,8 @@ module RSpec
64
106
 
65
107
  context "when both :should and :expect are enabled", :uses_should do
66
108
  before do
67
- expect(Syntax.should_enabled?).to be_true
68
- expect(Syntax.expect_enabled?).to be_true
109
+ expect(Syntax.should_enabled?).to be_truthy
110
+ expect(Syntax.expect_enabled?).to be_truthy
69
111
  end
70
112
 
71
113
  it 'generates a positive expression using the expect syntax' do
@@ -79,8 +121,8 @@ module RSpec
79
121
 
80
122
  context "when only :should is enabled", :uses_only_should do
81
123
  before do
82
- Syntax.should_enabled?.should be_true
83
- Syntax.expect_enabled?.should be_false
124
+ Syntax.should_enabled?.should be_truthy
125
+ Syntax.expect_enabled?.should be_falsey
84
126
  end
85
127
 
86
128
  it 'generates a positive expression using the expect syntax' do
@@ -0,0 +1,71 @@
1
+ require 'spec_helper'
2
+
3
+ module RSpec
4
+ describe Expectations do
5
+ def file_contents_for(lib, filename)
6
+ # http://rubular.com/r/HYpUMftlG2
7
+ path = $LOAD_PATH.find { |p| p.match(/\/rspec-#{lib}(-[a-f0-9]+)?\/lib/) }
8
+ file = File.join(path, filename)
9
+ File.read(file)
10
+ end
11
+
12
+ it 'has an up-to-date caller_filter file' do
13
+ expectations = file_contents_for("expectations", "rspec/expectations/caller_filter.rb")
14
+ core = file_contents_for("core", "rspec/core/caller_filter.rb")
15
+
16
+ expect(expectations).to eq(core)
17
+ end
18
+
19
+ it 'prints a deprecation warning when the root file is loaded' do
20
+ expect_deprecation_with_call_site(__FILE__, __LINE__ + 1, /rspec-expectations/)
21
+ load "rspec-expectations.rb"
22
+ end
23
+
24
+ describe '.method_handle_for(object, method_name)' do
25
+
26
+ class UntamperedClass
27
+ def foo
28
+ :bar
29
+ end
30
+ end
31
+
32
+ class ClassWithMethodOverridden < UntamperedClass
33
+ def method
34
+ :baz
35
+ end
36
+ end
37
+
38
+ if RUBY_VERSION.to_f > 1.8
39
+ class BasicClass < BasicObject
40
+ def foo
41
+ :bar
42
+ end
43
+ end
44
+
45
+ class BasicClassWithKernel < BasicClass
46
+ include ::Kernel
47
+ end
48
+ end
49
+
50
+ it 'fetches method definitions for vanilla objects' do
51
+ object = UntamperedClass.new
52
+ expect(Expectations.method_handle_for(object, :foo).call).to eq :bar
53
+ end
54
+
55
+ it 'fetches method definitions for objects with method redefined' do
56
+ object = ClassWithMethodOverridden.new
57
+ expect(Expectations.method_handle_for(object, :foo).call).to eq :bar
58
+ end
59
+
60
+ it 'fetches method definitions for basic objects', :if => (RUBY_VERSION.to_i >= 2 && RUBY_ENGINE != 'rbx') do
61
+ object = BasicClass.new
62
+ expect(Expectations.method_handle_for(object, :foo).call).to eq :bar
63
+ end
64
+
65
+ it 'fetches method definitions for basic objects with kernel mixed in', :if => RUBY_VERSION.to_f > 1.8 do
66
+ object = BasicClassWithKernel.new
67
+ expect(Expectations.method_handle_for(object, :foo).call).to eq :bar
68
+ end
69
+ end
70
+ end
71
+ end
@@ -8,21 +8,21 @@ module RSpec::Matchers::BuiltIn
8
8
  end
9
9
 
10
10
  it "returns true if there are no errors" do
11
- expect(matcher.match_unless_raises {}).to be_true
11
+ expect(matcher.match_unless_raises {}).to be_truthy
12
12
  end
13
13
 
14
14
  it "returns false if there is an error" do
15
- expect(matcher.match_unless_raises { raise }).to be_false
15
+ expect(matcher.match_unless_raises { raise }).to be_falsey
16
16
  end
17
17
 
18
18
  it "returns false if the only submitted error is raised" do
19
- expect(matcher.match_unless_raises(RuntimeError){ raise "foo" }).to be_false
19
+ expect(matcher.match_unless_raises(RuntimeError){ raise "foo" }).to be_falsey
20
20
  end
21
21
 
22
22
  it "returns false if any of several errors submitted is raised" do
23
- expect(matcher.match_unless_raises(RuntimeError, ArgumentError, NameError) { raise "foo" }).to be_false
24
- expect(matcher.match_unless_raises(RuntimeError, ArgumentError, NameError) { raise ArgumentError.new('') }).to be_false
25
- expect(matcher.match_unless_raises(RuntimeError, ArgumentError, NameError) { raise NameError.new('') }).to be_false
23
+ expect(matcher.match_unless_raises(RuntimeError, ArgumentError, NameError) { raise "foo" }).to be_falsey
24
+ expect(matcher.match_unless_raises(RuntimeError, ArgumentError, NameError) { raise ArgumentError.new('') }).to be_falsey
25
+ expect(matcher.match_unless_raises(RuntimeError, ArgumentError, NameError) { raise NameError.new('') }).to be_falsey
26
26
  end
27
27
 
28
28
  it "re-raises any error other than one of those specified" do
@@ -39,24 +39,39 @@ module RSpec::Matchers::BuiltIn
39
39
 
40
40
  end
41
41
 
42
- describe "#==" do
43
- it "responds the same way as matches?" do
44
- matcher = Class.new(BaseMatcher) do
45
- def initialize(expected)
46
- @expected = expected
47
- end
42
+ describe "#failure_message_for_should" 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
48
49
 
49
- def matches?(actual)
50
- (@actual = actual) == @expected
50
+ def match(expected, actual)
51
+ false
52
+ end
51
53
  end
54
+
55
+ matcher = matcher_class.new
56
+ matcher.name = "be something"
57
+ matcher.matches?("foo")
58
+ expect(matcher.failure_message_for_should).to eq('expected "foo" to be something')
52
59
  end
60
+ end
61
+ end
53
62
 
54
- expect(matcher.new(3).matches?(3)).to be_true
55
- expect(matcher.new(3)).to eq(3)
63
+ it_behaves_like "an RSpec matcher", :valid_value => 3, :invalid_value => 4 do
64
+ matcher_class = Class.new(BaseMatcher) do
65
+ def initialize(expected)
66
+ @expected = expected
67
+ end
56
68
 
57
- expect(matcher.new(3).matches?(4)).to be_false
58
- expect(matcher.new(3)).not_to eq(4)
69
+ def matches?(actual)
70
+ (@actual = actual) == @expected
71
+ end
59
72
  end
73
+
74
+ let(:matcher) { matcher_class.new(3) }
60
75
  end
61
76
  end
62
77
  end
@@ -4,17 +4,20 @@ module RSpec
4
4
  module Matchers
5
5
  describe "expect(actual).to be_close(expected, delta)" do
6
6
  before(:each) do
7
- RSpec.stub(:warn)
7
+ allow(RSpec).to receive(:deprecate)
8
8
  end
9
9
 
10
- it "delegates to be_within(delta).of(expected)" do
11
- should_receive(:be_within).with(0.5).and_return( be_within_matcher = stub )
12
- be_within_matcher.should_receive(:of).with(3.0)
10
+ it "is deprecated" do
11
+ expect_deprecation_with_type('be_close(3.0, 0.5)',
12
+ 'be_within(0.5).of(3.0)',
13
+ 'the be_close matcher'
14
+ )
13
15
  be_close(3.0, 0.5)
14
16
  end
15
17
 
16
- it "prints a deprecation warning" do
17
- RSpec.should_receive(:warn).with(/please use be_within.*instead/)
18
+ it "delegates to be_within(delta).of(expected)" do
19
+ should_receive(:be_within).with(0.5).and_return( be_within_matcher = double )
20
+ be_within_matcher.should_receive(:of).with(3.0)
18
21
  be_close(3.0, 0.5)
19
22
  end
20
23
  end