spinach-console-reporter 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -1,3 +1,4 @@
1
+ .DS_Store
1
2
  *.gem
2
3
  *.rbc
3
4
  .bundle
data/README.md CHANGED
@@ -1,6 +1,18 @@
1
- # Spinach::Console::Reporter
1
+ # Spinach::Reporter::Console
2
2
 
3
- TODO: Write a gem description
3
+ [![Gem Version](https://fury-badge.herokuapp.com/rb/spinach-console-reporter.png)](http://badge.fury.io/rb/spinach-console-reporter)
4
+
5
+ This is a reporter that meant to use on Jenkins, combined with (https://github.com/dblock/jenkins-ansicolor-plugin) to bring the color output to Jenkins console.
6
+
7
+ See the comparison:
8
+
9
+ ### Before
10
+
11
+ ![before](https://raw.github.com/ywen/spinach-console-reporter/master/images/before.png "Before")
12
+
13
+ ### After
14
+
15
+ ![after](https://raw.github.com/ywen/spinach-console-reporter/master/images/after.png "After")
4
16
 
5
17
  ## Installation
6
18
 
@@ -18,8 +30,9 @@ Or install it yourself as:
18
30
 
19
31
  ## Usage
20
32
 
21
- TODO: Write usage instructions here
22
-
33
+ ```bash
34
+ $ bundle exec spinach -r console
35
+ ```
23
36
  ## Contributing
24
37
 
25
38
  1. Fork it
Binary file
Binary file
@@ -1,2 +1,2 @@
1
1
  require_relative "spinach-console-reporter/error_reporting"
2
- require_relative "spinach-console-reporter/out"
2
+ require_relative "spinach-console-reporter/console"
@@ -0,0 +1,274 @@
1
+ # encoding: utf-8
2
+ module Spinach
3
+ class Reporter
4
+ class Console < Spinach::Reporter
5
+ include ErrorReporting
6
+
7
+ # The output buffers to store the reports.
8
+ attr_reader :out, :error
9
+
10
+ # The last scenario error
11
+ attr_accessor :scenario_error
12
+
13
+ # The last scenario
14
+ attr_accessor :scenario
15
+
16
+ # Initialitzes the runner
17
+ #
18
+ # @param [Hash] options
19
+ # Sets a custom output buffer by setting options[:output]
20
+ # Sets a custom error buffer by setting options[:error]
21
+ #
22
+ def initialize(*args)
23
+ super(*args)
24
+ @out = options[:output] || $stdout
25
+ @error = options[:error] || $stdout
26
+ @max_step_name_length = 0
27
+ end
28
+
29
+ # Prints the feature name to the standard output
30
+ #
31
+ # @param [Hash] data
32
+ # The feature in a JSON Gherkin format
33
+ #
34
+ def before_feature_run(feature)
35
+ name = feature.name
36
+ out.puts %Q|\n#{magenta("Feature:")} #{magenta(name)}|
37
+ end
38
+
39
+ # Prints the scenario name to the standard ouput
40
+ #
41
+ # @param [Hash] data
42
+ # The feature in a JSON Gherkin format
43
+ #
44
+ def before_scenario_run(scenario, step_definitions = nil)
45
+ @max_step_name_length = scenario.steps.map(&:name).map(&:length).max if scenario.steps.any?
46
+ name = scenario.name
47
+ out.puts "\n #{green('Scenario:')} #{green(name)}"
48
+ end
49
+
50
+ # Adds an error report and re
51
+ #
52
+ # @param [Hash] data
53
+ # The feature in a JSON Gherkin format
54
+ #
55
+ def after_scenario_run(scenario, step_definitions = nil)
56
+ if scenario_error
57
+ report_error(scenario_error, :full)
58
+ self.scenario_error = nil
59
+ end
60
+ end
61
+
62
+ # Adds a passed step to the output buffer.
63
+ #
64
+ # @param [Step] step
65
+ # The step.
66
+ #
67
+ # @param [Array] step_location
68
+ # The step source location
69
+ #
70
+ def on_successful_step(step, step_location, step_definitions = nil)
71
+ output_step('✔', step, :green, step_location)
72
+ self.scenario = [current_feature, current_scenario, step]
73
+ successful_steps << scenario
74
+ end
75
+
76
+ # Adds a failing step to the output buffer.
77
+ #
78
+ # @param [Hash] step
79
+ # The step in a JSON Gherkin format
80
+ #
81
+ # @param [Exception] failure
82
+ # The exception that caused the failure
83
+ #
84
+ def on_failed_step(step, failure, step_location, step_definitions = nil)
85
+ output_step('✘', step, :red, step_location)
86
+ self.scenario_error = [current_feature, current_scenario, step, failure]
87
+ failed_steps << scenario_error
88
+ end
89
+
90
+ # Adds a step that has raised an error to the output buffer.
91
+ #
92
+ # @param [Hash] step
93
+ # The step in a JSON Gherkin format
94
+ #
95
+ # @param [Exception] failure
96
+ # The exception that caused the failure
97
+ #
98
+ def on_error_step(step, failure, step_location, step_definitions = nil)
99
+ output_step('!', step, :red, step_location)
100
+ self.scenario_error = [current_feature, current_scenario, step, failure]
101
+ error_steps << scenario_error
102
+ end
103
+
104
+ # Adds an undefined step to the output buffer.
105
+ #
106
+ # @param [Hash] step
107
+ # The step in a JSON Gherkin format
108
+ #
109
+ def on_undefined_step(step, failure, step_definitions = nil)
110
+ output_step('?', step, :yellow)
111
+ self.scenario_error = [current_feature, current_scenario, step, failure]
112
+ undefined_steps << scenario_error
113
+ end
114
+
115
+ # Adds an undefined step to the output buffer.
116
+ #
117
+ # @param [Hash] step
118
+ # The step in a JSON Gherkin format
119
+ #
120
+ def on_pending_step(step, failure)
121
+ output_step('P', step, :yellow)
122
+ self.scenario_error = [current_feature, current_scenario, step, failure]
123
+ pending_steps << scenario_error
124
+ end
125
+
126
+ # Adds a feature not found message to the output buffer.
127
+ #
128
+ # @param [Hash] feature
129
+ # the feature in a json gherkin format
130
+ #
131
+ # @param [Spinach::FeatureNotFoundException] exception
132
+ # the related exception
133
+ #
134
+ def on_feature_not_found(feature)
135
+ generator = Generators::FeatureGenerator.new(feature)
136
+ lines = "Could not find steps for `#{feature.name}` feature\n\n"
137
+ lines << "\nPlease create the file #{generator.filename} at #{generator.path}, with:\n\n"
138
+
139
+ lines << generator.generate
140
+
141
+ lines.split("\n").each do |line|
142
+ out.puts " #{line}".yellow
143
+ end
144
+ out.puts "\n\n"
145
+
146
+ undefined_features << feature
147
+ end
148
+
149
+ # Adds a step that has been skipped to the output buffer.
150
+ #
151
+ # @param [Hash] step
152
+ # The step that Gherkin extracts
153
+ #
154
+ def on_skipped_step(step, step_definitions = nil)
155
+ output_step('~', step, :cyan)
156
+ end
157
+
158
+ # Adds to the output buffer a step result
159
+ #
160
+ # @param [String] symbol
161
+ # A symbol to prepend before the step keyword (might be useful to
162
+ # indicate if everything went ok or not).
163
+ #
164
+ # @param [Hash] step
165
+ # The step in a JSON Gherkin format
166
+ #
167
+ # @param [Symbol] color
168
+ # The color code to use with Colorize to colorize the output.
169
+ #
170
+ # @param [Array] step_location
171
+ # step source location and file line
172
+ #
173
+ def output_step(symbol, step, color, step_location = nil)
174
+ step_location = step_location.first.gsub("#{File.expand_path('.')}/", '# ')+":#{step_location.last.to_s}" if step_location
175
+ max_length = @max_step_name_length + 30 # Colorize and output format correction
176
+
177
+ # REMEMBER TO CORRECT PREVIOUS MAX LENGTH IF OUTPUT FORMAT IS MODIFIED
178
+ buffer = []
179
+ buffer << indent(4)
180
+ # buffer << symbol.foreground(color).bright
181
+ buffer << indent(2)
182
+ buffer << send(color, step.keyword)
183
+ buffer << indent(1)
184
+ buffer << send(color, step.name)
185
+ joined = buffer.join.ljust(max_length)
186
+
187
+ out.puts(joined + white(step_location.to_s))
188
+ end
189
+
190
+ # It prints the error summary if the run has failed
191
+ # It always print feature success summary
192
+ #
193
+ # @param [True,False] success
194
+ # whether the run has succeed or not
195
+ #
196
+ def after_run(success)
197
+ error_summary unless success
198
+ out.puts ""
199
+ run_summary
200
+ end
201
+
202
+ # Prints the feature success summary for this run.
203
+ #
204
+ def run_summary
205
+ successful_summary = format_summary(:green, successful_steps, 'Successful')
206
+ undefined_summary = format_summary(:yellow, undefined_steps, 'Undefined')
207
+ pending_summary = format_summary(:yellow, pending_steps, 'Pending')
208
+ failed_summary = format_summary(:red, failed_steps, 'Failed')
209
+ error_summary = format_summary(:red, error_steps, 'Error')
210
+
211
+ out.puts "Steps Summary: #{successful_summary}, #{undefined_summary}, #{pending_summary}, #{failed_summary}, #{error_summary}\n\n"
212
+ end
213
+
214
+ # Constructs the full step definition
215
+ #
216
+ # @param [Hash] step
217
+ # The step.
218
+ #
219
+ def full_step(step)
220
+ "#{step.keyword} #{step.name}"
221
+ end
222
+
223
+ private
224
+
225
+ def indent(n = 1)
226
+ " " * n
227
+ end
228
+
229
+ def format_summary(color, steps, message)
230
+ buffer = []
231
+ buffer << "(".colorize(color)
232
+ buffer << steps.length.to_s.colorize(:"light_#{color}")
233
+ buffer << ") ".colorize(color)
234
+ buffer << message.colorize(color)
235
+ buffer.join
236
+ end
237
+ def color(text, color_code)
238
+ "#{color_code}#{text}\e[0m"
239
+ end
240
+
241
+ def bold(text)
242
+ color(text, "\e[1m")
243
+ end
244
+
245
+ def red(text)
246
+ color(text, "\e[31m")
247
+ end
248
+
249
+ def green(text)
250
+ color(text, "\e[32m")
251
+ end
252
+
253
+ def yellow(text)
254
+ color(text, "\e[33m")
255
+ end
256
+
257
+ def blue(text)
258
+ color(text, "\e[34m")
259
+ end
260
+
261
+ def magenta(text)
262
+ color(text, "\e[35m")
263
+ end
264
+
265
+ def cyan(text)
266
+ color(text, "\e[36m")
267
+ end
268
+
269
+ def white(text)
270
+ color(text, "\e[37m")
271
+ end
272
+ end
273
+ end
274
+ end
@@ -20,5 +20,4 @@ end
20
20
  Spork.each_run do
21
21
  load "#{File.dirname(__FILE__)}/../lib/spinach-console-reporter.rb"
22
22
  Dir["#{File.dirname(__FILE__)}/../lib/spinach-console-reporter/*.rb"].each {|f| load f}
23
- end
24
-
23
+ end
@@ -15,7 +15,7 @@ Gem::Specification.new do |gem|
15
15
  gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
16
16
  gem.name = "spinach-console-reporter"
17
17
  gem.require_paths = ["lib"]
18
- gem.version = "0.0.1"
18
+ gem.version = "0.0.2"
19
19
  gem.add_runtime_dependency(%q<spinach>)
20
20
  gem.add_development_dependency(%q<rspec>)
21
21
  gem.add_development_dependency(%q<rake>)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: spinach-console-reporter
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-12-05 00:00:00.000000000 Z
12
+ date: 2013-04-12 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: spinach
@@ -156,10 +156,12 @@ files:
156
156
  - LICENSE
157
157
  - README.md
158
158
  - Rakefile
159
+ - images/after.png
160
+ - images/before.png
159
161
  - lib/spinach-console-reporter.rb
162
+ - lib/spinach-console-reporter/console.rb
160
163
  - lib/spinach-console-reporter/error_reporting.rb
161
164
  - lib/spinach-console-reporter/gem_description.rb
162
- - lib/spinach-console-reporter/out.rb
163
165
  - spec/spec_helper.rb
164
166
  - spinach-console-reporter.gemspec
165
167
  - tasks/ci.rake
@@ -183,7 +185,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
183
185
  version: '0'
184
186
  requirements: []
185
187
  rubyforge_project:
186
- rubygems_version: 1.8.23
188
+ rubygems_version: 1.8.25
187
189
  signing_key:
188
190
  specification_version: 3
189
191
  summary: A console reporter for spinach
@@ -1,276 +0,0 @@
1
- # encoding: utf-8
2
- module Spinach
3
- module Console
4
- module Reporter
5
- class Out < Spinach::Reporter
6
- include ErrorReporting
7
-
8
- # The output buffers to store the reports.
9
- attr_reader :out, :error
10
-
11
- # The last scenario error
12
- attr_accessor :scenario_error
13
-
14
- # The last scenario
15
- attr_accessor :scenario
16
-
17
- # Initialitzes the runner
18
- #
19
- # @param [Hash] options
20
- # Sets a custom output buffer by setting options[:output]
21
- # Sets a custom error buffer by setting options[:error]
22
- #
23
- def initialize(*args)
24
- super(*args)
25
- @out = options[:output] || $stdout
26
- @error = options[:error] || $stdout
27
- @max_step_name_length = 0
28
- end
29
-
30
- # Prints the feature name to the standard output
31
- #
32
- # @param [Hash] data
33
- # The feature in a JSON Gherkin format
34
- #
35
- def before_feature_run(feature)
36
- name = feature.name
37
- out.puts %Q|\n#{magenta("Feature:")} #{magenta(name)}|
38
- end
39
-
40
- # Prints the scenario name to the standard ouput
41
- #
42
- # @param [Hash] data
43
- # The feature in a JSON Gherkin format
44
- #
45
- def before_scenario_run(scenario, step_definitions = nil)
46
- @max_step_name_length = scenario.steps.map(&:name).map(&:length).max if scenario.steps.any?
47
- name = scenario.name
48
- out.puts "\n #{green('Scenario:')} #{green(name)}"
49
- end
50
-
51
- # Adds an error report and re
52
- #
53
- # @param [Hash] data
54
- # The feature in a JSON Gherkin format
55
- #
56
- def after_scenario_run(scenario, step_definitions = nil)
57
- if scenario_error
58
- report_error(scenario_error, :full)
59
- self.scenario_error = nil
60
- end
61
- end
62
-
63
- # Adds a passed step to the output buffer.
64
- #
65
- # @param [Step] step
66
- # The step.
67
- #
68
- # @param [Array] step_location
69
- # The step source location
70
- #
71
- def on_successful_step(step, step_location, step_definitions = nil)
72
- output_step('✔', step, :green, step_location)
73
- self.scenario = [current_feature, current_scenario, step]
74
- successful_steps << scenario
75
- end
76
-
77
- # Adds a failing step to the output buffer.
78
- #
79
- # @param [Hash] step
80
- # The step in a JSON Gherkin format
81
- #
82
- # @param [Exception] failure
83
- # The exception that caused the failure
84
- #
85
- def on_failed_step(step, failure, step_location, step_definitions = nil)
86
- output_step('✘', step, :red, step_location)
87
- self.scenario_error = [current_feature, current_scenario, step, failure]
88
- failed_steps << scenario_error
89
- end
90
-
91
- # Adds a step that has raised an error to the output buffer.
92
- #
93
- # @param [Hash] step
94
- # The step in a JSON Gherkin format
95
- #
96
- # @param [Exception] failure
97
- # The exception that caused the failure
98
- #
99
- def on_error_step(step, failure, step_location, step_definitions = nil)
100
- output_step('!', step, :red, step_location)
101
- self.scenario_error = [current_feature, current_scenario, step, failure]
102
- error_steps << scenario_error
103
- end
104
-
105
- # Adds an undefined step to the output buffer.
106
- #
107
- # @param [Hash] step
108
- # The step in a JSON Gherkin format
109
- #
110
- def on_undefined_step(step, failure, step_definitions = nil)
111
- output_step('?', step, :yellow)
112
- self.scenario_error = [current_feature, current_scenario, step, failure]
113
- undefined_steps << scenario_error
114
- end
115
-
116
- # Adds an undefined step to the output buffer.
117
- #
118
- # @param [Hash] step
119
- # The step in a JSON Gherkin format
120
- #
121
- def on_pending_step(step, failure)
122
- output_step('P', step, :yellow)
123
- self.scenario_error = [current_feature, current_scenario, step, failure]
124
- pending_steps << scenario_error
125
- end
126
-
127
- # Adds a feature not found message to the output buffer.
128
- #
129
- # @param [Hash] feature
130
- # the feature in a json gherkin format
131
- #
132
- # @param [Spinach::FeatureNotFoundException] exception
133
- # the related exception
134
- #
135
- def on_feature_not_found(feature)
136
- generator = Generators::FeatureGenerator.new(feature)
137
- lines = "Could not find steps for `#{feature.name}` feature\n\n"
138
- lines << "\nPlease create the file #{generator.filename} at #{generator.path}, with:\n\n"
139
-
140
- lines << generator.generate
141
-
142
- lines.split("\n").each do |line|
143
- out.puts " #{line}".yellow
144
- end
145
- out.puts "\n\n"
146
-
147
- undefined_features << feature
148
- end
149
-
150
- # Adds a step that has been skipped to the output buffer.
151
- #
152
- # @param [Hash] step
153
- # The step that Gherkin extracts
154
- #
155
- def on_skipped_step(step, step_definitions = nil)
156
- output_step('~', step, :cyan)
157
- end
158
-
159
- # Adds to the output buffer a step result
160
- #
161
- # @param [String] symbol
162
- # A symbol to prepend before the step keyword (might be useful to
163
- # indicate if everything went ok or not).
164
- #
165
- # @param [Hash] step
166
- # The step in a JSON Gherkin format
167
- #
168
- # @param [Symbol] color
169
- # The color code to use with Colorize to colorize the output.
170
- #
171
- # @param [Array] step_location
172
- # step source location and file line
173
- #
174
- def output_step(symbol, step, color, step_location = nil)
175
- step_location = step_location.first.gsub("#{File.expand_path('.')}/", '# ')+":#{step_location.last.to_s}" if step_location
176
- max_length = @max_step_name_length + 30 # Colorize and output format correction
177
-
178
- # REMEMBER TO CORRECT PREVIOUS MAX LENGTH IF OUTPUT FORMAT IS MODIFIED
179
- buffer = []
180
- buffer << indent(4)
181
- # buffer << symbol.foreground(color).bright
182
- buffer << indent(2)
183
- buffer << send(color, step.keyword)
184
- buffer << indent(1)
185
- buffer << send(color, step.name)
186
- joined = buffer.join.ljust(max_length)
187
-
188
- out.puts(joined + white(step_location.to_s))
189
- end
190
-
191
- # It prints the error summary if the run has failed
192
- # It always print feature success summary
193
- #
194
- # @param [True,False] success
195
- # whether the run has succeed or not
196
- #
197
- def after_run(success)
198
- error_summary unless success
199
- out.puts ""
200
- run_summary
201
- end
202
-
203
- # Prints the feature success summary for this run.
204
- #
205
- def run_summary
206
- successful_summary = format_summary(:green, successful_steps, 'Successful')
207
- undefined_summary = format_summary(:yellow, undefined_steps, 'Undefined')
208
- pending_summary = format_summary(:yellow, pending_steps, 'Pending')
209
- failed_summary = format_summary(:red, failed_steps, 'Failed')
210
- error_summary = format_summary(:red, error_steps, 'Error')
211
-
212
- out.puts "Steps Summary: #{successful_summary}, #{undefined_summary}, #{pending_summary}, #{failed_summary}, #{error_summary}\n\n"
213
- end
214
-
215
- # Constructs the full step definition
216
- #
217
- # @param [Hash] step
218
- # The step.
219
- #
220
- def full_step(step)
221
- "#{step.keyword} #{step.name}"
222
- end
223
-
224
- private
225
-
226
- def indent(n = 1)
227
- " " * n
228
- end
229
-
230
- def format_summary(color, steps, message)
231
- buffer = []
232
- buffer << "(".colorize(color)
233
- buffer << steps.length.to_s.colorize(:"light_#{color}")
234
- buffer << ") ".colorize(color)
235
- buffer << message.colorize(color)
236
- buffer.join
237
- end
238
- def color(text, color_code)
239
- "#{color_code}#{text}\e[0m"
240
- end
241
-
242
- def bold(text)
243
- color(text, "\e[1m")
244
- end
245
-
246
- def red(text)
247
- color(text, "\e[31m")
248
- end
249
-
250
- def green(text)
251
- color(text, "\e[32m")
252
- end
253
-
254
- def yellow(text)
255
- color(text, "\e[33m")
256
- end
257
-
258
- def blue(text)
259
- color(text, "\e[34m")
260
- end
261
-
262
- def magenta(text)
263
- color(text, "\e[35m")
264
- end
265
-
266
- def cyan(text)
267
- color(text, "\e[36m")
268
- end
269
-
270
- def white(text)
271
- color(text, "\e[37m")
272
- end
273
- end
274
- end
275
- end
276
- end