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,184 @@
1
+ include Rake
2
+ include Rake::Funnel::Support
3
+
4
+ describe Rake::Funnel::Tasks::Paket do
5
+ before {
6
+ Task.clear
7
+ }
8
+
9
+ describe 'defaults' do
10
+ its(:name) { should == :paket }
11
+ its(:paket) { should == '.paket/paket.exe' }
12
+ its(:paket_args) { should == 'restore' }
13
+ its(:bootstrapper) { should == '.paket/paket.bootstrapper.exe' }
14
+ its(:bootstrapper_args) { should == nil }
15
+ end
16
+
17
+ describe 'overriding defaults' do
18
+ context 'when bootstrapper executable is specified' do
19
+ subject {
20
+ described_class.new do |t|
21
+ t.bootstrapper = 'custom bootstrapper.exe'
22
+ end
23
+ }
24
+
25
+ its(:bootstrapper) { should == 'custom bootstrapper.exe' }
26
+ end
27
+
28
+ context 'when bootstrapper args are specified' do
29
+ subject {
30
+ described_class.new do |t|
31
+ t.bootstrapper_args = %w(arg1 arg2)
32
+ end
33
+ }
34
+
35
+ its(:bootstrapper_args) { should == %w(arg1 arg2) }
36
+ end
37
+
38
+ context 'when paket executable is specified' do
39
+ subject {
40
+ described_class.new do |t|
41
+ t.paket = 'custom paket.exe'
42
+ end
43
+ }
44
+
45
+ its(:paket) { should == 'custom paket.exe' }
46
+ end
47
+
48
+ context 'when paket args are specified' do
49
+ subject {
50
+ described_class.new do |t|
51
+ t.paket_args = %w(arg1 arg2)
52
+ end
53
+ }
54
+
55
+ its(:paket_args) { should == %w(arg1 arg2) }
56
+ end
57
+ end
58
+
59
+ describe 'execution' do
60
+ before {
61
+ allow(subject).to receive(:sh)
62
+ allow(Mono).to receive(:invocation).and_wrap_original do |original_method, *args, &block|
63
+ args.compact
64
+ end
65
+ }
66
+
67
+ context 'with overridden defaults' do
68
+ subject {
69
+ described_class.new do |t|
70
+ t.bootstrapper = 'custom bootstrapper.exe'
71
+ t.bootstrapper_args = %w(arg1 arg2)
72
+ t.paket = 'custom paket.exe'
73
+ t.paket_args = %w(arg1 arg2)
74
+ end
75
+ }
76
+
77
+ before {
78
+ allow(File).to receive(:exist?).with(subject.paket).and_return(false)
79
+ allow(subject).to receive(:sh)
80
+ }
81
+
82
+ before {
83
+ Task[subject.name].invoke
84
+ }
85
+
86
+ it 'should use custom bootstrapper' do
87
+ expect(subject).to have_received(:sh).with(subject.bootstrapper, subject.bootstrapper_args)
88
+ end
89
+
90
+ it 'should use custom paket' do
91
+ expect(subject).to have_received(:sh).with(subject.paket, subject.paket_args)
92
+ end
93
+ end
94
+
95
+ describe 'mono invocation' do
96
+ before {
97
+ Task[subject.name].invoke
98
+ }
99
+
100
+ it 'should use mono invocation for bootstrapper' do
101
+ expect(Mono).to have_received(:invocation).with(subject.bootstrapper, subject.bootstrapper_args)
102
+ end
103
+
104
+ it 'should use mono invocation for paket' do
105
+ expect(Mono).to have_received(:invocation).with(subject.paket, subject.paket_args)
106
+ end
107
+ end
108
+
109
+ describe 'optional download' do
110
+ before {
111
+ allow(File).to receive(:exist?).with(subject.paket).and_return(paket_exists)
112
+ allow(subject).to receive(:sh).with(subject.bootstrapper)
113
+ }
114
+
115
+ context 'success' do
116
+ before {
117
+ Task[subject.name].invoke
118
+ }
119
+
120
+ context 'paket.exe exists' do
121
+ let(:paket_exists) { true }
122
+
123
+ it 'should not run bootstrapper' do
124
+ expect(subject).not_to have_received(:sh).with(subject.bootstrapper)
125
+ end
126
+
127
+ it 'should run paket' do
128
+ expect(subject).to have_received(:sh).with(subject.paket, subject.paket_args)
129
+ end
130
+ end
131
+
132
+ context 'paket.exe does not exist' do
133
+ let(:paket_exists) { false }
134
+
135
+ it 'should run bootstrapper' do
136
+ expect(subject).to have_received(:sh).with(subject.bootstrapper)
137
+ end
138
+
139
+ it 'should run paket' do
140
+ expect(subject).to have_received(:sh).with(subject.paket, subject.paket_args)
141
+ end
142
+ end
143
+ end
144
+
145
+ context 'failure' do
146
+
147
+
148
+ context 'paket.exe exists' do
149
+ let(:paket_exists) { true }
150
+
151
+ context 'paket failed' do
152
+ before {
153
+ allow(subject).to receive(:sh).with(subject.paket, anything).and_raise
154
+ }
155
+
156
+ it 'should fail' do
157
+ expect(lambda { Task[subject.name].invoke }).to raise_error
158
+ end
159
+ end
160
+ end
161
+
162
+ context 'paket.exe does not exist' do
163
+ let(:paket_exists) { false }
164
+
165
+ context 'bootstrapper failed' do
166
+ before {
167
+ allow(subject).to receive(:sh).with(subject.bootstrapper).and_raise
168
+ }
169
+
170
+ it 'should not run paket' do
171
+ Task[subject.name].invoke rescue nil
172
+
173
+ expect(subject).not_to have_received(:sh).with(subject.paket, subject.paket_args)
174
+ end
175
+
176
+ it 'should fail' do
177
+ expect(lambda { Task[subject.name].invoke }).to raise_error
178
+ end
179
+ end
180
+ end
181
+ end
182
+ end
183
+ end
184
+ end
@@ -0,0 +1,89 @@
1
+ require 'tmpdir'
2
+
3
+ include Rake
4
+ include Rake::Funnel::Support
5
+
6
+ describe Rake::Funnel::Tasks::QuickTemplate do
7
+ before {
8
+ CLEAN.clear
9
+ Task.clear
10
+ }
11
+
12
+ describe 'defaults' do
13
+ its(:name) { should == :template }
14
+ its(:search_pattern) { should eq(%w(**/*.template)) }
15
+ its(:context) { should kind_of?(Binding) }
16
+
17
+ describe 'target files are cleaned' do
18
+ let(:templates) { [] }
19
+ let(:finder) { double(Finder).as_null_object }
20
+
21
+ before {
22
+ allow(finder).to receive(:all_or_default).and_return(templates)
23
+ allow(Finder).to receive(:new).and_return(finder)
24
+ }
25
+
26
+ subject! { described_class.new }
27
+
28
+ context 'no templates found' do
29
+ it 'should not add the target files' do
30
+ expect(CLEAN).to be_empty
31
+ end
32
+ end
33
+
34
+ context 'templates found' do
35
+ let(:templates) { %w(1.template foo/2.template bar/3.some_other_extension) }
36
+
37
+ it 'should add the target files' do
38
+ expect(CLEAN).to match_array(%w(1 foo/2 bar/3))
39
+ end
40
+ end
41
+ end
42
+ end
43
+
44
+ describe 'execution' do
45
+ let(:templates) { %w(1.template two/2.template) }
46
+
47
+ let(:finder) { double(Finder).as_null_object }
48
+ let(:engine) { TemplateEngine }
49
+
50
+ before {
51
+ allow(finder).to receive(:all_or_default).and_return(templates)
52
+ allow(Finder).to receive(:new).and_return(finder)
53
+ allow(engine).to receive(:render).and_return('file content')
54
+ allow(Rake).to receive(:rake_output_message)
55
+ allow(File).to receive(:read).and_return('template content')
56
+ allow(File).to receive(:write)
57
+ }
58
+
59
+ subject! { described_class.new }
60
+
61
+ before {
62
+ Task[subject.name].invoke
63
+ }
64
+
65
+ it 'should report created files' do
66
+ templates.each do |template|
67
+ expect(Rake).to have_received(:rake_output_message).with("Creating file #{template.ext}")
68
+ end
69
+ end
70
+
71
+ it 'should read all templates' do
72
+ templates.each do |template|
73
+ expect(File).to have_received(:read).with(template)
74
+ end
75
+ end
76
+
77
+ it 'should render all templates' do
78
+ templates.each do |template|
79
+ expect(engine).to have_received(:render).with('template content', template, subject.context)
80
+ end
81
+ end
82
+
83
+ it 'should write all files' do
84
+ templates.each do |template|
85
+ expect(File).to have_received(:write).with(template.ext, 'file content')
86
+ end
87
+ end
88
+ end
89
+ end
@@ -0,0 +1,58 @@
1
+ require 'tmpdir'
2
+
3
+ include Rake
4
+ include Rake::Funnel::Support
5
+
6
+ describe Rake::Funnel::Tasks::SideBySideSpecs do
7
+ before {
8
+ Task.clear
9
+ }
10
+
11
+ describe 'defaults' do
12
+ its(:name) { should == :compile }
13
+ its(:projects) { should == %w(**/*.csproj **/*.vbproj **/*.fsproj) }
14
+ its(:references) { should == [] }
15
+ its(:specs) { should == %w(*Specs.cs **/*Specs.cs *Tests.cs **/*Tests.cs) }
16
+ its(:enabled) { should == false }
17
+ end
18
+
19
+ describe 'execution' do
20
+ subject {
21
+ described_class.new do |t|
22
+ t.projects = %w(**/*.??proj)
23
+ t.references = %w(Ref-1)
24
+ t.specs = %w(*Specs.cs **/*Specs.cs)
25
+ t.enabled = enabled
26
+ end
27
+ }
28
+
29
+ before {
30
+ allow(Rake::Funnel::Tasks::SideBySideSpecsSupport::Remover).to receive(:remove)
31
+ }
32
+
33
+ before {
34
+ Task[subject.name].invoke
35
+ }
36
+
37
+ context 'enabled' do
38
+ let(:enabled) { true }
39
+
40
+ it 'should use remover' do
41
+ expect(Rake::Funnel::Tasks::SideBySideSpecsSupport::Remover).to have_received(:remove)
42
+ .with({
43
+ projects: subject.projects,
44
+ references: subject.references,
45
+ specs: subject.specs
46
+ })
47
+ end
48
+ end
49
+
50
+ context 'disabled' do
51
+ let(:enabled) { false }
52
+
53
+ it 'should do nothing' do
54
+ expect(Rake::Funnel::Tasks::SideBySideSpecsSupport::Remover).not_to have_received(:remove)
55
+ end
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,28 @@
1
+ <?xml version="1.0" encoding="utf-8"?>
2
+ <Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3
+ <ItemGroup>
4
+ <Reference Include="Sample-Ref-1">
5
+ <HintPath>somewhere\Sample-Ref-1.dll</HintPath>
6
+ </Reference>
7
+ <Reference Include="Sample-Ref-2" />
8
+ <Reference Include="System" />
9
+ </ItemGroup>
10
+ <ItemGroup>
11
+ <Compile Include="Specs.cs" />
12
+ <Compile Include="FooCode.cs" />
13
+ <Compile Include="FooSpecs.cs" />
14
+ <Compile Include="subdir\BarCode.cs" />
15
+ <Compile Include="subdir\BarSpecs.cs" />
16
+ </ItemGroup>
17
+ <Choose>
18
+ <When Condition="ignored">
19
+ <ItemGroup>
20
+ <Reference Include="Sample-Ref-3">
21
+ <HintPath>packages\sample\sample.dll</HintPath>
22
+ <Private>True</Private>
23
+ <Paket>True</Paket>
24
+ </Reference>
25
+ </ItemGroup>
26
+ </When>
27
+ </Choose>
28
+ </Project>
@@ -0,0 +1,116 @@
1
+ describe Rake::Funnel::Tasks::SideBySideSpecsSupport::Remover do
2
+ describe 'removal' do
3
+ let(:projects) { [] }
4
+ let(:references) { [] }
5
+ let(:specs) { [] }
6
+
7
+ before {
8
+ allow(Dir).to receive(:[]).and_return(%w(project.proj))
9
+ allow(File).to receive(:read).and_return('<root></root>')
10
+ allow(File).to receive(:open)
11
+ allow(RakeFileUtils).to receive(:rm)
12
+ }
13
+
14
+ before {
15
+ described_class.remove({
16
+ projects: projects,
17
+ references: references,
18
+ specs: specs
19
+ })
20
+ }
21
+
22
+ describe 'arguments' do
23
+ context 'string projects' do
24
+ let(:projects) { '**/*.??proj' }
25
+
26
+ it 'should succeed' do
27
+ expect(true).to be(true)
28
+ end
29
+ end
30
+
31
+ context 'string references' do
32
+ let(:projects) { '**/*.??proj' }
33
+ let(:references) { 'Reference' }
34
+
35
+ it 'should succeed' do
36
+ expect(true).to be(true)
37
+ end
38
+ end
39
+
40
+ context 'string specs' do
41
+ let(:projects) { '**/*.??proj' }
42
+ let(:specs) { '*Specs.cs' }
43
+
44
+ it 'should succeed' do
45
+ expect(true).to be(true)
46
+ end
47
+ end
48
+ end
49
+
50
+ context 'project unchanged' do
51
+ let(:projects) { '**/*.??proj' }
52
+ let(:references) { 'Reference' }
53
+ let(:specs) { '*Specs.cs' }
54
+
55
+ it 'should not write XML' do
56
+ expect(File).not_to have_received(:open)
57
+ end
58
+ end
59
+ end
60
+
61
+ describe 'example' do
62
+ let(:projects) { %w(**/*.??proj) }
63
+ let(:references) { %w(Sample-Ref-1 Sample-Ref-2 Sample-Ref-3) }
64
+ let(:specs) { %w(*Specs.cs **/*Specs.cs) }
65
+
66
+ let(:temp_dir) { Dir.mktmpdir }
67
+
68
+ before {
69
+ FileUtils.cp_r(File.join(File.dirname(__FILE__), 'example/.'), temp_dir)
70
+ }
71
+
72
+ before {
73
+ allow(RakeFileUtils).to receive(:rm)
74
+ }
75
+
76
+ before {
77
+ Dir.chdir(temp_dir) do
78
+ described_class.remove({
79
+ projects: projects,
80
+ references: references,
81
+ specs: specs
82
+ })
83
+ end
84
+ }
85
+
86
+ after {
87
+ FileUtils.rm_rf(temp_dir)
88
+ }
89
+
90
+ describe 'code files' do
91
+ it 'should keep production code' do
92
+ expect(RakeFileUtils).not_to have_received(:rm).with('Code.cs')
93
+ end
94
+
95
+ it 'should delete specs' do
96
+ expect(RakeFileUtils).to have_received(:rm).with('Specs.cs')
97
+ expect(RakeFileUtils).to have_received(:rm).with('FooSpecs.cs')
98
+ expect(RakeFileUtils).to have_received(:rm).with('subdir/BarSpecs.cs')
99
+ end
100
+ end
101
+
102
+ describe 'projects' do
103
+ def project_xml
104
+ File.read(File.join(temp_dir, 'Sample.csproj'))
105
+ end
106
+
107
+ it 'should remove references' do
108
+ expect(project_xml).not_to include('Sample-Ref-1', 'Sample-Ref-2', 'Sample-Ref-3')
109
+ end
110
+
111
+ it 'should remove spec files' do
112
+ expect(project_xml).not_to include('Specs.cs', 'SampleSpecs.cs')
113
+ end
114
+ end
115
+ end
116
+ end
@@ -0,0 +1,133 @@
1
+ include Rake
2
+
3
+ describe Rake::Funnel::Tasks::Timing do
4
+ include DSL
5
+
6
+ before {
7
+ Rake.application = nil
8
+ Task.clear
9
+
10
+ expect(define_tasks).to be
11
+ expect(subject).to be
12
+ }
13
+
14
+ let(:define_tasks) { task :task }
15
+
16
+ after {
17
+ subject.reset!
18
+ }
19
+
20
+ describe 'defaults' do
21
+ its(:name) { should == :timing }
22
+ its(:stats) { should have(0).items }
23
+ end
24
+
25
+ describe 'task is automatically executed' do
26
+ it 'should add itself to the top level tasks' do
27
+ expect(Rake.application.top_level_tasks).to include(:timing)
28
+ end
29
+
30
+ it 'should append itself to the top level tasks' do
31
+ allow(Rake.application).to receive(:handle_options).and_return([])
32
+ Rake.application.init
33
+
34
+ described_class.new
35
+
36
+ expect(Rake.application.top_level_tasks).to have_at_least(2).items
37
+ expect(Rake.application.top_level_tasks.last).to eq(:timing)
38
+ end
39
+
40
+ context 'task defined in namespace' do
41
+ it 'should add namespaced top level task' do
42
+ allow(Rake.application).to receive(:handle_options).and_return([])
43
+ Rake.application.init
44
+
45
+ namespace :namespace do
46
+ described_class.new
47
+ end
48
+
49
+ expect(Rake.application.top_level_tasks).to include('namespace:timing')
50
+ end
51
+ end
52
+ end
53
+
54
+ describe 'execution' do
55
+ before {
56
+ allow(Rake.application).to receive(:init)
57
+ allow(Rake.application).to receive(:load_rakefile)
58
+ Rake.application.top_level_tasks.unshift(:task)
59
+ allow(Rake.application).to receive(:exit_because_of_exception)
60
+
61
+ allow($stdout).to receive(:puts)
62
+ allow($stderr).to receive(:puts)
63
+ # The 'rake aborted!' message is #printed on $stderr.
64
+ allow($stderr).to receive(:print)
65
+
66
+ Rake.application.run
67
+ }
68
+
69
+ context 'with task defined' do
70
+ let(:define_tasks) {
71
+ task :task do
72
+ puts 'hello'
73
+ end
74
+ }
75
+
76
+ it 'should execute tasks' do
77
+ expect($stdout).to have_received(:puts).with('hello')
78
+ end
79
+
80
+ it 'should record timing information for executed tasks' do
81
+ expect(subject.stats).to have(2).items
82
+ expect(subject.stats.first[:task].name).to eq('task')
83
+ expect(subject.stats.first[:time]).to be_a(Float)
84
+ end
85
+
86
+ it 'should record timing information for itself' do
87
+ expect(subject.stats).to have(2).items
88
+
89
+ # Ruby has no #last on Enumerable, WTF.
90
+ expect(subject.stats.reverse_each.first[:task].name).to eq('timing')
91
+ end
92
+ end
93
+
94
+ context 'with unreachable task defined' do
95
+ let(:define_tasks) {
96
+ task :task
97
+ task :not_executed
98
+ }
99
+
100
+ it 'should not record timing information for unexecuted tasks' do
101
+ expect(subject.stats.map { |s| s[:task].name }).not_to include('not_executed')
102
+ end
103
+ end
104
+
105
+ describe 'build finished' do
106
+ context 'when rake succeeded' do
107
+ it 'should print the report' do
108
+ expect($stdout).to have_received(:puts).with(/Build time report/)
109
+ end
110
+
111
+ it 'should report success' do
112
+ expect($stdout).to have_received(:puts).with(/Status\s+OK/)
113
+ end
114
+ end
115
+
116
+ context 'when rake failed' do
117
+ let(:define_tasks) {
118
+ task :task do
119
+ raise
120
+ end
121
+ }
122
+
123
+ it 'should print the report' do
124
+ expect($stdout).to have_received(:puts).with(/Build time report/)
125
+ end
126
+
127
+ it 'should report failure' do
128
+ expect($stderr).to have_received(:puts).with(/Status\s+Failed/)
129
+ end
130
+ end
131
+ end
132
+ end
133
+ end