Sha256: 3d7ab4577a05b67a67c7688c745affd3a6bae535e83338e15c8f17a21c44571f
Contents?: true
Size: 1.43 KB
Versions: 1
Compression:
Stored size: 1.43 KB
Contents
require 'assay/assertions/compare_failure' module Assay class InstanceFailure < CompareFailure def self.assertion_name :instance end def self.assertion_operator :instance_of? end # Check assertion. def self.pass?(exp, act) exp.instance_of?(act) end # def to_s return super unless @arguments.size == 2 exp = @arguments[0].inspect act = @arguments[1].inspect if @_negated "Expected #{act} to NOT be an instance of #{exp}" else "Expected #{act} to be an instance of #{exp}" end end end module Assertives # Passes if object .instance_of? klass # # assert_instance_of(String, 'foo') # def assert_instance_of(cls, obj, opts={}) opts[:backtrace] ||= caller InstanceFailure.assert(cls, obj, opts) end # Passes if object .instance_of? klass # # assert_instance_of(String, 'foo') # def refute_instance_of(cls, obj, opts={}) opts[:backtrace] ||= caller InstanceFailure.refute(cls, obj, opts) end alias_method :assert_not_instance_of, :refute_instance_of end module Matchers # # # object.assert is_instance_of(class) # def is_instance_of(cls) InstanceFailure.to_matcher(cls) end # # # object.should be_instance_of(class) # def be_instance_of(cls) InstanceFailure.to_matcher(cls) end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
assay-0.2.0 | lib/assay/assertions/instance_failure.rb |