Sha256: 6fdc4650dad8fb3febc43bf7bbaf7a156779a91dad5f39a778c48d7e71a31bc8

Contents?: true

Size: 1.14 KB

Versions: 2

Compression:

Stored size: 1.14 KB

Contents

module Defekt
  module Assertions
    def true!(value)
      unless value
        raise Errors::TrueError, message(value, 'is not', true)
      end
    end

    def equal_to!(expected, actual)
      unless actual == expected
        raise Errors::EqualToError, message(actual, 'is not equal to', expected)
      end
    end

    def identical_to!(expected, actual)
      unless actual.equal?(expected)
        raise Errors::IdenticalToError, message(actual, 'is not identical to', expected)
      end
    end

    def included_in!(collection, member)
      unless collection.include?(member)
        raise Errors::IncludedInError, message(member, 'is not included in', collection)
      end
    end

    def instance_of!(klass, instance)
      unless instance.instance_of?(klass)
        raise Errors::InstanceOfError, message(instance, 'is not an instance of', klass)
      end
    end

    def kind_of!(klass, instance)
      unless instance.kind_of?(klass)
        raise Errors::KindOfError, message(instance, 'is not a kind of', klass)
      end
    end

    private

    def message(object1, text, object2)
      "~#{object1}~ #{text} #{object2}"
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
defekt-0.0.3 lib/defekt/assertions.rb
defekt-0.0.2 lib/defekt/assertions.rb