Class: FactoryBurgers::SequenceInjector

Inherits:
BasicObject
Defined in:
lib/factory_burgers/sequence_injector.rb

Overview

A SequenceInjector is a probe that can be used to hijcak a FactoryBot sequence. It injects a specific replacement value in place of the sequence argument, or any usage of that argument.

For an injector with a replacement value “foo”:

  • A sequence defined with a block “{ |ii| “thing-#ii ”}‘

    will evaluate to "thing-foo".
    
  • A sequence defined with a block “{ |ii| “thing-#iiii.daysii.days.from_onwii.days.from_onw.month ”}‘

    will also evaluate to "thing-foo".
    

This allows us to generate wildcard, such as for SQL

SequenceInjector.new("%")

or Regex

SequenceInjector.new(".")

Instance Method Summary collapse

Constructor Details

#initialize(replacement_value) ⇒ SequenceInjector

Returns a new instance of SequenceInjector.



18
19
20
# File 'lib/factory_burgers/sequence_injector.rb', line 18

def initialize(replacement_value)
  @replacement_value = replacement_value
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(_name, *_args) ⇒ Object

We explicitly want to swallow and do nothing on method_missing; We want to chain all method calls until we get to to_s



28
29
30
# File 'lib/factory_burgers/sequence_injector.rb', line 28

def method_missing(_name, *_args)
  return self
end

Instance Method Details

#to_sObject



22
23
24
# File 'lib/factory_burgers/sequence_injector.rb', line 22

def to_s
  @replacement_value
end