Skip to content
Browse files

Eliminate some warnings and align some failure messages in the process.

  • Loading branch information...
1 parent 084c6b1 commit 039baf500983bf2aac3b71c0dba0f4dec3c3df65 @dchelimsky dchelimsky committed Jul 1, 2011
View
2 lib/rspec/matchers/be_within.rb
@@ -16,7 +16,7 @@ def be_within(delta)
end
match do |actual|
- unless @_expected
+ unless defined?(@_expected)
raise ArgumentError.new("You must set an expected value using #of: be_within(#{_delta_}).of(expected_value)")
end
(actual - @_expected).abs < _delta_
View
6 lib/rspec/matchers/eq.rb
@@ -24,8 +24,8 @@ def eq(expected)
failure_message_for_should do |actual|
<<-MESSAGE
-expected #{_expected_.inspect}
- got #{actual.inspect}
+expected: #{_expected_.inspect}
+ got: #{actual.inspect}
(compared using ==)
MESSAGE
@@ -41,7 +41,7 @@ def eq(expected)
end
description do
- "== #{_expected_}"
+ "eq #{_expected_}"
end
end
end
View
64 spec/rspec/matchers/description_generation_spec.rb
@@ -5,151 +5,151 @@
RSpec::Matchers.clear_generated_description
end
- it "should == expected" do
- "this".should == "this"
- RSpec::Matchers.generated_description.should == "should == \"this\""
+ it "should eq expected" do
+ "this".should eq "this"
+ RSpec::Matchers.generated_description.should eq "should eq this"
end
- it "should not == expected" do
- "this".should_not == "that"
- RSpec::Matchers.generated_description.should == "should not == \"that\""
+ it "should not eq expected" do
+ "this".should_not eq "that"
+ RSpec::Matchers.generated_description.should eq "should not eq that"
end
it "should be empty (arbitrary predicate)" do
[].should be_empty
- RSpec::Matchers.generated_description.should == "should be empty"
+ RSpec::Matchers.generated_description.should eq "should be empty"
end
it "should not be empty (arbitrary predicate)" do
[1].should_not be_empty
- RSpec::Matchers.generated_description.should == "should not be empty"
+ RSpec::Matchers.generated_description.should eq "should not be empty"
end
it "should be true" do
true.should be_true
- RSpec::Matchers.generated_description.should == "should be true"
+ RSpec::Matchers.generated_description.should eq "should be true"
end
it "should be false" do
false.should be_false
- RSpec::Matchers.generated_description.should == "should be false"
+ RSpec::Matchers.generated_description.should eq "should be false"
end
it "should be nil" do
nil.should be_nil
- RSpec::Matchers.generated_description.should == "should be nil"
+ RSpec::Matchers.generated_description.should eq "should be nil"
end
it "should be > n" do
5.should be > 3
- RSpec::Matchers.generated_description.should == "should be > 3"
+ RSpec::Matchers.generated_description.should eq "should be > 3"
end
it "should be predicate arg1, arg2 and arg3" do
5.0.should be_between(0,10)
- RSpec::Matchers.generated_description.should == "should be between 0 and 10"
+ RSpec::Matchers.generated_description.should eq "should be between 0 and 10"
end
it "should equal" do
expected = "expected"
expected.should equal(expected)
- RSpec::Matchers.generated_description.should == "should equal \"expected\""
+ RSpec::Matchers.generated_description.should eq "should equal \"expected\""
end
it "should_not equal" do
5.should_not equal(37)
- RSpec::Matchers.generated_description.should == "should not equal 37"
+ RSpec::Matchers.generated_description.should eq "should not equal 37"
end
it "should eql" do
"string".should eql("string")
- RSpec::Matchers.generated_description.should == "should eql \"string\""
+ RSpec::Matchers.generated_description.should eq "should eql \"string\""
end
it "should not eql" do
"a".should_not eql(:a)
- RSpec::Matchers.generated_description.should == "should not eql :a"
+ RSpec::Matchers.generated_description.should eq "should not eql :a"
end
it "should have_key" do
{:a => "a"}.should have_key(:a)
- RSpec::Matchers.generated_description.should == "should have key :a"
+ RSpec::Matchers.generated_description.should eq "should have key :a"
end
it "should have_some_method" do
object = Object.new
def object.has_eyes_closed?; true; end
object.should have_eyes_closed
- RSpec::Matchers.generated_description.should == 'should have eyes closed'
+ RSpec::Matchers.generated_description.should eq 'should have eyes closed'
end
it "should have_some_method(args*)" do
object = Object.new
def object.has_taste_for?(*args); true; end
object.should have_taste_for("wine", "cheese")
- RSpec::Matchers.generated_description.should == 'should have taste for "wine", "cheese"'
+ RSpec::Matchers.generated_description.should eq 'should have taste for "wine", "cheese"'
end
it "should have n items" do
team.should have(3).players
- RSpec::Matchers.generated_description.should == "should have 3 players"
+ RSpec::Matchers.generated_description.should eq "should have 3 players"
end
it "should have at least n items" do
team.should have_at_least(2).players
- RSpec::Matchers.generated_description.should == "should have at least 2 players"
+ RSpec::Matchers.generated_description.should eq "should have at least 2 players"
end
it "should have at most n items" do
team.should have_at_most(4).players
- RSpec::Matchers.generated_description.should == "should have at most 4 players"
+ RSpec::Matchers.generated_description.should eq "should have at most 4 players"
end
it "should include" do
[1,2,3].should include(3)
- RSpec::Matchers.generated_description.should == "should include 3"
+ RSpec::Matchers.generated_description.should eq "should include 3"
end
it "array.should =~ [1,2,3]" do
[1,2,3].should =~ [1,2,3]
- RSpec::Matchers.generated_description.should == "should contain exactly 1, 2 and 3"
+ RSpec::Matchers.generated_description.should eq "should contain exactly 1, 2 and 3"
end
it "should match" do
"this string".should match(/this string/)
- RSpec::Matchers.generated_description.should == "should match /this string/"
+ RSpec::Matchers.generated_description.should eq "should match /this string/"
end
it "should raise_error" do
lambda { raise }.should raise_error
- RSpec::Matchers.generated_description.should == "should raise Exception"
+ RSpec::Matchers.generated_description.should eq "should raise Exception"
end
it "should raise_error with type" do
lambda { raise }.should raise_error(RuntimeError)
- RSpec::Matchers.generated_description.should == "should raise RuntimeError"
+ RSpec::Matchers.generated_description.should eq "should raise RuntimeError"
end
it "should raise_error with type and message" do
lambda { raise "there was an error" }.should raise_error(RuntimeError, "there was an error")
- RSpec::Matchers.generated_description.should == "should raise RuntimeError with \"there was an error\""
+ RSpec::Matchers.generated_description.should eq "should raise RuntimeError with \"there was an error\""
end
it "should respond_to" do
[].should respond_to(:insert)
- RSpec::Matchers.generated_description.should == "should respond to #insert"
+ RSpec::Matchers.generated_description.should eq "should respond to #insert"
end
it "should throw symbol" do
lambda { throw :what_a_mess }.should throw_symbol
- RSpec::Matchers.generated_description.should == "should throw a Symbol"
+ RSpec::Matchers.generated_description.should eq "should throw a Symbol"
end
it "should throw symbol (with named symbol)" do
lambda { throw :what_a_mess }.should throw_symbol(:what_a_mess)
- RSpec::Matchers.generated_description.should == "should throw :what_a_mess"
+ RSpec::Matchers.generated_description.should eq "should throw :what_a_mess"
end
def team
View
4 spec/rspec/matchers/eq_spec.rb
@@ -18,13 +18,13 @@ module Matchers
it "describes itself" do
matcher = eq(1)
matcher.matches?(1)
- matcher.description.should == "== 1"
+ matcher.description.should == "eq 1"
end
it "provides message, expected and actual on #failure_message" do
matcher = eq("1")
matcher.matches?(1)
- matcher.failure_message_for_should.should == "\nexpected \"1\"\n got 1\n\n(compared using ==)\n"
+ matcher.failure_message_for_should.should == "\nexpected: \"1\"\n got: 1\n\n(compared using ==)\n"
end
it "provides message, expected and actual on #negative_failure_message" do
View
8 spec/rspec/matchers/have_spec.rb
@@ -227,15 +227,15 @@ def items
size_matcher.matches?(owner)
#then
- length_matcher.failure_message_for_should_not.should == <<-EOF
+ length_matcher.failure_message_for_should_not.should eq <<-EOF
Isn't life confusing enough?
Instead of having to figure out the meaning of this:
should_not have_at_least(3).items_in_collection_with_length_method
We recommend that you use this instead:
should have_at_most(2).items_in_collection_with_length_method
EOF
- size_matcher.failure_message_for_should_not.should == <<-EOF
+ size_matcher.failure_message_for_should_not.should eq <<-EOF
Isn't life confusing enough?
Instead of having to figure out the meaning of this:
should_not have_at_least(3).items_in_collection_with_size_method
@@ -279,15 +279,15 @@ def items
size_matcher.matches?(owner)
#then
- length_matcher.failure_message_for_should_not.should == <<-EOF
+ length_matcher.failure_message_for_should_not.should eq <<-EOF
Isn't life confusing enough?
Instead of having to figure out the meaning of this:
should_not have_at_most(3).items_in_collection_with_length_method
We recommend that you use this instead:
should have_at_least(4).items_in_collection_with_length_method
EOF
- size_matcher.failure_message_for_should_not.should == <<-EOF
+ size_matcher.failure_message_for_should_not.should eq <<-EOF
Isn't life confusing enough?
Instead of having to figure out the meaning of this:
should_not have_at_most(3).items_in_collection_with_size_method
View
14 spec/rspec/matchers/operator_matcher_spec.rb
@@ -151,11 +151,14 @@
describe "should >=" do
- it "passes if >= passes" do
- 4.should > 3
+ it "passes if actual == expected" do
4.should >= 4
end
+ it "passes if actual > expected" do
+ 4.should >= 3
+ end
+
it "fails if > fails" do
RSpec::Expectations.should_receive(:fail_with).with(%[expected: >= 5\n got: 4], 5, 4)
4.should >= 5
@@ -178,11 +181,14 @@
describe "should <=" do
- it "passes if <= passes" do
- 4.should <= 5
+ it "passes if actual == expected" do
4.should <= 4
end
+ it "passes if actual < expected" do
+ 4.should <= 5
+ end
+
it "fails if > fails" do
RSpec::Expectations.should_receive(:fail_with).with(%[expected: <= 3\n got: 4], 3, 4)
4.should <= 3
View
12 spec/rspec/matchers/raise_error_spec.rb
@@ -161,11 +161,11 @@
raise "example message"
}.should raise_error(RuntimeError, "example message") { |err|
ran = true
- err.class.should == RuntimeError
- err.message.should == "example message"
+ err.class.should eq RuntimeError
+ err.message.should eq "example message"
}
- ran.should == true
+ ran.should be(true)
end
it "yielded block fails on it's own right" do
@@ -176,13 +176,13 @@
raise "example message"
}.should raise_error(RuntimeError, "example message") { |err|
ran = true
- 5.should == 4
+ 5.should eq 4
passed = true
}
}.should fail_with(/expected: 4/m)
- ran.should == true
- passed.should == false
+ ran.should be(true)
+ passed.should be(false)
end
it "does NOT yield exception if no error was thrown" do

0 comments on commit 039baf5

Please sign in to comment.
Something went wrong with that request. Please try again.