Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Renamed positive_msg and negative_msg to positive_failure_message and…

… negative_failure_message which seems more obvious to me.

Removed minitest support. I don't use minitest and the way it was added to matchy was causing issues with rails.
  • Loading branch information...
commit cd629cddf9e781635c113b60b4b1ecb47202417b 1 parent ed51a84
@jnunemaker authored
View
2  .gitignore
@@ -1,3 +1,3 @@
pkg/*
.DS_Store
-
+*.gem
View
1  Manifest.txt
@@ -31,7 +31,6 @@ test/test_error_expectations.rb
test/test_expectation_builder.rb
test/test_helper.rb
test/test_matcher_builder.rb
-test/test_minitest_compatibility.rb
test/test_modals.rb
test/test_operator_expectations.rb
test/test_truth_expectations.rb
View
6 README.rdoc
@@ -65,8 +65,8 @@ Hate writing assertions? Need a little behavior-driven love in your tests? Then
# also you can set positive (should) and negative (should not) failure messages
custom_matcher :be_nil do |receiver, matcher, args|
- matcher.positive_msg = "Expected #{receiver} to be nil but it wasn't"
- matcher.negative_msg = "Expected #{receiver} not to be nil but it was"
+ matcher.positive_failure_message = "Expected #{receiver} to be nil but it wasn't"
+ matcher.negative_failure_message = "Expected #{receiver} not to be nil but it was"
receiver.nil?
end
end
@@ -110,7 +110,7 @@ Hate writing assertions? Need a little behavior-driven love in your tests? Then
count = args[0]
something = matcher.msgs[0].name
actual = receiver.send(something).length
- matcher.positive_msg = "Expected #{receiver} to have #{actual} #{something}, but found #{count} "
+ matcher.positive_failure_message = "Expected #{receiver} to have #{actual} #{something}, but found #{count} "
actual == count
end
end
View
41 lib/matchy.rb
@@ -1,29 +1,7 @@
$:.unshift(File.dirname(__FILE__)) unless
$:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
-# Matchy should work with either test/unit or minitest
-module Matchy
- def self.minitest?
- # This needs to be better.
- # How can we decide if we really have a
- # suite of MiniTest Tests?
- # Rails for example defines MiniTest, so only check for
- # defined?(MiniTest) would be malicious
- defined?(MiniTest) && defined?(MiniTest::Assertions) &&
- (!defined?(Test::Unit::TestCase) || !(Test::Unit::TestCase < MiniTest::Assertions))
- end
-
- def self.assertions_module
- minitest? ? MiniTest::Assertions : Test::Unit::Assertions
- end
-
- def self.test_case_class
- minitest? ? MiniTest::Unit::TestCase : Test::Unit::TestCase
- end
-end
-
-require 'rubygems'
-require 'test/unit' unless Matchy.minitest?
+require 'test/unit'
require 'matchy/expectation_builder'
require 'matchy/modals'
@@ -37,18 +15,5 @@ def self.test_case_class
require 'matchy/built_in/operator_expectations'
require 'matchy/built_in/change_expectations'
-
-# Hack of Evil.
-# Track the current testcase and
-# provide it to the operator matchers.
-Matchy.test_case_class.class_eval do
- alias_method :old_run_method_aliased_by_matchy, :run
- def run(whatever, *args, &block)
- $current_test_case = self
- old_run_method_aliased_by_matchy(whatever, *args, &block)
- end
-end
-
-Matchy.test_case_class.send(:include, Matchy::Expectations::TestCaseExtensions)
-Matchy.test_case_class.send(:include, Matchy::MatcherBuilder)
-Matchy.test_case_class.send(:extend, Matchy::CustomMatcher)
+Test::Unit::TestCase.send(:include, Matchy::Expectations::TestCaseExtensions)
+include Matchy::CustomMatcher
View
4 lib/matchy/built_in/change_expectations.rb
@@ -21,8 +21,8 @@ def change(&block)
when :from then (before == list[0].args[0]) && (after == list[1].args[0])
end
end
- matcher.positive_msg = "given block shouldn't alter the block attached to change"
- matcher.negative_msg = "given block should alter the block attached to change"
+ matcher.positive_failure_message = "given block shouldn't alter the block attached to change"
+ matcher.negative_failure_message = "given block should alter the block attached to change"
comparison
end
end
View
4 lib/matchy/built_in/enumerable_expectations.rb
@@ -31,8 +31,8 @@ def exclude(*obj)
private
def _clude(sym, obj)
build_matcher(sym, obj) do |given, matcher, args|
- matcher.positive_msg = "Expected #{given.inspect} to #{sym} #{args.inspect}."
- matcher.negative_msg = "Expected #{given.inspect} to not #{sym} #{args.inspect}."
+ matcher.positive_failure_message = "Expected #{given.inspect} to #{sym} #{args.inspect}."
+ matcher.negative_failure_message = "Expected #{given.inspect} to not #{sym} #{args.inspect}."
args.inject(true) {|m,o| m && (given.include?(o) == (sym == :include)) }
end
end
View
12 lib/matchy/built_in/error_expectations.rb
@@ -21,14 +21,14 @@ def raise_error(*obj)
error = e
end
if expected.respond_to?(:ancestors) && expected.ancestors.include?(Exception)
- matcher.positive_msg = "Expected #{receiver.inspect} to raise #{expected.name}, " +
+ matcher.positive_failure_message = "Expected #{receiver.inspect} to raise #{expected.name}, " +
(error ? "but #{error.class.name} was raised instead." : "but none was raised.")
- matcher.negative_msg = "Expected #{receiver.inspect} to not raise #{expected.name}."
+ matcher.negative_failure_message = "Expected #{receiver.inspect} to not raise #{expected.name}."
comparison = (raised && error.class.ancestors.include?(expected))
else
message = error ? error.message : "none"
- matcher.positive_msg = "Expected #{receiver.inspect} to raise error with message matching '#{expected}', but '#{message}' was raised."
- matcher.negative_msg = "Expected #{receiver.inspect} to raise error with message not matching '#{expected}', but '#{message}' was raised."
+ matcher.positive_failure_message = "Expected #{receiver.inspect} to raise error with message matching '#{expected}', but '#{message}' was raised."
+ matcher.negative_failure_message = "Expected #{receiver.inspect} to raise error with message not matching '#{expected}', but '#{message}' was raised."
comparison = (raised && (expected.kind_of?(Regexp) ? ((error.message =~ expected) ? true : false) : expected == error.message))
end
comparison
@@ -55,9 +55,9 @@ def throw_symbol(*obj)
raise e unless e.message =~ /uncaught throw/
thrown_symbol = e.message.match(/uncaught throw :(.+)/)[1].to_sym
end
- matcher.positive_msg = "Expected #{receiver.inspect} to throw :#{expected}, but " +
+ matcher.positive_failure_message = "Expected #{receiver.inspect} to throw :#{expected}, but " +
"#{thrown_symbol ? ':' + thrown_symbol.to_s + ' was thrown instead' : 'no symbol was thrown'}."
- matcher.negative_msg = "Expected #{receiver.inspect} to not throw :#{expected}."
+ matcher.negative_failure_message = "Expected #{receiver.inspect} to not throw :#{expected}."
expected == thrown_symbol
end
end
View
2  lib/matchy/built_in/operator_expectations.rb
@@ -8,7 +8,7 @@ module Expectations
# "hello".length.should_not == 2
#
class OperatorExpectation #< Base
- include Matchy.assertions_module
+ include Test::Unit::Assertions
def initialize(receiver, match)
@receiver, @match = receiver, match
View
16 lib/matchy/built_in/truth_expectations.rb
@@ -12,8 +12,8 @@ module TestCaseExtensions
def be(*obj)
build_matcher(:be, obj) do |receiver, matcher, args|
@receiver, expected = receiver, args[0]
- matcher.positive_msg = "Expected #{@receiver.inspect} to be #{expected.inspect}."
- matcher.negative_msg = "Expected #{@receiver.inspect} to not be #{expected.inspect}."
+ matcher.positive_failure_message = "Expected #{@receiver.inspect} to be #{expected.inspect}."
+ matcher.negative_failure_message = "Expected #{@receiver.inspect} to not be #{expected.inspect}."
expected == @receiver
end
end
@@ -28,8 +28,8 @@ def be(*obj)
def be_close(obj, delta = 0.3)
build_matcher(:be_close, [obj, delta]) do |receiver, matcher, args|
@receiver, expected, delta = receiver, args[0], args[1]
- matcher.positive_msg = "Expected #{@receiver.inspect} to be close to #{expected.inspect} (delta: #{delta})."
- matcher.negative_msg = "Expected #{@receiver.inspect} to not be close to #{expected.inspect} (delta: #{delta})."
+ matcher.positive_failure_message = "Expected #{@receiver.inspect} to be close to #{expected.inspect} (delta: #{delta})."
+ matcher.negative_failure_message = "Expected #{@receiver.inspect} to not be close to #{expected.inspect} (delta: #{delta})."
(@receiver - expected).abs < delta
end
end
@@ -84,8 +84,8 @@ def equal(*obj)
def satisfy(*obj)
build_matcher(:satisfy, obj) do |receiver, matcher, args|
@receiver, expected = receiver, args[0]
- matcher.positive_msg = "Expected #{@receiver.inspect} to satisfy given block."
- matcher.negative_msg = "Expected #{@receiver.inspect} to not satisfy given block."
+ matcher.positive_failure_message = "Expected #{@receiver.inspect} to satisfy given block."
+ matcher.negative_failure_message = "Expected #{@receiver.inspect} to not satisfy given block."
expected.call(@receiver) == true
end
end
@@ -136,8 +136,8 @@ def method_missing(name, *args, &block)
def ask_for(sym, option={})
build_matcher(sym, (option[:with_arg] || [])) do |receiver, matcher, args|
expected, meth = args[0], (sym.to_s + "?" ).to_sym
- matcher.positive_msg = "Expected #{receiver.inspect} to return true for #{sym}?, with '#{(expected && expected.inspect) || 'no args'}'."
- matcher.negative_msg = "Expected #{receiver.inspect} to not return true for #{sym}?, with '#{(expected && expected.inspect) || 'no args'}'."
+ matcher.positive_failure_message = "Expected #{receiver.inspect} to return true for #{sym}?, with '#{(expected && expected.inspect) || 'no args'}'."
+ matcher.negative_failure_message = "Expected #{receiver.inspect} to not return true for #{sym}?, with '#{(expected && expected.inspect) || 'no args'}'."
expected ? receiver.send(meth, expected) : receiver.send(meth)
end
end
View
3  lib/matchy/custom_matcher.rb
@@ -1,5 +1,6 @@
module Matchy
- module CustomMatcher
+ module CustomMatcher
+ include Matchy::MatcherBuilder
def custom_matcher(matcher_name, &block)
define_method matcher_name do |*args|
build_matcher(matcher_name, args, &block)
View
22 lib/matchy/matcher_builder.rb
@@ -6,29 +6,30 @@ def build_matcher(matcher_name=nil, args=[], &block)
end
body = lambda do |klass|
- include Matchy.assertions_module
+ include Test::Unit::Assertions
@matcher_name = matcher_name.to_s
+
def self.matcher_name
@matcher_name
end
- attr_accessor :positive_msg, :negative_msg, :msgs
+ attr_accessor :positive_failure_message, :negative_failure_message, :msgs
attr_reader :matcher_name
- def initialize match_block, test_case
+ def initialize(match_block, test_case)
@match_block, @test_case = match_block, test_case
@matcher_name = self.class.matcher_name
end
- def method_missing id, *args, &block
+ def method_missing(id, *args, &block)
require 'ostruct'
- (self.msgs ||= []) << OpenStruct.new( "name" => id, "args" => args, "block" => block )
+ (self.msgs ||= []) << OpenStruct.new("name" => id, "args" => args, "block" => block)
self
end
- def matches? given
- @positive_msg ||= "Matching with '#{matcher_name}' failed, although it should match."
- @negative_msg ||= "Matching with '#{matcher_name}' passed, although it should_not match."
+ def matches?(given)
+ @positive_failure_message ||= "Matching with '#{matcher_name}' failed, although it should match."
+ @negative_failure_message ||= "Matching with '#{matcher_name}' passed, although it should_not match."
@match_block.call(given, self)
end
@@ -39,9 +40,10 @@ def fail!(which)
def pass!(which)
@test_case.assert true
end
- alias_method :failure_message, :positive_msg
- alias_method :negative_failure_message, :negative_msg
+ alias_method :failure_message, :positive_failure_message
+ alias_method :negative_failure_message, :negative_failure_message
end
+
Class.new(&body).new(match_block, self)
end
end
View
67 matchy.gemspec
@@ -1,53 +1,26 @@
Gem::Specification.new do |s|
- s.name = "matchy"
- s.version = "0.3.1"
- s.date = "2009-02-08"
- s.summary = "RSpec-esque matchers for use in Test::Unit"
- s.email = "mhennemeyer@gmail.com"
- s.homepage = "http://github.com/mhennemeyer/matchy"
- s.description = "A 300loc refactoring of Jeremy Mcanally's Matchy. Original Description: Hate writing assertions? Need a little behavior-driven love in your tests? Then matchy is for you."
+ s.name = %q{matchy}
+ s.version = "0.4.0"
+ s.authors = ["Jeremy McAnally"]
+ s.date = %q{2009-03-23}
+ s.description = %q{RSpec-esque matchers for use in Test::Unit}
+ s.email = ["jeremy@entp.com"]
+ s.extra_rdoc_files = ["History.txt", "License.txt", "Manifest.txt", "PostInstall.txt", "README.rdoc"]
+ s.files = ["History.txt", "License.txt", "Manifest.txt", "PostInstall.txt", "README.rdoc", "Rakefile", "config/hoe.rb", "config/requirements.rb", "countloc.rb", "lib/matchy.rb", "lib/matchy/built_in/change_expectations.rb", "lib/matchy/built_in/enumerable_expectations.rb", "lib/matchy/built_in/error_expectations.rb", "lib/matchy/built_in/operator_expectations.rb", "lib/matchy/built_in/truth_expectations.rb", "lib/matchy/custom_matcher.rb", "lib/matchy/expectation_builder.rb", "lib/matchy/matcher_builder.rb", "lib/matchy/modals.rb", "lib/matchy/version.rb", "matchy.gemspec", "setup.rb", "tasks/deployment.rake", "tasks/environment.rake", "test/all.rb", "test/ruby1.9.compatibility_tests.rb", "test/test_change_expectation.rb", "test/test_custom_matcher.rb", "test/test_enumerable_expectations.rb", "test/test_error_expectations.rb", "test/test_expectation_builder.rb", "test/test_helper.rb", "test/test_matcher_builder.rb", "test/test_modals.rb", "test/test_operator_expectations.rb", "test/test_truth_expectations.rb"]
s.has_rdoc = true
- s.authors = ["Jeremy McAnally", "Matthias Hennemeyer"]
- s.files = [
- "History.txt",
- "Manifest.txt",
- "README.rdoc",
- "Rakefile",
- "matchy.gemspec",
- "History.txt",
- "License.txt",
- "Manifest.txt",
- "PostInstall.txt",
- "Rakefile",
- "config/hoe.rb",
- "config/requirements.rb",
- "lib/matchy.rb",
- "lib/matchy/version.rb",
- "lib/matchy/expectation_builder.rb",
- "lib/matchy/modals.rb",
- "lib/matchy/def_matcher.rb",
- "lib/matchy/matcher_builder.rb",
- "lib/matchy/built_in/enumerable_expectations.rb",
- "lib/matchy/built_in/error_expectations.rb",
- "lib/matchy/built_in/operator_expectations.rb",
- "lib/matchy/built_in/truth_expectations.rb",
- "lib/matchy/built_in/change_expectations.rb",
- "setup.rb"
- ]
-
- s.test_files = [
- "test/test_change_expectation.rb",
- "test/test_expectation_builder.rb",
- "test/test_minitest_compatibility.rb",
- "test/test_def_matcher.rb",
- "test/test_enumerable_expectations.rb",
- "test/test_error_expectations.rb",
- "test/test_matcher_builder.rb",
- "test/test_operator_expectations.rb",
- "test/test_truth_expectations.rb",
- "test/test_modals.rb"
- ]
+ s.homepage = %q{http://matchy.rubyforge.org}
+ s.post_install_message = %q{
+For more information on matchy, see http://matchy.rubyforge.org
+NOTE: Change this information in PostInstall.txt
+You can also delete it if you don't want it.
+
+}
s.rdoc_options = ["--main", "README.rdoc"]
s.extra_rdoc_files = ["History.txt", "Manifest.txt", "README.rdoc"]
+ s.require_paths = ["lib"]
+ s.rubyforge_project = %q{matchy}
+ s.rubygems_version = %q{1.3.1}
+ s.summary = %q{RSpec-esque matchers for use in Test::Unit}
+ s.test_files = ["test/test_change_expectation.rb", "test/test_custom_matcher.rb", "test/test_enumerable_expectations.rb", "test/test_error_expectations.rb", "test/test_expectation_builder.rb", "test/test_helper.rb", "test/test_matcher_builder.rb", "test/test_modals.rb", "test/test_operator_expectations.rb", "test/test_truth_expectations.rb"]
end
View
6 test/test_custom_matcher.rb
@@ -99,8 +99,8 @@ def test_calling_receiver_method
def test_matcher
self.class.class_eval do
custom_matcher :be_valid do |receiver, matcher, args|
- matcher.positive_msg = "Expected to be valid but wasn't"
- matcher.negative_msg = "Expected to not be valid but was"
+ matcher.positive_failure_message = "Expected to be valid but wasn't"
+ matcher.negative_failure_message = "Expected to not be valid but was"
receiver.valid?
end
end
@@ -124,7 +124,7 @@ def test_matcher_with_chained_messages
count = args[0]
something = matcher.msgs[0].name
actual = receiver.send(something).length
- matcher.positive_msg = "Expected #{receiver} to have #{actual} #{something}, but found #{count} "
+ matcher.positive_failure_message = "Expected #{receiver} to have #{actual} #{something}, but found #{count} "
actual == count
end
end
View
24 test/test_minitest_compatibility.rb
@@ -1,24 +0,0 @@
-require 'rubygems'
-require 'minitest/unit'
-load File.dirname(__FILE__) + '/../lib/matchy.rb'
-
-MiniTest::Unit.autorun
-
-class TestAThing < MiniTest::Unit::TestCase
- def test_equal_equal
- 1.should == 1
- end
-
- def test_equal_equal_fails
- #1.should == 2
- lambda{ 1.should == 2 }.should raise_error
- end
-
- def test_equal_equal_negative
- 1.should_not == 2
- end
-
- def test_equal_equal_negative_fails
- lambda{ 1.should_not == 1 }.should raise_error
- end
-end
Please sign in to comment.
Something went wrong with that request. Please try again.