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.


8
9
10
# File 'lib/enumerize/integrations/rspec/matcher.rb', line 8

def initialize(expected_attr)
  self.expected_attr = expected_attr
end

Instance Method Details

#descriptionObject


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

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


42
43
44
# File 'lib/enumerize/integrations/rspec/matcher.rb', line 42

def failure_message
  "Expected #{expectation}"
end

#failure_message_when_negatedObject


46
47
48
# File 'lib/enumerize/integrations/rspec/matcher.rb', line 46

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

#in(*expected_values) ⇒ Object


12
13
14
15
# File 'lib/enumerize/integrations/rspec/matcher.rb', line 12

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

#matches?(subject) ⇒ Boolean

Returns:

  • (Boolean)

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

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


17
18
19
20
# File 'lib/enumerize/integrations/rspec/matcher.rb', line 17

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

#with_i18n_scope(expected_i18n_scope) ⇒ Object


22
23
24
25
# File 'lib/enumerize/integrations/rspec/matcher.rb', line 22

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

#with_multiple(expected_multiple) ⇒ Object


32
33
34
35
# File 'lib/enumerize/integrations/rspec/matcher.rb', line 32

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

#with_predicates(expected_predicates) ⇒ Object


27
28
29
30
# File 'lib/enumerize/integrations/rspec/matcher.rb', line 27

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

#with_scope(expected_scope) ⇒ Object


37
38
39
40
# File 'lib/enumerize/integrations/rspec/matcher.rb', line 37

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