From afd3a36089c5678c674146e1dce39057e711480d Mon Sep 17 00:00:00 2001 From: coreyhaines Date: Sat, 30 Jun 2012 16:55:54 -0500 Subject: [PATCH 1/5] Remove dependence on minitest/pride from default testing --- Rakefile | 1 - 1 file changed, 1 deletion(-) diff --git a/Rakefile b/Rakefile index 7d299ac..b7b2048 100644 --- a/Rakefile +++ b/Rakefile @@ -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 From 9a1d7bb201e0df748d2b86c5bd6b9f5ad9586e64 Mon Sep 17 00:00:00 2001 From: coreyhaines Date: Sat, 30 Jun 2012 16:57:52 -0500 Subject: [PATCH 2/5] Cleaner to have a default nil parameter than explicitly passing nil --- lib/ramcrest/match.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/ramcrest/match.rb b/lib/ramcrest/match.rb index 5f0f21b..ab8c3a8 100644 --- a/lib/ramcrest/match.rb +++ b/lib/ramcrest/match.rb @@ -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 From a357474af5c26c7c953b97c0da6c1c39a85c65e4 Mon Sep 17 00:00:00 2001 From: coreyhaines Date: Sat, 30 Jun 2012 17:06:41 -0500 Subject: [PATCH 3/5] Module contains type of matcher, implementation class doesn't need type --- lib/ramcrest/aint.rb | 4 ++-- lib/ramcrest/anything.rb | 4 ++-- lib/ramcrest/equal_to.rb | 4 ++-- lib/ramcrest/has_attribute.rb | 6 +++--- lib/ramcrest/includes_exactly.rb | 4 ++-- lib/ramcrest/includes_in_any_order_exactly.rb | 4 ++-- lib/ramcrest/is.rb | 4 ++-- lib/ramcrest/such_that.rb | 4 ++-- 8 files changed, 17 insertions(+), 17 deletions(-) diff --git a/lib/ramcrest/aint.rb b/lib/ramcrest/aint.rb index c217859..b1f3672 100644 --- a/lib/ramcrest/aint.rb +++ b/lib/ramcrest/aint.rb @@ -4,10 +4,10 @@ module Ramcrest module Aint module_function def aint(matcher) - AintMatcher.new(Ramcrest::EqualTo.to_matcher(matcher)) + Matcher.new(Ramcrest::EqualTo.to_matcher(matcher)) end - class AintMatcher + class Matcher include Ramcrest::Match def initialize(matcher) diff --git a/lib/ramcrest/anything.rb b/lib/ramcrest/anything.rb index ca1eb03..bb92afd 100644 --- a/lib/ramcrest/anything.rb +++ b/lib/ramcrest/anything.rb @@ -5,10 +5,10 @@ module Anything module_function def anything - AnythingMatcher.new + Matcher.new end - class AnythingMatcher + class Matcher def matches?(actual) success end diff --git a/lib/ramcrest/equal_to.rb b/lib/ramcrest/equal_to.rb index 3c0e069..947825a 100644 --- a/lib/ramcrest/equal_to.rb +++ b/lib/ramcrest/equal_to.rb @@ -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) diff --git a/lib/ramcrest/has_attribute.rb b/lib/ramcrest/has_attribute.rb index 78ddcec..41e22b8 100644 --- a/lib/ramcrest/has_attribute.rb +++ b/lib/ramcrest/has_attribute.rb @@ -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 @@ -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 diff --git a/lib/ramcrest/includes_exactly.rb b/lib/ramcrest/includes_exactly.rb index 5dde40d..cc0a9ee 100644 --- a/lib/ramcrest/includes_exactly.rb +++ b/lib/ramcrest/includes_exactly.rb @@ -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 diff --git a/lib/ramcrest/includes_in_any_order_exactly.rb b/lib/ramcrest/includes_in_any_order_exactly.rb index c68b2e7..9a9d7d9 100644 --- a/lib/ramcrest/includes_in_any_order_exactly.rb +++ b/lib/ramcrest/includes_in_any_order_exactly.rb @@ -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 diff --git a/lib/ramcrest/is.rb b/lib/ramcrest/is.rb index 97868fd..a1a0a6a 100644 --- a/lib/ramcrest/is.rb +++ b/lib/ramcrest/is.rb @@ -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) diff --git a/lib/ramcrest/such_that.rb b/lib/ramcrest/such_that.rb index 4e8aadf..4fd2ef5 100644 --- a/lib/ramcrest/such_that.rb +++ b/lib/ramcrest/such_that.rb @@ -5,10 +5,10 @@ module SuchThat module_function def such_that(description = "", &matcher_block) - matcher = SuchThatMatcher.new(description, matcher_block) + matcher = Matcher.new(description, matcher_block) end - class SuchThatMatcher + class Matcher include Ramcrest::Match def initialize(description, matcher_block) From d80a6445182d763d8a3a7c46e1eaed403d100856 Mon Sep 17 00:00:00 2001 From: coreyhaines Date: Sat, 30 Jun 2012 17:18:11 -0500 Subject: [PATCH 4/5] Rest of matchers use expected as name, Aint was using 'matcher' --- lib/ramcrest/aint.rb | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/ramcrest/aint.rb b/lib/ramcrest/aint.rb index b1f3672..0055021 100644 --- a/lib/ramcrest/aint.rb +++ b/lib/ramcrest/aint.rb @@ -3,19 +3,19 @@ module Ramcrest module Aint module_function - def aint(matcher) - Matcher.new(Ramcrest::EqualTo.to_matcher(matcher)) + def aint(expected) + Matcher.new(Ramcrest::EqualTo.to_matcher(expected)) end 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 @@ -24,7 +24,7 @@ def matches?(actual) end def description - "not #{@matcher.description}" + "not #{@expected.description}" end end end From 1eb0014100526265f5e69fea0a8eec8e933354b0 Mon Sep 17 00:00:00 2001 From: coreyhaines Date: Sat, 30 Jun 2012 17:18:55 -0500 Subject: [PATCH 5/5] Don't need that variable set --- lib/ramcrest/such_that.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/ramcrest/such_that.rb b/lib/ramcrest/such_that.rb index 4fd2ef5..6e07217 100644 --- a/lib/ramcrest/such_that.rb +++ b/lib/ramcrest/such_that.rb @@ -5,7 +5,7 @@ module SuchThat module_function def such_that(description = "", &matcher_block) - matcher = Matcher.new(description, matcher_block) + Matcher.new(description, matcher_block) end class Matcher