QuickFactory.Sequence (quick_factory v0.2.1)

View Source

Module for generating sequential values.

Use QuickFactory.Sequence/1 or QuickFactory.Sequence/2 to generate sequential values instead of calling this module directly.

Summary

Functions

Returns a specification to start this module under a supervisor.

Reset all sequences so that the next sequence starts from 0

Reset specific sequences so long as they already exist. The sequences specified will be reset to 0, while others will remain at their current index.

Functions

child_spec(arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

reset()

@spec reset() :: :ok

Reset all sequences so that the next sequence starts from 0

Example

QuickFactory.Sequence.next("joe") # "joe0"
QuickFactory.Sequence.next("joe") # "joe1"

QuickFactory.Sequence.reset()

QuickFactory.Sequence.next("joe") # resets so the return value is "joe0"

You can use list as well

QuickFactory.Sequence.next("alphabet_sequence", ["A", "B"]) # "A"
QuickFactory.Sequence.next("alphabet_sequence", ["A", "B"]) # "B"

QuickFactory.Sequence.reset()

QuickFactory.Sequence.next("alphabet_sequence", ["A", "B"]) # resets so the return value is "A"

If you want to reset sequences at the beginning of every test, put it in a setup block in your test.

setup do
  QuickFactory.Sequence.reset()
end

reset(sequence_names)

@spec reset(any()) :: :ok

Reset specific sequences so long as they already exist. The sequences specified will be reset to 0, while others will remain at their current index.

You can reset a single sequence,

Example

QuickFactory.Sequence.next(:alphabet, ["A", "B", "C"]) # "A"
QuickFactory.Sequence.next(:alphabet, ["A", "B", "C"]) # "B"

QuickFactory.Sequence.reset(:alphabet)

QuickFactory.Sequence.next(:alphabet, ["A", "B", "C"]) # "A"

And you can also reset multiple sequences at once,

Example

QuickFactory.Sequence.next(:numeric, [1, 2, 3]) # 1
QuickFactory.Sequence.next(:numeric, [1, 2, 3]) # 2
QuickFactory.Sequence.next("joe") # "joe0"
QuickFactory.Sequence.next("joe") # "joe1"

QuickFactory.Sequence.reset(["joe", :numeric])

QuickFactory.Sequence.next(:numeric, [1, 2, 3]) # 1
QuickFactory.Sequence.next("joe") # "joe0"