SusSourceSusHaveAttribute

class Attribute

Represents a predicate that checks if an object has a specific attribute.

Definitions

def initialize(name, predicate)

Initialize a new Attribute predicate.

Signature

parameter name Symbol, String

The attribute name to check for.

parameter predicate Object

The predicate to apply to the attribute's value.

Implementation

def initialize(name, predicate)
	@name = name
	@predicate = predicate
end

def print(output)

Print a representation of this predicate.

Signature

parameter output Output

The output target.

Implementation

def print(output)
	output.write("attribute ", :variable, @name.to_s, :reset, " ", @predicate, :reset)
end

def call(assertions, subject)

Evaluate this predicate against a subject.

Signature

parameter assertions Assertions

The assertions instance to use.

parameter subject Object

The subject to evaluate.

Implementation

def call(assertions, subject)
	assertions.nested(self, distinct: true) do |assertions|
		assertions.assert(subject.respond_to?(@name), "has attribute")
		if @predicate
			Expect.new(assertions, subject.public_send(@name)).to(@predicate)
		end
	end
end