Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Added 1.9 compatibility suite. New Release.

Signed-off-by: Jeremy McAnally <jeremymcanally@gmail.com>
  • Loading branch information...
commit b5fbf56d9c77cc9f229b4bbbd7b97cedb4736364 1 parent 90a5ba0
@mhennemeyer mhennemeyer authored jm committed
View
4 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/
@@ -22,6 +22,8 @@ def all?
ARGV.join =~ /-a/
end
+
+
def comment?(line)
line =~ /^\s*#/
end
View
10 lib/matchy.rb
@@ -3,7 +3,6 @@
# Matchy should work with either test/unit
# or minitest
-
module Matchy
def self.minitest?
# This needs to be better.
@@ -11,8 +10,7 @@ def self.minitest?
# 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
@@ -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
View
2  lib/matchy/built_in/change_expectations.rb
@@ -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])
View
16 lib/matchy/built_in/error_expectations.rb
@@ -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
View
26 lib/matchy/built_in/truth_expectations.rb
@@ -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
@@ -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),
@@ -131,15 +121,12 @@ 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
@@ -147,11 +134,10 @@ def method_missing(name, *args, &block)
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
View
2  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('.')
View
2  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"
View
635 test/ruby1.9.compatibility_tests.rb
@@ -0,0 +1,635 @@
+# Eval this file with ruby 1.9
+
+require 'test/unit'
+require "/Users/macbook/Projekte/matchy/lib/matchy.rb"
+
+class TestAThing < Test::Unit::TestCase
+
+ def setup
+ @obj = Object.new
+ end
+
+ # ==
+ def test_operator_eql_eql
+ 1.should == 1
+ end
+
+ def test_operator_eql_eql_fails
+ lambda {1.should == 2}.should raise_error
+ end
+
+ def test_operator_eql_eql_negative
+ 1.should_not == 2
+ end
+
+ def test_operator_eql_eql_negative_fails
+ lambda {1.should_not == 1}.should raise_error
+ end
+
+ # ===
+ def test_operator_eql_eql_eql
+ 1.should === 1
+ end
+
+ def test_operator_eql_eql_eql_fails
+ lambda {1.should === 2}.should raise_error
+ end
+
+ def test_operator_eql_eql_eql_negative
+ 1.should_not === 2
+ end
+
+ def test_operator_eql_eql_eql_negative_fails
+ lambda {1.should_not === 1}.should raise_error
+ end
+
+ # =~
+ def test_operator_eql_match
+ "string".should =~ /in/
+ end
+
+ def test_operator_eql_match_fails
+ lambda {"string".should =~ /an/}.should raise_error
+ end
+
+ def test_operator_eql_match_negative
+ "string".should_not =~ /an/
+ end
+
+ def test_operator_eql_match_negative_fails
+ lambda {"string".should_not =~ /in/}.should raise_error
+ end
+
+ # <=
+ def test_operator_lt_eql
+ 1.should <= 2
+ end
+
+ def test_operator_lt_eql_fails
+ lambda {1.should <= 0}.should raise_error
+ end
+
+ def test_operator_lt_eql_negative
+ 1.should_not <= 0
+ end
+
+ def test_operator_lt_eql_negative_fails
+ lambda {1.should_not <= 2}.should raise_error
+ end
+
+ # >=
+ def test_operator_gt_eql
+ 1.should >= 0
+ end
+
+ def test_operator_gt_eql_fails
+ lambda {1.should >= 2}.should raise_error
+ end
+
+ def test_operator_gt_eql_negative
+ 1.should_not >= 2
+ end
+
+ def test_operator_gt_eql_negative_fails
+ lambda {1.should_not >= 0}.should raise_error
+ end
+
+ # <
+ def test_operator_lt
+ 1.should < 2
+ end
+
+ def test_operator_lt_fails
+ lambda {1.should < 0}.should raise_error
+ end
+
+ def test_operator_lt_negative
+ 1.should_not < 0
+ end
+
+ def test_operator_lt_negative_fails
+ lambda {1.should_not < 2}.should raise_error
+ end
+
+ # >
+ def test_operator_gt
+ 1.should > 0
+ end
+
+ def test_operator_gt_fails
+ lambda {1.should > 2}.should raise_error
+ end
+
+ def test_operator_gt_negative
+ 1.should_not > 2
+ end
+
+ def test_operator_gt_negative_fails
+ lambda {1.should_not > 0}.should raise_error
+ end
+
+ # be()
+ def test_be
+ 1.should be(1)
+ end
+
+ def test_be_fails
+ lambda {1.should be(2)}.should raise_error
+ end
+
+ def test_be_negative
+ 1.should_not be(2)
+ end
+
+ def test_be_negative_fails
+ lambda {1.should_not be(1)}.should raise_error
+ end
+
+ # be_something
+ def test_positive_be_something_method_missing_pass
+ def @obj.something?
+ true
+ end
+ @obj.should be_something
+ end
+
+ def test_positive_be_something_method_missing_fails
+ def @obj.something?
+ false
+ end
+ lambda {@obj.should be_something}.should raise_error(Test::Unit::AssertionFailedError)
+ end
+
+ def test_negative_be_something_method_missing_pass
+ def @obj.something?
+ false
+ end
+ @obj.should_not be_something
+ end
+
+ def test_negative_be_something_method_missing_fails
+ def @obj.something?
+ true
+ end
+ lambda {@obj.should_not be_something}.should raise_error(Test::Unit::AssertionFailedError)
+ end
+
+ def test_be_something_method_missing_fail_message
+ obj = "foo"
+ def obj.something?
+ true
+ end
+ matcher_obj = be_something
+ obj.should matcher_obj
+
+ matcher_obj.failure_message.should be("Expected \"foo\" to return true for something?, with 'no args'.")
+ end
+
+ def test_be_something_method_missing_negative_fail_message
+ obj = "foo"
+ def obj.something?
+ false
+ end
+ matcher_obj = be_something
+ obj.should_not matcher_obj
+
+ matcher_obj.negative_failure_message.should =~ /Expected \"foo\" to not return true for something?/
+ end
+
+ # be_something(arg)
+ def test_positive_be_something_with_arg_method_missing_pass
+ def @obj.something?(arg)
+ true
+ end
+ @obj.should be_something(1)
+ end
+
+ def test_positive_be_something_with_arg_method_missing_fails
+ def @obj.something?(arg)
+ false
+ end
+ lambda {@obj.should be_something(1)}.should raise_error(Test::Unit::AssertionFailedError)
+ end
+
+ def test_negative_be_something_method_missing_pass
+ def @obj.something?(arg)
+ false
+ end
+ @obj.should_not be_something(1)
+ end
+
+ def test_negative_be_something_method_missing_fails
+ def @obj.something?(arg)
+ true
+ end
+ lambda {@obj.should_not be_something(1)}.should raise_error(Test::Unit::AssertionFailedError)
+ end
+
+ def test_be_something_method_missing_fail_message
+ obj = "foo"
+ def obj.something?(arg)
+ true
+ end
+ matcher_obj = be_something(1)
+ obj.should matcher_obj
+
+ matcher_obj.failure_message.should be("Expected \"foo\" to return true for something?, with '1'.")
+ end
+
+ def test_be_something_method_missing_negative_fail_message
+ obj = "foo"
+ def obj.something?(arg)
+ false
+ end
+ matcher_obj = be_something(1)
+ obj.should_not matcher_obj
+
+ matcher_obj.negative_failure_message.should be("Expected \"foo\" to not return true for something?, with '1'.")
+ end
+
+ # change
+ def test_change
+ var = 1
+ lambda {var += 1}.should change {var}
+ end
+
+ def test_change_fails
+ var = 1
+ lambda do
+ lambda { }.should change {var}
+ end.should raise_error
+ end
+
+ def test_change_by
+ var = 1
+ lambda {var += 1}.should change {var}.by(1)
+ end
+
+ def test_change_by_fails
+ var = 1
+ lambda do
+ lambda {var += 2}.should change {var}.by(1)
+ end.should raise_error
+ end
+
+ def test_change_by_at_least
+ var = 1
+ lambda {var += 1}.should change {var}.by_at_least(1)
+ end
+
+ def test_change_by_at_least_fails
+ var = 1
+ lambda do
+ lambda {var += 0.9}.should change {var}.by_at_least(1)
+ end.should raise_error
+ end
+
+ def test_change_by_at_most
+ var = 1
+ lambda {var += 1}.should change {var}.by_at_most(1)
+ end
+
+ def test_change_by_at_most_fails
+ var = 1
+ lambda do
+ lambda {var += 1.1}.should change {var}.by_at_most(1)
+ end.should raise_error
+ end
+
+ def test_change_from_to
+ var = 1
+ lambda {var += 1}.should change {var}.from(1).to(2)
+ end
+
+ def test_change_from_to_fails
+ var = 1
+ lambda do
+ lambda {var += 1.1}.should change {var}.from(1).to(2)
+ end.should raise_error
+ end
+
+ # def_matcher
+ def test_def_matcher_defines_method
+ def_matcher :method_ do |given, matcher, args|
+ end
+ self.should respond_to(:method_)
+ end
+
+ def test_def_matcher_object_responds_to_matches
+ def_matcher :method_ do |given, matcher, args|
+ end
+ method_.should respond_to(:matches?)
+ end
+
+ def test_def_matcher_fail_positive
+ def_matcher :matcher do |given, matcher, args|
+ false
+ end
+ lambda {1.should matcher}.should raise_error
+ end
+
+ def test_def_matcher_pass_positive
+ def_matcher :matcher do |given, matcher, args|
+ true
+ end
+ 1.should matcher
+ end
+
+ def test_def_matcher_fail_negative
+ def_matcher :matcher do |given, matcher, args|
+ true
+ end
+ lambda {1.should_not matcher}.should raise_error
+ end
+
+ def test_def_matcher_pass_negative
+ def_matcher :matcher do |given, matcher, args|
+ false
+ end
+ 1.should_not matcher
+ end
+
+ def test_def_matcher_takes_arguments
+ def_matcher :matcher do |given, matcher, args|
+ $args = args
+ true
+ end
+ @obj.should matcher(1,2,3)
+ $args.should eql([1,2,3])
+ end
+
+ def test_def_matcher_received_method
+ def_matcher :matcher do |given, matcher, args|
+ $msgs = matcher.msgs
+ true
+ end
+ @obj.should matcher.method1
+ $msgs[0].name.should eql(:method1)
+ end
+
+ def test_def_matcher_received_method_takes_args
+ def_matcher :matcher do |given, matcher, args|
+ $msgs = matcher.msgs
+ true
+ end
+ @obj.should matcher.method1(1,2,3)
+ $msgs[0].args.should eql([1,2,3])
+ end
+
+ def test_def_matcher_received_method_takes_block
+ def_matcher :matcher do |given, matcher, args|
+ $msgs = matcher.msgs
+ true
+ end
+ @obj.should matcher.method1 { "Hello, World!"}
+ $msgs[0].block.call.should eql("Hello, World!")
+ end
+
+ def test_def_matcher_received_method_chained
+ def_matcher :matcher do |given, matcher, args|
+ $msgs = matcher.msgs
+ true
+ end
+ @obj.should matcher.method1(1,2,3) { "Hello, World!"}.
+ method2(4,5,6) { "Hello chained messages" }
+
+ $msgs[0].name.should eql(:method1)
+ $msgs[1].name.should eql(:method2)
+ $msgs[0].args.should eql([1,2,3])
+ $msgs[1].args.should eql([4,5,6])
+ $msgs[0].block.call.should eql("Hello, World!")
+ $msgs[1].block.call.should eql("Hello chained messages")
+ end
+
+ # include/exclude
+ def test_include
+ [1,2,3,4].should include(4)
+ end
+
+ def test_include_fail
+ lambda {
+ [1,2,3,4].should include(6)
+ }.should raise_error(Test::Unit::AssertionFailedError)
+ end
+
+ def test_exclude
+ [1,2,3,4].should exclude(9)
+ end
+
+ def test_exclude_fail
+ lambda {
+ [1,2,3,4].should exclude(4)
+ }.should raise_error(Test::Unit::AssertionFailedError)
+ end
+
+ def test_multi_include
+ [1,2,3,4].should include(1,2)
+ end
+
+ def test_multi_include_fail
+ lambda {
+ [1,2,3,4].should include(6,7,8)
+ }.should raise_error(Test::Unit::AssertionFailedError)
+ end
+
+ def test_multi_exclude
+ [1,2,3,4].should exclude(13,14)
+ end
+
+ def test_multi_exclude_fail
+ lambda {
+ [1,2,3,4].should exclude(2,3,4)
+ }.should raise_error(Test::Unit::AssertionFailedError)
+ end
+
+ def test_negative_include
+ [1,2,3,4].should_not include(9)
+ end
+
+ def test_negative_include_fail
+ lambda {
+ [1,2,3,4].should_not include(4)
+ }.should raise_error(Test::Unit::AssertionFailedError)
+ end
+
+ def test_negative_exclude
+ [1,2,3,4].should_not exclude(3)
+ end
+
+ def test_negative_exclude_fail
+ lambda {
+ [1,2,3,4].should_not exclude(6,7)
+ }.should raise_error(Test::Unit::AssertionFailedError)
+ end
+
+ def test_include_fail_message
+ obj = include(1)
+ obj.matches?([4,5,6])
+
+ obj.failure_message.should be("Expected [4, 5, 6] to include [1].")
+ end
+
+ def test_include_negative_fail_message
+ obj = include(1)
+ obj.matches?([4,5,6])
+
+ obj.negative_failure_message.should be("Expected [4, 5, 6] to not include [1].")
+ end
+
+ def test_exclude_fail_message
+ obj = exclude(4)
+ obj.matches?([4,5,6])
+
+ obj.failure_message.should be("Expected [4, 5, 6] to exclude [4].")
+ end
+
+ def test_exclude_negative_fail_message
+ obj = exclude(4)
+ obj.matches?([4,5,6])
+
+ obj.negative_failure_message.should be("Expected [4, 5, 6] to not exclude [4].")
+ end
+
+ # raise_error
+ def test_raises_error
+ lambda { raise "FAIL" }.should raise_error
+ end
+
+ def test_raises_error_fail
+ lambda {
+ lambda { "WIN" }.should raise_error
+ }.should raise_error(Test::Unit::AssertionFailedError)
+ end
+
+ def test_raise_error_negative_raises_error
+ lambda { "WIN" }.should_not raise_error
+ end
+
+ def test_raise_error_negative_raises_error_fail
+ lambda {
+ lambda { raise "FAIL" }.should_not raise_error
+ }.should raise_error(Test::Unit::AssertionFailedError)
+ end
+
+ def test_raise_error_raises_specific_error
+ lambda { raise TypeError }.should raise_error(TypeError)
+ end
+
+ def test_raise_error_raises_specific_error_fail_with_no_error
+ lambda {
+ lambda { "WIN" }.should raise_error(TypeError)
+ }.should raise_error(Test::Unit::AssertionFailedError)
+ end
+
+ def test_raise_error_raises_specific_error_fail_with_different_error
+ lambda {
+ lambda { raise StandardError }.should raise_error(TypeError)
+ }.should raise_error(Test::Unit::AssertionFailedError)
+ end
+
+ def test_raise_error_error_fail_message
+ obj = raise_error(TypeError)
+ obj.matches?(lambda { raise NameError })
+
+ obj.failure_message.should =~ /Expected #<(.*)> to raise TypeError, but NameError was raised instead./
+ end
+
+ def test_raise_error_error_fail_message_when_no_error
+ obj = raise_error(TypeError)
+ obj.matches?(lambda { "moop" })
+
+ obj.failure_message.should =~ /Expected #<(.*)> to raise TypeError, but none was raised./
+ end
+
+ def test_raise_error_error_negative_fail_message
+ obj = raise_error(TypeError)
+ obj.matches?(lambda { raise TypeError })
+
+ obj.negative_failure_message.should =~ /Expected #<(.*)> to not raise TypeError./
+ end
+
+ def test_raise_error_string_argument_message
+ lambda {raise "message"}.should raise_error("message")
+ end
+
+ def test_string_argument_message_fails_no_error
+ lambda do
+ lambda { 1 }.should raise_error("message")
+
+ end.should raise_error
+ end
+
+ def test_raise_error_string_argument_message_fails_wrong_message
+ lambda do
+ lambda { raise "other message" }.should raise_error("message")
+ end.should raise_error
+ end
+
+ def test_raise_error_regexp_argument_message
+ lambda {raise "message"}.should raise_error(/essa/)
+ end
+
+ def test_raise_error_regexp_argument_message_fails_no_error
+ lambda do
+ lambda { 1 }.should raise_error(/essa/)
+ end.should raise_error
+ end
+
+ def test_raise_error_regexp_argument_message_fails_wrong_message
+ lambda do
+ lambda { raise "other message" }.should raise_error(/abc/)
+ end.should raise_error(/matching/)
+ end
+
+ # throw
+ def test_throws_symbol
+ lambda {
+ throw :win
+ }.should throw_symbol(:win)
+ end
+
+ def test_throws_symbol_fails_with_different_symbol
+ lambda {
+ lambda {
+ throw :fail
+ }.should throw_symbol(:win)
+ }.should raise_error(Test::Unit::AssertionFailedError)
+ end
+
+ def test_negative_throws_symbol
+ lambda {
+ "not this time!"
+ }.should_not throw_symbol(:win)
+ end
+
+ def test_negative_throws_symbol_fails_with_different_symbol
+
+ lambda{
+ lambda {
+ throw :fail
+ }.should_not throw_symbol(:fail)
+ }.should raise_error(Test::Unit::AssertionFailedError)
+
+ end
+
+ def test_throw_fail_message
+ obj = throw_symbol(:fail)
+ obj.matches?(lambda { throw :lame })
+
+ obj.failure_message.should =~ /Expected #<(.*)> to throw :fail, but :lame was thrown instead./
+ end
+
+ def test_throw_fail_message_when_no_symbol
+ obj = throw_symbol(:fail)
+ obj.matches?(lambda { "moop" })
+
+ obj.failure_message.should =~ /Expected #<(.*)> to throw :fail, but no symbol was thrown./
+ end
+
+ def test_throw_negative_fail_message
+ obj = throw_symbol(:fail)
+ obj.matches?(lambda { throw :fail })
+
+ obj.negative_failure_message.should =~ /Expected #<(.*)> to not throw :fail./
+ end
+end
View
15 test/test_minitest_compatibility.rb
@@ -5,7 +5,20 @@
MiniTest::Unit.autorun
class TestAThing < MiniTest::Unit::TestCase
- def test_a_thing
+ 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
View
68 test/test_truth_expectations.rb
@@ -148,42 +148,42 @@ def test_equal_fail_message
obj = equal(4)
obj.matches?(5)
- obj.failure_message.should be("Expected 5 to equal 4.")
+ obj.failure_message.should be("Expected 5 to return true for equal?, with '4'.")
end
def test_equal_negative_fail_message
obj = equal(5)
obj.matches?(5)
- obj.negative_failure_message.should be("Expected 5 to not equal 5.")
+ obj.negative_failure_message.should be("Expected 5 to not return true for equal?, with '5'.")
end
def test_eql_fail_message
obj = eql(4)
obj.matches?(5)
- obj.failure_message.should be("Expected 5 to eql 4.")
+ obj.failure_message.should be("Expected 5 to return true for eql?, with '4'.")
end
def test_eql_negative_fail_message_for_eql
obj = eql(5)
obj.matches?(5)
- obj.negative_failure_message.should be("Expected 5 to not eql 5.")
+ obj.negative_failure_message.should be("Expected 5 to not return true for eql?, with '5'.")
end
def test_exist_fail_message
obj = exist
obj.matches?(Exister.new(false))
- obj.failure_message.should =~ /Expected #<(.*)> to exist./
+ obj.failure_message.should =~ /Expected #<(.*)> to return true for exist?./
end
def test_exist_negative_fail_message
obj = exist
obj.matches?(Exister.new(true))
- obj.negative_failure_message.should =~ /Expected #<(.*)> to not exist./
+ obj.negative_failure_message.should =~ /Expected #<(.*)> to not return true for exist?./
end
def test_be_close_fail_message
@@ -268,6 +268,7 @@ def test_negative_respond_to_fail
}.should raise_error(Test::Unit::AssertionFailedError)
end
+ # be_something
def test_positive_be_something_method_missing_pass
def @obj.something?
true
@@ -304,7 +305,7 @@ def obj.something?
matcher_obj = be_something
obj.should matcher_obj
- matcher_obj.failure_message.should be("Expected \"foo\" to return true for something?.")
+ matcher_obj.failure_message.should be("Expected \"foo\" to return true for something?, with 'no args'.")
end
def test_be_something_method_missing_negative_fail_message
@@ -315,7 +316,58 @@ def obj.something?
matcher_obj = be_something
obj.should_not matcher_obj
- matcher_obj.negative_failure_message.should be("Expected \"foo\" to return false for something?.")
+ matcher_obj.negative_failure_message.should =~ /Expected \"foo\" to not return true for something?/
+ end
+
+ # be_something(arg)
+ def test_positive_be_something_with_arg_method_missing_pass
+ def @obj.something?(arg)
+ true
+ end
+ @obj.should be_something(1)
+ end
+
+ def test_positive_be_something_with_arg_method_missing_fails
+ def @obj.something?(arg)
+ false
+ end
+ lambda {@obj.should be_something(1)}.should raise_error(Test::Unit::AssertionFailedError)
+ end
+
+ def test_negative_be_something_method_missing_pass
+ def @obj.something?(arg)
+ false
+ end
+ @obj.should_not be_something(1)
+ end
+
+ def test_negative_be_something_method_missing_fails
+ def @obj.something?(arg)
+ true
+ end
+ lambda {@obj.should_not be_something(1)}.should raise_error(Test::Unit::AssertionFailedError)
+ end
+
+ def test_be_something_method_missing_fail_message
+ obj = "foo"
+ def obj.something?(arg)
+ true
+ end
+ matcher_obj = be_something(1)
+ obj.should matcher_obj
+
+ matcher_obj.failure_message.should be("Expected \"foo\" to return true for something?, with '1'.")
+ end
+
+ def test_be_something_method_missing_negative_fail_message
+ obj = "foo"
+ def obj.something?(arg)
+ false
+ end
+ matcher_obj = be_something(1)
+ obj.should_not matcher_obj
+
+ matcher_obj.negative_failure_message.should be("Expected \"foo\" to not return true for something?, with '1'.")
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.