Class: Sus::Have::Attribute

Inherits:
Object
  • Object
show all
Defined in:
lib/sus/have.rb

Instance Method Summary collapse

Constructor Details

#initialize(name, predicate) ⇒ Attribute

Returns a new instance of Attribute.



33
34
35
36
# File 'lib/sus/have.rb', line 33

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

Instance Method Details

#call(assertions, subject) ⇒ Object



42
43
44
45
46
47
48
49
# File 'lib/sus/have.rb', line 42

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


38
39
40
# File 'lib/sus/have.rb', line 38

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