Class: Enumerize::Integrations::RSpec::Matcher

Inherits:
Object
  • Object
show all
Defined in:
lib/enumerize/integrations/rspec/matcher.rb

Instance Method Summary collapse

Constructor Details

#initialize(expected_attr) ⇒ Matcher

Returns a new instance of Matcher.



6
7
8
# File 'lib/enumerize/integrations/rspec/matcher.rb', line 6

def initialize(expected_attr)
  self.expected_attr = expected_attr
end

Instance Method Details

#descriptionObject



48
49
50
51
52
53
54
55
56
57
58
# File 'lib/enumerize/integrations/rspec/matcher.rb', line 48

def description
  description  = "define enumerize :#{expected_attr}"
  description += " in: #{quote_values(expected_values)}" if expected_values
  description += " with #{expected_default.inspect} as default value" if expected_default
  description += " i18n_scope: #{expected_i18n_scope.inspect}" if expected_i18n_scope
  description += " predicates: #{expected_predicates.inspect}" if expected_predicates
  description += " multiple: #{expected_multiple.inspect}" if expected_multiple
  description += " scope: #{expected_scope.inspect}" if expected_scope

  description
end

#failure_messageObject



40
41
42
# File 'lib/enumerize/integrations/rspec/matcher.rb', line 40

def failure_message
  "Expected #{expectation}"
end

#failure_message_when_negatedObject



44
45
46
# File 'lib/enumerize/integrations/rspec/matcher.rb', line 44

def failure_message_when_negated
  "Did not expect #{expectation}"
end

#in(*expected_values) ⇒ Object



10
11
12
13
# File 'lib/enumerize/integrations/rspec/matcher.rb', line 10

def in(*expected_values)
  self.expected_values = expected_values.flatten
  self
end

#matches?(subject) ⇒ Boolean

Returns:

  • (Boolean)


60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/enumerize/integrations/rspec/matcher.rb', line 60

def matches?(subject)
  self.subject = subject
  matches      = true

  matches &= matches_attribute?
  matches &= matches_values? if expected_values
  matches &= matches_default_value? if expected_default
  matches &= matches_i18n_scope? if expected_i18n_scope
  matches &= matches_predicates? if expected_predicates
  matches &= matches_multiple? if expected_multiple
  matches &= matches_scope? if expected_scope

  matches
end

#with_default(expected_default) ⇒ Object



15
16
17
18
# File 'lib/enumerize/integrations/rspec/matcher.rb', line 15

def with_default(expected_default)
  self.expected_default = expected_default.to_s
  self
end

#with_i18n_scope(expected_i18n_scope) ⇒ Object



20
21
22
23
# File 'lib/enumerize/integrations/rspec/matcher.rb', line 20

def with_i18n_scope(expected_i18n_scope)
  self.expected_i18n_scope = expected_i18n_scope
  self
end

#with_multiple(expected_multiple) ⇒ Object



30
31
32
33
# File 'lib/enumerize/integrations/rspec/matcher.rb', line 30

def with_multiple(expected_multiple)
  self.expected_multiple = expected_multiple
  self
end

#with_predicates(expected_predicates) ⇒ Object



25
26
27
28
# File 'lib/enumerize/integrations/rspec/matcher.rb', line 25

def with_predicates(expected_predicates)
  self.expected_predicates = expected_predicates
  self
end

#with_scope(expected_scope) ⇒ Object



35
36
37
38
# File 'lib/enumerize/integrations/rspec/matcher.rb', line 35

def with_scope(expected_scope)
  self.expected_scope = expected_scope
  self
end