Permalink
Browse files

Use proper names for stuff ("receiver"/"expected"). Also, fixed a tes…

…t that was a duplicate for be_close
  • Loading branch information...
1 parent 108a1be commit cc72cd2deddad24c95646ae4d6e8938169d1e6ef @jm committed Oct 9, 2008
@@ -1,19 +1,19 @@
module Matchy
module Expectations
class IncludeExpectation < Base
- def matches?(obj)
- @object.each do |o|
- return false unless obj.include?(o)
+ def matches?(receiver)
+ @expected.each do |o|
+ return false unless receiver.include?(o)
end
true
end
end
class ExcludeExpectation < Base
- def matches?(obj)
- @object.each do |o|
- return false unless !obj.include?(o)
+ def matches?(receiver)
+ @expected.each do |o|
+ return false unless !receiver.include?(o)
end
true
@@ -1,27 +1,27 @@
module Matchy
module Expectations
class RaiseErrorExpectation < Base
- def matches?(obj)
+ def matches?(receiver)
begin
- obj.call
+ receiver.call
return false
rescue StandardError => e
- return false unless e.class.ancestors.include?(@object)
+ return false unless e.class.ancestors.include?(@expected)
return true
end
end
end
class ThrowSymbolExpectation < Base
- def matches?(obj)
+ def matches?(receiver)
begin
- obj.call
+ receiver.call
rescue NameError => e
raise e unless e.message =~ /uncaught throw/
thrown_symbol = e.name.to_sym
ensure
- return @object == thrown_symbol
+ return @expected == thrown_symbol
end
end
end
@@ -8,61 +8,61 @@ module Expectations
# "hello".length.should_not == 2
#
class OperatorExpectation < Base
- def initialize(obj, match)
- @object = obj
+ def initialize(receiver, match)
+ @receiver = receiver
@match = match
end
- def ==(obj)
- if @object.send(:==, obj) == @match
+ def ==(expected)
+ if @receiver.send(:==, expected) == @match
pass!
else
fail!
end
end
- def ===(obj)
- if @object.send(:===, obj) == @match
+ def ===(expected)
+ if @receiver.send(:===, expected) == @match
pass!
else
fail!
end
end
- def =~(obj)
- if @object.send(:=~, obj).nil? != @match
+ def =~(expected)
+ if @receiver.send(:=~, expected).nil? != @match
pass!
else
fail!
end
end
- def >(obj)
- if @object.send(:>, obj) == @match
+ def >(expected)
+ if @receiver.send(:>, expected) == @match
pass!
else
fail!
end
end
- def <(obj)
- if @object.send(:<, obj) == @match
+ def <(expected)
+ if @receiver.send(:<, expected) == @match
pass!
else
fail!
end
end
- def >=(obj)
- if @object.send(:>=, obj) == @match
+ def >=(expected)
+ if @receiver.send(:>=, expected) == @match
pass!
else
fail!
end
end
- def <=(obj)
- if @object.send(:<=, obj) == @match
+ def <=(expected)
+ if @receiver.send(:<=, expected) == @match
pass!
else
fail!
@@ -1,20 +1,20 @@
module Matchy
module Expectations
class BeExpectation < Base
- def matches?(obj)
- @object == obj
+ def matches?(receiver)
+ @expected == receiver
end
end
class BeCloseExpectation < Base
- def initialize(obj, delta, test_case)
- @object = obj
+ def initialize(expected, delta, test_case)
+ @expected = expected
@test_case = test_case
@delta = delta
end
- def matches?(obj)
- (obj - @object).abs < @delta
+ def matches?(receiver)
+ (receiver - @expected).abs < @delta
end
end
@@ -23,26 +23,26 @@ def initialize(test_case)
@test_case = test_case
end
- def matches?(obj)
- obj.exist?
+ def matches?(receiver)
+ receiver.exist?
end
end
class EqlExpectation < Base
- def matches?(obj)
- @object.eql?(obj)
+ def matches?(receiver)
+ @expected.eql?(receiver)
end
end
class EqualExpectation < Base
- def matches?(obj)
- @object.equal?(obj)
+ def matches?(receiver)
+ @expected.equal?(receiver)
end
end
class SatisfyExpectation < Base
- def matches?(obj)
- @object.call(obj) == true
+ def matches?(receiver)
+ @expected.call(receiver) == true
end
end
@@ -11,14 +11,14 @@ class Base
# Takes object to match against and the test_case we're in so we can feed it the
# successes/failures.
- def initialize(obj, test_case)
- @object = obj
+ def initialize(expected, test_case)
+ @expected = expected
@test_case = test_case
end
# Match the given objects against some logic. This raises an error in Base because
# each matcher (obviously) has to implement its own logic.
- def matches?(obj)
+ def matches?(receiver)
raise "Please provide logic to match your expectation to an object! OR ELSE."
end
@@ -6,7 +6,7 @@ def setup
end
def test_ivars
- @instance.instance_variable_get("@object").should eql(true)
+ @instance.instance_variable_get("@expected").should eql(true)
end
def test_matches_throws_error
@@ -17,7 +17,7 @@ def test_matches_throws_error
def test_fail_should_raise
lambda {
- @instance.fail!
+ @instance.fail!(false)
}.should raise_error(Test::Unit::AssertionFailedError)
end
@@ -28,4 +28,8 @@ def test_pass
def test_failure_message
@instance.failure_message.should eql("OMG FAIL.")
end
+
+ def test_negative_failure_message
+ @instance.negative_failure_message.should eql("OMG FAIL TO FAIL.")
+ end
end
@@ -92,9 +92,7 @@ def test_be_fail
end
def test_be_close
- lambda {
- true.should_not be(true)
- }.should raise_error(Test::Unit::AssertionFailedError)
+ (5.0 - 2.0).should be_close(3.0)
end
def test_satisfy

0 comments on commit cc72cd2

Please sign in to comment.