rspec-expectations 2.14.0.rc1 → 2.14.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,15 @@
1
+ ### 2.14.0 / 2013-07-06
2
+ [full changelog](http://github.com/rspec/rspec-expectations/compare/v2.14.0.rc1...v2.14.0)
3
+
4
+ Bug fixes
5
+
6
+ * Values that are not matchers use `#inspect`, rather than `#description` for
7
+ documentation output (Andy Lindeman, Sam Phippen).
8
+ * Make `expect(a).to be_within(x).percent_of(y)` work with negative y
9
+ (Katsuhiko Nishimra).
10
+ * Make the `be_predicate` matcher work as expected used with `expect{...}.to
11
+ change...` (Sam Phippen).
12
+
1
13
  ### 2.14.0.rc1 / 2013-05-27
2
14
  [full changelog](http://github.com/rspec/rspec-expectations/compare/v2.13.0...v2.14.0.rc1)
3
15
 
@@ -2,7 +2,7 @@ module RSpec
2
2
  module Expectations
3
3
  # @private
4
4
  module Version
5
- STRING = '2.14.0.rc1'
5
+ STRING = '2.14.0'
6
6
  end
7
7
  end
8
8
  end
@@ -174,6 +174,14 @@ module RSpec
174
174
  # config.include(CustomGameMatchers)
175
175
  # end
176
176
  module Matchers
177
+ # @api private
178
+ def self.is_a_matcher?(obj)
179
+ return true if ::RSpec::Matchers::BuiltIn::BaseMatcher === obj
180
+ return false if obj.respond_to?(:i_respond_to_everything_so_im_not_really_a_matcher)
181
+ return false unless obj.respond_to?(:matches?)
182
+
183
+ obj.respond_to?(:failure_message_for_should) || obj.respond_to?(:failure_message)
184
+ end
177
185
 
178
186
  # Passes if actual is truthy (anything but false or nil)
179
187
  def be_true
@@ -148,6 +148,8 @@ it is a bit confusing.
148
148
  end
149
149
  end
150
150
 
151
+ alias === matches?
152
+
151
153
  def failure_message_for_should
152
154
  "expected #{predicate}#{args_to_s} to return true, got #{@result.inspect}"
153
155
  end
@@ -23,7 +23,7 @@ module RSpec
23
23
 
24
24
  def percent_of(expected)
25
25
  @expected = expected
26
- @tolerance = @delta * @expected / 100.0
26
+ @tolerance = @delta * @expected.abs / 100.0
27
27
  @unit = '%'
28
28
  self
29
29
  end
@@ -39,7 +39,7 @@ MESSAGE
39
39
  if @eval_before && !expected_matches_actual?(@expected_before, @actual_before)
40
40
  "#{message} should have initially been #{@expected_before.inspect}, but was #{@actual_before.inspect}"
41
41
  elsif @eval_after && !expected_matches_actual?(@expected_after, @actual_after)
42
- "#{message} should have been changed to #{@expected_after.inspect}, but is now #{@actual_after.inspect}"
42
+ "#{message} should have been changed to #{failure_message_for_expected_after}, but is now #{@actual_after.inspect}"
43
43
  elsif @expected_delta
44
44
  "#{message} should have been changed by #{@expected_delta.inspect}, but was changed by #{actual_delta.inspect}"
45
45
  elsif @minimum
@@ -92,6 +92,14 @@ MESSAGE
92
92
 
93
93
  private
94
94
 
95
+ def failure_message_for_expected_after
96
+ if RSpec::Matchers.is_a_matcher?(@expected_after)
97
+ @expected_after.description
98
+ else
99
+ @expected_after.inspect
100
+ end
101
+ end
102
+
95
103
  def message
96
104
  @message || "result"
97
105
  end
@@ -23,7 +23,7 @@ module RSpec
23
23
  def diffable?
24
24
  # Matchers do not diff well, since diff uses their inspect
25
25
  # output, which includes their instance variables and such.
26
- @expected.none? { |e| is_a_matcher?(e) }
26
+ @expected.none? { |e| RSpec::Matchers.is_a_matcher?(e) }
27
27
  end
28
28
 
29
29
  private
@@ -53,15 +53,7 @@ module RSpec
53
53
  end
54
54
 
55
55
  def comparing_with_matcher?(actual, expected)
56
- actual.is_a?(Array) && is_a_matcher?(expected)
57
- end
58
-
59
- def is_a_matcher?(object)
60
- return false if object.respond_to?(:i_respond_to_everything_so_im_not_really_a_matcher)
61
-
62
- [:failure_message_for_should, :failure_message].any? do |msg|
63
- object.respond_to?(msg)
64
- end && object.respond_to?(:matches?)
56
+ actual.is_a?(Array) && RSpec::Matchers.is_a_matcher?(expected)
65
57
  end
66
58
  end
67
59
  end
@@ -35,7 +35,7 @@ module RSpec
35
35
  end
36
36
 
37
37
  def to_word(item)
38
- item.respond_to?(:description) ? item.description : item.inspect
38
+ is_matcher_with_description?(item) ? item.description : item.inspect
39
39
  end
40
40
 
41
41
  def name_to_sentence
@@ -59,6 +59,12 @@ module RSpec
59
59
  word.downcase!
60
60
  word
61
61
  end
62
+
63
+ private
64
+
65
+ def is_matcher_with_description?(object)
66
+ RSpec::Matchers.is_a_matcher?(object) && object.respond_to?(:description)
67
+ end
62
68
  end
63
69
  end
64
70
  end
@@ -31,6 +31,10 @@ module RSpec
31
31
  expect(1.0001).to be_within(5).percent_of(1)
32
32
  end
33
33
 
34
+ it "passes with negative arguments" do
35
+ expect(-1.0001).to be_within(5).percent_of(-1)
36
+ end
37
+
34
38
  it "fails when actual < (expected - delta)" do
35
39
  expect {
36
40
  expect(4.49).to be_within(0.5).of(5.0)
@@ -72,6 +72,17 @@ describe "expect { ... }.to change(actual, message)" do
72
72
  expect {@instance.some_value << 1}.to change(@instance, :some_value)
73
73
  end
74
74
 
75
+ it "fails when a predicate on the actual fails" do
76
+ expect do
77
+ expect {@instance.some_value << 1}.to change { @instance.some_value }.to be_empty
78
+ end.to fail_with(/result should have been changed to/)
79
+ end
80
+
81
+ it "passes when a predicate on the actual passes" do
82
+ @instance.some_value = [1]
83
+ expect {@instance.some_value.pop}.to change { @instance.some_value }.to be_empty
84
+ end
85
+
75
86
  it "fails when actual is not modified by the block" do
76
87
  expect do
77
88
  expect {}.to change(@instance, :some_value)
@@ -107,11 +107,25 @@ describe "Matchers should be able to generate their own descriptions" do
107
107
  expect(RSpec::Matchers.generated_description).to eq "should have at most 4 players"
108
108
  end
109
109
 
110
- it "expect(...).to include" do
110
+ it "expect(...).to include(x)" do
111
111
  expect([1,2,3]).to include(3)
112
112
  expect(RSpec::Matchers.generated_description).to eq "should include 3"
113
113
  end
114
114
 
115
+ it "expect(...).to include(x) when x responds to description but is not a matcher" do
116
+ obj = double(:description => "description", :inspect => "inspect")
117
+ expect([obj]).to include(obj)
118
+ expect(RSpec::Matchers.generated_description).to eq "should include inspect"
119
+ end
120
+
121
+ it "expect(...).to include(x) when x responds to description and is a matcher" do
122
+ matcher = double(:description => "description",
123
+ :matches? => true,
124
+ :failure_message_for_should => "")
125
+ expect([matcher]).to include(matcher)
126
+ expect(RSpec::Matchers.generated_description).to eq "should include description"
127
+ end
128
+
115
129
  it "expect(array).not_to match_array [1,2,3]" do
116
130
  expect([1,2,3]).to match_array [1,2,3]
117
131
  expect(RSpec::Matchers.generated_description).to eq "should contain exactly 1, 2 and 3"
metadata CHANGED
@@ -1,8 +1,8 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rspec-expectations
3
3
  version: !ruby/object:Gem::Version
4
- prerelease: 7
5
- version: 2.14.0.rc1
4
+ prerelease:
5
+ version: 2.14.0
6
6
  platform: ruby
7
7
  authors:
8
8
  - Steven Baker
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2013-05-27 00:00:00.000000000 Z
13
+ date: 2013-07-06 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  version_requirements: !ruby/object:Gem::Requirement
@@ -233,20 +233,23 @@ required_ruby_version: !ruby/object:Gem::Requirement
233
233
  version: '0'
234
234
  segments:
235
235
  - 0
236
- hash: -3852254251876092451
236
+ hash: -2919541554530046896
237
237
  none: false
238
238
  required_rubygems_version: !ruby/object:Gem::Requirement
239
239
  requirements:
240
- - - ! '>'
240
+ - - ! '>='
241
241
  - !ruby/object:Gem::Version
242
- version: 1.3.1
242
+ version: '0'
243
+ segments:
244
+ - 0
245
+ hash: -2919541554530046896
243
246
  none: false
244
247
  requirements: []
245
248
  rubyforge_project: rspec
246
249
  rubygems_version: 1.8.24
247
250
  signing_key:
248
251
  specification_version: 3
249
- summary: rspec-expectations-2.14.0.rc1
252
+ summary: rspec-expectations-2.14.0
250
253
  test_files:
251
254
  - features/README.md
252
255
  - features/Upgrade.md