assembly_line 0.1.0 → 0.2.0
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 +14 -0
- data/README.md +18 -3
- data/VERSION +1 -1
- data/assembly_line.gemspec +71 -0
- data/lib/assembly_line.rb +16 -1
- data/lib/assembly_line/global_context.rb +31 -0
- data/spec/assembly_line/global_context_spec.rb +33 -0
- data/spec/functional/global_context_spec.rb +30 -0
- data/spec/spec.opts +1 -0
- metadata +9 -2
data/History.md
ADDED
data/README.md
CHANGED
@@ -20,7 +20,7 @@ Edit your *spec/spec_helper.rb*
|
|
20
20
|
|
21
21
|
Define an AssemblyLine
|
22
22
|
|
23
|
-
|
23
|
+
AssemblyLine.define(:user_with_payment_address) do
|
24
24
|
let(:user) { Factory(:user)}
|
25
25
|
let(:payment_address) { Factory(:payment_address, :user => user) }
|
26
26
|
end
|
@@ -28,7 +28,14 @@ Define an AssemblyLine
|
|
28
28
|
Example
|
29
29
|
-------
|
30
30
|
|
31
|
-
Place your AssemblyLine definitions in *spec/support/assemblies.rb*
|
31
|
+
### Place your AssemblyLine definitions in *spec/support/assemblies.rb*
|
32
|
+
|
33
|
+
class Party < Struct.new(:host, :attendees)
|
34
|
+
attr_writer :drinks
|
35
|
+
def drinks
|
36
|
+
@drinks ||= []
|
37
|
+
end
|
38
|
+
end
|
32
39
|
|
33
40
|
AssemblyLine.define(:drinks) do
|
34
41
|
let(:drinks) { [:gin, :vodka] }
|
@@ -43,7 +50,7 @@ Place your AssemblyLine definitions in *spec/support/assemblies.rb*
|
|
43
50
|
let(:party_crasher) { attendees << :crasher; :crasher }
|
44
51
|
end
|
45
52
|
|
46
|
-
Use your AssemblyLine in a test
|
53
|
+
### Use your AssemblyLine in a test
|
47
54
|
|
48
55
|
describe "README example" do
|
49
56
|
context "attendees" do
|
@@ -70,6 +77,14 @@ Use your AssemblyLine in a test
|
|
70
77
|
end
|
71
78
|
end
|
72
79
|
end
|
80
|
+
|
81
|
+
### Use your AssemblyLine in an irb session
|
82
|
+
|
83
|
+
>> Assemble(:drinks)
|
84
|
+
=> #<AssemblyLine::Constructor:0x10049e958 @code_block=#<Proc:0x000000010049ea98@(irb):1>, @name=:drinks, @rspec_context=AssemblyLine::GlobalContext, @options={}>
|
85
|
+
>> drinks
|
86
|
+
=> [:gin, :vodka]
|
87
|
+
|
73
88
|
|
74
89
|
Thanks!
|
75
90
|
-------
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.2.0
|
@@ -0,0 +1,71 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{assembly_line}
|
8
|
+
s.version = "0.2.0"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Sandro Turriate"]
|
12
|
+
s.date = %q{2010-02-08}
|
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
|
+
s.email = %q{sandro.turriate@gmail.com}
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"README.md"
|
17
|
+
]
|
18
|
+
s.files = [
|
19
|
+
".document",
|
20
|
+
".gitignore",
|
21
|
+
"History.md",
|
22
|
+
"MIT_LICENSE",
|
23
|
+
"README.md",
|
24
|
+
"Rakefile",
|
25
|
+
"VERSION",
|
26
|
+
"assembly_line.gemspec",
|
27
|
+
"lib/assembly_line.rb",
|
28
|
+
"lib/assembly_line/constructor.rb",
|
29
|
+
"lib/assembly_line/global_context.rb",
|
30
|
+
"lib/assembly_line/registry.rb",
|
31
|
+
"spec/assembly_line/constructor_spec.rb",
|
32
|
+
"spec/assembly_line/global_context_spec.rb",
|
33
|
+
"spec/assembly_line/registry_spec.rb",
|
34
|
+
"spec/assembly_line_spec.rb",
|
35
|
+
"spec/functional/assemble_spec.rb",
|
36
|
+
"spec/functional/global_context_spec.rb",
|
37
|
+
"spec/spec.opts",
|
38
|
+
"spec/spec_helper.rb"
|
39
|
+
]
|
40
|
+
s.homepage = %q{http://github.com/sandro/assembly_line}
|
41
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
42
|
+
s.require_paths = ["lib"]
|
43
|
+
s.rubygems_version = %q{1.3.5}
|
44
|
+
s.summary = %q{Modularize setup blocks for rspec}
|
45
|
+
s.test_files = [
|
46
|
+
"spec/assembly_line/constructor_spec.rb",
|
47
|
+
"spec/assembly_line/global_context_spec.rb",
|
48
|
+
"spec/assembly_line/registry_spec.rb",
|
49
|
+
"spec/assembly_line_spec.rb",
|
50
|
+
"spec/functional/assemble_spec.rb",
|
51
|
+
"spec/functional/global_context_spec.rb",
|
52
|
+
"spec/spec_helper.rb"
|
53
|
+
]
|
54
|
+
|
55
|
+
if s.respond_to? :specification_version then
|
56
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
57
|
+
s.specification_version = 3
|
58
|
+
|
59
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
60
|
+
s.add_development_dependency(%q<rspec>, ["= 1.2.9"])
|
61
|
+
s.add_development_dependency(%q<yard>, ["= 0.5.3"])
|
62
|
+
else
|
63
|
+
s.add_dependency(%q<rspec>, ["= 1.2.9"])
|
64
|
+
s.add_dependency(%q<yard>, ["= 0.5.3"])
|
65
|
+
end
|
66
|
+
else
|
67
|
+
s.add_dependency(%q<rspec>, ["= 1.2.9"])
|
68
|
+
s.add_dependency(%q<yard>, ["= 0.5.3"])
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
data/lib/assembly_line.rb
CHANGED
@@ -1,9 +1,10 @@
|
|
1
1
|
require 'forwardable'
|
2
2
|
require 'assembly_line/registry'
|
3
3
|
require 'assembly_line/constructor'
|
4
|
+
require 'assembly_line/global_context'
|
4
5
|
|
5
6
|
module AssemblyLine
|
6
|
-
VERSION = "0.
|
7
|
+
VERSION = "0.2.0".freeze
|
7
8
|
|
8
9
|
def self.define(name, &block)
|
9
10
|
Registry.add(name, block)
|
@@ -17,3 +18,17 @@ module AssemblyLine
|
|
17
18
|
AssemblyLine.assemble(name, self, options)
|
18
19
|
end
|
19
20
|
end
|
21
|
+
|
22
|
+
module Kernel
|
23
|
+
extend Forwardable
|
24
|
+
|
25
|
+
def Assemble(name, options={})
|
26
|
+
AssemblyLine.assemble(name, assembly_line_global_context, options)
|
27
|
+
end
|
28
|
+
|
29
|
+
protected
|
30
|
+
|
31
|
+
def assembly_line_global_context
|
32
|
+
AssemblyLine::GlobalContext
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module AssemblyLine
|
2
|
+
module GlobalContext
|
3
|
+
extend self
|
4
|
+
|
5
|
+
def let(name, &block)
|
6
|
+
define_method name do
|
7
|
+
let_values[name] ||= instance_eval(&block)
|
8
|
+
end
|
9
|
+
::Kernel.def_delegator :assembly_line_global_context, name
|
10
|
+
end
|
11
|
+
|
12
|
+
# there are no tests so just run the block
|
13
|
+
def before(scope=:each, &block)
|
14
|
+
instance_eval &block
|
15
|
+
end
|
16
|
+
|
17
|
+
def clear
|
18
|
+
instance_variables.each do |name|
|
19
|
+
instance_variable_set(name, nil)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
protected
|
24
|
+
|
25
|
+
def let_values
|
26
|
+
@let_values ||= {}
|
27
|
+
end
|
28
|
+
|
29
|
+
attr_writer :context
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,33 @@
|
|
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
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
global_assembly_set_up = lambda do
|
4
|
+
AssemblyLine.define(:global_assembly) do
|
5
|
+
let(:foo) { @bar +=1 }
|
6
|
+
before do
|
7
|
+
@bar = 0
|
8
|
+
end
|
9
|
+
end
|
10
|
+
Assemble(:global_assembly)
|
11
|
+
end
|
12
|
+
|
13
|
+
def call_global_assembly(count = 5)
|
14
|
+
(count - 1).times { foo }
|
15
|
+
foo
|
16
|
+
end
|
17
|
+
|
18
|
+
describe "in the global context" do
|
19
|
+
before(:all) do
|
20
|
+
global_assembly_set_up.call
|
21
|
+
end
|
22
|
+
|
23
|
+
it "defined the method within AssemblyLine::GlobalContext" do
|
24
|
+
AssemblyLine::GlobalContext.should respond_to(:foo)
|
25
|
+
end
|
26
|
+
|
27
|
+
it "does not increase the value because the method is memoized" do
|
28
|
+
call_global_assembly.should == 1
|
29
|
+
end
|
30
|
+
end
|
data/spec/spec.opts
CHANGED
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.
|
4
|
+
version: 0.2.0
|
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-08 00:00:00 -05:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -43,17 +43,22 @@ extra_rdoc_files:
|
|
43
43
|
files:
|
44
44
|
- .document
|
45
45
|
- .gitignore
|
46
|
+
- History.md
|
46
47
|
- MIT_LICENSE
|
47
48
|
- README.md
|
48
49
|
- Rakefile
|
49
50
|
- VERSION
|
51
|
+
- assembly_line.gemspec
|
50
52
|
- lib/assembly_line.rb
|
51
53
|
- lib/assembly_line/constructor.rb
|
54
|
+
- lib/assembly_line/global_context.rb
|
52
55
|
- lib/assembly_line/registry.rb
|
53
56
|
- spec/assembly_line/constructor_spec.rb
|
57
|
+
- spec/assembly_line/global_context_spec.rb
|
54
58
|
- spec/assembly_line/registry_spec.rb
|
55
59
|
- spec/assembly_line_spec.rb
|
56
60
|
- spec/functional/assemble_spec.rb
|
61
|
+
- spec/functional/global_context_spec.rb
|
57
62
|
- spec/spec.opts
|
58
63
|
- spec/spec_helper.rb
|
59
64
|
has_rdoc: true
|
@@ -86,7 +91,9 @@ specification_version: 3
|
|
86
91
|
summary: Modularize setup blocks for rspec
|
87
92
|
test_files:
|
88
93
|
- spec/assembly_line/constructor_spec.rb
|
94
|
+
- spec/assembly_line/global_context_spec.rb
|
89
95
|
- spec/assembly_line/registry_spec.rb
|
90
96
|
- spec/assembly_line_spec.rb
|
91
97
|
- spec/functional/assemble_spec.rb
|
98
|
+
- spec/functional/global_context_spec.rb
|
92
99
|
- spec/spec_helper.rb
|