Class: Expects::Handler

Inherits:
Object
  • Object
show all
Defined in:
lib/expects/handler.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(subject, objects) ⇒ Handler

Returns a new instance of Handler.



5
6
7
8
# File 'lib/expects/handler.rb', line 5

def initialize(subject, objects)
  @subject = subject
  @objects = objects
end

Instance Attribute Details

#objectsObject (readonly)

Returns the value of attribute objects.



3
4
5
# File 'lib/expects/handler.rb', line 3

def objects
  @objects
end

#subjectObject (readonly)

Returns the value of attribute subject.



3
4
5
# File 'lib/expects/handler.rb', line 3

def subject
  @subject
end

Instance Method Details

#accept!Object

Raises:



14
15
16
# File 'lib/expects/handler.rb', line 14

def accept!
  raise UnexpectedInput.new(self) unless valid?
end

#build_messageObject



22
23
24
# File 'lib/expects/handler.rb', line 22

def build_message
  "Expected #{@subject.inspect} to be #{@objects.join(", ")}"
end

#reject!Object

Raises:



18
19
20
# File 'lib/expects/handler.rb', line 18

def reject!
  raise UnexpectedInput.new(self) if valid?
end

#valid?Boolean

Returns:

  • (Boolean)


10
11
12
# File 'lib/expects/handler.rb', line 10

def valid?
  @objects.include? @subject.class
end