Skip to content

Commit

Permalink
more more consistency across failure messages for operator matchers
Browse files Browse the repository at this point in the history
  • Loading branch information
dchelimsky committed Dec 20, 2010
1 parent fe8f85e commit d1566d4
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 47 deletions.
58 changes: 13 additions & 45 deletions features/matchers/operators.feature
Expand Up @@ -90,17 +90,13 @@ Feature: Operator matchers
"""
describe "Strawberry" do
it { should == "Strawberry" }
it { should < "Tomato" }
it { should > "Apple" }
it { should <= "Turnip" }
it { should >= "Banana" }
it { should be < "Tomato" }
it { should be > "Apple" }
it { should be <= "Turnip" }
it { should be >= "Banana" }
it { should =~ /berry/ }
it { should_not == "Peach" }
it { should_not < "Cranberry" }
it { should_not > "Zuchini" }
it { should_not <= "Potato" }
it { should_not >= "Tomato" }
it { should_not =~ /apple/ }
it "reports that it is a string using ===" do
Expand All @@ -109,17 +105,13 @@ Feature: Operator matchers
# deliberate failures
it { should == "Peach" }
it { should < "Cranberry" }
it { should > "Zuchini" }
it { should <= "Potato" }
it { should >= "Tomato" }
it { should be < "Cranberry" }
it { should be > "Zuchini" }
it { should be <= "Potato" }
it { should be >= "Tomato" }
it { should =~ /apple/ }
it { should_not == "Strawberry" }
it { should_not < "Tomato" }
it { should_not > "Apple" }
it { should_not <= "Turnip" }
it { should_not >= "Banana" }
it { should_not =~ /berry/ }
it "fails a spec asserting that it is a symbol" do
Expand All @@ -128,7 +120,7 @@ Feature: Operator matchers
end
"""
When I run "rspec string_operator_matchers_spec.rb"
Then the output should contain "26 examples, 13 failures"
Then the output should contain "18 examples, 9 failures"
And the output should contain:
"""
Failure/Error: it { should == "Peach" }
Expand All @@ -137,25 +129,25 @@ Feature: Operator matchers
"""
And the output should contain:
"""
Failure/Error: it { should < "Cranberry" }
Failure/Error: it { should be < "Cranberry" }
expected: < "Cranberry"
got: "Strawberry"
"""
And the output should contain:
"""
Failure/Error: it { should > "Zuchini" }
Failure/Error: it { should be > "Zuchini" }
expected: > "Zuchini"
got: "Strawberry"
"""
And the output should contain:
"""
Failure/Error: it { should <= "Potato" }
Failure/Error: it { should be <= "Potato" }
expected: <= "Potato"
got: "Strawberry"
"""
And the output should contain:
"""
Failure/Error: it { should >= "Tomato" }
Failure/Error: it { should be >= "Tomato" }
expected: >= "Tomato"
got: "Strawberry"
"""
Expand All @@ -172,30 +164,6 @@ Feature: Operator matchers
got: "Strawberry"
"""
And the output should contain:
"""
Failure/Error: it { should_not < "Tomato" }
expected not: < "Tomato"
got: "Strawberry"
"""
And the output should contain:
"""
Failure/Error: it { should_not > "Apple" }
expected not: > "Apple"
got: "Strawberry"
"""
And the output should contain:
"""
Failure/Error: it { should_not <= "Turnip" }
expected not: <= "Turnip"
got: "Strawberry"
"""
And the output should contain:
"""
Failure/Error: it { should_not >= "Banana" }
expected not: >= "Banana"
got: "Strawberry"
"""
And the output should contain:
"""
Failure/Error: it { should_not =~ /berry/ }
expected not: =~ /berry/
Expand Down
2 changes: 1 addition & 1 deletion lib/rspec/matchers/be.rb
Expand Up @@ -96,7 +96,7 @@ def matches?(actual)
end

def failure_message_for_should
"expected: #{@operator} #{@expected}\n got: #{@operator.to_s.gsub(/./, ' ')} #{@actual.inspect}"
"expected: #{@operator} #{@expected.inspect}\n got: #{@operator.to_s.gsub(/./, ' ')} #{@actual.inspect}"
end

def failure_message_for_should_not
Expand Down
2 changes: 1 addition & 1 deletion spec/rspec/matchers/be_spec.rb
Expand Up @@ -347,7 +347,7 @@
end

it "fails when === operator returns false" do
lambda { Hash.should be === "not a hash" }.should fail_with(%[expected: === not a hash\n got: Hash])
lambda { Hash.should be === "not a hash" }.should fail_with(%[expected: === "not a hash"\n got: Hash])
end
end

Expand Down

0 comments on commit d1566d4

Please sign in to comment.