Class: RSpec::Virtus::Matcher

Inherits:
Object
  • Object
show all
Defined in:
lib/rspec-virtus/matcher.rb

Instance Method Summary collapse

Constructor Details

#initialize(attribute_name) ⇒ Matcher

Returns a new instance of Matcher.



4
5
6
7
# File 'lib/rspec-virtus/matcher.rb', line 4

def initialize(attribute_name)
  @attribute_name = attribute_name
  @options = {}
end

Instance Method Details

#descriptionObject



9
10
11
# File 'lib/rspec-virtus/matcher.rb', line 9

def description
  "have #{@attribute_name} defined"
end

#failure_messageObject



24
25
26
# File 'lib/rspec-virtus/matcher.rb', line 24

def failure_message
  "expected #{@attribute_name} to be defined"
end

#failure_message_when_negatedObject



28
29
30
# File 'lib/rspec-virtus/matcher.rb', line 28

def failure_message_when_negated
  "expected #{@attribute_name} not to be defined"
end

#matches?(subject) ⇒ Boolean

Returns:

  • (Boolean)


19
20
21
22
# File 'lib/rspec-virtus/matcher.rb', line 19

def matches?(subject)
  @subject = subject
  attribute_exists? && type_correct?
end

#of_type(type, options = {}) ⇒ Object



13
14
15
16
17
# File 'lib/rspec-virtus/matcher.rb', line 13

def of_type(type, options={})
  @options[:type] = type
  @options[:member_type] = options.delete(:member_type)
  self
end