Class: Sus::Be

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

Overview

Represents a predicate matcher that can be used with ‘expect(…).to be(…)`.

Defined Under Namespace

Classes: And, Or

Constant Summary collapse

NIL =

A predicate that checks if the subject is nil.

Be.new(:nil?)

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*arguments) ⇒ Be

Initialize a new Be predicate.



109
110
111
# File 'lib/sus/be.rb', line 109

def initialize(*arguments)
	@arguments = arguments
end

Class Method Details

.!=(value) ⇒ Object

Create a predicate that checks inequality.



176
177
178
# File 'lib/sus/be.rb', line 176

def != value
	Be.new(:!=, value)
end

.<(value) ⇒ Object

Create a predicate that checks if the subject is less than a value.



197
198
199
# File 'lib/sus/be.rb', line 197

def < value
	Be.new(:<, value)
end

.<=(value) ⇒ Object

Create a predicate that checks if the subject is less than or equal to a value.



204
205
206
# File 'lib/sus/be.rb', line 204

def <= value
	Be.new(:<=, value)
end

.==(value) ⇒ Object

Create a predicate that checks equality.



169
170
171
# File 'lib/sus/be.rb', line 169

def == value
	Be.new(:==, value)
end

.===(value) ⇒ Object

Create a predicate that checks case equality.



218
219
220
# File 'lib/sus/be.rb', line 218

def === value
	Be.new(:===, value)
end

.=~(value) ⇒ Object

Create a predicate that checks if the subject matches a pattern.



211
212
213
# File 'lib/sus/be.rb', line 211

def =~ value
	Be.new(:=~, value)
end

.>(value) ⇒ Object

Create a predicate that checks if the subject is greater than a value.



183
184
185
# File 'lib/sus/be.rb', line 183

def > value
	Be.new(:>, value)
end

.>=(value) ⇒ Object

Create a predicate that checks if the subject is greater than or equal to a value.



190
191
192
# File 'lib/sus/be.rb', line 190

def >= value
	Be.new(:>=, value)
end

Instance Method Details

#&(other) ⇒ Object

Combine this predicate with another using AND logic.



130
131
132
# File 'lib/sus/be.rb', line 130

def &(other)
	And.new([self, other])
end

#and(*others) ⇒ Object

Combine this predicate with others using AND logic.



137
138
139
# File 'lib/sus/be.rb', line 137

def and(*others)
	And.new([self, *others])
end

#call(assertions, subject) ⇒ Object

Evaluate this predicate against a subject.



159
160
161
162
163
# File 'lib/sus/be.rb', line 159

def call(assertions, subject)
	assertions.nested(self) do |assertions|
		assertions.assert(subject.public_send(*@arguments))
	end
end

#or(*others) ⇒ Object

Combine this predicate with others using OR logic.



123
124
125
# File 'lib/sus/be.rb', line 123

def or(*others)
	Or.new([self, *others])
end

Print a representation of this predicate.



143
144
145
146
147
148
149
150
151
152
153
154
# File 'lib/sus/be.rb', line 143

def print(output)
	operation, *arguments = *@arguments
	
	output.write("be ", :be, operation.to_s, :reset)
	
	if arguments.any?
		output.write(" ")
		arguments.each do |argument|
			output.variable(argument)
		end
	end
end

#|(other) ⇒ Object

Combine this predicate with another using OR logic.



116
117
118
# File 'lib/sus/be.rb', line 116

def |(other)
	Or.new([self, other])
end