hem 1.0.1.beta1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.editorconfig +10 -0
- data/.gitignore +3 -0
- data/.rspec +2 -0
- data/CHANGELOG.md +125 -0
- data/DoD.md +5 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +71 -0
- data/Guardfile +14 -0
- data/Hemfile +43 -0
- data/LICENSE +21 -0
- data/README.md +42 -0
- data/Rakefile +23 -0
- data/bin/hem +64 -0
- data/features/deps.feature +43 -0
- data/features/hem/basic.feature +43 -0
- data/features/hem/help.feature +16 -0
- data/features/hem/subcommands.feature +15 -0
- data/features/seed/plant.feature +64 -0
- data/features/step_definitions/env.rb +6 -0
- data/features/step_definitions/seed.rb +11 -0
- data/features/support/env.rb +6 -0
- data/hem.gemspec +47 -0
- data/lib/hem/asset_applicator.rb +33 -0
- data/lib/hem/asset_applicators/files.rb +5 -0
- data/lib/hem/asset_applicators/sqldump.rb +38 -0
- data/lib/hem/cli.rb +252 -0
- data/lib/hem/config/file.rb +22 -0
- data/lib/hem/config.rb +5 -0
- data/lib/hem/error_handlers/debug.rb +12 -0
- data/lib/hem/error_handlers/exit_code_map.rb +17 -0
- data/lib/hem/error_handlers/friendly.rb +58 -0
- data/lib/hem/errors.rb +89 -0
- data/lib/hem/help_formatter.rb +118 -0
- data/lib/hem/helper/file_locator.rb +44 -0
- data/lib/hem/helper/github.rb +10 -0
- data/lib/hem/helper/http_download.rb +41 -0
- data/lib/hem/helper/shell.rb +101 -0
- data/lib/hem/helper/vm_command.rb +30 -0
- data/lib/hem/lib/github/api.rb +48 -0
- data/lib/hem/lib/github/client.rb +52 -0
- data/lib/hem/lib/host_check/deps.rb +39 -0
- data/lib/hem/lib/host_check/git.rb +76 -0
- data/lib/hem/lib/host_check/ruby.rb +53 -0
- data/lib/hem/lib/host_check/vagrant.rb +45 -0
- data/lib/hem/lib/host_check.rb +34 -0
- data/lib/hem/lib/s3/local/file.rb +40 -0
- data/lib/hem/lib/s3/local/iohandler.rb +36 -0
- data/lib/hem/lib/s3/remote/file.rb +57 -0
- data/lib/hem/lib/s3/remote/iohandler.rb +38 -0
- data/lib/hem/lib/s3/sync.rb +134 -0
- data/lib/hem/lib/seed/project.rb +71 -0
- data/lib/hem/lib/seed/replacer.rb +56 -0
- data/lib/hem/lib/seed/seed.rb +111 -0
- data/lib/hem/lib/self_signed_cert_generator.rb +38 -0
- data/lib/hem/lib/vm/command.rb +131 -0
- data/lib/hem/lib/vm/inspector.rb +73 -0
- data/lib/hem/logging.rb +20 -0
- data/lib/hem/metadata.rb +42 -0
- data/lib/hem/null.rb +31 -0
- data/lib/hem/patches/deepstruct.rb +21 -0
- data/lib/hem/patches/rake.rb +101 -0
- data/lib/hem/patches/rubygems.rb +6 -0
- data/lib/hem/patches/slop.rb +69 -0
- data/lib/hem/paths.rb +96 -0
- data/lib/hem/tasks/assets.rb +92 -0
- data/lib/hem/tasks/config.rb +15 -0
- data/lib/hem/tasks/deps.rb +103 -0
- data/lib/hem/tasks/exec.rb +3 -0
- data/lib/hem/tasks/magento.rb +281 -0
- data/lib/hem/tasks/ops.rb +6 -0
- data/lib/hem/tasks/pr.rb +45 -0
- data/lib/hem/tasks/seed.rb +61 -0
- data/lib/hem/tasks/self.rb +45 -0
- data/lib/hem/tasks/shell_init.rb +25 -0
- data/lib/hem/tasks/system/completions.rb +76 -0
- data/lib/hem/tasks/system.rb +18 -0
- data/lib/hem/tasks/tools.rb +17 -0
- data/lib/hem/tasks/vm.rb +140 -0
- data/lib/hem/ui.rb +182 -0
- data/lib/hem/util.rb +76 -0
- data/lib/hem/version.rb +3 -0
- data/lib/hem.rb +72 -0
- data/lib/hobo/tasks/magento.rb +3 -0
- data/spec/hem/asset_applicator_spec.rb +30 -0
- data/spec/hem/cli_spec.rb +166 -0
- data/spec/hem/config/file_spec.rb +55 -0
- data/spec/hem/error_handlers/debug_spec.rb +43 -0
- data/spec/hem/error_handlers/friendly_spec.rb +97 -0
- data/spec/hem/error_spec.rb +0 -0
- data/spec/hem/help_formatter_spec.rb +162 -0
- data/spec/hem/helpers/file_locator_spec.rb +11 -0
- data/spec/hem/helpers/github_spec.rb +31 -0
- data/spec/hem/helpers/shell_spec.rb +22 -0
- data/spec/hem/helpers/vm_command_spec.rb +96 -0
- data/spec/hem/lib/github/api_spec.rb +92 -0
- data/spec/hem/lib/s3/sync_spec.rb +16 -0
- data/spec/hem/lib/seed/project_spec.rb +80 -0
- data/spec/hem/lib/seed/replacer_spec.rb +45 -0
- data/spec/hem/lib/seed/seed_spec.rb +127 -0
- data/spec/hem/logging_spec.rb +27 -0
- data/spec/hem/metadata_spec.rb +55 -0
- data/spec/hem/null_spec.rb +30 -0
- data/spec/hem/patches/rake_spec.rb +230 -0
- data/spec/hem/paths_spec.rb +75 -0
- data/spec/hem/ui_spec.rb +189 -0
- data/spec/hem/util_spec.rb +74 -0
- data/spec/spec_helper.rb +12 -0
- data/ssl/ca-bundle-s3.crt +3554 -0
- data/test_files/vagrant_fail/vagrant +2 -0
- metadata +339 -0
@@ -0,0 +1,80 @@
|
|
1
|
+
|
2
|
+
describe Hem::Lib::Seed::Project do
|
3
|
+
pwd = nil
|
4
|
+
tmp_dir = nil
|
5
|
+
default_config = {}
|
6
|
+
|
7
|
+
before do
|
8
|
+
tmp_dir = Dir.mktmpdir
|
9
|
+
pwd = Dir.pwd
|
10
|
+
Dir.chdir tmp_dir
|
11
|
+
FileUtils.mkdir_p "project_path"
|
12
|
+
FileUtils.touch "project_path/test"
|
13
|
+
Hem.ui = double(Hem::Ui).as_null_object
|
14
|
+
default_config = {
|
15
|
+
:config_class => double(Hem::Config::File).as_null_object,
|
16
|
+
:replacer => double(Hem::Lib::Seed::Replacer.new).as_null_object
|
17
|
+
}
|
18
|
+
end
|
19
|
+
|
20
|
+
after do
|
21
|
+
Dir.chdir pwd
|
22
|
+
FileUtils.remove_entry tmp_dir
|
23
|
+
end
|
24
|
+
|
25
|
+
describe "setup" do
|
26
|
+
it "should update seed before use" do
|
27
|
+
seed = double(Hem::Lib::Seed::Seed).as_null_object
|
28
|
+
seed.should_receive :update
|
29
|
+
|
30
|
+
project = Hem::Lib::Seed::Project.new(default_config)
|
31
|
+
|
32
|
+
project.setup(seed, { :project_path => "project_path", :seed => {}, :git_url => '.' })
|
33
|
+
end
|
34
|
+
|
35
|
+
it "should export seed to project directory" do
|
36
|
+
seed = double(Hem::Lib::Seed::Seed).as_null_object
|
37
|
+
seed.should_recieve(:export).with("project_path")
|
38
|
+
|
39
|
+
project = Hem::Lib::Seed::Project.new(default_config)
|
40
|
+
|
41
|
+
project.setup(seed, { :project_path => "project_path", :seed => {}, :git_url => '.' })
|
42
|
+
end
|
43
|
+
|
44
|
+
it "should save config in project" do
|
45
|
+
seed = double(Hem::Lib::Seed::Seed).as_null_object
|
46
|
+
seed.should_recieve :export, "project_path"
|
47
|
+
|
48
|
+
config_class = double(Hem::Config::File).as_null_object
|
49
|
+
config_class.should_recieve(:save).with("project_config_file")
|
50
|
+
|
51
|
+
project = Hem::Lib::Seed::Project.new(default_config.merge({ :project_config_file => "project_config_file" }))
|
52
|
+
|
53
|
+
project.setup(seed, { :project_path => "project_path", :seed => {}, :git_url => '.' })
|
54
|
+
end
|
55
|
+
|
56
|
+
it "should initialize the project git repository" do
|
57
|
+
seed = double(Hem::Lib::Seed::Seed).as_null_object
|
58
|
+
|
59
|
+
project = Hem::Lib::Seed::Project.new(default_config)
|
60
|
+
|
61
|
+
project.setup(seed, { :project_path => "project_path", :seed => {}, :git_url => '.' })
|
62
|
+
expect { Hem::Helper.shell("cd project_path && git status")}.not_to raise_error
|
63
|
+
end
|
64
|
+
|
65
|
+
it "should add the git url as the origin remote" do
|
66
|
+
seed = double(Hem::Lib::Seed::Seed).as_null_object
|
67
|
+
|
68
|
+
project = Hem::Lib::Seed::Project.new(default_config)
|
69
|
+
|
70
|
+
project.setup(seed, { :project_path => "project_path", :seed => {}, :git_url => 'remote_url' })
|
71
|
+
Hem::Helper.shell("cd project_path && git remote show -n origin", :capture => true).should match /remote_url/
|
72
|
+
end
|
73
|
+
|
74
|
+
it "should load seed init file if present"
|
75
|
+
it "should remove seed init file"
|
76
|
+
|
77
|
+
it "should set hostname in config"
|
78
|
+
it "should set asset bucket in config"
|
79
|
+
end
|
80
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
|
2
|
+
describe Hem::Lib::Seed::Replacer do
|
3
|
+
before do
|
4
|
+
FakeFS.activate!
|
5
|
+
Dir.mkdir("bin")
|
6
|
+
Dir.mkdir("dir")
|
7
|
+
{
|
8
|
+
"./test1" => "some {{test}} is here",
|
9
|
+
"./test2" => "no test is here",
|
10
|
+
"./dir/test" => "subdir {{test}}",
|
11
|
+
"./dir/nested" => "nested {{nested.test}}",
|
12
|
+
"./dir/no-utf" => "\xc2 {{test}}", # invalid utf should be skipped
|
13
|
+
"./bin/test" => "{{test}}" # bin/ should be ignored
|
14
|
+
}.each do |name, content|
|
15
|
+
File.write(name, content)
|
16
|
+
end
|
17
|
+
|
18
|
+
@replacer = Hem::Lib::Seed::Replacer.new
|
19
|
+
end
|
20
|
+
|
21
|
+
after do
|
22
|
+
FakeFS::FileSystem.clear
|
23
|
+
FakeFS.deactivate!
|
24
|
+
end
|
25
|
+
|
26
|
+
it "should respect exclude directories" do
|
27
|
+
files = @replacer.replace(".", { :test => 'badger' })
|
28
|
+
File.read("./bin/test").should eq "{{test}}"
|
29
|
+
end
|
30
|
+
|
31
|
+
it "should replace placeholders in files" do
|
32
|
+
files = @replacer.replace(".", { :test => 'badger' })
|
33
|
+
expect(files.sort).to eq(["./dir/test", "./test1"])
|
34
|
+
|
35
|
+
File.read("./test1").should eq "some badger is here"
|
36
|
+
File.read("./dir/test").should eq "subdir badger"
|
37
|
+
end
|
38
|
+
|
39
|
+
it "should handle nested hashes" do
|
40
|
+
files = @replacer.replace(".", { :nested => { :test => 'nested' } })
|
41
|
+
expect(files.sort).to eq(["./dir/nested"])
|
42
|
+
|
43
|
+
File.read("./dir/nested").should eq "nested nested"
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,127 @@
|
|
1
|
+
|
2
|
+
describe Hem::Lib::Seed::Seed do
|
3
|
+
pwd = nil
|
4
|
+
tmp_dir = nil
|
5
|
+
|
6
|
+
before do
|
7
|
+
tmp_dir = Dir.mktmpdir
|
8
|
+
pwd = Dir.pwd
|
9
|
+
Dir.chdir tmp_dir
|
10
|
+
Hem.ui = double(Hem::Ui).as_null_object
|
11
|
+
end
|
12
|
+
|
13
|
+
after do
|
14
|
+
Dir.chdir pwd
|
15
|
+
FileUtils.remove_entry tmp_dir
|
16
|
+
end
|
17
|
+
|
18
|
+
def create_test_repo path, content
|
19
|
+
FileUtils.mkdir_p path
|
20
|
+
Dir.chdir path do
|
21
|
+
`git init`
|
22
|
+
`echo "#{content}" > test`
|
23
|
+
`git add *`
|
24
|
+
`git commit -m "test"`
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def tag_repo path, tag
|
29
|
+
Dir.chdir path do
|
30
|
+
`git tag #{tag}`
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
describe "update", :integration do
|
35
|
+
it "should fetch the seed if it does not exist locally" do
|
36
|
+
# Create test repo as seed remote
|
37
|
+
remote_seed_path = File.join(tmp_dir, "seed_1")
|
38
|
+
create_test_repo remote_seed_path, "does not exist locally"
|
39
|
+
|
40
|
+
seed = Hem::Lib::Seed::Seed.new 'seeds/seed_1', remote_seed_path
|
41
|
+
seed.update
|
42
|
+
|
43
|
+
# Repo is bare so we need to use git show to get contents
|
44
|
+
`cd seeds/seed_1 && git show HEAD:test`.strip.should eq "does not exist locally"
|
45
|
+
end
|
46
|
+
|
47
|
+
it "should update the seed if it exists locally" do
|
48
|
+
# Create test repo as seed remote
|
49
|
+
remote_seed_path = File.join(tmp_dir, "seed_2")
|
50
|
+
create_test_repo remote_seed_path, "does exist locally"
|
51
|
+
|
52
|
+
# Clone seed to seed cache directory
|
53
|
+
FileUtils.mkdir_p "seeds"
|
54
|
+
`cd seeds && git clone #{remote_seed_path} seed_2 --mirror 2> /dev/null`
|
55
|
+
|
56
|
+
# Update seed origin repo to give test something to update
|
57
|
+
`cd seed_2 && echo "updated" > test && git add test && git commit -m "test"`
|
58
|
+
|
59
|
+
seed = Hem::Lib::Seed::Seed.new 'seeds/seed_2', remote_seed_path
|
60
|
+
seed.update
|
61
|
+
|
62
|
+
# Repo is bare so we need to use git show to get contents
|
63
|
+
`cd seeds/seed_2 && git show HEAD:test`.strip.should eq "updated"
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
describe "export", :integration do
|
68
|
+
it "should export the seed contents to specified directory" do
|
69
|
+
# Create test repo as seed remote
|
70
|
+
remote_seed_path = File.join(tmp_dir, "seed_3")
|
71
|
+
create_test_repo remote_seed_path, "exported"
|
72
|
+
|
73
|
+
# Update seed and export
|
74
|
+
seed = Hem::Lib::Seed::Seed.new 'seeds/seed_3', remote_seed_path
|
75
|
+
seed.update
|
76
|
+
seed.export "exported"
|
77
|
+
|
78
|
+
File.read("exported/test").strip.should eq "exported"
|
79
|
+
File.exists?("exported/.git").should be false
|
80
|
+
end
|
81
|
+
|
82
|
+
it "should export seed submodules to the specified directory"
|
83
|
+
it "should export a specifified git :ref"
|
84
|
+
end
|
85
|
+
|
86
|
+
describe "tags" do
|
87
|
+
it "should return no tags if the repository doesn't have any" do
|
88
|
+
# Create test repo as seed remote
|
89
|
+
remote_seed_path = File.join(tmp_dir, "seed_5")
|
90
|
+
create_test_repo remote_seed_path, "version_test"
|
91
|
+
|
92
|
+
# Update seed and export
|
93
|
+
seed = Hem::Lib::Seed::Seed.new 'seeds/seed_3', remote_seed_path
|
94
|
+
seed.update
|
95
|
+
|
96
|
+
seed.tags.should eq []
|
97
|
+
end
|
98
|
+
|
99
|
+
it "should return a list of tags if there are any" do
|
100
|
+
# Create test repo as seed remote
|
101
|
+
remote_seed_path = File.join(tmp_dir, "seed_5")
|
102
|
+
create_test_repo remote_seed_path, "version_test"
|
103
|
+
tag_repo remote_seed_path, "1.2.3"
|
104
|
+
tag_repo remote_seed_path, "1.2.4"
|
105
|
+
|
106
|
+
# Update seed and export
|
107
|
+
seed = Hem::Lib::Seed::Seed.new 'seeds/seed_3', remote_seed_path
|
108
|
+
seed.update
|
109
|
+
|
110
|
+
seed.tags.should eq ['1.2.3', '1.2.4']
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
describe "version", :integration do
|
115
|
+
it "should return the git sha of the seed" do
|
116
|
+
# Create test repo as seed remote
|
117
|
+
remote_seed_path = File.join(tmp_dir, "seed_4")
|
118
|
+
create_test_repo remote_seed_path, "version_test"
|
119
|
+
|
120
|
+
# Update seed and export
|
121
|
+
seed = Hem::Lib::Seed::Seed.new 'seeds/seed_4', remote_seed_path
|
122
|
+
seed.update
|
123
|
+
|
124
|
+
seed.version.should eq `cd seeds/seed_4 && git rev-parse --short HEAD`.strip
|
125
|
+
end
|
126
|
+
end
|
127
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
|
2
|
+
describe Hem::Logging do
|
3
|
+
before do
|
4
|
+
Hem.logger = nil
|
5
|
+
end
|
6
|
+
|
7
|
+
describe "module logger" do
|
8
|
+
it "should return global logger instance" do
|
9
|
+
Hem.logger = "TEST"
|
10
|
+
class LoggerTest
|
11
|
+
include Hem::Logging
|
12
|
+
end
|
13
|
+
|
14
|
+
LoggerTest.new.logger.should match "TEST"
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
describe "global logger" do
|
19
|
+
it "should initialize to STDOUT logger" do
|
20
|
+
Hem::Logging.logger.instance_variable_get('@logdev').dev.should be STDOUT
|
21
|
+
end
|
22
|
+
|
23
|
+
it "should initialize to WARN log level" do
|
24
|
+
Hem::Logging.logger.level.should eq Logger::WARN
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
|
2
|
+
describe Hem::Metadata do
|
3
|
+
before do
|
4
|
+
Hem::Metadata.store = {}
|
5
|
+
Hem::Metadata.metadata = {}
|
6
|
+
Hem::Metadata.defaults = {}
|
7
|
+
end
|
8
|
+
|
9
|
+
describe "store" do
|
10
|
+
it "should expose storage" do
|
11
|
+
Hem::Metadata.store[:opts] = {}
|
12
|
+
Hem::Metadata.store[:opts].should be {}
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
describe "metadata" do
|
17
|
+
it "should expose metadata" do
|
18
|
+
Hem::Metadata.store[:type] = "value"
|
19
|
+
Hem::Metadata.add "key", :type
|
20
|
+
Hem::Metadata.metadata["key"][:type].should match "value"
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
describe "add" do
|
25
|
+
it "should assign store value to task metadata for type" do
|
26
|
+
Hem::Metadata.store[:type] = "value"
|
27
|
+
Hem::Metadata.add "key", :type
|
28
|
+
Hem::Metadata.metadata["key"][:type].should match "value"
|
29
|
+
end
|
30
|
+
|
31
|
+
it "should set store value to default after add" do
|
32
|
+
Hem::Metadata.default :type, "value"
|
33
|
+
Hem::Metadata.add "key", :type
|
34
|
+
Hem::Metadata.metadata["key"][:type].should match "value"
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
describe "default" do
|
39
|
+
it "should store default value for type" do
|
40
|
+
Hem::Metadata.default :type, "default"
|
41
|
+
Hem::Metadata.add "key", :type
|
42
|
+
Hem::Metadata.metadata["key"][:type].should match "default"
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
describe "reset" do
|
47
|
+
it "should reset all current store values to defaults" do
|
48
|
+
Hem::Metadata.default :type, "default"
|
49
|
+
Hem::Metadata.add "key", :type
|
50
|
+
Hem::Metadata.add "key", :other_type
|
51
|
+
Hem::Metadata.reset_store
|
52
|
+
Hem::Metadata.store.should eq({ :type => "default" })
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
|
2
|
+
describe Hem::Null do
|
3
|
+
it "should return itself for any method call" do
|
4
|
+
null = Hem::Null.new
|
5
|
+
null["test"].should eq null
|
6
|
+
null.test.should eq null
|
7
|
+
(null + null).should eq null
|
8
|
+
end
|
9
|
+
|
10
|
+
it "should convert to identity of types" do
|
11
|
+
null = Hem::Null.new
|
12
|
+
null.to_s.should match ""
|
13
|
+
null.to_i.should eq 0
|
14
|
+
null.to_f.should eq 0.0
|
15
|
+
null.to_a.should eq []
|
16
|
+
end
|
17
|
+
|
18
|
+
describe "maybe" do
|
19
|
+
it "should return nil if nil?" do
|
20
|
+
maybe(nil).should eq nil
|
21
|
+
maybe(Hem::Null.new).should eq nil
|
22
|
+
end
|
23
|
+
|
24
|
+
it "should return value for !nil?" do
|
25
|
+
maybe(true).should eq true
|
26
|
+
maybe("").should eq ""
|
27
|
+
maybe(1).should eq 1
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,230 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Rake do
|
4
|
+
cli = nil
|
5
|
+
|
6
|
+
before do
|
7
|
+
Rake::Task.clear
|
8
|
+
Hem::Metadata.default :opts, []
|
9
|
+
Hem::Metadata.default :desc, nil
|
10
|
+
Hem::Metadata.reset_store
|
11
|
+
Hem::Metadata.metadata = {}
|
12
|
+
|
13
|
+
Hem.ui = double(Hem::Ui).as_null_object
|
14
|
+
help = double(Hem::HelpFormatter).as_null_object
|
15
|
+
host_check = double(Hem::Lib::HostCheck).as_null_object
|
16
|
+
cli = Hem::Cli.new help: help, host_check: host_check
|
17
|
+
|
18
|
+
FakeFS.activate!
|
19
|
+
end
|
20
|
+
|
21
|
+
after do
|
22
|
+
FakeFS::FileSystem.clear
|
23
|
+
FakeFS.deactivate!
|
24
|
+
end
|
25
|
+
|
26
|
+
describe "before hook" do
|
27
|
+
|
28
|
+
it "should run block type task before specified task" do
|
29
|
+
File.write('Hemfile', "
|
30
|
+
task 'block-test' do
|
31
|
+
Hem.ui.info 'test'
|
32
|
+
end
|
33
|
+
before 'block-test' do
|
34
|
+
Hem.ui.info 'before'
|
35
|
+
end"
|
36
|
+
)
|
37
|
+
|
38
|
+
Hem.ui.should_receive(:info).with('before')
|
39
|
+
Hem.ui.should_receive(:info).with('test')
|
40
|
+
|
41
|
+
cli.start ['block-test']
|
42
|
+
end
|
43
|
+
|
44
|
+
it "should run string type task before specified task" do
|
45
|
+
File.write('Hemfile', "
|
46
|
+
task 'string-test' do
|
47
|
+
Hem.ui.info 'test'
|
48
|
+
end
|
49
|
+
task 'before' do
|
50
|
+
Hem.ui.info 'before'
|
51
|
+
end
|
52
|
+
before 'string-test', 'before'
|
53
|
+
"
|
54
|
+
)
|
55
|
+
|
56
|
+
Hem.ui.should_receive(:info).with('before')
|
57
|
+
Hem.ui.should_receive(:info).with('test')
|
58
|
+
|
59
|
+
cli.start ['string-test']
|
60
|
+
end
|
61
|
+
|
62
|
+
it "should run multiple string type tasks before specified task" do
|
63
|
+
File.write('Hemfile', "
|
64
|
+
task 'multiple-string-test' do
|
65
|
+
Hem.ui.info 'test'
|
66
|
+
end
|
67
|
+
task 'before1' do
|
68
|
+
Hem.ui.info 'before1'
|
69
|
+
end
|
70
|
+
task 'before2' do
|
71
|
+
Hem.ui.info 'before2'
|
72
|
+
end
|
73
|
+
before 'multiple-string-test', ['before1', 'before2']
|
74
|
+
"
|
75
|
+
)
|
76
|
+
|
77
|
+
Hem.ui.should_receive(:info).with('before1')
|
78
|
+
Hem.ui.should_receive(:info).with('before2')
|
79
|
+
Hem.ui.should_receive(:info).with('test')
|
80
|
+
|
81
|
+
cli.start ['multiple-string-test']
|
82
|
+
end
|
83
|
+
|
84
|
+
it "should maintain all task metadata" do
|
85
|
+
File.write('Hemfile', "
|
86
|
+
option '--test', 'A test'
|
87
|
+
desc 'A description'
|
88
|
+
long_desc 'A long description'
|
89
|
+
project_only
|
90
|
+
hidden
|
91
|
+
task 'metadata-test' do
|
92
|
+
Hem.ui.info 'test'
|
93
|
+
end
|
94
|
+
|
95
|
+
task 'before' do
|
96
|
+
Hem.ui.info 'before'
|
97
|
+
end
|
98
|
+
|
99
|
+
before 'metadata-test', 'before'
|
100
|
+
"
|
101
|
+
)
|
102
|
+
|
103
|
+
cli.start ['metadata-test']
|
104
|
+
|
105
|
+
Hem::Metadata.metadata['metadata-test'][:opts].should eql([["--test", "A test"]])
|
106
|
+
Hem::Metadata.metadata['metadata-test'][:desc].should eql("A description")
|
107
|
+
Hem::Metadata.metadata['metadata-test'][:long_desc].should eql("A long description")
|
108
|
+
Hem::Metadata.metadata['metadata-test'][:project_only].should be(true)
|
109
|
+
Hem::Metadata.metadata['metadata-test'][:hidden].should be(true)
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
describe "after hook" do
|
114
|
+
it "should run block type task after specified task" do
|
115
|
+
File.write('Hemfile', "
|
116
|
+
task 'block-test' do
|
117
|
+
Hem.ui.info 'test'
|
118
|
+
end
|
119
|
+
after 'block-test' do
|
120
|
+
Hem.ui.info 'after'
|
121
|
+
end"
|
122
|
+
)
|
123
|
+
|
124
|
+
Hem.ui.should_receive(:info).with('test')
|
125
|
+
Hem.ui.should_receive(:info).with('after')
|
126
|
+
|
127
|
+
cli.start ['block-test']
|
128
|
+
end
|
129
|
+
|
130
|
+
it "should run string type task after specified task" do
|
131
|
+
File.write('Hemfile', "
|
132
|
+
task 'string-test' do
|
133
|
+
Hem.ui.info 'test'
|
134
|
+
end
|
135
|
+
task 'after' do
|
136
|
+
Hem.ui.info 'after'
|
137
|
+
end
|
138
|
+
after 'string-test', 'after'
|
139
|
+
"
|
140
|
+
)
|
141
|
+
|
142
|
+
Hem.ui.should_receive(:info).with('test')
|
143
|
+
Hem.ui.should_receive(:info).with('after')
|
144
|
+
|
145
|
+
cli.start ['string-test']
|
146
|
+
end
|
147
|
+
|
148
|
+
it "should run multiple string type tasks after specified task" do
|
149
|
+
File.write('Hemfile', "
|
150
|
+
task 'multiple-string-test' do
|
151
|
+
Hem.ui.info 'test'
|
152
|
+
end
|
153
|
+
task 'after1' do
|
154
|
+
Hem.ui.info 'after1'
|
155
|
+
end
|
156
|
+
task 'after2' do
|
157
|
+
Hem.ui.info 'after2'
|
158
|
+
end
|
159
|
+
after 'multiple-string-test', ['after1', 'after2']
|
160
|
+
"
|
161
|
+
)
|
162
|
+
|
163
|
+
Hem.ui.should_receive(:info).with('test')
|
164
|
+
Hem.ui.should_receive(:info).with('after1')
|
165
|
+
Hem.ui.should_receive(:info).with('after2')
|
166
|
+
|
167
|
+
cli.start ['multiple-string-test']
|
168
|
+
end
|
169
|
+
|
170
|
+
it "should maintain all task metadata" do
|
171
|
+
File.write('Hemfile', "
|
172
|
+
option '--test', 'A test'
|
173
|
+
desc 'A description'
|
174
|
+
long_desc 'A long description'
|
175
|
+
project_only
|
176
|
+
hidden
|
177
|
+
task :'metadata-test' do
|
178
|
+
Hem.ui.info 'test'
|
179
|
+
end
|
180
|
+
|
181
|
+
task 'after' do
|
182
|
+
Hem.ui.info 'after'
|
183
|
+
end
|
184
|
+
|
185
|
+
after :'metadata-test', 'after'
|
186
|
+
"
|
187
|
+
)
|
188
|
+
|
189
|
+
cli.start ['metadata-test']
|
190
|
+
|
191
|
+
Hem::Metadata.metadata['metadata-test'][:opts].should eql([["--test", "A test"]])
|
192
|
+
Hem::Metadata.metadata['metadata-test'][:desc].should eql("A description")
|
193
|
+
Hem::Metadata.metadata['metadata-test'][:long_desc].should eql("A long description")
|
194
|
+
Hem::Metadata.metadata['metadata-test'][:project_only].should be(true)
|
195
|
+
Hem::Metadata.metadata['metadata-test'][:hidden].should be(true)
|
196
|
+
end
|
197
|
+
end
|
198
|
+
|
199
|
+
describe 'invoke' do
|
200
|
+
it "should invoke an existing task without args" do
|
201
|
+
File.write('Hemfile', "
|
202
|
+
task 'invoke-target'do
|
203
|
+
Hem.ui.info 'invoked'
|
204
|
+
end
|
205
|
+
task 'invoker' do
|
206
|
+
invoke('invoke-target')
|
207
|
+
end
|
208
|
+
"
|
209
|
+
)
|
210
|
+
|
211
|
+
Hem.ui.should_receive(:info).with('invoked')
|
212
|
+
cli.start ['invoker']
|
213
|
+
end
|
214
|
+
|
215
|
+
it "should invoke an existing task with args" do
|
216
|
+
File.write('Hemfile', "
|
217
|
+
task 'invoke-target', [:arg1] do |task, args|
|
218
|
+
Hem.ui.info args[:arg1]
|
219
|
+
end
|
220
|
+
task 'invoker' do
|
221
|
+
invoke('invoke-target', 'arg1')
|
222
|
+
end
|
223
|
+
"
|
224
|
+
)
|
225
|
+
|
226
|
+
Hem.ui.should_receive(:info).with('arg1')
|
227
|
+
cli.start ['invoker']
|
228
|
+
end
|
229
|
+
end
|
230
|
+
end
|
@@ -0,0 +1,75 @@
|
|
1
|
+
|
2
|
+
describe Hem do
|
3
|
+
describe 'project_path' do
|
4
|
+
before do
|
5
|
+
Hem.project_path = nil
|
6
|
+
FakeFS.activate!
|
7
|
+
end
|
8
|
+
|
9
|
+
after do
|
10
|
+
FakeFS::FileSystem.clear
|
11
|
+
FakeFS.deactivate!
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'should return nil if not in project' do
|
15
|
+
Hem.project_path.should eq nil
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'should return project directory if tools/hem exists' do
|
19
|
+
FileUtils.mkdir_p 'project/test/tools/hem'
|
20
|
+
Dir.chdir 'project/test' do
|
21
|
+
Hem.project_path.should eq '/project/test'
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
it 'should traverse up directories search for tools/hem' do
|
26
|
+
FileUtils.mkdir_p 'project/test/tools/hem'
|
27
|
+
Dir.chdir 'project/test/tools/hem' do
|
28
|
+
Hem.project_path.should eq '/project/test'
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
it 'should memoize project path' do
|
33
|
+
FileUtils.mkdir_p 'project/test/tools/hem'
|
34
|
+
Dir.chdir 'project/test/tools/hem' do
|
35
|
+
Hem.project_path.should eq '/project/test'
|
36
|
+
end
|
37
|
+
|
38
|
+
# We remove the hem directory to see if the path was memoized or not
|
39
|
+
FileUtils.rmdir('project/test/tools/hem')
|
40
|
+
Dir.chdir 'project/test/tools' do
|
41
|
+
Hem.project_path.should eq '/project/test'
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
describe 'config_path' do
|
47
|
+
it 'should be ~/.hem' do
|
48
|
+
Hem.config_path.should eq File.join(ENV['HOME'], '.hem')
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
describe 'seed_cache_path' do
|
53
|
+
it 'should be ~/.hem/seeds' do
|
54
|
+
Hem.seed_cache_path.should eq File.join(ENV['HOME'], '.hem', 'seeds')
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
describe 'hemfile_path' do
|
59
|
+
it 'should be project_path + Hemfile' do
|
60
|
+
Hem.hemfile_path.should eq File.join(Hem.project_path, 'Hemfile')
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
describe 'project_config_file' do
|
65
|
+
it 'should be project_path + tools/hem/config.yaml' do
|
66
|
+
Hem.project_config_file.should eq File.join(Hem.project_path, 'tools', 'hem', 'config.yaml')
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
describe 'user_config_file' do
|
71
|
+
it 'should be ~/.hem/config.yaml' do
|
72
|
+
Hem.user_config_file.should eq File.join(Hem.config_path, 'config.yaml')
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|