Skip to content

Commit

Permalink
Merge pull request hamcrest#1 from coreyhaines/master
Browse files Browse the repository at this point in the history
Default parameter vs explicit nil passing
  • Loading branch information
zaphod42 committed Jun 30, 2012
2 parents 0557f60 + 1eb0014 commit 907f8b7
Show file tree
Hide file tree
Showing 10 changed files with 25 additions and 26 deletions.
1 change: 0 additions & 1 deletion Rakefile
Expand Up @@ -20,6 +20,5 @@ end
Gem::PackageTask.new(spec).define

Rake::TestTask.new do |t|
t.ruby_opts = %w{-rminitest/pride}
t.pattern = 'test/**/*.rb'
end
14 changes: 7 additions & 7 deletions lib/ramcrest/aint.rb
Expand Up @@ -3,19 +3,19 @@
module Ramcrest
module Aint
module_function
def aint(matcher)
AintMatcher.new(Ramcrest::EqualTo.to_matcher(matcher))
def aint(expected)
Matcher.new(Ramcrest::EqualTo.to_matcher(expected))
end

class AintMatcher
class Matcher
include Ramcrest::Match

def initialize(matcher)
@matcher = matcher
def initialize(expected)
@expected = expected
end

def matches?(actual)
match = @matcher.matches?(actual)
match = @expected.matches?(actual)
if match.matched?
mismatch("<#{actual}>")
else
Expand All @@ -24,7 +24,7 @@ def matches?(actual)
end

def description
"not #{@matcher.description}"
"not #{@expected.description}"
end
end
end
Expand Down
4 changes: 2 additions & 2 deletions lib/ramcrest/anything.rb
Expand Up @@ -5,10 +5,10 @@ module Anything
module_function

def anything
AnythingMatcher.new
Matcher.new
end

class AnythingMatcher
class Matcher
def matches?(actual)
success
end
Expand Down
4 changes: 2 additions & 2 deletions lib/ramcrest/equal_to.rb
Expand Up @@ -10,10 +10,10 @@ def self.to_matcher(possible_matcher)
module_function

def equal_to(expected)
EqualToMatcher.new(expected)
Matcher.new(expected)
end

class EqualToMatcher
class Matcher
include Ramcrest::Match

def initialize(expected)
Expand Down
6 changes: 3 additions & 3 deletions lib/ramcrest/has_attribute.rb
Expand Up @@ -6,10 +6,10 @@ module HasAttribute
module_function

def has_attribute(attribute_name, value_matcher = Ramcrest::Anything.anything())
HasAttribute.new(attribute_name, value_matcher)
Matcher.new(attribute_name, value_matcher)
end

class HasAttribute
class Matcher
def initialize(attribute_name, value_matcher)
@attribute_name = attribute_name
@value_matcher = value_matcher
Expand All @@ -23,7 +23,7 @@ def matches?(actual)
else
return mismatch("object <#{actual}> attribute '#{@attribute_name}' #{match.description}")
end
else
else
return mismatch("object <#{actual}> was missing attribute '#{@attribute_name}'")
end
end
Expand Down
4 changes: 2 additions & 2 deletions lib/ramcrest/includes_exactly.rb
Expand Up @@ -6,10 +6,10 @@ module IncludesExactly

def includes_exactly(*expected)
expected_matchers = expected.collect(&Ramcrest::EqualTo.method(:to_matcher))
IncludesExactlyMatcher.new(expected_matchers)
Matcher.new(expected_matchers)
end

class IncludesExactlyMatcher < Ramcrest::Enumerable::BaseEnumerableMatcher
class Matcher < Ramcrest::Enumerable::BaseEnumerableMatcher
def initialize(expected)
super("including exactly", expected)
end
Expand Down
4 changes: 2 additions & 2 deletions lib/ramcrest/includes_in_any_order_exactly.rb
Expand Up @@ -6,10 +6,10 @@ module IncludesInAnyOrderExactly

def includes_in_any_order_exactly(*expected)
expected_matchers = expected.collect(&Ramcrest::EqualTo.method(:to_matcher))
IncludesInAnyOrderExactlyMatcher.new(expected_matchers)
Matcher.new(expected_matchers)
end

class IncludesInAnyOrderExactlyMatcher < Ramcrest::Enumerable::BaseEnumerableMatcher
class Matcher < Ramcrest::Enumerable::BaseEnumerableMatcher
def initialize(expected)
super("including in any order exactly", expected)
end
Expand Down
4 changes: 2 additions & 2 deletions lib/ramcrest/is.rb
Expand Up @@ -5,10 +5,10 @@ module Is
module_function

def is(expected)
IsMatcher.new(Ramcrest::EqualTo.to_matcher(expected))
Matcher.new(Ramcrest::EqualTo.to_matcher(expected))
end

class IsMatcher
class Matcher
include Ramcrest::Match

def initialize(expected)
Expand Down
6 changes: 3 additions & 3 deletions lib/ramcrest/match.rb
Expand Up @@ -3,17 +3,17 @@ module Match
module_function

def success
MatchResult.new(true, nil)
MatchResult.new(true)
end

def mismatch(description)
def mismatch(description)
MatchResult.new(false, description)
end

class MatchResult
attr_reader :description

def initialize(matched, description)
def initialize(matched, description = nil)
@matched = matched
@description = description
end
Expand Down
4 changes: 2 additions & 2 deletions lib/ramcrest/such_that.rb
Expand Up @@ -5,10 +5,10 @@ module SuchThat
module_function

def such_that(description = "<anonymous>", &matcher_block)
matcher = SuchThatMatcher.new(description, matcher_block)
Matcher.new(description, matcher_block)
end

class SuchThatMatcher
class Matcher
include Ramcrest::Match

def initialize(description, matcher_block)
Expand Down

0 comments on commit 907f8b7

Please sign in to comment.