Class: Storext::Matchers::HaveAttributeMatcher
- Inherits:
-
Object
- Object
- Storext::Matchers::HaveAttributeMatcher
- Defined in:
- lib/storext/matchers/have_attribute_matcher.rb
Instance Method Summary collapse
- #description ⇒ Object
- #failure_message ⇒ Object
- #in_column(column) ⇒ Object
-
#initialize(name, type = nil) ⇒ HaveAttributeMatcher
constructor
A new instance of HaveAttributeMatcher.
- #matches?(class_or_record) ⇒ Boolean
- #with_default(expected_default) ⇒ Object
Constructor Details
#initialize(name, type = nil) ⇒ HaveAttributeMatcher
Returns a new instance of HaveAttributeMatcher.
4 5 6 7 |
# File 'lib/storext/matchers/have_attribute_matcher.rb', line 4 def initialize(name, type = nil) @name = name @expected_type = type end |
Instance Method Details
#description ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/storext/matchers/have_attribute_matcher.rb', line 30 def description = ["have attribute #{@name}"] << ["of type #{@expected_type}"] if @expected_column << [%Q(in column "#{@expected_column}")] end if @expected_default << [%Q(with default "#{@expected_default}")] end .join(" ") end |
#failure_message ⇒ Object
43 44 45 |
# File 'lib/storext/matchers/have_attribute_matcher.rb', line 43 def "expected #{@klass} to #{description}" end |
#in_column(column) ⇒ Object
9 10 11 12 |
# File 'lib/storext/matchers/have_attribute_matcher.rb', line 9 def in_column(column) @expected_column = column self end |
#matches?(class_or_record) ⇒ Boolean
19 20 21 22 23 24 25 26 27 28 |
# File 'lib/storext/matchers/have_attribute_matcher.rb', line 19 def matches?(class_or_record) @klass = class_or_record.is_a?(ActiveRecord::Base) ? class_or_record.class : class_or_record definition = @klass.storext_definitions[@name] definition.present? && matches_type?(definition[:type]) && matches_column?(definition[:column]) && matches_default?(definition[:opts][:default]) end |
#with_default(expected_default) ⇒ Object
14 15 16 17 |
# File 'lib/storext/matchers/have_attribute_matcher.rb', line 14 def with_default(expected_default) @expected_default = expected_default self end |