Class: Enumerize::Integrations::RSpec::Matcher
- Inherits:
-
Object
- Object
- Enumerize::Integrations::RSpec::Matcher
- Defined in:
- lib/enumerize/integrations/rspec/matcher.rb
Instance Attribute Summary collapse
-
#attr ⇒ Object
Returns the value of attribute attr.
-
#default ⇒ Object
Returns the value of attribute default.
-
#subject ⇒ Object
Returns the value of attribute subject.
-
#values ⇒ Object
Returns the value of attribute values.
Instance Method Summary collapse
- #description ⇒ Object
- #failure_message ⇒ Object
- #in(*values) ⇒ Object
-
#initialize(attr) ⇒ Matcher
constructor
A new instance of Matcher.
- #matches?(subject) ⇒ Boolean
- #with_default(default) ⇒ Object
Constructor Details
#initialize(attr) ⇒ Matcher
Returns a new instance of Matcher.
7 8 9 |
# File 'lib/enumerize/integrations/rspec/matcher.rb', line 7 def initialize(attr) self.attr = attr end |
Instance Attribute Details
#attr ⇒ Object
Returns the value of attribute attr.
5 6 7 |
# File 'lib/enumerize/integrations/rspec/matcher.rb', line 5 def attr @attr end |
#default ⇒ Object
Returns the value of attribute default.
5 6 7 |
# File 'lib/enumerize/integrations/rspec/matcher.rb', line 5 def default @default end |
#subject ⇒ Object
Returns the value of attribute subject.
5 6 7 |
# File 'lib/enumerize/integrations/rspec/matcher.rb', line 5 def subject @subject end |
#values ⇒ Object
Returns the value of attribute values.
5 6 7 |
# File 'lib/enumerize/integrations/rspec/matcher.rb', line 5 def values @values end |
Instance Method Details
#description ⇒ Object
33 34 35 36 37 38 |
# File 'lib/enumerize/integrations/rspec/matcher.rb', line 33 def description description = "enumerize :#{attr} in: #{quote_values(values)}" description += " with #{default.inspect} as default value" if default description end |
#failure_message ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/enumerize/integrations/rspec/matcher.rb', line 21 def = " expected :#{attr} to allow value#{values.size == 1 ? nil : 's'}: #{quote_values(values)}," += " but it allows #{quote_values(enumerized_values)} instead" if default && !matches_default_value? = " expected :#{attr} to have #{default.inspect} as default value," += " but it sets #{enumerized_default.inspect} instead" end end |
#in(*values) ⇒ Object
11 12 13 14 |
# File 'lib/enumerize/integrations/rspec/matcher.rb', line 11 def in(*values) self.values = values.map(&:to_s).sort self end |
#matches?(subject) ⇒ Boolean
40 41 42 43 44 45 46 47 48 |
# File 'lib/enumerize/integrations/rspec/matcher.rb', line 40 def matches?(subject) self.subject = subject matches = true matches &= matches_attributes? matches &= matches_default_value? if default matches end |
#with_default(default) ⇒ Object
16 17 18 19 |
# File 'lib/enumerize/integrations/rspec/matcher.rb', line 16 def with_default(default) self.default = default.to_s self end |