rake-funnel 0.0.1.pre

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.
Files changed (111) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +7 -0
  3. data/.rspec +2 -0
  4. data/.travis.yml +21 -0
  5. data/Gemfile +29 -0
  6. data/Guardfile +24 -0
  7. data/README.md +29 -0
  8. data/Rakefile +77 -0
  9. data/build.cmd +30 -0
  10. data/bundle.cmd +26 -0
  11. data/config/.gitignore +1 -0
  12. data/config/.local.yaml.example +9 -0
  13. data/config/default.yaml +5 -0
  14. data/config/dev.yaml +0 -0
  15. data/config/production.yaml +3 -0
  16. data/lib/rake/funnel/ambiguous_file_error.rb +29 -0
  17. data/lib/rake/funnel/execution_error.rb +26 -0
  18. data/lib/rake/funnel/extensions/camel_case.rb +19 -0
  19. data/lib/rake/funnel/extensions/common_path.rb +52 -0
  20. data/lib/rake/funnel/extensions/disable_colors.rb +27 -0
  21. data/lib/rake/funnel/extensions/rexml.rb +23 -0
  22. data/lib/rake/funnel/extensions/shell.rb +56 -0
  23. data/lib/rake/funnel/framework.rb +15 -0
  24. data/lib/rake/funnel/integration/progress_report.rb +70 -0
  25. data/lib/rake/funnel/integration/sync_output.rb +8 -0
  26. data/lib/rake/funnel/integration/teamcity/nunit_plugin.rb +59 -0
  27. data/lib/rake/funnel/integration/teamcity/progress_report.rb +33 -0
  28. data/lib/rake/funnel/integration/teamcity/service_messages.rb +40 -0
  29. data/lib/rake/funnel/integration/teamcity/teamcity.rb +15 -0
  30. data/lib/rake/funnel/integration/teamcity.rb +5 -0
  31. data/lib/rake/funnel/support/finder.rb +51 -0
  32. data/lib/rake/funnel/support/mapper.rb +81 -0
  33. data/lib/rake/funnel/support/mapper_styles/default.rb +31 -0
  34. data/lib/rake/funnel/support/mapper_styles/msbuild.rb +33 -0
  35. data/lib/rake/funnel/support/mapper_styles/msdeploy.rb +47 -0
  36. data/lib/rake/funnel/support/mapper_styles/nunit.rb +33 -0
  37. data/lib/rake/funnel/support/mono.rb +17 -0
  38. data/lib/rake/funnel/support/patch.rb +37 -0
  39. data/lib/rake/funnel/support/template_engine.rb +26 -0
  40. data/lib/rake/funnel/support/which.rb +15 -0
  41. data/lib/rake/funnel/tasks/bin_path.rb +34 -0
  42. data/lib/rake/funnel/tasks/copy.rb +54 -0
  43. data/lib/rake/funnel/tasks/environments.rb +74 -0
  44. data/lib/rake/funnel/tasks/environments_support/loader.rb +37 -0
  45. data/lib/rake/funnel/tasks/msbuild.rb +52 -0
  46. data/lib/rake/funnel/tasks/msbuild_support/build_tool.rb +28 -0
  47. data/lib/rake/funnel/tasks/msdeploy.rb +58 -0
  48. data/lib/rake/funnel/tasks/msdeploy_support/registry_patch.rb +84 -0
  49. data/lib/rake/funnel/tasks/nunit.rb +46 -0
  50. data/lib/rake/funnel/tasks/paket.rb +39 -0
  51. data/lib/rake/funnel/tasks/quick_template.rb +45 -0
  52. data/lib/rake/funnel/tasks/side_by_side_specs.rb +33 -0
  53. data/lib/rake/funnel/tasks/side_by_side_specs_support/remover.rb +62 -0
  54. data/lib/rake/funnel/tasks/timing.rb +100 -0
  55. data/lib/rake/funnel/tasks/timing_support/report.rb +89 -0
  56. data/lib/rake/funnel/tasks/timing_support/statistics.rb +26 -0
  57. data/lib/rake/funnel/tasks/zip.rb +66 -0
  58. data/lib/rake/funnel/version.rb +5 -0
  59. data/lib/rake/funnel.rb +7 -0
  60. data/rake-funnel.gemspec +28 -0
  61. data/spec/rake/funnel/execution_error_spec.rb +67 -0
  62. data/spec/rake/funnel/extensions/camel_case_spec.rb +17 -0
  63. data/spec/rake/funnel/extensions/common_path_spec.rb +56 -0
  64. data/spec/rake/funnel/extensions/disable_colors_spec.rb +33 -0
  65. data/spec/rake/funnel/extensions/rexml_spec.rb +20 -0
  66. data/spec/rake/funnel/extensions/shell_spec.rb +237 -0
  67. data/spec/rake/funnel/integration/progress_report_spec.rb +149 -0
  68. data/spec/rake/funnel/integration/sync_output_spec.rb +16 -0
  69. data/spec/rake/funnel/integration/teamcity/nunit_plugin_spec.rb +112 -0
  70. data/spec/rake/funnel/integration/teamcity/progress_report_spec.rb +174 -0
  71. data/spec/rake/funnel/integration/teamcity/service_messages_spec.rb +136 -0
  72. data/spec/rake/funnel/integration/teamcity/teamcity_spec.rb +34 -0
  73. data/spec/rake/funnel/support/finder_spec.rb +210 -0
  74. data/spec/rake/funnel/support/mapper_spec.rb +87 -0
  75. data/spec/rake/funnel/support/mapper_styles/msdeploy_spec.rb +222 -0
  76. data/spec/rake/funnel/support/mapper_styles/nunit_spec.rb +25 -0
  77. data/spec/rake/funnel/support/mapper_styles/styles_spec.rb +214 -0
  78. data/spec/rake/funnel/support/mono_spec.rb +57 -0
  79. data/spec/rake/funnel/support/patch_spec.rb +108 -0
  80. data/spec/rake/funnel/support/template_engine_spec.rb +65 -0
  81. data/spec/rake/funnel/support/which_spec.rb +65 -0
  82. data/spec/rake/funnel/tasks/bin_path_spec.rb +40 -0
  83. data/spec/rake/funnel/tasks/copy_spec.rb +101 -0
  84. data/spec/rake/funnel/tasks/environments_spec.rb +237 -0
  85. data/spec/rake/funnel/tasks/environments_support/loader_spec.rb +114 -0
  86. data/spec/rake/funnel/tasks/msbuild_spec.rb +91 -0
  87. data/spec/rake/funnel/tasks/msbuild_support/build_tool_spec.rb +21 -0
  88. data/spec/rake/funnel/tasks/msdeploy_spec.rb +243 -0
  89. data/spec/rake/funnel/tasks/msdeploy_support/registry_patch_spec.rb +139 -0
  90. data/spec/rake/funnel/tasks/nunit_spec.rb +76 -0
  91. data/spec/rake/funnel/tasks/paket_spec.rb +184 -0
  92. data/spec/rake/funnel/tasks/quick_template_spec.rb +89 -0
  93. data/spec/rake/funnel/tasks/side_by_side_specs_spec.rb +58 -0
  94. data/spec/rake/funnel/tasks/side_by_side_specs_support/example/FooCode.cs +0 -0
  95. data/spec/rake/funnel/tasks/side_by_side_specs_support/example/FooSpecs.cs +0 -0
  96. data/spec/rake/funnel/tasks/side_by_side_specs_support/example/Sample.csproj +28 -0
  97. data/spec/rake/funnel/tasks/side_by_side_specs_support/example/Specs.cs +0 -0
  98. data/spec/rake/funnel/tasks/side_by_side_specs_support/example/subdir/BarCode.cs +0 -0
  99. data/spec/rake/funnel/tasks/side_by_side_specs_support/example/subdir/BarSpecs.cs +0 -0
  100. data/spec/rake/funnel/tasks/side_by_side_specs_support/remover_spec.rb +116 -0
  101. data/spec/rake/funnel/tasks/timing_spec.rb +133 -0
  102. data/spec/rake/funnel/tasks/timing_support/report_spec.rb +129 -0
  103. data/spec/rake/funnel/tasks/zip_spec.rb +119 -0
  104. data/spec/spec_helper.rb +32 -0
  105. data/tools/MSDeploy/Microsoft.Web.Delegation.dll +0 -0
  106. data/tools/MSDeploy/Microsoft.Web.Deployment.Tracing.dll +0 -0
  107. data/tools/MSDeploy/Microsoft.Web.Deployment.dll +0 -0
  108. data/tools/MSDeploy/en/msdeploy.resources.dll +0 -0
  109. data/tools/MSDeploy/msdeploy.exe +0 -0
  110. data/tools/MSDeploy/msdeploy.exe.config +6 -0
  111. metadata +253 -0
@@ -0,0 +1,108 @@
1
+ describe Rake::Funnel::Support::Patch do
2
+ describe 'without definition' do
3
+ it 'should be applicable' do
4
+ subject.apply!
5
+ end
6
+
7
+ it 'should be revertable' do
8
+ subject.revert!
9
+ end
10
+
11
+ it 'should be applicable and revertable' do
12
+ subject.apply!.revert!
13
+ end
14
+ end
15
+
16
+ describe 'with definition' do
17
+ subject {
18
+ described_class.new do |p|
19
+ p.setup do
20
+ output.puts 'setup'
21
+ 42
22
+ end
23
+
24
+ p.reset do |memo|
25
+ output.puts memo
26
+ end
27
+ end
28
+ }
29
+
30
+ let(:output) { double.as_null_object }
31
+
32
+ context 'when applying the patch' do
33
+ let!(:ret) { subject.apply! }
34
+
35
+ it 'should execute the setup' do
36
+ expect(output).to have_received(:puts).with('setup')
37
+ end
38
+
39
+ it 'should return self' do
40
+ expect(ret).to eq(subject)
41
+ end
42
+ end
43
+
44
+ context 'when reverting the patch' do
45
+ let!(:ret) {
46
+ subject.apply!
47
+ subject.revert!
48
+ }
49
+
50
+ it 'should execute the reset' do
51
+ expect(output).to have_received(:puts).with(42)
52
+ end
53
+
54
+ it 'should return self' do
55
+ expect(ret).to eq(subject)
56
+ end
57
+ end
58
+
59
+ context 'when reverting an unapplied patch' do
60
+ before { subject.revert! }
61
+
62
+ it 'should not execute the reset' do
63
+ expect(output).to_not have_received(:puts).with(42)
64
+ end
65
+ end
66
+
67
+ context 'when applying twice' do
68
+ before {
69
+ subject.apply!
70
+ subject.apply!
71
+ }
72
+
73
+ it 'should execute the setup once' do
74
+ expect(output).to have_received(:puts).with('setup').once
75
+ end
76
+ end
77
+
78
+ context 'when reverting twice' do
79
+ before {
80
+ subject.apply!
81
+ subject.revert!
82
+ subject.revert!
83
+ }
84
+
85
+ it 'should execute the revert once' do
86
+ expect(output).to have_received(:puts).with(42).once
87
+ end
88
+ end
89
+
90
+ describe 'context' do
91
+ let(:context) { 42 }
92
+
93
+ subject {
94
+ described_class.new(context) do |p|
95
+ p.setup do |context|
96
+ output.puts context
97
+ end
98
+ end
99
+ }
100
+
101
+ before { subject.apply!.revert! }
102
+
103
+ it 'should be accessible from within the patch definition' do
104
+ expect(output).to have_received(:puts).with(42)
105
+ end
106
+ end
107
+ end
108
+ end
@@ -0,0 +1,65 @@
1
+ describe Rake::Funnel::Support::TemplateEngine do
2
+ it 'should render nil' do
3
+ expect(described_class.render(nil)).to eq('')
4
+ end
5
+
6
+ it 'should render empty string' do
7
+ expect(described_class.render('')).to eq('')
8
+ end
9
+
10
+ it 'should static string' do
11
+ expect(described_class.render('hello world')).to eq('hello world')
12
+ end
13
+
14
+ it 'should support ruby' do
15
+ expect(described_class.render('<%= 42 %>')).to eq('42')
16
+ end
17
+
18
+ it 'should omit newlines for pure ruby lines' do
19
+ template = <<-EOF
20
+ <%= 42 %>
21
+ EOF
22
+
23
+ expect(described_class.render(template)).to eq('42')
24
+ end
25
+
26
+ it 'should not omit newlines for mixed ruby lines' do
27
+ template = <<-EOF
28
+ 12 <%= 34 %> 56
29
+ EOF
30
+
31
+ expect(described_class.render(template)).to eq("12 34 56\n")
32
+ end
33
+
34
+ it 'should support @ instead of <%= %>' do
35
+ expect(described_class.render('@String.to_s@')).to eq('String')
36
+ end
37
+
38
+ describe 'binding' do
39
+ context 'without binding' do
40
+ it 'should not support contextual variables' do
41
+ var = 42
42
+ template = '<%= var %>'
43
+
44
+ expect(lambda { described_class.render(template) }).to raise_error
45
+ end
46
+ end
47
+
48
+ context 'with binding' do
49
+ def get_binding(value)
50
+ binding
51
+ end
52
+
53
+ it 'should support contextual variables with binding' do
54
+ template = '<%= value %>'
55
+
56
+ expect(described_class.render(template, nil, get_binding(42))).to eq('42')
57
+ end
58
+ end
59
+ end
60
+
61
+ it 'should report errors with file name' do
62
+ expect(lambda { described_class.render('<%= undefined %>', 'file.template') })
63
+ .to raise_error { |ex| expect(ex.backtrace.join("\n")).to match(/file\.template/) }
64
+ end
65
+ end
@@ -0,0 +1,65 @@
1
+ require 'tmpdir'
2
+
3
+ describe Rake::Funnel::Support::Which do
4
+ let(:temp_dir) { Dir.mktmpdir }
5
+ let(:executable_path) { File.join(temp_dir, 'executable.exe') }
6
+ let(:create_entry) { lambda { |p| FileUtils.touch(p) }}
7
+
8
+ before {
9
+ create_entry.call(executable_path)
10
+
11
+ allow(ENV).to receive(:[]).with('PATH').and_return(temp_dir)
12
+ }
13
+
14
+ after {
15
+ FileUtils.rm_rf(temp_dir)
16
+ }
17
+
18
+ describe 'executable in PATH' do
19
+ context 'found' do
20
+ it 'should yield executable' do
21
+ expect(described_class.which(File.basename(executable_path))).to eq(executable_path)
22
+ end
23
+ end
24
+
25
+ context 'not found' do
26
+ it 'should yield nil' do
27
+ expect(described_class.which('does-not-exist.exe')).to be_nil
28
+ end
29
+ end
30
+
31
+ context 'found as directory' do
32
+ let(:create_entry) { lambda { |p| FileUtils.mkdir_p(p) } }
33
+
34
+ it 'should yield nil' do
35
+ expect(described_class.which('executable.exe')).to be_nil
36
+ end
37
+ end
38
+ end
39
+
40
+ describe 'executable in current working directory' do
41
+ context 'found' do
42
+ it 'should yield executable' do
43
+ Dir.chdir(temp_dir) do
44
+ expect(described_class.which(File.basename(executable_path))).to eq(File.basename(executable_path))
45
+ end
46
+ end
47
+ end
48
+
49
+ context 'not found' do
50
+ it 'should yield nil' do
51
+ Dir.chdir(temp_dir) do
52
+ expect(described_class.which('does-not-exist.exe')).to be_nil
53
+ end
54
+ end
55
+ end
56
+
57
+ context 'found as directory' do
58
+ let(:create_entry) { lambda { |p| FileUtils.mkdir_p(p) } }
59
+
60
+ it 'should yield nil' do
61
+ expect(described_class.which('executable.exe')).to be_nil
62
+ end
63
+ end
64
+ end
65
+ end
@@ -0,0 +1,40 @@
1
+ include Rake
2
+
3
+ describe Rake::Funnel::Tasks::BinPath do
4
+ before {
5
+ Task.clear
6
+ expect(subject).to be
7
+ }
8
+
9
+ describe 'defaults' do
10
+ its(:name) { should == :bin_path }
11
+ its(:pattern) { is_expected.to match_array(%w(tools/* tools/*/bin packages/**/tools)) }
12
+ end
13
+
14
+ describe 'execution' do
15
+ before {
16
+ allow(ENV).to receive(:[]).with('PATH').and_return('default PATH contents')
17
+ allow(ENV).to receive(:[]=)
18
+ allow(Rake).to receive(:rake_output_message)
19
+ }
20
+
21
+ before {
22
+ subject.pattern = %w(foo bar)
23
+
24
+ allow(Dir).to receive(:[]).with(*subject.pattern).and_return(subject.pattern)
25
+
26
+ Task[:bin_path].invoke
27
+ }
28
+
29
+ it 'should prepend sorted matching folders to the PATH environment variable' do
30
+ paths = subject.pattern.sort.map { |path| File.expand_path(path) } << ENV['PATH']
31
+
32
+ expect(ENV).to have_received(:[]=).with('PATH', paths.join(File::PATH_SEPARATOR))
33
+ end
34
+
35
+ it 'should report added paths' do
36
+ expect(Rake).to have_received(:rake_output_message).with(%r|/foo$|)
37
+ expect(Rake).to have_received(:rake_output_message).with(%r|/bar$|)
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,101 @@
1
+ require 'tmpdir'
2
+
3
+ include Rake
4
+ include Rake::Funnel::Support
5
+
6
+ describe Rake::Funnel::Tasks::Copy do
7
+ before {
8
+ CLEAN.clear
9
+ Task.clear
10
+ }
11
+
12
+ describe 'defaults' do
13
+ its(:name) { should == :copy }
14
+ its(:source) { should eq([]) }
15
+ its(:target) { should be_nil }
16
+
17
+ it 'should not add the target file to the files to be cleaned' do
18
+ expect(CLEAN).to be_empty
19
+ end
20
+
21
+ describe 'overriding defaults' do
22
+ subject {
23
+ described_class.new do |t|
24
+ t.target = 'something'
25
+ end
26
+ }
27
+
28
+ it 'should add the target file to the files to be cleaned' do
29
+ expect(CLEAN).to include(subject.target)
30
+ end
31
+ end
32
+ end
33
+
34
+ describe 'execution' do
35
+ let(:source) { %w(bin/1 bin/2 bin/3/4 bin/directory/file bin/directory bin/directory-no-content) }
36
+ let(:target) { 'some path' }
37
+
38
+ subject! {
39
+ described_class.new do |t|
40
+ t.source = source
41
+ t.target = target
42
+ end
43
+ }
44
+
45
+ context 'failure' do
46
+ context 'target not defined' do
47
+ let(:target) { nil }
48
+
49
+ it 'should fail' do
50
+ expect(lambda { Task[subject.name].invoke }).to raise_error(/Target not defined/)
51
+ end
52
+ end
53
+ end
54
+
55
+ context 'success' do
56
+ let(:finder) { double(Finder).as_null_object }
57
+
58
+ before {
59
+ allow(finder).to receive(:all_or_default).and_return(source)
60
+ allow(Finder).to receive(:new).and_return(finder)
61
+
62
+ allow(File).to receive(:directory?).and_return(false)
63
+ source.last(2).each do |dir|
64
+ allow(File).to receive(:directory?).with(dir).and_return(true)
65
+ end
66
+
67
+ allow(RakeFileUtils).to receive(:mkdir_p)
68
+ allow(RakeFileUtils).to receive(:cp)
69
+ }
70
+
71
+ before {
72
+ Task[subject.name].invoke
73
+ }
74
+
75
+ def no_prefix(file)
76
+ file.sub(%r|bin/|, '')
77
+ end
78
+
79
+ it 'should create target directories' do
80
+ expect(RakeFileUtils).to have_received(:mkdir_p).with(subject.target + '/3')
81
+ expect(RakeFileUtils).to have_received(:mkdir_p).with(subject.target + '/directory')
82
+ end
83
+
84
+ it 'should skip source directories' do
85
+ source
86
+ .select { |src| File.directory?(src) }
87
+ .each do |src|
88
+ expect(RakeFileUtils).not_to have_received(:cp).with(src, anything)
89
+ end
90
+ end
91
+
92
+ it 'should copy files with common path removed' do
93
+ source
94
+ .select { |src| !File.directory?(src) }
95
+ .each do |src|
96
+ expect(RakeFileUtils).to have_received(:cp).with(src, File.join(subject.target, no_prefix(src)))
97
+ end
98
+ end
99
+ end
100
+ end
101
+ end
@@ -0,0 +1,237 @@
1
+ include Rake
2
+ include Rake::Funnel::Support
3
+ include Rake::Funnel::Tasks
4
+
5
+ describe Rake::Funnel::Tasks::Environments do
6
+ include Rake::DSL
7
+
8
+ before {
9
+ Task.clear
10
+ }
11
+
12
+ let(:files) { [] }
13
+
14
+ before {
15
+ allow(Dir).to receive(:[]).and_return(files)
16
+ }
17
+
18
+ def disable_default_env_setup
19
+ allow_any_instance_of(described_class).to receive(:default_environment_setup)
20
+ end
21
+
22
+ describe 'defaults' do
23
+ before {
24
+ disable_default_env_setup
25
+ }
26
+
27
+ its(:base_dir) { should == 'config' }
28
+ its(:default_env) { should be_nil }
29
+ its(:default_config) { should == 'default' }
30
+ its(:local_config) { should == 'local' }
31
+
32
+ describe 'overriding defaults' do
33
+ subject {
34
+ described_class.new do |t|
35
+ t.base_dir = 'custom base_dir'
36
+ t.default_env = 'custom default_env'
37
+ t.default_config = 'custom default_config'
38
+ t.local_config = 'custom local_config'
39
+ end
40
+ }
41
+
42
+ its(:base_dir) { should == subject.base_dir }
43
+ its(:default_env) { should == subject.default_env }
44
+ its(:default_config) { should == subject.default_config }
45
+ its(:local_config) { should == subject.local_config }
46
+ end
47
+ end
48
+
49
+ describe 'definition' do
50
+ before {
51
+ disable_default_env_setup
52
+ }
53
+
54
+ before {
55
+ allow_any_instance_of(described_class).to receive(:task)
56
+ }
57
+
58
+ let(:files) {
59
+ %w(config/default.yaml config/local.yaml config/dev.yaml config/production.yaml)
60
+ }
61
+
62
+ it 'should define a task for each config file' do
63
+ expect(subject).to have_received(:task).with('dev')
64
+ expect(subject).to have_received(:task).with('production')
65
+ end
66
+
67
+ it 'should omit environment for the default config file' do
68
+ expect(subject).not_to have_received(:task).with('default')
69
+ end
70
+
71
+ it 'should omit environment for the local config file' do
72
+ expect(subject).not_to have_received(:task).with('local')
73
+ end
74
+ end
75
+
76
+ describe 'config files to load' do
77
+ let(:files) {
78
+ %w(config/dev.yaml)
79
+ }
80
+
81
+ before {
82
+ allow(EnvironmentsSupport::Loader).to receive(:load_configuration)
83
+ }
84
+
85
+ before {
86
+ allow(File).to receive(:exists?).and_return(true)
87
+ allow(File).to receive(:exists?).with(optional).and_return(false)
88
+ }
89
+
90
+ subject {
91
+ described_class.new do |t|
92
+ t.default_env = 'dev'
93
+ end
94
+ }
95
+
96
+ before {
97
+ expect(subject).to be
98
+ }
99
+
100
+ context 'default and local config files exist' do
101
+ let(:optional) { nil }
102
+
103
+ it 'should load all files' do
104
+ expect(EnvironmentsSupport::Loader)
105
+ .to have_received(:load_configuration).with(hash_including({ config_files: %w(config/default.yaml config/dev.yaml config/local.yaml) }))
106
+ end
107
+ end
108
+
109
+ context 'default config file does not exist' do
110
+ let(:optional) { 'config/default.yaml' }
111
+
112
+ it 'should load environment file and local file' do
113
+ expect(EnvironmentsSupport::Loader)
114
+ .to have_received(:load_configuration).with(hash_including({ config_files: %w(config/dev.yaml config/local.yaml) }))
115
+ end
116
+ end
117
+
118
+ context 'local config file does not exist' do
119
+ let(:optional) { 'config/local.yaml' }
120
+
121
+ it 'should load default file and environment file' do
122
+ expect(EnvironmentsSupport::Loader)
123
+ .to have_received(:load_configuration).with(hash_including({ config_files: %w(config/default.yaml config/dev.yaml) }))
124
+ end
125
+ end
126
+ end
127
+
128
+ describe 'automatic environment setup' do
129
+ let(:files) {
130
+ %w(config/dev.yaml config/production.yaml)
131
+ }
132
+
133
+ before {
134
+ allow(EnvironmentsSupport::Loader).to receive(:load_configuration)
135
+ }
136
+
137
+ context 'no default environment configured' do
138
+ before {
139
+ expect(subject).to be
140
+ }
141
+
142
+ it 'should not invoke environment tasks' do
143
+ expect(EnvironmentsSupport::Loader).not_to have_received(:load_configuration)
144
+ end
145
+ end
146
+
147
+ context 'default environment configured' do
148
+ subject {
149
+ described_class.new do |t|
150
+ t.default_env = 'dev'
151
+ end
152
+ }
153
+
154
+ before {
155
+ allow(Rake.application).to receive(:top_level_tasks).and_return(user_defined_task)
156
+ }
157
+
158
+ before {
159
+ expect(subject).to be
160
+ }
161
+
162
+ context 'no user-defined environment' do
163
+ let(:user_defined_task) { %w(foo) }
164
+
165
+ it 'should invoke default environment task' do
166
+ expect(EnvironmentsSupport::Loader)
167
+ .to have_received(:load_configuration).with(hash_including({ name: 'dev' }))
168
+ end
169
+
170
+ it 'should not invoke other environment tasks' do
171
+ expect(EnvironmentsSupport::Loader)
172
+ .not_to have_received(:load_configuration).with(hash_including({ name: 'production' }))
173
+ end
174
+ end
175
+
176
+ context 'user-defined environment' do
177
+ let(:user_defined_task) { %w(foo production) }
178
+
179
+ it 'should invoke user-defined environment task' do
180
+ expect(EnvironmentsSupport::Loader)
181
+ .to have_received(:load_configuration).with(hash_including({ name: 'production' }))
182
+ end
183
+
184
+ it 'should not invoke other environment tasks' do
185
+ expect(EnvironmentsSupport::Loader)
186
+ .not_to have_received(:load_configuration).with(hash_including({ name: 'dev' }))
187
+ end
188
+ end
189
+
190
+ context 'environment task defined in Rake namespace' do
191
+ subject {
192
+ namespace :foo do
193
+ namespace :bar do
194
+ described_class.new do |t|
195
+ t.default_env = 'dev'
196
+ end
197
+ end
198
+ end
199
+ }
200
+
201
+ context 'default environment configured' do
202
+ before {
203
+ expect(subject).to be
204
+ }
205
+
206
+ context 'no user-defined environment' do
207
+ let(:user_defined_task) { %w(foo) }
208
+
209
+ it 'should invoke default environment task' do
210
+ expect(EnvironmentsSupport::Loader)
211
+ .to have_received(:load_configuration).with(hash_including({ name: 'dev' }))
212
+ end
213
+
214
+ it 'should not invoke other environment tasks' do
215
+ expect(EnvironmentsSupport::Loader)
216
+ .not_to have_received(:load_configuration).with(hash_including({ name: 'production' }))
217
+ end
218
+ end
219
+
220
+ context 'user-defined environment' do
221
+ let(:user_defined_task) { %w(foo foo:bar:production) }
222
+
223
+ it 'should invoke user-defined environment task' do
224
+ expect(EnvironmentsSupport::Loader)
225
+ .to have_received(:load_configuration).with(hash_including({ name: 'production' }))
226
+ end
227
+
228
+ it 'should not invoke other environment tasks' do
229
+ expect(EnvironmentsSupport::Loader)
230
+ .not_to have_received(:load_configuration).with(hash_including({ name: 'dev' }))
231
+ end
232
+ end
233
+ end
234
+ end
235
+ end
236
+ end
237
+ end