rspec-expectations 2.14.1 → 2.14.2

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.
@@ -1,3 +1,19 @@
1
+ ### 2.14.2 / 2013-08-14
2
+ [full changelog](http://github.com/rspec/rspec-expectations/compare/v2.14.1...v2.14.2)
3
+
4
+ Bug fixes
5
+
6
+ * Fix `be_<predicate>` matcher to not support operator chaining like the
7
+ `be` matcher does (e.g. `be == 5`). This led to some odd behaviors
8
+ since `be_<predicate> == anything` returned a `BeComparedTo` matcher
9
+ and was thus always truthy. This was a consequence of the implementation
10
+ (e.g. subclassing the basic `Be` matcher) and was not intended behavior.
11
+ (Myron Marston).
12
+ * Fix `change` matcher to compare using `==` in addition to `===`. This
13
+ is important for an expression like:
14
+ `expect {}.to change { a.class }.from(ClassA).to(ClassB)` because
15
+ `SomeClass === SomeClass` returns false. (Myron Marston)
16
+
1
17
  ### 2.14.1 / 2013-08-08
2
18
  [full changelog](http://github.com/rspec/rspec-expectations/compare/v2.14.0...2.14.1)
3
19
 
@@ -2,7 +2,8 @@ module RSpec
2
2
  module Expectations
3
3
  # @private
4
4
  module Version
5
- STRING = '2.14.1'
5
+ STRING = '2.14.2'
6
6
  end
7
7
  end
8
8
  end
9
+
@@ -45,7 +45,33 @@ module RSpec
45
45
  end
46
46
  end
47
47
 
48
+ module BeHelpers
49
+ private
50
+
51
+ def args_to_s
52
+ @args.empty? ? "" : parenthesize(inspected_args.join(', '))
53
+ end
54
+
55
+ def parenthesize(string)
56
+ "(#{string})"
57
+ end
58
+
59
+ def inspected_args
60
+ @args.collect{|a| a.inspect}
61
+ end
62
+
63
+ def expected_to_sentence
64
+ split_words(@expected)
65
+ end
66
+
67
+ def args_to_sentence
68
+ to_sentence(@args)
69
+ end
70
+ end
71
+
48
72
  class Be < BaseMatcher
73
+ include BeHelpers
74
+
49
75
  def initialize(*args, &block)
50
76
  @args = args
51
77
  end
@@ -67,28 +93,6 @@ module RSpec
67
93
  BeComparedTo.new(operand, operator)
68
94
  end
69
95
  end
70
-
71
- private
72
-
73
- def args_to_s
74
- @args.empty? ? "" : parenthesize(inspected_args.join(', '))
75
- end
76
-
77
- def parenthesize(string)
78
- "(#{string})"
79
- end
80
-
81
- def inspected_args
82
- @args.collect{|a| a.inspect}
83
- end
84
-
85
- def expected_to_sentence
86
- split_words(@expected)
87
- end
88
-
89
- def args_to_sentence
90
- to_sentence(@args)
91
- end
92
96
  end
93
97
 
94
98
  class BeComparedTo < Be
@@ -126,7 +130,9 @@ it is a bit confusing.
126
130
  end
127
131
  end
128
132
 
129
- class BePredicate < Be
133
+ class BePredicate < BaseMatcher
134
+ include BeHelpers
135
+
130
136
  def initialize(*args, &block)
131
137
  @expected = parse_expected(args.shift)
132
138
  @args = args
@@ -133,7 +133,7 @@ MESSAGE
133
133
  end
134
134
 
135
135
  def expected_matches_actual?(expected, actual)
136
- expected === actual
136
+ expected === actual || actual == expected
137
137
  end
138
138
  end
139
139
  end
@@ -46,6 +46,12 @@ describe "expect(...).to be_predicate" do
46
46
  expect(actual).to be_foo
47
47
  }.to raise_error(/aaaah/)
48
48
  end
49
+
50
+ it "does not support operator chaining like a basic `be` matcher does" do
51
+ matcher = be_happy
52
+ value = double(:happy? => false)
53
+ expect(be_happy == value).to be false
54
+ end
49
55
  end
50
56
 
51
57
  describe "expect(...).not_to be_predicate" do
@@ -28,6 +28,20 @@ describe "expect { ... }.to change(actual, message)" do
28
28
  end
29
29
  end
30
30
 
31
+ it "can specify the change of a variable's class" do
32
+ val = nil
33
+
34
+ expect {
35
+ val = 42
36
+ }.to change { val.class }.from(NilClass).to(Fixnum)
37
+
38
+ expect {
39
+ expect {
40
+ val = "string"
41
+ }.to change { val.class }.from(Fixnum).to(NilClass)
42
+ }.to fail_with(/but is now String/)
43
+ end
44
+
31
45
  context "with boolean values" do
32
46
  before(:each) do
33
47
  @instance = SomethingExpected.new
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: rspec-expectations
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 2.14.1
5
+ version: 2.14.2
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-08-09 00:00:00.000000000 Z
13
+ date: 2013-08-15 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  version_requirements: !ruby/object:Gem::Requirement
@@ -234,7 +234,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
234
234
  version: '0'
235
235
  segments:
236
236
  - 0
237
- hash: 1211748927981190592
237
+ hash: 2244321019137391681
238
238
  none: false
239
239
  required_rubygems_version: !ruby/object:Gem::Requirement
240
240
  requirements:
@@ -243,14 +243,14 @@ required_rubygems_version: !ruby/object:Gem::Requirement
243
243
  version: '0'
244
244
  segments:
245
245
  - 0
246
- hash: 1211748927981190592
246
+ hash: 2244321019137391681
247
247
  none: false
248
248
  requirements: []
249
249
  rubyforge_project: rspec
250
250
  rubygems_version: 1.8.24
251
251
  signing_key:
252
252
  specification_version: 3
253
- summary: rspec-expectations-2.14.1
253
+ summary: rspec-expectations-2.14.2
254
254
  test_files:
255
255
  - features/README.md
256
256
  - features/Upgrade.md