rake-funnel 0.3.2.pre → 0.4.0.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 (122) hide show
  1. checksums.yaml +4 -4
  2. data/.rspec +2 -2
  3. data/Gemfile +4 -0
  4. data/README.md +2 -2
  5. data/lib/rake/funnel/ambiguous_file_error.rb +31 -29
  6. data/lib/rake/funnel/execution_error.rb +28 -26
  7. data/lib/rake/funnel/extensions/case/camel_case.rb +24 -19
  8. data/lib/rake/funnel/extensions/case/pascal_case.rb +24 -19
  9. data/lib/rake/funnel/extensions/case.rb +3 -3
  10. data/lib/rake/funnel/extensions/common_path.rb +60 -52
  11. data/lib/rake/funnel/extensions/disable_colors.rb +33 -27
  12. data/lib/rake/funnel/extensions/rexml.rb +27 -23
  13. data/lib/rake/funnel/extensions/shell.rb +92 -56
  14. data/lib/rake/funnel/extensions/windows_path.rb +15 -11
  15. data/lib/rake/funnel/framework.rb +11 -16
  16. data/lib/rake/funnel/integration/progress_report.rb +72 -70
  17. data/lib/rake/funnel/integration/sync_output.rb +12 -8
  18. data/lib/rake/funnel/integration/teamcity/nunit_plugin.rb +61 -55
  19. data/lib/rake/funnel/integration/teamcity/progress_report.rb +39 -33
  20. data/lib/rake/funnel/integration/teamcity/service_messages.rb +46 -40
  21. data/lib/rake/funnel/integration/teamcity/teamcity.rb +19 -15
  22. data/lib/rake/funnel/integration/teamcity.rb +3 -5
  23. data/lib/rake/funnel/support/argument_mapper/key_value_pair.rb +16 -10
  24. data/lib/rake/funnel/support/argument_mapper/styles/default.rb +39 -31
  25. data/lib/rake/funnel/support/argument_mapper/styles/msbuild.rb +41 -33
  26. data/lib/rake/funnel/support/argument_mapper/styles/msdeploy.rb +55 -47
  27. data/lib/rake/funnel/support/argument_mapper/styles/nunit.rb +41 -33
  28. data/lib/rake/funnel/support/argument_mapper/styles.rb +3 -5
  29. data/lib/rake/funnel/support/argument_mapper/switch.rb +16 -10
  30. data/lib/rake/funnel/support/argument_mapper/value.rb +16 -10
  31. data/lib/rake/funnel/support/assembly_version/from_version_files.rb +39 -35
  32. data/lib/rake/funnel/support/assembly_version/languages/cs +5 -5
  33. data/lib/rake/funnel/support/assembly_version/languages/fs +12 -12
  34. data/lib/rake/funnel/support/assembly_version/languages/vb +5 -5
  35. data/lib/rake/funnel/support/assembly_version_writer.rb +56 -52
  36. data/lib/rake/funnel/support/binary_version_reader.rb +37 -32
  37. data/lib/rake/funnel/support/copier.rb +31 -27
  38. data/lib/rake/funnel/support/environments/loader.rb +46 -40
  39. data/lib/rake/funnel/support/environments.rb +3 -3
  40. data/lib/rake/funnel/support/internal/finder.rb +55 -51
  41. data/lib/rake/funnel/support/internal/instantiate_symbol.rb +38 -34
  42. data/lib/rake/funnel/support/mapper.rb +57 -53
  43. data/lib/rake/funnel/support/mono.rb +21 -17
  44. data/lib/rake/funnel/support/msbuild/build_tool.rb +30 -24
  45. data/lib/rake/funnel/support/msbuild.rb +3 -3
  46. data/lib/rake/funnel/support/msdeploy/registry_patch.rb +90 -84
  47. data/lib/rake/funnel/support/msdeploy.rb +3 -3
  48. data/lib/rake/funnel/support/patch.rb +41 -37
  49. data/lib/rake/funnel/support/specs_remover.rb +66 -62
  50. data/lib/rake/funnel/support/template_engine.rb +30 -26
  51. data/lib/rake/funnel/support/timing/report.rb +95 -89
  52. data/lib/rake/funnel/support/timing/statistics.rb +32 -26
  53. data/lib/rake/funnel/support/timing.rb +3 -3
  54. data/lib/rake/funnel/support/version_info.rb +103 -72
  55. data/lib/rake/funnel/support/which.rb +19 -15
  56. data/lib/rake/funnel/support/zipper.rb +53 -49
  57. data/lib/rake/funnel/tasks/assembly_version.rb +44 -40
  58. data/lib/rake/funnel/tasks/bin_path.rb +45 -41
  59. data/lib/rake/funnel/tasks/copy.rb +43 -39
  60. data/lib/rake/funnel/tasks/environments.rb +89 -89
  61. data/lib/rake/funnel/tasks/msbuild.rb +55 -51
  62. data/lib/rake/funnel/tasks/msdeploy.rb +54 -50
  63. data/lib/rake/funnel/tasks/nunit.rb +52 -48
  64. data/lib/rake/funnel/tasks/paket.rb +51 -47
  65. data/lib/rake/funnel/tasks/quick_template.rb +53 -49
  66. data/lib/rake/funnel/tasks/side_by_side_specs.rb +41 -37
  67. data/lib/rake/funnel/tasks/timing.rb +108 -104
  68. data/lib/rake/funnel/tasks/zip.rb +46 -42
  69. data/lib/rake/funnel/version.rb +1 -1
  70. data/lib/rake/funnel.rb +7 -7
  71. data/rake-funnel.gemspec +12 -3
  72. data/spec/rake/funnel/execution_error_spec.rb +67 -67
  73. data/spec/rake/funnel/extensions/case/camel_case_spec.rb +17 -17
  74. data/spec/rake/funnel/extensions/case/pascal_case_spec.rb +17 -17
  75. data/spec/rake/funnel/extensions/common_path_spec.rb +56 -56
  76. data/spec/rake/funnel/extensions/disable_colors_spec.rb +33 -33
  77. data/spec/rake/funnel/extensions/rexml_spec.rb +20 -20
  78. data/spec/rake/funnel/extensions/shell_spec.rb +237 -237
  79. data/spec/rake/funnel/extensions/windows_path_spec.rb +5 -5
  80. data/spec/rake/funnel/integration/progress_report_spec.rb +149 -149
  81. data/spec/rake/funnel/integration/sync_output_spec.rb +16 -16
  82. data/spec/rake/funnel/integration/teamcity/nunit_plugin_spec.rb +110 -110
  83. data/spec/rake/funnel/integration/teamcity/progress_report_spec.rb +174 -174
  84. data/spec/rake/funnel/integration/teamcity/service_messages_spec.rb +136 -136
  85. data/spec/rake/funnel/integration/teamcity/teamcity_spec.rb +34 -34
  86. data/spec/rake/funnel/support/argument_mapper/styles/msdeploy_spec.rb +222 -222
  87. data/spec/rake/funnel/support/argument_mapper/styles/nunit_spec.rb +25 -25
  88. data/spec/rake/funnel/support/argument_mapper/styles/styles_spec.rb +214 -214
  89. data/spec/rake/funnel/support/assembly_version/from_version_files_spec.rb +66 -61
  90. data/spec/rake/funnel/support/assembly_version_writer_spec.rb +140 -140
  91. data/spec/rake/funnel/support/binary_version_reader_spec.rb +29 -29
  92. data/spec/rake/funnel/support/copier_spec.rb +58 -58
  93. data/spec/rake/funnel/support/environments/loader_spec.rb +143 -143
  94. data/spec/rake/funnel/support/internal/finder_spec.rb +229 -229
  95. data/spec/rake/funnel/support/internal/instantiate_symbol_spec.rb +182 -183
  96. data/spec/rake/funnel/support/mapper_spec.rb +87 -87
  97. data/spec/rake/funnel/support/mono_spec.rb +57 -57
  98. data/spec/rake/funnel/support/msbuild/build_tool_spec.rb +21 -21
  99. data/spec/rake/funnel/support/msdeploy/registry_patch_spec.rb +139 -139
  100. data/spec/rake/funnel/support/patch_spec.rb +108 -108
  101. data/spec/rake/funnel/support/specs_remover/Sample.csproj +28 -28
  102. data/spec/rake/funnel/support/specs_remover_spec.rb +116 -116
  103. data/spec/rake/funnel/support/template_engine_spec.rb +65 -65
  104. data/spec/rake/funnel/support/timing/report_spec.rb +129 -129
  105. data/spec/rake/funnel/support/version_info_spec.rb +333 -228
  106. data/spec/rake/funnel/support/which_spec.rb +65 -65
  107. data/spec/rake/funnel/support/zipper_spec.rb +77 -77
  108. data/spec/rake/funnel/tasks/assembly_version_spec.rb +45 -45
  109. data/spec/rake/funnel/tasks/bin_path_spec.rb +52 -52
  110. data/spec/rake/funnel/tasks/copy_spec.rb +44 -44
  111. data/spec/rake/funnel/tasks/environments_spec.rb +249 -247
  112. data/spec/rake/funnel/tasks/msbuild_spec.rb +91 -91
  113. data/spec/rake/funnel/tasks/msdeploy_spec.rb +220 -220
  114. data/spec/rake/funnel/tasks/nunit_spec.rb +74 -74
  115. data/spec/rake/funnel/tasks/paket_spec.rb +140 -142
  116. data/spec/rake/funnel/tasks/quick_template_spec.rb +62 -62
  117. data/spec/rake/funnel/tasks/side_by_side_specs_spec.rb +58 -58
  118. data/spec/rake/funnel/tasks/timing_spec.rb +133 -133
  119. data/spec/rake/funnel/tasks/zip_spec.rb +50 -50
  120. data/spec/spec_helper.rb +43 -33
  121. metadata +2 -3
  122. data/lib/rake/funnel/support/side_by_side_specs.rb +0 -3
@@ -1,174 +1,174 @@
1
- include Rake
2
- include Rake::Funnel::Integration
3
- include Rake::Funnel::Integration::TeamCity
4
-
5
- describe Rake::Funnel::Integration::TeamCity::ProgressReport do
6
- include DSL
7
-
8
- let(:teamcity_running?) { false }
9
- let(:teamcity_rake_runner?) { false }
10
-
11
- before {
12
- allow(TeamCity).to receive(:running?).and_return(teamcity_running?)
13
- allow(TeamCity).to receive(:rake_runner?).and_return(teamcity_rake_runner?)
14
- allow(ServiceMessages).to receive(:block_opened)
15
- allow(ServiceMessages).to receive(:block_closed)
16
- allow(ServiceMessages).to receive(:progress_start)
17
- allow(ServiceMessages).to receive(:progress_finish)
18
- allow(ServiceMessages).to receive(:build_problem)
19
-
20
- Task.clear
21
- }
22
-
23
- subject! {
24
- described_class.new
25
- }
26
-
27
- after {
28
- subject.disable!
29
- }
30
-
31
- shared_examples :block_report do
32
- it 'should write block start' do
33
- expect(ServiceMessages).to have_received(:block_opened).with(name: 'task')
34
- end
35
-
36
- it 'should write block end' do
37
- expect(ServiceMessages).to have_received(:block_closed).with(name: 'task')
38
- end
39
- end
40
-
41
- shared_examples :no_block_report do
42
- it 'should not write block start' do
43
- expect(ServiceMessages).not_to have_received(:block_opened)
44
- end
45
-
46
- it 'should not write block end' do
47
- expect(ServiceMessages).not_to have_received(:block_closed)
48
- end
49
- end
50
-
51
- context 'when task succeeds' do
52
- before {
53
- task :task
54
-
55
- Task[:task].invoke
56
- }
57
-
58
- it 'should not report build problems' do
59
- expect(ServiceMessages).to_not have_received(:build_problem)
60
- end
61
-
62
- context 'not on TeamCity' do
63
- it_behaves_like :no_block_report
64
- end
65
-
66
- context 'on TeamCity' do
67
- let(:teamcity_running?) { true }
68
-
69
- context 'without rake runner' do
70
- it_behaves_like :block_report
71
- end
72
-
73
- context 'with rake runner' do
74
- let(:teamcity_rake_runner?) { true }
75
-
76
- it_behaves_like :no_block_report
77
- end
78
- end
79
- end
80
-
81
- context 'when task fails' do
82
- class SpecificError < StandardError; end
83
-
84
- before {
85
- module Rake
86
- class ApplicationAbortedException < StandardError
87
- attr_reader :inner_exception
88
-
89
- def initialize(other_exception)
90
- @inner_exception = other_exception
91
- end
92
- end
93
- end
94
- }
95
-
96
- let(:error) { SpecificError.new('task error' * 4000) }
97
-
98
- before {
99
- task :task do
100
- raise error
101
- end
102
-
103
- begin
104
- Task[:task].invoke
105
- rescue ApplicationAbortedException => e
106
- rescue SpecificError => e
107
- @raised_error = e
108
- end
109
- }
110
-
111
- context 'not on TeamCity' do
112
- it_behaves_like :no_block_report
113
-
114
- it 'should not swallow the error' do
115
- expect(@raised_error).to be_a_kind_of(SpecificError)
116
- end
117
- end
118
-
119
- context 'on TeamCity' do
120
- let(:teamcity_running?) { true }
121
-
122
- describe 'build problems' do
123
- it 'should report build problems' do
124
- expect(ServiceMessages).to have_received(:build_problem)
125
- end
126
-
127
- it 'should report the error message' do
128
- expect(ServiceMessages).to have_received(:build_problem).with(hash_including({ description: be_an_instance_of(String) }))
129
- end
130
-
131
- it 'should report the first 4000 characters of the error message' do
132
- expect(ServiceMessages).to have_received(:build_problem).with(hash_including({ description: have(4000).items }))
133
- end
134
- end
135
-
136
- context 'without rake runner' do
137
- it_behaves_like :block_report
138
-
139
- it 'should report the error as a build problem' do
140
- expect(ServiceMessages).to have_received(:build_problem)
141
- end
142
- end
143
-
144
- context 'with rake runner' do
145
- let(:teamcity_rake_runner?) { true }
146
- let(:error) {
147
- ApplicationAbortedException.new(SpecificError.new('inner message'))
148
- }
149
-
150
- it 'should report the inner error as a build problem (as it will be wrapped in a ApplicationAbortedException)' do
151
- expect(ServiceMessages).to have_received(:build_problem).with({ description: 'inner message' })
152
- end
153
-
154
- it_behaves_like :no_block_report
155
- end
156
- end
157
- end
158
-
159
- context 'when progess report was disabled' do
160
- let(:teamcity_running?) { true }
161
-
162
- before {
163
- subject.disable!
164
-
165
- task :task
166
-
167
- Task[:task].invoke
168
- }
169
-
170
- it 'should not write' do
171
- expect(ServiceMessages).to_not have_received(:block_opened)
172
- end
173
- end
174
- end
1
+ include Rake
2
+ include Rake::Funnel::Integration
3
+ include Rake::Funnel::Integration::TeamCity
4
+
5
+ describe Rake::Funnel::Integration::TeamCity::ProgressReport do
6
+ include DSL
7
+
8
+ let(:teamcity_running?) { false }
9
+ let(:teamcity_rake_runner?) { false }
10
+
11
+ before {
12
+ allow(TeamCity).to receive(:running?).and_return(teamcity_running?)
13
+ allow(TeamCity).to receive(:rake_runner?).and_return(teamcity_rake_runner?)
14
+ allow(ServiceMessages).to receive(:block_opened)
15
+ allow(ServiceMessages).to receive(:block_closed)
16
+ allow(ServiceMessages).to receive(:progress_start)
17
+ allow(ServiceMessages).to receive(:progress_finish)
18
+ allow(ServiceMessages).to receive(:build_problem)
19
+
20
+ Task.clear
21
+ }
22
+
23
+ subject! {
24
+ described_class.new
25
+ }
26
+
27
+ after {
28
+ subject.disable!
29
+ }
30
+
31
+ shared_examples :block_report do
32
+ it 'should write block start' do
33
+ expect(ServiceMessages).to have_received(:block_opened).with(name: 'task')
34
+ end
35
+
36
+ it 'should write block end' do
37
+ expect(ServiceMessages).to have_received(:block_closed).with(name: 'task')
38
+ end
39
+ end
40
+
41
+ shared_examples :no_block_report do
42
+ it 'should not write block start' do
43
+ expect(ServiceMessages).not_to have_received(:block_opened)
44
+ end
45
+
46
+ it 'should not write block end' do
47
+ expect(ServiceMessages).not_to have_received(:block_closed)
48
+ end
49
+ end
50
+
51
+ context 'when task succeeds' do
52
+ before {
53
+ task :task
54
+
55
+ Task[:task].invoke
56
+ }
57
+
58
+ it 'should not report build problems' do
59
+ expect(ServiceMessages).to_not have_received(:build_problem)
60
+ end
61
+
62
+ context 'not on TeamCity' do
63
+ it_behaves_like :no_block_report
64
+ end
65
+
66
+ context 'on TeamCity' do
67
+ let(:teamcity_running?) { true }
68
+
69
+ context 'without rake runner' do
70
+ it_behaves_like :block_report
71
+ end
72
+
73
+ context 'with rake runner' do
74
+ let(:teamcity_rake_runner?) { true }
75
+
76
+ it_behaves_like :no_block_report
77
+ end
78
+ end
79
+ end
80
+
81
+ context 'when task fails' do
82
+ class SpecificError < StandardError; end
83
+
84
+ before {
85
+ module Rake
86
+ class ApplicationAbortedException < StandardError
87
+ attr_reader :inner_exception
88
+
89
+ def initialize(other_exception)
90
+ @inner_exception = other_exception
91
+ end
92
+ end
93
+ end
94
+ }
95
+
96
+ let(:error) { SpecificError.new('task error' * 4000) }
97
+
98
+ before {
99
+ task :task do
100
+ raise error
101
+ end
102
+
103
+ begin
104
+ Task[:task].invoke
105
+ rescue ApplicationAbortedException => e
106
+ rescue SpecificError => e
107
+ @raised_error = e
108
+ end
109
+ }
110
+
111
+ context 'not on TeamCity' do
112
+ it_behaves_like :no_block_report
113
+
114
+ it 'should not swallow the error' do
115
+ expect(@raised_error).to be_a_kind_of(SpecificError)
116
+ end
117
+ end
118
+
119
+ context 'on TeamCity' do
120
+ let(:teamcity_running?) { true }
121
+
122
+ describe 'build problems' do
123
+ it 'should report build problems' do
124
+ expect(ServiceMessages).to have_received(:build_problem)
125
+ end
126
+
127
+ it 'should report the error message' do
128
+ expect(ServiceMessages).to have_received(:build_problem).with(hash_including({ description: be_an_instance_of(String) }))
129
+ end
130
+
131
+ it 'should report the first 4000 characters of the error message' do
132
+ expect(ServiceMessages).to have_received(:build_problem).with(hash_including({ description: have(4000).items }))
133
+ end
134
+ end
135
+
136
+ context 'without rake runner' do
137
+ it_behaves_like :block_report
138
+
139
+ it 'should report the error as a build problem' do
140
+ expect(ServiceMessages).to have_received(:build_problem)
141
+ end
142
+ end
143
+
144
+ context 'with rake runner' do
145
+ let(:teamcity_rake_runner?) { true }
146
+ let(:error) {
147
+ ApplicationAbortedException.new(SpecificError.new('inner message'))
148
+ }
149
+
150
+ it 'should report the inner error as a build problem (as it will be wrapped in a ApplicationAbortedException)' do
151
+ expect(ServiceMessages).to have_received(:build_problem).with({ description: 'inner message' })
152
+ end
153
+
154
+ it_behaves_like :no_block_report
155
+ end
156
+ end
157
+ end
158
+
159
+ context 'when progess report was disabled' do
160
+ let(:teamcity_running?) { true }
161
+
162
+ before {
163
+ subject.disable!
164
+
165
+ task :task
166
+
167
+ Task[:task].invoke
168
+ }
169
+
170
+ it 'should not write' do
171
+ expect(ServiceMessages).to_not have_received(:block_opened)
172
+ end
173
+ end
174
+ end
@@ -1,136 +1,136 @@
1
- include Rake::Funnel::Integration
2
-
3
- describe Rake::Funnel::Integration::TeamCity::ServiceMessages do
4
- before {
5
- allow(TeamCity).to receive(:running?).and_return(teamcity_running?)
6
- allow($stdout).to receive(:puts)
7
- }
8
-
9
- context 'when running outside TeamCity' do
10
- let(:teamcity_running?) { false }
11
-
12
- it 'should not publish messages' do
13
- described_class.progress_start 'foo'
14
-
15
- expect($stdout).not_to have_received(:puts)
16
- end
17
- end
18
-
19
- context 'when running inside TeamCity' do
20
- let(:teamcity_running?) { true }
21
-
22
- describe 'escaping' do
23
- context 'when publishing messages without special characters' do
24
- it 'should not escape' do
25
- described_class.progress_start "the message"
26
-
27
- expect($stdout).to have_received(:puts).with("##teamcity[progressStart 'the message']")
28
- end
29
- end
30
-
31
- context 'when publishing messages with special characters' do
32
- it 'should escape apostrophes' do
33
- described_class.progress_start "'"
34
-
35
- expect($stdout).to have_received(:puts).with("##teamcity[progressStart '|'']")
36
- end
37
-
38
- it 'should escape line feeds' do
39
- described_class.progress_start "\n"
40
-
41
- expect($stdout).to have_received(:puts).with("##teamcity[progressStart '|n']")
42
- end
43
-
44
- it 'should escape carriage returns' do
45
- described_class.progress_start "\r"
46
-
47
- expect($stdout).to have_received(:puts).with("##teamcity[progressStart '|r']")
48
- end
49
-
50
- it 'should escape next lines' do
51
- described_class.progress_start "\u0085"
52
-
53
- expect($stdout).to have_received(:puts).with("##teamcity[progressStart '|x']")
54
- end
55
-
56
- it 'should escape line separators' do
57
- described_class.progress_start "\u2028"
58
-
59
- expect($stdout).to have_received(:puts).with("##teamcity[progressStart '|l']")
60
- end
61
-
62
- it 'should escape paragraph separators' do
63
- described_class.progress_start "\u2029"
64
-
65
- expect($stdout).to have_received(:puts).with("##teamcity[progressStart '|p']")
66
- end
67
-
68
- it 'should escape vertical bars' do
69
- described_class.progress_start '|'
70
-
71
- expect($stdout).to have_received(:puts).with("##teamcity[progressStart '||']")
72
- end
73
-
74
- it 'should escape opening brackets' do
75
- described_class.progress_start '['
76
-
77
- expect($stdout).to have_received(:puts).with("##teamcity[progressStart '|[']")
78
- end
79
-
80
- it 'should escape closing brackets' do
81
- described_class.progress_start ']'
82
-
83
- expect($stdout).to have_received(:puts).with("##teamcity[progressStart '|]']")
84
- end
85
-
86
- it 'should escape all special characters in a string' do
87
- described_class.progress_start "[\r|\n]"
88
-
89
- expect($stdout).to have_received(:puts).with("##teamcity[progressStart '|[|r|||n|]']")
90
- end
91
- end
92
- end
93
-
94
- describe 'parameters' do
95
- context 'when reporting a message without parameters' do
96
- it 'should print the service message' do
97
- described_class.enable_service_messages
98
-
99
- expect($stdout).to have_received(:puts).with('##teamcity[enableServiceMessages]')
100
- end
101
- end
102
-
103
- context 'when reporting a message with an unnamed parameter' do
104
- it 'should print the service message' do
105
- described_class.progress_message 'the message'
106
-
107
- expect($stdout).to have_received(:puts).with("##teamcity[progressMessage 'the message']")
108
- end
109
- end
110
-
111
- context 'when reporting a message with a named parameter' do
112
- it 'should print the service message' do
113
- described_class.block_opened({ name: 'block name' })
114
-
115
- expect($stdout).to have_received(:puts).with("##teamcity[blockOpened name='block name']")
116
- end
117
- end
118
-
119
- context 'when reporting a message with multiple named parameters' do
120
- it 'should print the service message' do
121
- described_class.test_started ({ name: 'test name', captureStandardOutput: true })
122
-
123
- expect($stdout).to have_received(:puts).with("##teamcity[testStarted name='test name' captureStandardOutput='true']")
124
- end
125
- end
126
-
127
- context 'when reporting a message with Ruby-style named parameters' do
128
- it 'should print the service message' do
129
- described_class.test_started ({ capture_standard_output: true })
130
-
131
- expect($stdout).to have_received(:puts).with("##teamcity[testStarted captureStandardOutput='true']")
132
- end
133
- end
134
- end
135
- end
136
- end
1
+ include Rake::Funnel::Integration
2
+
3
+ describe Rake::Funnel::Integration::TeamCity::ServiceMessages do
4
+ before {
5
+ allow(TeamCity).to receive(:running?).and_return(teamcity_running?)
6
+ allow($stdout).to receive(:puts)
7
+ }
8
+
9
+ context 'when running outside TeamCity' do
10
+ let(:teamcity_running?) { false }
11
+
12
+ it 'should not publish messages' do
13
+ described_class.progress_start 'foo'
14
+
15
+ expect($stdout).not_to have_received(:puts)
16
+ end
17
+ end
18
+
19
+ context 'when running inside TeamCity' do
20
+ let(:teamcity_running?) { true }
21
+
22
+ describe 'escaping' do
23
+ context 'when publishing messages without special characters' do
24
+ it 'should not escape' do
25
+ described_class.progress_start "the message"
26
+
27
+ expect($stdout).to have_received(:puts).with("##teamcity[progressStart 'the message']")
28
+ end
29
+ end
30
+
31
+ context 'when publishing messages with special characters' do
32
+ it 'should escape apostrophes' do
33
+ described_class.progress_start "'"
34
+
35
+ expect($stdout).to have_received(:puts).with("##teamcity[progressStart '|'']")
36
+ end
37
+
38
+ it 'should escape line feeds' do
39
+ described_class.progress_start "\n"
40
+
41
+ expect($stdout).to have_received(:puts).with("##teamcity[progressStart '|n']")
42
+ end
43
+
44
+ it 'should escape carriage returns' do
45
+ described_class.progress_start "\r"
46
+
47
+ expect($stdout).to have_received(:puts).with("##teamcity[progressStart '|r']")
48
+ end
49
+
50
+ it 'should escape next lines' do
51
+ described_class.progress_start "\u0085"
52
+
53
+ expect($stdout).to have_received(:puts).with("##teamcity[progressStart '|x']")
54
+ end
55
+
56
+ it 'should escape line separators' do
57
+ described_class.progress_start "\u2028"
58
+
59
+ expect($stdout).to have_received(:puts).with("##teamcity[progressStart '|l']")
60
+ end
61
+
62
+ it 'should escape paragraph separators' do
63
+ described_class.progress_start "\u2029"
64
+
65
+ expect($stdout).to have_received(:puts).with("##teamcity[progressStart '|p']")
66
+ end
67
+
68
+ it 'should escape vertical bars' do
69
+ described_class.progress_start '|'
70
+
71
+ expect($stdout).to have_received(:puts).with("##teamcity[progressStart '||']")
72
+ end
73
+
74
+ it 'should escape opening brackets' do
75
+ described_class.progress_start '['
76
+
77
+ expect($stdout).to have_received(:puts).with("##teamcity[progressStart '|[']")
78
+ end
79
+
80
+ it 'should escape closing brackets' do
81
+ described_class.progress_start ']'
82
+
83
+ expect($stdout).to have_received(:puts).with("##teamcity[progressStart '|]']")
84
+ end
85
+
86
+ it 'should escape all special characters in a string' do
87
+ described_class.progress_start "[\r|\n]"
88
+
89
+ expect($stdout).to have_received(:puts).with("##teamcity[progressStart '|[|r|||n|]']")
90
+ end
91
+ end
92
+ end
93
+
94
+ describe 'parameters' do
95
+ context 'when reporting a message without parameters' do
96
+ it 'should print the service message' do
97
+ described_class.enable_service_messages
98
+
99
+ expect($stdout).to have_received(:puts).with('##teamcity[enableServiceMessages]')
100
+ end
101
+ end
102
+
103
+ context 'when reporting a message with an unnamed parameter' do
104
+ it 'should print the service message' do
105
+ described_class.progress_message 'the message'
106
+
107
+ expect($stdout).to have_received(:puts).with("##teamcity[progressMessage 'the message']")
108
+ end
109
+ end
110
+
111
+ context 'when reporting a message with a named parameter' do
112
+ it 'should print the service message' do
113
+ described_class.block_opened({ name: 'block name' })
114
+
115
+ expect($stdout).to have_received(:puts).with("##teamcity[blockOpened name='block name']")
116
+ end
117
+ end
118
+
119
+ context 'when reporting a message with multiple named parameters' do
120
+ it 'should print the service message' do
121
+ described_class.test_started ({ name: 'test name', captureStandardOutput: true })
122
+
123
+ expect($stdout).to have_received(:puts).with("##teamcity[testStarted name='test name' captureStandardOutput='true']")
124
+ end
125
+ end
126
+
127
+ context 'when reporting a message with Ruby-style named parameters' do
128
+ it 'should print the service message' do
129
+ described_class.test_started ({ capture_standard_output: true })
130
+
131
+ expect($stdout).to have_received(:puts).with("##teamcity[testStarted captureStandardOutput='true']")
132
+ end
133
+ end
134
+ end
135
+ end
136
+ end