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

#failure_messageObject



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

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

#matches?(subject) ⇒ Boolean

Returns:

  • (Boolean)


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

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

#negative_failure_messageObject



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

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

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



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

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