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.



173
174
175
# File 'lib/sus/be.rb', line 173

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

.<(value) ⇒ Object

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



194
195
196
# File 'lib/sus/be.rb', line 194

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

.<=(value) ⇒ Object

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



201
202
203
# File 'lib/sus/be.rb', line 201

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

.==(value) ⇒ Object

Create a predicate that checks equality.



166
167
168
# File 'lib/sus/be.rb', line 166

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

.===(value) ⇒ Object

Create a predicate that checks case equality.



215
216
217
# File 'lib/sus/be.rb', line 215

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

.=~(value) ⇒ Object

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



208
209
210
# File 'lib/sus/be.rb', line 208

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

.>(value) ⇒ Object

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



180
181
182
# File 'lib/sus/be.rb', line 180

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

.>=(value) ⇒ Object

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



187
188
189
# File 'lib/sus/be.rb', line 187

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.



156
157
158
159
160
# File 'lib/sus/be.rb', line 156

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
# 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(" ", :variable, arguments.map(&:inspect).join, :reset)
	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