Class: Phillumeny::FactoryBot::HaveAValidFactory
- Inherits:
-
Object
- Object
- Phillumeny::FactoryBot::HaveAValidFactory
- Defined in:
- lib/phillumeny/factory_bot.rb
Overview
it { should_not have_a_valid_factory } it { should have_a_valid_factory.with_trait(:valid) }
Instance Method Summary collapse
- #description ⇒ Object
- #failure_message ⇒ Object
- #failure_message_when_negated ⇒ Object
-
#initialize(name = nil) ⇒ HaveAValidFactory
constructor
A new instance of HaveAValidFactory.
- #matches?(subject) ⇒ Boolean
- #with_trait(trait) ⇒ Object
Constructor Details
#initialize(name = nil) ⇒ HaveAValidFactory
Returns a new instance of HaveAValidFactory.
35 36 37 38 |
# File 'lib/phillumeny/factory_bot.rb', line 35 def initialize(name = nil) @name = name @trait = nil end |
Instance Method Details
#description ⇒ Object
21 22 23 24 25 |
# File 'lib/phillumeny/factory_bot.rb', line 21 def description msg = "have a valid factory '#{@name}'" msg << " with the trait '#{@trait}'" if @trait msg end |
#failure_message ⇒ Object
27 28 29 |
# File 'lib/phillumeny/factory_bot.rb', line 27 def "The '#{@name}' factory did not pass validation.\n#{@error_messages.join("\n")}" end |
#failure_message_when_negated ⇒ Object
31 32 33 |
# File 'lib/phillumeny/factory_bot.rb', line 31 def "The '#{@name}' factory passed validation unexpectedly" end |
#matches?(subject) ⇒ Boolean
40 41 42 43 44 45 |
# File 'lib/phillumeny/factory_bot.rb', line 40 def matches?(subject) factory_name = @name = @name.nil? ? subject.class.to_s.underscore : @name object = ::FactoryBot.build(factory_name, @trait) @error_messages = object.errors. unless object.valid? object.valid? end |
#with_trait(trait) ⇒ Object
47 48 49 50 |
# File 'lib/phillumeny/factory_bot.rb', line 47 def with_trait(trait) @trait = trait self end |