lib/assert/assertions.rb in assert-0.1.0 vs lib/assert/assertions.rb in assert-0.2.0

- old
+ new

@@ -65,82 +65,81 @@ end alias_method :refute_instance_of, :assert_not_instance_of - def assert_respond_to(object, method, fail_desc=nil) + def assert_respond_to(method, object, fail_desc=nil) what_failed_msg = [ "Expected #{object.inspect} (#{object.class}) to ", "respond to ##{method}." ].join assert(object.respond_to?(method), fail_desc, what_failed_msg) end - def assert_not_respond_to(object, method, fail_desc=nil) + def assert_not_respond_to(method, object, fail_desc=nil) what_failed_msg = [ "#{object.inspect} (#{object.class}) not expected to ", "respond to ##{method}." ].join assert(!object.respond_to?(method), fail_desc, what_failed_msg) end alias_method :refute_respond_to, :assert_not_respond_to - def assert_same(left, right, fail_desc=nil) + def assert_same(expected, actual, fail_desc=nil) what_failed_msg = [ - "Expected #{left} (#{left.object_id}) to be the same ", - "as #{right} (#{right.object_id})." + "Expected #{expected} (#{expected.object_id}) to be the same ", + "as #{actual} (#{actual.object_id})." ].join - assert(right.equal?(left), fail_desc, what_failed_msg) + assert(actual.equal?(expected), fail_desc, what_failed_msg) end - def assert_not_same(left, right, fail_desc=nil) + def assert_not_same(expected, actual, fail_desc=nil) what_failed_msg = [ - "#{left} (#{left.object_id}) not expected to be the same ", - "as #{right} (#{right.object_id})." + "#{expected} (#{expected.object_id}) not expected to be the same ", + "as #{actual} (#{actual.object_id})." ].join - assert(!right.equal?(left), fail_desc, what_failed_msg) + assert(!actual.equal?(expected), fail_desc, what_failed_msg) end alias_method :refute_same, :assert_not_same - def assert_equal(left, right, fail_desc=nil) - what_failed_msg = "Expected #{left.inspect}, not #{right.inspect}." - assert(right == left, fail_desc, what_failed_msg) + def assert_equal(expected, actual, fail_desc=nil) + what_failed_msg = "Expected #{expected.inspect}, not #{actual.inspect}." + assert(actual == expected, fail_desc, what_failed_msg) end - def assert_not_equal(left, right, fail_desc=nil) + def assert_not_equal(expected, actual, fail_desc=nil) what_failed_msg = [ - "#{left.inspect} not expected to be equal ", "to #{right.inspect}." + "#{expected.inspect} not expected to be equal ", "to #{actual.inspect}." ].join - assert(right != left, fail_desc, what_failed_msg) + assert(actual != expected, fail_desc, what_failed_msg) end alias_method :refute_equal, :assert_not_equal - def assert_match(left, right, fail_desc=nil) - what_failed_msg = "Expected #{left.inspect} to match #{right.inspect}." - left = /#{Regexp.escape(left)}/ if String === left && String === right - assert(left =~ right, fail_desc, what_failed_msg) + def assert_match(expected, actual, fail_desc=nil) + what_failed_msg = "Expected #{actual.inspect} to match #{expected.inspect}." + expected = /#{Regexp.escape(expected)}/ if String === expected && String === actual + assert(actual =~ expected, fail_desc, what_failed_msg) end - def assert_not_match(left, right, fail_desc=nil) + def assert_not_match(expected, actual, fail_desc=nil) what_failed_msg = [ - "#{left.inspect} not expected to ", "match #{right.inspect}." + "#{actual.inspect} not expected to ", "match #{expected.inspect}." ].join - left = /#{Regexp.escape(left)}/ if String === left && String === right - assert(left !~ right, fail_desc, what_failed_msg) + expected = /#{Regexp.escape(expected)}/ if String === expected && String === actual + assert(actual !~ expected, fail_desc, what_failed_msg) end alias_method :refute_match, :assert_not_match alias_method :assert_no_match, :assert_not_match - # TODO: tests! def assert_empty(collection, fail_desc=nil) what_failed_msg = "Expected #{collection.inspect} to be empty." assert(collection.empty?, fail_desc, what_failed_msg) end @@ -150,24 +149,25 @@ end alias_method :refute_empty, :assert_not_empty - # TODO: tests! - def assert_includes(collection, object, fail_desc=nil) + def assert_includes(object, collection, fail_desc=nil) what_failed_msg = "Expected #{collection.inspect} to include #{object.inspect}." assert(collection.include?(object), fail_desc, what_failed_msg) end + alias_method :assert_included, :assert_includes - def assert_not_included(collection, object, fail_desc=nil) + def assert_not_includes(object, collection, fail_desc=nil) what_failed_msg = "Expected #{collection.inspect} to not include #{object.inspect}." assert(!collection.include?(object), fail_desc, what_failed_msg) end - alias_method :refute_includes, :assert_not_included + alias_method :assert_not_included, :assert_not_includes + alias_method :refute_includes, :assert_not_includes + alias_method :refute_included, :assert_not_includes - # TODO: tests! def assert_nil(object, fail_desc=nil) what_failed_msg = "Expected nil, not #{object.inspect}." assert(object.nil?, fail_desc, what_failed_msg) end