Skip to content

Commit

Permalink
Added 1.9 compatibility suite. New Release.
Browse files Browse the repository at this point in the history
Signed-off-by: Jeremy McAnally <jeremymcanally@gmail.com>
  • Loading branch information
mhennemeyer authored and jm committed Feb 11, 2009
1 parent 90a5ba0 commit b5fbf56
Show file tree
Hide file tree
Showing 10 changed files with 732 additions and 48 deletions.
4 changes: 3 additions & 1 deletion countloc.rb
@@ -1,4 +1,4 @@

# This is here because OptionsParser is SO slow.
def extract_path(argv)
if argv[1].nil?
if argv[0] =~ /-a/
Expand All @@ -22,6 +22,8 @@ def all?
ARGV.join =~ /-a/
end



def comment?(line)
line =~ /^\s*#/
end
Expand Down
10 changes: 4 additions & 6 deletions lib/matchy.rb
Expand Up @@ -3,16 +3,14 @@

# 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?(MiniTest) && defined?(MiniTest::Assertions) &&
(!defined?(Test::Unit::TestCase) || !(Test::Unit::TestCase < MiniTest::Assertions))
end
def self.assertions_module
Expand All @@ -39,14 +37,14 @@ def self.test_case_class
require 'matchy/built_in/change_expectations'


# Evil hack.
# 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_300, :run
alias_method :old_run_method_aliased_by_matchy, :run
def run(whatever, *args, &block)
$current_test_case = self
old_run_method_aliased_by_matchy_300(whatever, *args, &block)
old_run_method_aliased_by_matchy(whatever, *args, &block)
end
end

Expand Down
2 changes: 1 addition & 1 deletion lib/matchy/built_in/change_expectations.rb
Expand Up @@ -14,7 +14,7 @@ def change(&block)
comparison = after != before
if list = matcher.msgs
comparison = case list[0].name
# todo provide meaningful messages
# todo: provide meaningful messages
when :by then (after == before + list[0].args[0] || after == before - list[0].args[0])
when :by_at_least then (after >= before + list[0].args[0] || after <= before - list[0].args[0])
when :by_at_most then (after <= before + list[0].args[0] && after >= before - list[0].args[0])
Expand Down
16 changes: 7 additions & 9 deletions lib/matchy/built_in/error_expectations.rb
Expand Up @@ -11,26 +11,24 @@ module TestCaseExtensions
#
def raise_error(*obj)
build_matcher(:raise_error, obj) do |receiver, matcher, args|
@receiver = receiver
expected = args[0] || StandardError
expected = args[0] || Exception
raised = false
error = nil
begin
@receiver.call
rescue StandardError => e
receiver.call
rescue Exception => e
raised = true
error = e
end

if expected.respond_to?(:ancestors) && expected.ancestors.include?(Exception)
matcher.positive_msg = "Expected #{@receiver.inspect} to raise #{expected.name}, " +
matcher.positive_msg = "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_msg = "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_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."
comparison = (raised && (expected.kind_of?(Regexp) ? ((error.message =~ expected) ? true : false) : expected == error.message))
end
comparison
Expand Down
26 changes: 6 additions & 20 deletions lib/matchy/built_in/truth_expectations.rb
Expand Up @@ -18,16 +18,6 @@ def be(*obj)
end
end

# Checks if the given object is kind_of? the expected class
#
# ==== Examples
#
# "hello".should be_kind_of(String)
# 3.should be_kind_of(Fixnum)
def be_kind_of(*klass)
ask_for(:kind_of, :with_arg => klass)
end

# Checks if the given object is within a given object and delta.
#
# ==== Examples
Expand Down Expand Up @@ -122,7 +112,7 @@ def be_success
end

alias_method :old_missing, :method_missing
# ==be_*something*
# ==be_*something(*args)
#
# ===This method_missing acts as a matcher builder.
# If a call to be_xyz() reaches this method_missing (say: obj.should be_xyz),
Expand All @@ -131,27 +121,23 @@ def be_success
# ==== Examples
#
# nil.should be_nil
# 17.should be_kind_of(Fixnum)
# obj.something? #=> true
# obj.should be_something
def method_missing(name, *args, &block)
if (name.to_s =~ /^be_(.+)/)
build_matcher(name, args) do |receiver, matcher, args|
matcher.positive_msg = "Expected #{receiver.inspect} to return true for #{$1}?."
matcher.negative_msg = "Expected #{receiver.inspect} to return false for #{$1}?."
receiver.send(($1 + "?").to_sym)
end
ask_for($1, :with_arg => args)
else
old_missing(name, *args, &block)
end
end

private
def ask_for(sym, option={})
obj = option[:with_arg] || []
build_matcher(sym, obj) do |receiver, matcher, args|
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 #{sym} #{(expected && expected.inspect) || ''}."
matcher.negative_msg = "Expected #{receiver.inspect} to not #{sym} #{(expected && expected.inspect) || ''}."
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'}'."
expected ? receiver.send(meth, expected) : receiver.send(meth)
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/matchy/version.rb
@@ -1,7 +1,7 @@
module Matchy
module VERSION #:nodoc:
MAJOR = 0
MINOR = 1
MINOR = 3
TINY = 0

STRING = [MAJOR, MINOR, TINY].join('.')
Expand Down
2 changes: 1 addition & 1 deletion matchy.gemspec
@@ -1,5 +1,5 @@
Gem::Specification.new do |s|
s.name = "matchy300"
s.name = "matchy"
s.version = "0.2.0"
s.date = "2009-02-08"
s.summary = "RSpec-esque matchers for use in Test::Unit"
Expand Down

0 comments on commit b5fbf56

Please sign in to comment.