Skip to content

Commit

Permalink
Fix be_<predicate> to not support comparative chaining like be does.
Browse files Browse the repository at this point in the history
  • Loading branch information
myronmarston committed Aug 15, 2013
1 parent c28bb58 commit 64e04b9
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 23 deletions.
52 changes: 29 additions & 23 deletions lib/rspec/matchers/built_in/be.rb
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions spec/rspec/matchers/be_spec.rb
Expand Up @@ -56,6 +56,12 @@ def happy?
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
Expand Down

0 comments on commit 64e04b9

Please sign in to comment.