assembly_line 0.2.0 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/History.md +6 -0
- data/README.md +6 -2
- data/VERSION +1 -1
- data/assembly_line.gemspec +5 -5
- data/lib/assembly_line.rb +10 -13
- data/lib/assembly_line/constructor.rb +4 -4
- data/lib/assembly_line/{global_context.rb → generic_context.rb} +5 -4
- data/spec/assembly_line/constructor_spec.rb +1 -1
- data/spec/assembly_line/generic_context_spec.rb +34 -0
- data/spec/functional/global_context_spec.rb +9 -13
- metadata +5 -5
- data/spec/assembly_line/global_context_spec.rb +0 -33
data/History.md
CHANGED
data/README.md
CHANGED
@@ -80,9 +80,12 @@ Example
|
|
80
80
|
|
81
81
|
### Use your AssemblyLine in an irb session
|
82
82
|
|
83
|
+
AssemblyLine works a little differently when using it in irb. Your `let` definitions will not be defined globally (see [e26a903](http://github.com/sandro/commit/e26a903)), instead you'll have to prefix all defined methods with `AssemblyLine`.
|
84
|
+
|
83
85
|
>> Assemble(:drinks)
|
84
86
|
=> #<AssemblyLine::Constructor:0x10049e958 @code_block=#<Proc:0x000000010049ea98@(irb):1>, @name=:drinks, @rspec_context=AssemblyLine::GlobalContext, @options={}>
|
85
|
-
>>
|
87
|
+
>>
|
88
|
+
>> AssemblyLine.drinks # the `drinks` method is prefixed with AssemblyLine
|
86
89
|
=> [:gin, :vodka]
|
87
90
|
|
88
91
|
|
@@ -92,7 +95,8 @@ Thanks!
|
|
92
95
|
- l4rk (initial spike declaring modules and including them in the rspec context)
|
93
96
|
- veezus (code contributions, introduced modular design / dependencies)
|
94
97
|
- bigtiger (named the project)
|
95
|
-
- leshill (support and testing)
|
98
|
+
- leshill (support and testing, suggested irb support)
|
99
|
+
- wgibbs (suggested irb support)
|
96
100
|
|
97
101
|
|
98
102
|
Note on Patches/Pull Requests
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.2.
|
1
|
+
0.2.1
|
data/assembly_line.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{assembly_line}
|
8
|
-
s.version = "0.2.
|
8
|
+
s.version = "0.2.1"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Sandro Turriate"]
|
12
|
-
s.date = %q{2010-02-
|
12
|
+
s.date = %q{2010-02-10}
|
13
13
|
s.description = %q{Assembly Line allows you to group together a series of rspec `let` statements which can later be evaluated to set up a specific state for your specs.}
|
14
14
|
s.email = %q{sandro.turriate@gmail.com}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -26,10 +26,10 @@ Gem::Specification.new do |s|
|
|
26
26
|
"assembly_line.gemspec",
|
27
27
|
"lib/assembly_line.rb",
|
28
28
|
"lib/assembly_line/constructor.rb",
|
29
|
-
"lib/assembly_line/
|
29
|
+
"lib/assembly_line/generic_context.rb",
|
30
30
|
"lib/assembly_line/registry.rb",
|
31
31
|
"spec/assembly_line/constructor_spec.rb",
|
32
|
-
"spec/assembly_line/
|
32
|
+
"spec/assembly_line/generic_context_spec.rb",
|
33
33
|
"spec/assembly_line/registry_spec.rb",
|
34
34
|
"spec/assembly_line_spec.rb",
|
35
35
|
"spec/functional/assemble_spec.rb",
|
@@ -44,7 +44,7 @@ Gem::Specification.new do |s|
|
|
44
44
|
s.summary = %q{Modularize setup blocks for rspec}
|
45
45
|
s.test_files = [
|
46
46
|
"spec/assembly_line/constructor_spec.rb",
|
47
|
-
"spec/assembly_line/
|
47
|
+
"spec/assembly_line/generic_context_spec.rb",
|
48
48
|
"spec/assembly_line/registry_spec.rb",
|
49
49
|
"spec/assembly_line_spec.rb",
|
50
50
|
"spec/functional/assemble_spec.rb",
|
data/lib/assembly_line.rb
CHANGED
@@ -1,17 +1,22 @@
|
|
1
1
|
require 'forwardable'
|
2
2
|
require 'assembly_line/registry'
|
3
3
|
require 'assembly_line/constructor'
|
4
|
-
require 'assembly_line/
|
4
|
+
require 'assembly_line/generic_context'
|
5
5
|
|
6
6
|
module AssemblyLine
|
7
|
-
VERSION = "0.2.
|
7
|
+
VERSION = "0.2.1".freeze
|
8
|
+
extend SingleForwardable
|
9
|
+
|
10
|
+
def self.assemble(name, context, options={})
|
11
|
+
Registry.locate(name).assemble(context, options)
|
12
|
+
end
|
8
13
|
|
9
14
|
def self.define(name, &block)
|
10
15
|
Registry.add(name, block)
|
11
16
|
end
|
12
17
|
|
13
|
-
def self.
|
14
|
-
|
18
|
+
def self.generic_context
|
19
|
+
@generic_context ||= GenericContext.new
|
15
20
|
end
|
16
21
|
|
17
22
|
def Assemble(name, options={})
|
@@ -20,15 +25,7 @@ module AssemblyLine
|
|
20
25
|
end
|
21
26
|
|
22
27
|
module Kernel
|
23
|
-
extend Forwardable
|
24
|
-
|
25
28
|
def Assemble(name, options={})
|
26
|
-
AssemblyLine.assemble(name,
|
27
|
-
end
|
28
|
-
|
29
|
-
protected
|
30
|
-
|
31
|
-
def assembly_line_global_context
|
32
|
-
AssemblyLine::GlobalContext
|
29
|
+
AssemblyLine.assemble(name, AssemblyLine.generic_context, options)
|
33
30
|
end
|
34
31
|
end
|
@@ -2,9 +2,9 @@ module AssemblyLine
|
|
2
2
|
class Constructor
|
3
3
|
extend Forwardable
|
4
4
|
|
5
|
-
def_delegators :
|
5
|
+
def_delegators :context, :let, :before
|
6
6
|
|
7
|
-
attr_reader :name, :code_block, :
|
7
|
+
attr_reader :name, :code_block, :context, :options
|
8
8
|
|
9
9
|
def initialize(name, code_block)
|
10
10
|
@name = name
|
@@ -13,7 +13,7 @@ module AssemblyLine
|
|
13
13
|
|
14
14
|
def assemble(context, options)
|
15
15
|
@options = options
|
16
|
-
@
|
16
|
+
@context = context
|
17
17
|
instance_eval(&code_block)
|
18
18
|
self
|
19
19
|
end
|
@@ -31,7 +31,7 @@ module AssemblyLine
|
|
31
31
|
constructors = Array(options[:depends_on])
|
32
32
|
end
|
33
33
|
constructors.each do |name|
|
34
|
-
AssemblyLine.assemble(name,
|
34
|
+
AssemblyLine.assemble(name, context)
|
35
35
|
end
|
36
36
|
end
|
37
37
|
|
@@ -1,12 +1,11 @@
|
|
1
1
|
module AssemblyLine
|
2
|
-
|
3
|
-
extend self
|
2
|
+
class GenericContext
|
4
3
|
|
5
4
|
def let(name, &block)
|
6
5
|
define_method name do
|
7
6
|
let_values[name] ||= instance_eval(&block)
|
8
7
|
end
|
9
|
-
|
8
|
+
AssemblyLine.def_delegator :generic_context, name
|
10
9
|
end
|
11
10
|
|
12
11
|
# there are no tests so just run the block
|
@@ -26,6 +25,8 @@ module AssemblyLine
|
|
26
25
|
@let_values ||= {}
|
27
26
|
end
|
28
27
|
|
29
|
-
|
28
|
+
def define_method(name, &block)
|
29
|
+
self.class.send(:define_method, name, &block)
|
30
|
+
end
|
30
31
|
end
|
31
32
|
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe AssemblyLine::GenericContext do
|
4
|
+
let(:generic_context) { AssemblyLine.generic_context }
|
5
|
+
|
6
|
+
after { generic_context.clear }
|
7
|
+
|
8
|
+
describe "#let" do
|
9
|
+
it "defines the method on the GenericContext instance" do
|
10
|
+
generic_context.let(:foobarish) { :bar }
|
11
|
+
generic_context.foobarish.should == :bar
|
12
|
+
end
|
13
|
+
|
14
|
+
it "memoizes the defined method" do
|
15
|
+
generic_context.instance_variable_set(:@count, 0)
|
16
|
+
generic_context.let(:my_count) { @count += 1 }
|
17
|
+
5.times { generic_context.my_count }
|
18
|
+
generic_context.my_count.should == 1
|
19
|
+
end
|
20
|
+
|
21
|
+
it "adds a delegating method to AssemblyLine" do
|
22
|
+
generic_context.let(:global_method) { :global }
|
23
|
+
AssemblyLine.global_method.should == :global
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
describe "#before" do
|
28
|
+
it "runs the code block" do
|
29
|
+
expect do
|
30
|
+
generic_context.before { @done = true }
|
31
|
+
end.to change { generic_context.instance_variable_get(:@done) }.from(nil).to(true)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -1,8 +1,8 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
|
3
|
+
set_up_assembly = lambda do
|
4
4
|
AssemblyLine.define(:global_assembly) do
|
5
|
-
let(:foo) { @bar +=1 }
|
5
|
+
let(:foo) { @bar += 1 }
|
6
6
|
before do
|
7
7
|
@bar = 0
|
8
8
|
end
|
@@ -10,21 +10,17 @@ global_assembly_set_up = lambda do
|
|
10
10
|
Assemble(:global_assembly)
|
11
11
|
end
|
12
12
|
|
13
|
-
def call_global_assembly(count = 5)
|
14
|
-
(count - 1).times { foo }
|
15
|
-
foo
|
16
|
-
end
|
17
|
-
|
18
13
|
describe "in the global context" do
|
19
|
-
before
|
20
|
-
|
14
|
+
before do
|
15
|
+
set_up_assembly.call
|
21
16
|
end
|
22
17
|
|
23
|
-
it "
|
24
|
-
AssemblyLine
|
18
|
+
it "defines the method on AssemblyLine.generic_context" do
|
19
|
+
AssemblyLine.generic_context.should respond_to(:foo)
|
25
20
|
end
|
26
21
|
|
27
|
-
it "
|
28
|
-
|
22
|
+
it "memoizes the value" do
|
23
|
+
5.times { AssemblyLine.foo }
|
24
|
+
AssemblyLine.foo.should == 1
|
29
25
|
end
|
30
26
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: assembly_line
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sandro Turriate
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2010-02-
|
12
|
+
date: 2010-02-10 00:00:00 -05:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -51,10 +51,10 @@ files:
|
|
51
51
|
- assembly_line.gemspec
|
52
52
|
- lib/assembly_line.rb
|
53
53
|
- lib/assembly_line/constructor.rb
|
54
|
-
- lib/assembly_line/
|
54
|
+
- lib/assembly_line/generic_context.rb
|
55
55
|
- lib/assembly_line/registry.rb
|
56
56
|
- spec/assembly_line/constructor_spec.rb
|
57
|
-
- spec/assembly_line/
|
57
|
+
- spec/assembly_line/generic_context_spec.rb
|
58
58
|
- spec/assembly_line/registry_spec.rb
|
59
59
|
- spec/assembly_line_spec.rb
|
60
60
|
- spec/functional/assemble_spec.rb
|
@@ -91,7 +91,7 @@ specification_version: 3
|
|
91
91
|
summary: Modularize setup blocks for rspec
|
92
92
|
test_files:
|
93
93
|
- spec/assembly_line/constructor_spec.rb
|
94
|
-
- spec/assembly_line/
|
94
|
+
- spec/assembly_line/generic_context_spec.rb
|
95
95
|
- spec/assembly_line/registry_spec.rb
|
96
96
|
- spec/assembly_line_spec.rb
|
97
97
|
- spec/functional/assemble_spec.rb
|
@@ -1,33 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe AssemblyLine::GlobalContext do
|
4
|
-
let(:global_context) { AssemblyLine::GlobalContext }
|
5
|
-
after { global_context.clear }
|
6
|
-
|
7
|
-
describe "#let" do
|
8
|
-
it "defines the method within AssemblyLine::GlobalContext" do
|
9
|
-
global_context.let(:foobarish) { :bar }
|
10
|
-
global_context.foobarish.should == :bar
|
11
|
-
end
|
12
|
-
|
13
|
-
it "memoizes the defined method" do
|
14
|
-
global_context.instance_variable_set(:@count, 0)
|
15
|
-
global_context.let(:my_count) { @count += 1 }
|
16
|
-
5.times { global_context.my_count }
|
17
|
-
global_context.my_count.should == 1
|
18
|
-
end
|
19
|
-
|
20
|
-
it "tells Kernel to delegate this method to AssemblyLine::GlobalContext" do
|
21
|
-
global_context.let(:global_method) { :global }
|
22
|
-
Kernel.global_method.should == :global
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
describe "#before" do
|
27
|
-
it "runs the code block" do
|
28
|
-
expect do
|
29
|
-
global_context.before { @done = true }
|
30
|
-
end.to change { global_context.instance_variable_get(:@done) }.from(nil).to(true)
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|