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.
33 34 35 36 |
# File 'lib/phillumeny/factory_bot.rb', line 33 def initialize(name = nil) @name = name @trait = nil end |
Instance Method Details
#description ⇒ Object
21 22 23 |
# File 'lib/phillumeny/factory_bot.rb', line 21 def description "have a valid factory '#{@name}'#{"with the trait '#{@trait}'" if @trait}" end |
#failure_message ⇒ Object
25 26 27 |
# File 'lib/phillumeny/factory_bot.rb', line 25 def "The '#{@name}' factory did not pass validation.\n#{@error_messages.join("\n")}" end |
#failure_message_when_negated ⇒ Object
29 30 31 |
# File 'lib/phillumeny/factory_bot.rb', line 29 def "The '#{@name}' factory passed validation unexpectedly" end |
#matches?(subject) ⇒ Boolean
38 39 40 41 42 43 |
# File 'lib/phillumeny/factory_bot.rb', line 38 def matches?(subject) factory_name = @name = @name.nil? ? subject.class.to_s.underscore : @name object = ::FactoryBot.build(factory_name, @trait) = object.errors. unless object.valid? object.valid? end |
#with_trait(trait) ⇒ Object
45 46 47 48 |
# File 'lib/phillumeny/factory_bot.rb', line 45 def with_trait(trait) @trait = trait self end |