module Journeyman

Public: Allows to define and use factory methods. It is capable of providing `build`, `create`, `find`, and `default` methods, the last two are optional.

Examples:

Journeyman.define :user do |t|
  {
    name: "Johnnie Walker",
    date_of_birth: ->{ 150.years.ago }
  }
end

Journeyman.build(:user)  => build_user
Journeyman.create(:user) => create_user

Constants

VERSION

Public Class Methods

attach(context) click to toggle source

Public: Attaches Journeyman to the specified context, which enables the use of the convenience acessors for the factory methods, like `Journeyman.build`.

# File lib/journeyman.rb, line 37
def self.attach(context)
  @context = context
end
build(name, *args, &block) click to toggle source

Public: Convenience accessor for build methods.

# File lib/journeyman.rb, line 42
def self.build(name, *args, &block)
  if @context.respond_to?("build_#{name}")
    @context.send("build_#{name}", *args, &block)
  else
    raise MissingFactoryError, "'#{name}' factory is not defined"
  end
end
create(name, *args, &block) click to toggle source

Public: Convenience accessor for create methods.

# File lib/journeyman.rb, line 51
def self.create(name, *args, &block)
  if @context.respond_to?("create_#{name}")
    @context.send("create_#{name}", *args, &block)
  else
    raise MissingFactoryError, "'#{name}' factory is not defined"
  end
end
default(name) click to toggle source

Public: Convenience accessor for default methods.

# File lib/journeyman.rb, line 60
def self.default(name)
  @context.send("default_#{name}")
end
execute(proc, *args) click to toggle source

Internal: Executes a proc in the context that is currently attached.

# File lib/journeyman.rb, line 65
def self.execute(proc, *args)
  if proc
    if proc.arity == 0
      @context.instance_exec(&proc)
    else
      @context.instance_exec(*args, &proc)
    end
  end
end
load(env, framework: nil) click to toggle source

Public: Initializes Journeyman by loading the libraries, attaching to the current context, and configuring the testing libraries.

# File lib/journeyman.rb, line 28
def self.load(env, framework: nil)
  @helpers = Module.new
  attach(env)
  load_factories
  setup_integration(env, framework)
end