developwithpassion_arrays 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,3 @@
1
+ pkg
2
+ .bundle
3
+ Gemfile.lock
data/.rvmrc ADDED
@@ -0,0 +1 @@
1
+ rvm 1.9.3@developwithpassion_arrays --create
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ gemspec
4
+
@@ -0,0 +1,5 @@
1
+ guard 'rspec' do
2
+ watch(%r{^spec/specs/.+_spec\.rb$})
3
+ watch(%r{^lib/developwithpassion_expander/(.+)\.rb$}) { |m| "spec/specs/#{m[1]}_spec.rb" }
4
+ watch('spec/spec_helper.rb') { "spec" }
5
+ end
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'developwithpassion_expander'
4
+ DevelopWithPassion::Expander::CLIInterface.new.run(ARGV)
@@ -0,0 +1,27 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib",__FILE__)
3
+ require "developwithpassion_arrays/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "developwithpassion_arrays"
7
+ s.version = DevelopWithPassion::Arrays::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.authors = ["Develop With Passion®"]
10
+ s.email = ["open_source@developwithpassion.com"]
11
+ s.homepage = "http://www.developwithpassion.com"
12
+ s.summary = %q{Simple DSL For Declaritive Arrays}
13
+ s.description = %q{Simple DSL For Declaritive Arrays}
14
+ s.rubyforge_project = "developwithpassion_arrays"
15
+
16
+ s.files = `git ls-files`.split("\n")
17
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
+ s.require_paths = ["lib"]
20
+
21
+ # specify any dependencies here; for example:
22
+ s.add_development_dependency "rake"
23
+ s.add_development_dependency "rspec"
24
+ s.add_development_dependency "guard"
25
+ s.add_development_dependency "guard-rspec"
26
+ s.add_development_dependency "developwithpassion_fakes"
27
+ end
@@ -0,0 +1,10 @@
1
+ require 'developwithpassion_arrays/add_criterion'
2
+ require 'developwithpassion_arrays/dsl'
3
+ require 'developwithpassion_arrays/module_registry'
4
+ require 'developwithpassion_arrays/mutator_detail'
5
+ require 'developwithpassion_arrays/mutator_step'
6
+ require 'developwithpassion_arrays/object_extensions'
7
+ require 'developwithpassion_arrays/readable_step'
8
+ require 'developwithpassion_arrays/visitor_detail'
9
+ require 'developwithpassion_arrays/visitor_detail_step'
10
+ require 'developwithpassion_arrays/writeable_step'
@@ -0,0 +1,18 @@
1
+ module DevelopWithPassion
2
+ module Arrays
3
+ class AddCriterion
4
+ attr_accessor :criteria,:failure_strategy
5
+
6
+ def initialize(criteria,failure_strategy)
7
+ @criteria = criteria
8
+ @failure_strategy = failure_strategy
9
+ end
10
+
11
+ def apply_to(value)
12
+ result = @criteria.is_satisfied_by(value)
13
+ @failure_strategy.run(@criteria.name,value) unless result
14
+ return result
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,38 @@
1
+ module DevelopWithPassion
2
+ module Arrays
3
+ class Dsl
4
+ attr_accessor :mutators,:visitors,:criteria,:name,:writable,:readable
5
+
6
+ def initialize(name)
7
+ @name = name
8
+ initialize_arrays :mutators,:visitors,:criteria
9
+ initialize_false :writable,:readable
10
+ end
11
+
12
+ def mutator(*names,&block)
13
+ names.each{|name| @mutators.push(MutatorDetail.new(name,block))}
14
+ end
15
+
16
+ def new_item_must(criteria,fail_option)
17
+ @criteria.push(AddCriterion.new(criteria,fail_option))
18
+ end
19
+
20
+ def process_using(name,visitor)
21
+ @visitors.push(VisitorDetail.new(name,visitor))
22
+ end
23
+
24
+ def read_and_write
25
+ writable
26
+ readable
27
+ end
28
+
29
+ def writable
30
+ @writable = true
31
+ end
32
+
33
+ def readable
34
+ @readable = true
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,14 @@
1
+ module DevelopWithPassion
2
+ module Arrays
3
+ class ModuleRegistry
4
+ def self.all_modules
5
+ return [
6
+ MutatorStep.new,
7
+ VisitorDetailStep.new,
8
+ WriteableStep.new,
9
+ ReadableStep.new
10
+ ]
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,12 @@
1
+ module DevelopWithPassion
2
+ module Arrays
3
+ class MutatorDetail
4
+ attr_accessor :name,:block
5
+
6
+ def initialize(name,block)
7
+ @name = name
8
+ @block = block
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,20 @@
1
+ module DevelopWithPassion
2
+ module Arrays
3
+ class MutatorStep
4
+ def run_using(builder)
5
+ Module.new do
6
+ builder.mutators.each do|mutator|
7
+ define_method(mutator.name) do|value|
8
+ array_var = instance_variable_get("@#{builder.name}")
9
+ continue_add = true
10
+ builder.criteria.each{|criteria| continue_add &= criteria.apply_to(value)}
11
+ return unless continue_add
12
+ array_var.push(value) unless mutator.block
13
+ mutator.block.call(value) if mutator.block
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,27 @@
1
+ class Object
2
+ def initialize_defaults(factory,*items)
3
+ items.each do|item|
4
+ instance_variable_set("@#{item}",factory.call)
5
+ end
6
+ end
7
+
8
+ def initialize_arrays(*items)
9
+ initialize_defaults(lambda{[]},*items)
10
+ end
11
+
12
+ def initialize_hashes(*items)
13
+ initialize_defaults(lambda{{}},*items)
14
+ end
15
+
16
+ def initialize_false(*items)
17
+ initialize_defaults(lambda{false},*items)
18
+ end
19
+
20
+ def array(name,&block)
21
+ initialize_arrays(name)
22
+ dsl = DevelopWithPassion::Arrays::Dsl.new(name)
23
+ yield dsl if block_given?
24
+ DevelopWithPassion::Arrays::ModuleRegistry.all_modules.each{|module_factory| self.extend(module_factory.run_using(dsl))}
25
+ end
26
+
27
+ end
@@ -0,0 +1,15 @@
1
+ module DevelopWithPassion
2
+ module Arrays
3
+ class ReadableStep
4
+ def run_using(builder)
5
+ Module.new do
6
+ if (builder.readable)
7
+ define_method(builder.name) do
8
+ return instance_variable_get("@#{builder.name}")
9
+ end
10
+ end
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,5 @@
1
+ module DevelopWithPassion
2
+ module Arrays
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
@@ -0,0 +1,12 @@
1
+ module DevelopWithPassion
2
+ module Arrays
3
+ class VisitorDetail
4
+ attr_accessor :name,:visitor
5
+
6
+ def initialize(name,visitor)
7
+ @name = name
8
+ @visitor = visitor
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,16 @@
1
+ module DevelopWithPassion
2
+ module Arrays
3
+ class VisitorDetailStep
4
+ def run_using(builder)
5
+ Module.new do
6
+ builder.visitors.each do|visitor|
7
+ define_method(visitor.name) do
8
+ array_var = instance_variable_get("@#{builder.name}")
9
+ array_var.each{|item| visitor.visitor.respond_to?(:run_using) ? visitor.visitor.run_using(item) : item.send(visitor.visitor)}
10
+ end
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,15 @@
1
+ module DevelopWithPassion
2
+ module Arrays
3
+ class WriteableStep
4
+ def run_using(builder)
5
+ Module.new do
6
+ if (builder.writable)
7
+ define_method("#{builder.name}=") do|value|
8
+ instance_variable_set("@#{builder.name}",value)
9
+ end
10
+ end
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,45 @@
1
+ require 'rspec'
2
+ require 'fileutils'
3
+ require 'developwithpassion_fakes'
4
+
5
+ Dir.chdir(File.join(File.dirname(__FILE__),"..,lib".split(','))) do
6
+ Dir.glob("**/*.rb").each do |file|
7
+ full_path = File.expand_path(file)
8
+ $:.unshift File.expand_path(File.dirname(full_path))
9
+ require full_path
10
+ end
11
+ end
12
+
13
+ def fake
14
+ DevelopWithPassion::Fakes::Fake.new
15
+ end
16
+
17
+ def catch_exception
18
+ begin
19
+ yield
20
+ rescue Exception => e
21
+ exception = e
22
+ end
23
+ exception
24
+ end
25
+
26
+ module RSpec
27
+ Matchers.define :have_received do|symbol,*args|
28
+ match do|fake|
29
+ fake.received(symbol).called_with(*args) != nil
30
+ end
31
+ end
32
+
33
+ Matchers.define :never_receive do|symbol,*args|
34
+ match do|fake|
35
+ item = fake.received(symbol)
36
+ result = true
37
+ if (item == nil)
38
+ result = (args.count == 0)
39
+ else
40
+ result = (item.called_with(*args) == nil)
41
+ end
42
+ result
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,44 @@
1
+ require 'spec_helper'
2
+
3
+ module DevelopWithPassion
4
+ module Arrays
5
+ describe AddCriterion do
6
+ context "when applied to a value" do
7
+ let(:failure_strategy){fake}
8
+ let(:criteria){fake}
9
+ let(:value){42}
10
+ let(:name){"Name of criteria"}
11
+ let(:sut){AddCriterion.new(criteria,failure_strategy)}
12
+
13
+ context "and the value does not match the criteria" do
14
+ before (:each) do
15
+ criteria.stub(:is_satisfied_by).with(value).and_return(false)
16
+ criteria.stub(:name).and_return(name)
17
+ end
18
+ before (:each) do
19
+ sut.apply_to(value)
20
+ end
21
+ it "should run the failure strategy with the correct information" do
22
+ failure_strategy.should have_received(:run,name,value)
23
+ end
24
+ end
25
+
26
+ context "and the value matches the criteria" do
27
+ before (:each) do
28
+ criteria.stub(:is_satisfied_by).with(value).and_return(true)
29
+ criteria.stub(:name).and_return(name)
30
+ end
31
+ before (:each) do
32
+ @result = sut.apply_to(value)
33
+ end
34
+ it "should not use the failure strategy" do
35
+ failure_strategy.should never_receive(:run)
36
+ end
37
+ it "should return true" do
38
+ @result.should be_true
39
+ end
40
+ end
41
+ end
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,279 @@
1
+ require 'spec_helper'
2
+
3
+ module DevelopWithPassion
4
+ module Arrays
5
+ describe Dsl do
6
+ context "when a criteria is specified" do
7
+ let(:fail_option){fake}
8
+ let(:real_criteria){fake}
9
+ let(:criteria){fake}
10
+ let(:sut){Dsl.new(:name)}
11
+ before (:each) do
12
+ AddCriterion.stub(:new).with(real_criteria,fail_option).and_return(criteria)
13
+ end
14
+ before (:each) do
15
+ sut.new_item_must(real_criteria,fail_option)
16
+ end
17
+ it "should be added to the list of add specifications for the array" do
18
+ sut.criteria[0].should == criteria
19
+ end
20
+ end
21
+ context "when specifying mutators" do
22
+ context "and a singular mutator is specified" do
23
+ let(:mutator){fake}
24
+ let(:name){"sdfsdf"}
25
+ let(:sut){Dsl.new("sdf")}
26
+ before (:each) do
27
+ MutatorDetail.stub(:new).with(name,nil).and_return(mutator)
28
+ end
29
+ before (:each) do
30
+ sut.mutator(name)
31
+ end
32
+ it "should be added to the list of mutators for the list" do
33
+ sut.mutators[0].should == mutator
34
+ end
35
+ end
36
+ context "and a set of mutators are specified" do
37
+ let(:mutator){fake}
38
+ let(:sut){Dsl.new("sdf")}
39
+ before (:each) do
40
+ MutatorDetail.stub(:new).with(:sdf,nil).and_return(mutator)
41
+ MutatorDetail.stub(:new).with(:other,nil).and_return(mutator)
42
+ end
43
+ before (:each) do
44
+ sut.mutator(:sdf,:other)
45
+ end
46
+ it "should add a new mutator for each name specified" do
47
+ sut.mutators.count.should == 2
48
+ end
49
+ end
50
+ end
51
+
52
+ context "when a visitor is specified" do
53
+ let(:visitor){fake}
54
+ let(:the_visitor){fake}
55
+ let(:name){"sdfsdf"}
56
+ let(:sut){Dsl.new("sdf")}
57
+ before (:each) do
58
+ VisitorDetail.stub(:new).with(name,the_visitor).and_return(visitor)
59
+ end
60
+ before (:each) do
61
+ sut.process_using(name,the_visitor)
62
+ end
63
+ it "should be added to the list of visitors for the list" do
64
+ sut.visitors[0].should == visitor
65
+ end
66
+ end
67
+
68
+ context "using the dsl" do
69
+ it "should be able to initialize all arrays specified on the instance and provide a method to expose addition" do
70
+ class Item
71
+
72
+ def initialize
73
+ array :kids do|a|
74
+ a.mutator :register_child
75
+ end
76
+ end
77
+ end
78
+
79
+ item = Item.new
80
+ item.methods.include?(:register_child).should be_true
81
+ item.register_child("hello")
82
+ item.kids.count.should == 1
83
+ end
84
+ it "should be able to expose a mutator with custom logic" do
85
+ class Item
86
+ attr_accessor :added,:item_added
87
+
88
+ def initialize
89
+ @added = 0
90
+
91
+ array :kids do|a|
92
+ a.mutator :register_child do|the_item|
93
+ @item_added = the_item
94
+ @added +=1
95
+ @kids.push(the_item)
96
+ end
97
+ end
98
+ end
99
+ end
100
+
101
+ item = Item.new
102
+ item.register_child("hello")
103
+ item.kids.count.should == 1
104
+ item.item_added.should == "hello"
105
+ item.added.should == 1
106
+ end
107
+
108
+ it "should be able to expose a processing visitor" do
109
+ class Item
110
+ attr_accessor :added
111
+
112
+ def initialize(visitor)
113
+ @added = 0
114
+ array :kids do|a|
115
+ a.mutator :register_child
116
+ a.process_using :register_kids,visitor
117
+ end
118
+ end
119
+ end
120
+
121
+ class OurVisitor
122
+ attr_accessor :items
123
+ def initialize
124
+ @items = 0
125
+ end
126
+ def run_using(item)
127
+ @items +=1
128
+ end
129
+ end
130
+
131
+ our_visitor = OurVisitor.new
132
+ item = Item.new(our_visitor)
133
+ item.register_child("hello")
134
+ item.kids.count.should == 1
135
+ item.register_kids
136
+ our_visitor.items.should == 1
137
+ end
138
+
139
+ it "should be able to expose a processing visitor by symbol" do
140
+ class Item
141
+ attr_accessor :added
142
+
143
+ def initialize
144
+ @added = 0
145
+ array :kids do|a|
146
+ a.mutator :register_child
147
+ a.process_using :register_kids,:speak
148
+ end
149
+ end
150
+ end
151
+
152
+ class Kid
153
+ def initialize(array)
154
+ @array = array
155
+ end
156
+ def speak
157
+ @array.push("spoke")
158
+ end
159
+ end
160
+
161
+ items = []
162
+ item = Item.new
163
+ item.register_child(Kid.new(items))
164
+ item.kids.count.should == 1
165
+ item.register_kids
166
+ items.count.should == 1
167
+ end
168
+ end
169
+
170
+ context "when specifying a mutator" do
171
+ context "and no block is provided" do
172
+ it "should expose the specified method to trigger addition" do
173
+ class Item
174
+
175
+ def initialize
176
+ array :kids do|a|
177
+ a.mutator :register_child
178
+ end
179
+ end
180
+ end
181
+
182
+ item = Item.new
183
+ item.methods.include?(:register_child).should be_true
184
+ item.register_child("hello")
185
+ item.kids.count.should == 1
186
+ end
187
+ end
188
+
189
+ context "and a block is provided" do
190
+ it "should provide a method that delegates to the block when invoked" do
191
+ class Item
192
+ attr_accessor :added
193
+
194
+ def initialize
195
+ @added = 0
196
+
197
+ array :kids do|a|
198
+ a.mutator :register_child do|item|
199
+ @kids.push(item)
200
+ @added+=1
201
+ end
202
+ end
203
+ end
204
+ end
205
+
206
+ item = Item.new
207
+ item.register_child("hello")
208
+ item.kids.count.should == 1
209
+ item.added.should == 1
210
+ end
211
+ end
212
+
213
+ context "when criterias have been specified on the array" do
214
+ class BeGreaterThanZero
215
+ def name
216
+ return "Be greater than 0"
217
+ end
218
+ def is_satisfied_by(item)
219
+ return item > 0
220
+ end
221
+ end
222
+ context "and the criteria is not met" do
223
+ context "and the failure strategy is set to raise an error" do
224
+ class RaiseCriteriaFailure
225
+ def run(name,value)
226
+ raise "The value #{value} does not meet the criteria #{name}"
227
+ end
228
+ end
229
+ class OneClass
230
+ def initialize
231
+ array :items do|a|
232
+ a.mutator :add_item,:add_this,:add_that
233
+ a.new_item_must BeGreaterThanZero.new, RaiseCriteriaFailure.new
234
+ end
235
+ end
236
+ end
237
+ let(:target){OneClass.new}
238
+ before (:each) do
239
+ @exception = catch_exception do
240
+ target.add_item(0)
241
+ end
242
+ end
243
+
244
+ it "should raise an error when a failed add is attempted" do
245
+ (@exception.message =~ /does not meet/).should be_true
246
+ end
247
+ it "should not add the item to the underlying list" do
248
+ target.items.count.should == 0
249
+ end
250
+ end
251
+
252
+ context "and the failure strategy is not set to raise an error" do
253
+ class DisplayCriteriaFailure
254
+ def run(name,value)
255
+ puts "The value #{value} does not meet the criteria #{name}"
256
+ end
257
+ end
258
+ class AnotherClass
259
+ def initialize
260
+ array :items do|a|
261
+ a.mutator :add_item,:add_this,:add_that
262
+ a.new_item_must BeGreaterThanZero.new, DisplayCriteriaFailure.new
263
+ end
264
+ end
265
+ end
266
+ let(:target){AnotherClass.new}
267
+ before (:each) do
268
+ target.add_item(0)
269
+ end
270
+ it "should not add the item to the underlying list" do
271
+ target.items.count.should == 0
272
+ end
273
+ end
274
+ end
275
+ end
276
+ end
277
+ end
278
+ end
279
+ end
@@ -0,0 +1,47 @@
1
+ require 'spec_helper'
2
+
3
+ module DevelopWithPassion
4
+ module Arrays
5
+ describe MutatorStep do
6
+ context "when run" do
7
+ let(:numbers){[]}
8
+ let(:target){Sample.new(numbers)}
9
+ let(:mutators){[]}
10
+ let(:sut){MutatorStep.new}
11
+ let(:builder){Dsl.new(:numbers)}
12
+
13
+ context "using a dsl fragment that contains no block usage" do
14
+ before (:each) do
15
+ builder.mutator(:add_a_number)
16
+ end
17
+ before (:each) do
18
+ target.extend(sut.run_using(builder))
19
+ end
20
+ it "should create a member on the target that allows mutation of the original list" do
21
+ target.respond_to?(:add_a_number).should be_true
22
+ target.add_a_number(2)
23
+ numbers[0].should == 2
24
+ end
25
+ end
26
+ context "using a dsl fragment that contains block usage" do
27
+ before (:each) do
28
+ builder.mutator(:add_a_number) do|value|
29
+ @value_attempted_to_be_added = value
30
+ end
31
+ end
32
+ before (:each) do
33
+ target.extend(sut.run_using(builder))
34
+ end
35
+ it "should create a member on the target that intercepts mutation using the provided block" do
36
+ target.respond_to?(:add_a_number).should be_true
37
+ target.add_a_number(2)
38
+ numbers.count.should == 0
39
+ @value_attempted_to_be_added.should == 2
40
+ end
41
+ end
42
+
43
+ end
44
+
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,55 @@
1
+ require 'spec_helper'
2
+
3
+ describe Object do
4
+ context "when initializing fields with defaults" do
5
+ it "should initialize based on the factory provided" do
6
+ class Item
7
+ attr_accessor :kids,:cars,:name
8
+
9
+ def initialize
10
+ initialize_defaults lambda{[]},:kids,:cars
11
+ initialize_defaults lambda{""},:name
12
+ end
13
+ end
14
+
15
+ item = Item.new
16
+ [item.kids,item.cars].each{|value| value.class.should == Array}
17
+ item.name.class.should == String
18
+ end
19
+ end
20
+
21
+ context "when initializing simple arrays" do
22
+ it "should initialize all arrays specified on the instance" do
23
+ class Item
24
+ attr_accessor :kids,:cars,:bikes
25
+
26
+ def initialize
27
+ initialize_arrays :kids,:cars,:bikes
28
+ end
29
+ end
30
+
31
+ item = Item.new
32
+ [item.kids,item.cars,item.bikes].each do|value|
33
+ value.class.should == Array
34
+ end
35
+ end
36
+ end
37
+
38
+ context "when initializing hashes" do
39
+ it "should initialize all hashes specified" do
40
+ class Item
41
+ attr_accessor :kids,:cars,:bikes
42
+
43
+ def initialize
44
+ initialize_hashes :kids,:cars,:bikes
45
+ end
46
+ end
47
+
48
+ item = Item.new
49
+ [item.kids,item.cars,item.bikes].each do|value|
50
+ value.class.should == Hash
51
+ end
52
+ end
53
+ end
54
+ end
55
+
@@ -0,0 +1,26 @@
1
+ require 'spec_helper'
2
+
3
+ module DevelopWithPassion
4
+ module Arrays
5
+ describe ReadableStep do
6
+ context "when run" do
7
+ let(:target){Sample.new}
8
+ let(:mutators){[]}
9
+ let(:sut){ReadableStep.new}
10
+ let(:builder){Dsl.new(:numbers)}
11
+
12
+ context "using a dsl fragment that contains no block usage" do
13
+ before (:each) do
14
+ builder.readable
15
+ end
16
+ before (:each) do
17
+ target.extend(sut.run_using(builder))
18
+ end
19
+ it "should create a member on the target that allows reading of the array" do
20
+ target.numbers.should be_a(Array)
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,5 @@
1
+ class Sample
2
+ def initialize(numbers = [])
3
+ @numbers = numbers
4
+ end
5
+ end
@@ -0,0 +1,78 @@
1
+ require 'spec_helper'
2
+
3
+ module DevelopWithPassion
4
+ module Arrays
5
+ describe VisitorDetailStep do
6
+ class OurSet
7
+ attr_accessor :items
8
+
9
+ def initialize
10
+ @items = []
11
+ end
12
+
13
+ def add(item)
14
+ @items << item
15
+ end
16
+ end
17
+ class Speak
18
+ def initialize(invocations)
19
+ @invocations = invocations
20
+ end
21
+ def hello
22
+ @invocations.push(1)
23
+ end
24
+ end
25
+ context "when run" do
26
+ context "using a visitor that is symbol based" do
27
+ let(:target){OurSet.new}
28
+ let(:mutators){[]}
29
+ let(:invocations){[]}
30
+ let(:sut){VisitorDetailStep.new}
31
+ let(:builder){Dsl.new(:items)}
32
+ before (:each) do
33
+ (1..10).each{|item| target.add(Speak.new(invocations))}
34
+ builder.process_using(:run,:hello)
35
+ end
36
+ before (:each) do
37
+ target.extend(sut.run_using(builder))
38
+ end
39
+
40
+ it "should create a method on the target that triggers each item in the list using its provided action" do
41
+ target.run
42
+ invocations.count.should == 10
43
+ end
44
+ end
45
+ context "using a visitor that is class based" do
46
+ class TheVisitor
47
+ attr_accessor :items
48
+ def initialize
49
+ @items = []
50
+ end
51
+ def run_using(item)
52
+ @items << item
53
+ end
54
+ end
55
+ let(:target){OurSet.new}
56
+ let(:visitor){TheVisitor.new}
57
+ let(:mutators){[]}
58
+ let(:invocations){[]}
59
+ let(:sut){VisitorDetailStep.new}
60
+ let(:builder){Dsl.new(:items)}
61
+
62
+ before (:each) do
63
+ (1..10).each{|item| target.add(item)}
64
+ builder.process_using(:run,visitor)
65
+ end
66
+ before (:each) do
67
+ target.extend(sut.run_using(builder))
68
+ end
69
+
70
+ it "should create a method on the target that triggers the visitor once for each item in the list" do
71
+ target.run
72
+ (1..10).each{|item| visitor.items.include?(item).should be_true}
73
+ end
74
+ end
75
+ end
76
+ end
77
+ end
78
+ end
@@ -0,0 +1,30 @@
1
+ require 'spec_helper'
2
+
3
+ module DevelopWithPassion
4
+ module Arrays
5
+ describe WriteableStep do
6
+ context "when run" do
7
+ context "using a dsl fragment that contains no block usage" do
8
+ let(:target){Sample.new}
9
+ let(:mutators){[]}
10
+ let(:sut){WriteableStep.new}
11
+ let(:builder){Dsl.new(:numbers)}
12
+ before (:each) do
13
+ builder.writable
14
+ end
15
+ before (:each) do
16
+ target.extend(sut.run_using(builder))
17
+ end
18
+ it "should create a member on the target that allows assignment to the array" do
19
+ new_array = [1]
20
+ target.numbers = new_array
21
+ def target.numbers
22
+ return @numbers
23
+ end
24
+ target.numbers.should == new_array
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
metadata ADDED
@@ -0,0 +1,138 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: developwithpassion_arrays
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Develop With Passion®
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-03-22 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rake
16
+ requirement: &70212187669740 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: *70212187669740
25
+ - !ruby/object:Gem::Dependency
26
+ name: rspec
27
+ requirement: &70212187669160 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :development
34
+ prerelease: false
35
+ version_requirements: *70212187669160
36
+ - !ruby/object:Gem::Dependency
37
+ name: guard
38
+ requirement: &70212187668340 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ type: :development
45
+ prerelease: false
46
+ version_requirements: *70212187668340
47
+ - !ruby/object:Gem::Dependency
48
+ name: guard-rspec
49
+ requirement: &70212187667420 !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ type: :development
56
+ prerelease: false
57
+ version_requirements: *70212187667420
58
+ - !ruby/object:Gem::Dependency
59
+ name: developwithpassion_fakes
60
+ requirement: &70212187666720 !ruby/object:Gem::Requirement
61
+ none: false
62
+ requirements:
63
+ - - ! '>='
64
+ - !ruby/object:Gem::Version
65
+ version: '0'
66
+ type: :development
67
+ prerelease: false
68
+ version_requirements: *70212187666720
69
+ description: Simple DSL For Declaritive Arrays
70
+ email:
71
+ - open_source@developwithpassion.com
72
+ executables:
73
+ - dwp_expand
74
+ extensions: []
75
+ extra_rdoc_files: []
76
+ files:
77
+ - .gitignore
78
+ - .rvmrc
79
+ - Gemfile
80
+ - Guardfile
81
+ - Rakefile
82
+ - bin/dwp_expand
83
+ - developwithpassion_arrays.gemspec
84
+ - lib/developwithpassion_arrays.rb
85
+ - lib/developwithpassion_arrays/add_criterion.rb
86
+ - lib/developwithpassion_arrays/dsl.rb
87
+ - lib/developwithpassion_arrays/module_registry.rb
88
+ - lib/developwithpassion_arrays/mutator_detail.rb
89
+ - lib/developwithpassion_arrays/mutator_step.rb
90
+ - lib/developwithpassion_arrays/object_extensions.rb
91
+ - lib/developwithpassion_arrays/readable_step.rb
92
+ - lib/developwithpassion_arrays/version.rb
93
+ - lib/developwithpassion_arrays/visitor_detail.rb
94
+ - lib/developwithpassion_arrays/visitor_detail_step.rb
95
+ - lib/developwithpassion_arrays/writeable_step.rb
96
+ - spec/spec_helper.rb
97
+ - spec/specs/add_criterion_spec.rb
98
+ - spec/specs/dsl_spec.rb
99
+ - spec/specs/mutator_step_spec.rb
100
+ - spec/specs/object_extensions_spec.rb
101
+ - spec/specs/readable_step_spec.rb
102
+ - spec/specs/sample.rb
103
+ - spec/specs/visitor_detail_step_spec.rb
104
+ - spec/specs/writeable_step_spec.rb
105
+ homepage: http://www.developwithpassion.com
106
+ licenses: []
107
+ post_install_message:
108
+ rdoc_options: []
109
+ require_paths:
110
+ - lib
111
+ required_ruby_version: !ruby/object:Gem::Requirement
112
+ none: false
113
+ requirements:
114
+ - - ! '>='
115
+ - !ruby/object:Gem::Version
116
+ version: '0'
117
+ required_rubygems_version: !ruby/object:Gem::Requirement
118
+ none: false
119
+ requirements:
120
+ - - ! '>='
121
+ - !ruby/object:Gem::Version
122
+ version: '0'
123
+ requirements: []
124
+ rubyforge_project: developwithpassion_arrays
125
+ rubygems_version: 1.8.15
126
+ signing_key:
127
+ specification_version: 3
128
+ summary: Simple DSL For Declaritive Arrays
129
+ test_files:
130
+ - spec/spec_helper.rb
131
+ - spec/specs/add_criterion_spec.rb
132
+ - spec/specs/dsl_spec.rb
133
+ - spec/specs/mutator_step_spec.rb
134
+ - spec/specs/object_extensions_spec.rb
135
+ - spec/specs/readable_step_spec.rb
136
+ - spec/specs/sample.rb
137
+ - spec/specs/visitor_detail_step_spec.rb
138
+ - spec/specs/writeable_step_spec.rb