Module: Journeyman

Extended by:
Definition, Integration, Load
Defined in:
lib/journeyman.rb,
lib/journeyman/load.rb,
lib/journeyman/builder.rb,
lib/journeyman/definition.rb,
lib/journeyman/integration.rb,
lib/journeyman/configuration.rb

Overview

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

Defined Under Namespace

Modules: Definition, Integration, Load Classes: Builder, Configuration

Instance Attribute Summary

Attributes included from Load

#factories_paths

Class Method Summary collapse

Methods included from Load

extended, load_factories

Methods included from Integration

setup_integration

Methods included from Definition

define

Class Method Details

.attach(context) ⇒ Object

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



36
37
38
# File 'lib/journeyman.rb', line 36

def self.attach(context)
  @context = context
end

.build(name, *args, &block) ⇒ Object

Public: Convenience accessor for build methods.



41
42
43
# File 'lib/journeyman.rb', line 41

def self.build(name, *args, &block)
  @context.send("build_#{name}", *args, &block)
end

.create(name, *args, &block) ⇒ Object

Public: Convenience accessor for create methods.



46
47
48
# File 'lib/journeyman.rb', line 46

def self.create(name, *args, &block)
  @context.send("create_#{name}", *args, &block)
end

.default(name) ⇒ Object

Public: Convenience accessor for default methods.



51
52
53
# File 'lib/journeyman.rb', line 51

def self.default(name)
  @context.send("default_#{name}")
end

.execute(proc, *args) ⇒ Object

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



56
57
58
59
60
61
62
63
64
# File 'lib/journeyman.rb', line 56

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) ⇒ Object

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



27
28
29
30
31
32
# File 'lib/journeyman.rb', line 27

def self.load(env, framework: nil)
  @helpers = Module.new
  attach(env)
  load_factories
  setup_integration(env, framework)
end