Module: Journeyman
- Extended by:
- Definition, Integration, Load
- Defined in:
- lib/journeyman.rb,
lib/journeyman/load.rb,
lib/journeyman/builder.rb,
lib/journeyman/version.rb,
lib/journeyman/definition.rb,
lib/journeyman/integration.rb,
lib/journeyman/configuration.rb,
lib/journeyman/missing_factory_error.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, MissingFactoryError
Constant Summary collapse
- VERSION =
'0.2.0'
Instance Attribute Summary
Attributes included from Load
Class Method Summary collapse
-
.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`.
-
.build(name, *args, &block) ⇒ Object
Public: Convenience accessor for build methods.
-
.create(name, *args, &block) ⇒ Object
Public: Convenience accessor for create methods.
-
.default(name) ⇒ Object
Public: Convenience accessor for default methods.
-
.execute(proc, *args) ⇒ Object
Internal: Executes a proc in the context that is currently attached.
-
.load(env, framework: nil) ⇒ Object
Public: Initializes Journeyman by loading the libraries, attaching to the current context, and configuring the testing libraries.
Methods included from Load
Methods included from Integration
Methods included from Definition
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`.
37 38 39 |
# File 'lib/journeyman.rb', line 37 def self.attach(context) @context = context end |
.build(name, *args, &block) ⇒ Object
Public: Convenience accessor for build methods.
42 43 44 45 46 47 48 |
# 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) ⇒ Object
Public: Convenience accessor for create methods.
51 52 53 54 55 56 57 |
# 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) ⇒ Object
Public: Convenience accessor for default methods.
60 61 62 |
# File 'lib/journeyman.rb', line 60 def self.default(name) @context.send("default_#{name}") end |
.execute(proc, *args) ⇒ Object
Internal: Executes a proc in the context that is currently attached.
65 66 67 68 69 70 71 72 73 |
# 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) ⇒ Object
Public: Initializes Journeyman by loading the libraries, attaching to the current context, and configuring the testing libraries.
28 29 30 31 32 33 |
# File 'lib/journeyman.rb', line 28 def self.load(env, framework: nil) @helpers = Module.new attach(env) load_factories setup_integration(env, framework) end |