Class: ErgomentumRspec::Matchers::ActiveModel::BeValidFor
- Inherits:
-
Object
- Object
- ErgomentumRspec::Matchers::ActiveModel::BeValidFor
- Defined in:
- lib/ergomentum_rspec/matchers/active_model/be_valid_for.rb
Instance Method Summary collapse
- #description ⇒ Object
- #failure_message ⇒ Object
-
#initialize(value) ⇒ BeValidFor
constructor
A new instance of BeValidFor.
- #matches?(validator) ⇒ Boolean
Constructor Details
#initialize(value) ⇒ BeValidFor
Returns a new instance of BeValidFor.
11 12 13 |
# File 'lib/ergomentum_rspec/matchers/active_model/be_valid_for.rb', line 11 def initialize(value) @value = value end |
Instance Method Details
#description ⇒ Object
37 38 39 |
# File 'lib/ergomentum_rspec/matchers/active_model/be_valid_for.rb', line 37 def description "'#{@value}' be an valid value" end |
#failure_message ⇒ Object
33 34 35 |
# File 'lib/ergomentum_rspec/matchers/active_model/be_valid_for.rb', line 33 def "expect '#{@value}' to be valid" end |
#matches?(validator) ⇒ Boolean
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/ergomentum_rspec/matchers/active_model/be_valid_for.rb', line 15 def matches?(validator) model = Class.new do include ::ActiveModel::Model include ::ActiveModel::Attributes # ActiveModel sometimes needs a non nil class name. # Because we are using an anonymous class, which have no name by default, we have to override the name # method. def self.name "SomeClass" end attribute :some_attribute validates :some_attribute, validator end.new(some_attribute: @value) model.valid? && model.errors.empty? end |