Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: rspec/rspec-expectations
...
head fork: rspec/rspec-expectations
Checking mergeability… Don't worry, you can still create the pull request.
  • 4 commits
  • 6 files changed
  • 0 commit comments
  • 1 contributor
View
16 Changelog.md
@@ -1,3 +1,19 @@
+### 2.14.2 / 2013-08-14
+[full changelog](http://github.com/rspec/rspec-expectations/compare/v2.14.1...v2.14.2)
+
+Bug fixes
+
+* Fix `be_<predicate>` matcher to not support operator chaining like the
+ `be` matcher does (e.g. `be == 5`). This led to some odd behaviors
+ since `be_<predicate> == anything` returned a `BeComparedTo` matcher
+ and was thus always truthy. This was a consequence of the implementation
+ (e.g. subclassing the basic `Be` matcher) and was not intended behavior.
+ (Myron Marston).
+* Fix `change` matcher to compare using `==` in addition to `===`. This
+ is important for an expression like:
+ `expect {}.to change { a.class }.from(ClassA).to(ClassB)` because
+ `SomeClass === SomeClass` returns false. (Myron Marston)
+
### 2.14.1 / 2013-08-08
[full changelog](http://github.com/rspec/rspec-expectations/compare/v2.14.0...2.14.1)
View
3  lib/rspec/expectations/version.rb
@@ -2,7 +2,8 @@ module RSpec
module Expectations
# @private
module Version
- STRING = '2.14.1'
+ STRING = '2.14.2'
end
end
end
+
View
52 lib/rspec/matchers/built_in/be.rb
@@ -45,7 +45,33 @@ def failure_message_for_should_not
end
end
+ module BeHelpers
+ private
+
+ def args_to_s
+ @args.empty? ? "" : parenthesize(inspected_args.join(', '))
+ end
+
+ def parenthesize(string)
+ "(#{string})"
+ end
+
+ def inspected_args
+ @args.collect{|a| a.inspect}
+ end
+
+ def expected_to_sentence
+ split_words(@expected)
+ end
+
+ def args_to_sentence
+ to_sentence(@args)
+ end
+ end
+
class Be < BaseMatcher
+ include BeHelpers
+
def initialize(*args, &block)
@args = args
end
@@ -67,28 +93,6 @@ def failure_message_for_should_not
BeComparedTo.new(operand, operator)
end
end
-
- private
-
- def args_to_s
- @args.empty? ? "" : parenthesize(inspected_args.join(', '))
- end
-
- def parenthesize(string)
- "(#{string})"
- end
-
- def inspected_args
- @args.collect{|a| a.inspect}
- end
-
- def expected_to_sentence
- split_words(@expected)
- end
-
- def args_to_sentence
- to_sentence(@args)
- end
end
class BeComparedTo < Be
@@ -126,7 +130,9 @@ def negative_expectation_expression
end
end
- class BePredicate < Be
+ class BePredicate < BaseMatcher
+ include BeHelpers
+
def initialize(*args, &block)
@expected = parse_expected(args.shift)
@args = args
View
2  lib/rspec/matchers/built_in/change.rb
@@ -133,7 +133,7 @@ def matches_max?
end
def expected_matches_actual?(expected, actual)
- expected === actual
+ expected === actual || actual == expected
end
end
end
View
6 spec/rspec/matchers/be_spec.rb
@@ -46,6 +46,12 @@
expect(actual).to be_foo
}.to raise_error(/aaaah/)
end
+
+ it "does not support operator chaining like a basic `be` matcher does" do
+ matcher = be_happy
+ value = double(:happy? => false)
+ expect(be_happy == value).to be false
+ end
end
describe "expect(...).not_to be_predicate" do
View
14 spec/rspec/matchers/change_spec.rb
@@ -28,6 +28,20 @@ class SomethingExpected
end
end
+ it "can specify the change of a variable's class" do
+ val = nil
+
+ expect {
+ val = 42
+ }.to change { val.class }.from(NilClass).to(Fixnum)
+
+ expect {
+ expect {
+ val = "string"
+ }.to change { val.class }.from(Fixnum).to(NilClass)
+ }.to fail_with(/but is now String/)
+ end
+
context "with boolean values" do
before(:each) do
@instance = SomethingExpected.new

No commit comments for this range

Something went wrong with that request. Please try again.