developwithpassion_expander 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +3 -0
- data/.rvmrc +1 -0
- data/Gemfile +4 -0
- data/Guardfile +5 -0
- data/Rakefile +1 -0
- data/bin/dwp_expand +4 -0
- data/develpwithpassion_expander.gemspec +29 -0
- data/lib/developwithpassion_expander.rb +32 -0
- data/lib/developwithpassion_expander/array.rb +8 -0
- data/lib/developwithpassion_expander/array_dsl.rb +34 -0
- data/lib/developwithpassion_expander/array_dsl_module_factory.rb +14 -0
- data/lib/developwithpassion_expander/array_mutator.rb +12 -0
- data/lib/developwithpassion_expander/array_mutator_step.rb +17 -0
- data/lib/developwithpassion_expander/array_readable_step.rb +15 -0
- data/lib/developwithpassion_expander/array_visitor.rb +12 -0
- data/lib/developwithpassion_expander/array_visitor_step.rb +16 -0
- data/lib/developwithpassion_expander/array_writeable_step.rb +15 -0
- data/lib/developwithpassion_expander/cli_interface.rb +41 -0
- data/lib/developwithpassion_expander/copy.rb +29 -0
- data/lib/developwithpassion_expander/copy_to_target.rb +13 -0
- data/lib/developwithpassion_expander/enumerable_extensions.rb +11 -0
- data/lib/developwithpassion_expander/erb_template_file.rb +33 -0
- data/lib/developwithpassion_expander/expansion.rb +84 -0
- data/lib/developwithpassion_expander/file.rb +32 -0
- data/lib/developwithpassion_expander/file_merge.rb +54 -0
- data/lib/developwithpassion_expander/kernel.rb +35 -0
- data/lib/developwithpassion_expander/log.rb +17 -0
- data/lib/developwithpassion_expander/mustache_template_file.rb +11 -0
- data/lib/developwithpassion_expander/object_extensions.rb +28 -0
- data/lib/developwithpassion_expander/shell.rb +9 -0
- data/lib/developwithpassion_expander/shell_action_against_file.rb +12 -0
- data/lib/developwithpassion_expander/string.rb +5 -0
- data/lib/developwithpassion_expander/template_processors.rb +24 -0
- data/lib/developwithpassion_expander/template_visitor.rb +20 -0
- data/lib/developwithpassion_expander/version.rb +5 -0
- data/spec/spec_helper.rb +77 -0
- data/spec/specs/array_dsl_spec.rb +38 -0
- data/spec/specs/array_mutator_step_spec.rb +47 -0
- data/spec/specs/array_readable_step_spec.rb +26 -0
- data/spec/specs/array_spec.rb +22 -0
- data/spec/specs/array_visitor_step_spec.rb +78 -0
- data/spec/specs/array_writeable_step_spec.rb +30 -0
- data/spec/specs/copy_spec.rb +89 -0
- data/spec/specs/copy_to_target_spec.rb +24 -0
- data/spec/specs/enumerable_extensions_spec.rb +27 -0
- data/spec/specs/erb_template_file_spec.rb +65 -0
- data/spec/specs/expansion_spec.rb +146 -0
- data/spec/specs/file_merge_spec.rb +133 -0
- data/spec/specs/file_spec.rb +81 -0
- data/spec/specs/kernel_spec.rb +56 -0
- data/spec/specs/mustache_template_file_spec.rb +50 -0
- data/spec/specs/object_spec.rb +202 -0
- data/spec/specs/sample.rb +5 -0
- data/spec/specs/shell_action_against_file_spec.rb +24 -0
- data/spec/specs/string_spec.rb +13 -0
- data/spec/specs/template_processors_spec.rb +64 -0
- data/spec/specs/template_visitor_spec.rb +86 -0
- metadata +202 -0
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module DevelopWithPassion
|
4
|
+
module Expander
|
5
|
+
describe Array do
|
6
|
+
it "should be able to return the array contents as a glob pattern" do
|
7
|
+
items = %w[this is cool **/*.rb]
|
8
|
+
%w[this is cool **/*.rb].as_glob_pattern.should == File.join(items)
|
9
|
+
end
|
10
|
+
|
11
|
+
it "should map each item as a home item" do
|
12
|
+
items = %w[this is cool]
|
13
|
+
items.as_home_files.should == items.map{|item| item.as_home_file}
|
14
|
+
end
|
15
|
+
|
16
|
+
it "should be able to be converted to a glob pattern" do
|
17
|
+
%w[this is cool].as_glob_pattern.should == "this/is/cool"
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,78 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module DevelopWithPassion
|
4
|
+
module Expander
|
5
|
+
describe ArrayVisitorStep 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){ArrayVisitorStep.new}
|
31
|
+
let(:builder){ArrayDSL.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){ArrayVisitorStep.new}
|
60
|
+
let(:builder){ArrayDSL.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 Expander
|
5
|
+
describe ArrayWriteableStep 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){ArrayWriteableStep.new}
|
11
|
+
let(:builder){ArrayDSL.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
|
@@ -0,0 +1,89 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module DevelopWithPassion
|
4
|
+
module Expander
|
5
|
+
class FakeVisitor
|
6
|
+
def initialize
|
7
|
+
array :sources do|a|
|
8
|
+
a.readable
|
9
|
+
a.writable
|
10
|
+
a.mutator :run_using
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
describe Copy do
|
15
|
+
let(:sources){[]}
|
16
|
+
let(:copy_visitor){FakeVisitor.new}
|
17
|
+
|
18
|
+
before (:each) do
|
19
|
+
@sut = Copy.new(copy_visitor)
|
20
|
+
@sut.sources = sources
|
21
|
+
end
|
22
|
+
|
23
|
+
context "when a folder is registered" do
|
24
|
+
let(:folder){"item"}
|
25
|
+
|
26
|
+
before (:each) do
|
27
|
+
@sut.folder(folder)
|
28
|
+
end
|
29
|
+
|
30
|
+
it "should be placed in the list of sources" do
|
31
|
+
sources[0].should == folder
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
context "when the contents of a folder is registered" do
|
36
|
+
let(:folder){"item"}
|
37
|
+
|
38
|
+
before (:each) do
|
39
|
+
@sut.contents(folder)
|
40
|
+
end
|
41
|
+
|
42
|
+
it "should be placed in the list of sources" do
|
43
|
+
sources[0].should == "#{folder}/."
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
context "when copying contents in a set of folders" do
|
48
|
+
let(:folder){"item"}
|
49
|
+
|
50
|
+
before (:each) do
|
51
|
+
@sut.all_contents_in(%w[1 2])
|
52
|
+
end
|
53
|
+
|
54
|
+
it "should place all of the folders in the sources set" do
|
55
|
+
sources[0].should == "1/."
|
56
|
+
sources[1].should == "2/."
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
context "when copying folders in a set of folders" do
|
61
|
+
let(:folder){"item"}
|
62
|
+
|
63
|
+
before (:each) do
|
64
|
+
@sut.all_folders_in(%w[1 2])
|
65
|
+
end
|
66
|
+
|
67
|
+
it "should place all of the folders in the sources set" do
|
68
|
+
sources[0].should == "1"
|
69
|
+
sources[1].should == "2"
|
70
|
+
end
|
71
|
+
end
|
72
|
+
context "when expanding all of the items" do
|
73
|
+
let(:folder){"item"}
|
74
|
+
|
75
|
+
before (:each) do
|
76
|
+
%w[1 2 3].each{|item| sources << item}
|
77
|
+
end
|
78
|
+
|
79
|
+
before (:each) do
|
80
|
+
@sut.run
|
81
|
+
end
|
82
|
+
|
83
|
+
it "should copy each of the sources tot he target" do
|
84
|
+
copy_visitor.sources.count.should == 3
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module DevelopWithPassion
|
4
|
+
module Expander
|
5
|
+
describe CopyToTarget do
|
6
|
+
context "when performing a copy" do
|
7
|
+
let(:target){"the_target"}
|
8
|
+
let(:shell){fake}
|
9
|
+
let(:source){"the_source"}
|
10
|
+
|
11
|
+
before (:each) do
|
12
|
+
Shell.stub(:instance).and_return(shell)
|
13
|
+
@sut = CopyToTarget.new(target)
|
14
|
+
end
|
15
|
+
before (:each) do
|
16
|
+
@sut.run_using(source)
|
17
|
+
end
|
18
|
+
it "should copy the source to the target" do
|
19
|
+
shell.should have_received(:run,"cp -rf #{source} #{target}")
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Enumerable do
|
4
|
+
class Visitor
|
5
|
+
attr_accessor :items_processed
|
6
|
+
|
7
|
+
def initialize
|
8
|
+
@items_processed = 0
|
9
|
+
end
|
10
|
+
def run_using(item)
|
11
|
+
@items_processed += 1
|
12
|
+
end
|
13
|
+
end
|
14
|
+
context "when processing each item with a visitor" do
|
15
|
+
let(:visitor){Visitor.new}
|
16
|
+
let(:items){(1..10).to_a}
|
17
|
+
|
18
|
+
before (:each) do
|
19
|
+
items.process_all_items_using(visitor)
|
20
|
+
end
|
21
|
+
|
22
|
+
it "should run each item against the visitor" do
|
23
|
+
visitor.items_processed.should == 10
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
@@ -0,0 +1,65 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module DevelopWithPassion
|
4
|
+
module Expander
|
5
|
+
describe ERBTemplateFile do
|
6
|
+
before (:each) do
|
7
|
+
@original_template = <<-original
|
8
|
+
This is the first line @item@
|
9
|
+
This is the second line @item@
|
10
|
+
original
|
11
|
+
end
|
12
|
+
context "when preparing a template" do
|
13
|
+
let(:sut){ERBTemplateFile.new}
|
14
|
+
|
15
|
+
before (:each) do
|
16
|
+
@result = sut.prepare_template(@original_template)
|
17
|
+
end
|
18
|
+
|
19
|
+
it "should replace all occurences of @item@ with <%=item %>" do
|
20
|
+
@expected = <<-template
|
21
|
+
This is the first line <%= item %>
|
22
|
+
This is the second line <%= item %>
|
23
|
+
template
|
24
|
+
|
25
|
+
@result.should == @expected
|
26
|
+
end
|
27
|
+
end
|
28
|
+
context "when processing" do
|
29
|
+
let(:item){"yo"}
|
30
|
+
let(:file){fake}
|
31
|
+
let(:file_name){"blah.rb"}
|
32
|
+
let(:sut){ERBTemplateFile.new}
|
33
|
+
|
34
|
+
before (:each) do
|
35
|
+
@filesystem = RelativeFileSystem.new
|
36
|
+
@output = RelativeFileSystem.file_name("out.rb")
|
37
|
+
@original_template = <<-original
|
38
|
+
This is the first line @item@
|
39
|
+
This is the second line @item@
|
40
|
+
original
|
41
|
+
|
42
|
+
File.stub(:read).with(file_name).and_return(@original_template)
|
43
|
+
end
|
44
|
+
|
45
|
+
after(:each) do
|
46
|
+
@filesystem.teardown
|
47
|
+
end
|
48
|
+
|
49
|
+
before (:each) do
|
50
|
+
sut.process(:input => file_name,:output => @output,:binding => binding)
|
51
|
+
end
|
52
|
+
|
53
|
+
it "should expand everything" do
|
54
|
+
@expected = <<-template
|
55
|
+
This is the first line #{item}
|
56
|
+
This is the second line #{item}
|
57
|
+
template
|
58
|
+
|
59
|
+
File.read_all_text(@output).should == @expected
|
60
|
+
end
|
61
|
+
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
@@ -0,0 +1,146 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module DevelopWithPassion
|
4
|
+
module Expander
|
5
|
+
describe Expansion do
|
6
|
+
let(:sources){[]}
|
7
|
+
let(:template_visitor){fake}
|
8
|
+
let(:builders){{
|
9
|
+
:cleanup_items => fake,
|
10
|
+
:setup_items => fake,
|
11
|
+
:executable_files => fake,
|
12
|
+
:templates => fake,
|
13
|
+
:files_with_line_endings_to_fix => fake,
|
14
|
+
:folders_to_purge => fake
|
15
|
+
}}
|
16
|
+
let(:mark_executable_visitor){fake}
|
17
|
+
let(:dos_2_unix_visitor){fake}
|
18
|
+
let(:rm_rf_visitor){fake}
|
19
|
+
let(:module_factory){fake}
|
20
|
+
|
21
|
+
context "when created" do
|
22
|
+
before (:each) do
|
23
|
+
TemplateVisitor.stub(:instance).and_return(template_visitor)
|
24
|
+
the_module = Module.new do
|
25
|
+
end
|
26
|
+
ArrayDSLModuleFactory.stub(:new).and_return(module_factory)
|
27
|
+
builders.each do|name,builder|
|
28
|
+
ArrayDSL.stub(:new).with(name).and_return(builder)
|
29
|
+
module_factory.stub(:create_modules_from).with(builder).and_return([the_module])
|
30
|
+
end
|
31
|
+
ShellActionAgainstFile.stub(:new).with("chmod +x").and_return(mark_executable_visitor)
|
32
|
+
ShellActionAgainstFile.stub(:new).with("d2u").and_return(dos_2_unix_visitor)
|
33
|
+
ShellActionAgainstFile.stub(:new).with("rm -rf").and_return(rm_rf_visitor)
|
34
|
+
end
|
35
|
+
before (:each) do
|
36
|
+
Expansion.new
|
37
|
+
end
|
38
|
+
|
39
|
+
it "should scaffold the cleanup items list" do
|
40
|
+
cleanup_items_builder = builders[:cleanup_items]
|
41
|
+
cleanup_items_builder.should have_received(:readable)
|
42
|
+
cleanup_items_builder.should have_received(:process_using,:run_cleanup,:call)
|
43
|
+
end
|
44
|
+
|
45
|
+
it "should scaffold the setup items list" do
|
46
|
+
setup_items_builder = builders[:setup_items]
|
47
|
+
setup_items_builder.should have_received(:readable)
|
48
|
+
setup_items_builder.should have_received(:process_using,:run_setup_items,:call)
|
49
|
+
end
|
50
|
+
|
51
|
+
it "should scaffold the executable files list" do
|
52
|
+
executable_files_builder = builders[:executable_files]
|
53
|
+
executable_files_builder.should have_received(:mutator,:register_executable)
|
54
|
+
executable_files_builder.should have_received(:process_using,:mark_files_executable,mark_executable_visitor)
|
55
|
+
end
|
56
|
+
|
57
|
+
it "should scaffold the list of files ending to fix" do
|
58
|
+
line_endings_to_fix_builder_builder = builders[:files_with_line_endings_to_fix]
|
59
|
+
line_endings_to_fix_builder_builder.should have_received(:mutator,:fix_line_endings_for)
|
60
|
+
line_endings_to_fix_builder_builder.should have_received(:process_using,:fix_line_endings,dos_2_unix_visitor)
|
61
|
+
end
|
62
|
+
|
63
|
+
it "should scaffold the folders to purge list" do
|
64
|
+
folders_to_purge_builder_builder = builders[:folders_to_purge]
|
65
|
+
folders_to_purge_builder_builder.should have_received(:mutator,:register_folder_to_purge)
|
66
|
+
folders_to_purge_builder_builder.should have_received(:process_using,:purge_targets,rm_rf_visitor)
|
67
|
+
end
|
68
|
+
|
69
|
+
it "should scaffold the templates list" do
|
70
|
+
templates_builder_builder = builders[:templates]
|
71
|
+
templates_builder_builder.should have_received(:mutator,:look_for_templates_in)
|
72
|
+
templates_builder_builder.should have_received(:process_using,:expand_templates,template_visitor)
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
context "when specifying a copy" do
|
77
|
+
before (:each) do
|
78
|
+
TemplateVisitor.stub(:instance).and_return(template_visitor)
|
79
|
+
@sut = Expansion.new
|
80
|
+
end
|
81
|
+
|
82
|
+
before (:each) do
|
83
|
+
@sut.copy_to "blah" do
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
it "should not affect the merges" do
|
88
|
+
@sut.files_to_merge.count.should == 0
|
89
|
+
end
|
90
|
+
|
91
|
+
it "should add a new copy element to the list of copies to be performed" do
|
92
|
+
@sut.copies.values.count.should == 1
|
93
|
+
@sut.copies[:blah].should be_an(Copy)
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
context "when specifying a merge" do
|
98
|
+
before (:each) do
|
99
|
+
TemplateVisitor.stub(:instance).and_return(template_visitor)
|
100
|
+
@sut = Expansion.new
|
101
|
+
end
|
102
|
+
before (:each) do
|
103
|
+
@sut.merge_to "blah" do
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
it "should not alter the copy files" do
|
108
|
+
@sut.copies.count.should == 0
|
109
|
+
end
|
110
|
+
|
111
|
+
it "should add a new copy element to the list of copies to be performed" do
|
112
|
+
@sut.files_to_merge.values.count.should == 1
|
113
|
+
@sut.files_to_merge[:blah].should be_an(FileMerge)
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
context "when a cleanup is specified" do
|
118
|
+
before (:each) do
|
119
|
+
TemplateVisitor.stub(:instance).and_return(template_visitor)
|
120
|
+
@sut = Expansion.new
|
121
|
+
end
|
122
|
+
before (:each) do
|
123
|
+
@sut.cleanup do
|
124
|
+
end
|
125
|
+
end
|
126
|
+
it "should be added to the set of cleanup blocks" do
|
127
|
+
@sut.cleanup_items.count.should == 1
|
128
|
+
end
|
129
|
+
end
|
130
|
+
|
131
|
+
context "when a before is specified" do
|
132
|
+
before (:each) do
|
133
|
+
TemplateVisitor.stub(:instance).and_return(template_visitor)
|
134
|
+
@sut = Expansion.new
|
135
|
+
end
|
136
|
+
before (:each) do
|
137
|
+
@sut.before do
|
138
|
+
end
|
139
|
+
end
|
140
|
+
it "should be added to the set of setup blocks" do
|
141
|
+
@sut.setup_items.count.should == 1
|
142
|
+
end
|
143
|
+
end
|
144
|
+
end
|
145
|
+
end
|
146
|
+
end
|