cucumber_spinner 0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 Henning Koch
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,49 @@
1
+ = CucumberSpinner
2
+
3
+ CucumberSpinner is a formatter for Cucumber. It allows you to show the progress
4
+ of your running features as a progress bar. Failing features are outputted at
5
+ once, not at the end of your feature run.
6
+
7
+ == Installation
8
+
9
+ Install the gem with
10
+
11
+ sudo gem install cucumber_spinner
12
+
13
+ To use the CucumberSpinner formatter, call cucumber with the following command
14
+ line option:
15
+
16
+ --formatter CucumberSpinner::ProgressBarFormatter --require cucumber_spinner
17
+
18
+ You might want to use an alias, so for example put this at the end of your
19
+ .bashrc
20
+ alias cuc='script/cucumber --formatter CucumberSpinner::ProgressBarFormatter --require cucumber_spinner'
21
+ and then start your features with
22
+ cuc features
23
+
24
+ Alternatively, you can require 'cucumber_spinner' in your cucumber environment,
25
+ and modify your config/cucumber.yml.
26
+
27
+
28
+ === Caveats
29
+
30
+ This has only been tested on cucumber 0.8.3 and ruby 1.8.7. Since cucumber does
31
+ not expose every information we need (like the total number of steps) cleanly,
32
+ this might easily break for other cucumber versions.
33
+
34
+ There are currently no tests either.
35
+
36
+
37
+ === Credits
38
+
39
+ Licensed under the MIT License.
40
+
41
+ The Gem is inspired and based on nofxx's RSpecSpinner gem
42
+ (http://github.com/nofxx/rspec_spinner), which is in turn based on the Advanced Progress Bar by Nicholas A. Evans.
43
+
44
+
45
+ Written by Tobias Kraze
46
+
47
+ {makandra.com}[http://makandra.com/]
48
+
49
+ {gem-session.com}[http://gem-session.com/]
@@ -0,0 +1,38 @@
1
+ require 'rake'
2
+ require 'rake/rdoctask'
3
+ require 'spec/rake/spectask'
4
+
5
+ desc 'Default: Run all specs.'
6
+ task :default => :spec
7
+
8
+ desc "Run all specs"
9
+ Spec::Rake::SpecTask.new() do |t|
10
+ t.spec_opts = ['--options', "\"spec/support/spec.opts\""]
11
+ t.spec_files = FileList['spec/**/*_spec.rb']
12
+ end
13
+
14
+ desc 'Generate documentation for the cucumber_spinner gem.'
15
+ Rake::RDocTask.new(:rdoc) do |rdoc|
16
+ rdoc.rdoc_dir = 'rdoc'
17
+ rdoc.title = 'mail_magnet'
18
+ rdoc.options << '--line-numbers' << '--inline-source'
19
+ rdoc.rdoc_files.include('README')
20
+ rdoc.rdoc_files.include('lib/**/*.rb')
21
+ end
22
+
23
+ begin
24
+ require 'jeweler'
25
+ Jeweler::Tasks.new do |gemspec|
26
+ gemspec.name = "cucumber_spinner"
27
+ gemspec.version = '0.1'
28
+ gemspec.summary = "Progress bar formatter for cucumber, shows failing scenarios immediately."
29
+ gemspec.email = "tobias.kraze@makandra.de"
30
+ gemspec.homepage = "http://github.com/makandra/cucumber_spinner"
31
+ gemspec.description = "Formatter for cucumber like the RSpecSpinner for RSpec. Shows a progress bar on the command line and prints failing scenarios immediately."
32
+ gemspec.authors = ["Tobias Kraze"]
33
+ gemspec.add_dependency('rtui', '>=0.2.2')
34
+ end
35
+ rescue LoadError
36
+ puts "Jeweler not available. Install it with: sudo gem install jeweler"
37
+ end
38
+
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1
@@ -0,0 +1,47 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{cucumber_spinner}
8
+ s.version = "0.1"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Tobias Kraze"]
12
+ s.date = %q{2010-07-28}
13
+ s.description = %q{Formatter for cucumber like the RSpecSpinner for RSpec. Shows a progress bar on the command line and prints failing scenarios immediately.}
14
+ s.email = %q{tobias.kraze@makandra.de}
15
+ s.extra_rdoc_files = [
16
+ "README.rdoc"
17
+ ]
18
+ s.files = [
19
+ "MIT-LICENSE",
20
+ "README.rdoc",
21
+ "Rakefile",
22
+ "VERSION",
23
+ "cucumber_spinner.gemspec",
24
+ "lib/cucumber_spinner.rb",
25
+ "lib/cucumber_spinner/formatted_io.rb",
26
+ "lib/cucumber_spinner/progress_bar_formatter.rb"
27
+ ]
28
+ s.homepage = %q{http://github.com/makandra/cucumber_spinner}
29
+ s.rdoc_options = ["--charset=UTF-8"]
30
+ s.require_paths = ["lib"]
31
+ s.rubygems_version = %q{1.3.6}
32
+ s.summary = %q{Progress bar formatter for cucumber, shows failing scenarios immediately.}
33
+
34
+ if s.respond_to? :specification_version then
35
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
36
+ s.specification_version = 3
37
+
38
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
39
+ s.add_runtime_dependency(%q<rtui>, [">= 0.2.2"])
40
+ else
41
+ s.add_dependency(%q<rtui>, [">= 0.2.2"])
42
+ end
43
+ else
44
+ s.add_dependency(%q<rtui>, [">= 0.2.2"])
45
+ end
46
+ end
47
+
@@ -0,0 +1,2 @@
1
+ require 'cucumber_spinner/formatted_io'
2
+ require 'cucumber_spinner/progress_bar_formatter'
@@ -0,0 +1,23 @@
1
+ require 'cucumber/formatter/console'
2
+
3
+ module CucumberSpinner
4
+
5
+ class FormattedIo
6
+ include Cucumber::Formatter::Console
7
+
8
+ attr_writer :status
9
+
10
+ def initialize(io)
11
+ @io = io
12
+ end
13
+
14
+ def print(string)
15
+ @io.print(format_string(string, @status))
16
+ end
17
+
18
+ def method_missing(method_name, *args)
19
+ @io.send(method_name, *args)
20
+ end
21
+ end
22
+
23
+ end
@@ -0,0 +1,155 @@
1
+ require 'cucumber/formatter/io'
2
+ require 'cucumber/formatter/pretty'
3
+ require 'rtui'
4
+
5
+ module CucumberSpinner
6
+
7
+ class ProgressBarFormatter
8
+ include Cucumber::Formatter::Io
9
+
10
+ attr_reader :step_mother
11
+
12
+ def initialize(step_mother, path_or_io, options)
13
+ @step_mother, @io, @options = step_mother, ensure_io(path_or_io, "progress"), options
14
+ @error_state = :passed
15
+ @coloured_io = FormattedIo.new(@io)
16
+ @coloured_io.status = @error_state
17
+ @pretty_printer_io = StringIO.new
18
+ @pretty_printer = Cucumber::Formatter::Pretty.new(step_mother, @pretty_printer_io, options)
19
+ end
20
+
21
+
22
+ def before_features(features)
23
+ @current = 0
24
+ @total = get_step_count(features)
25
+ @progress_bar = RTUI::Progress.new("#{@total} steps", @total, {:out => @coloured_io})
26
+ end
27
+
28
+ def after_step_result(keyword, step_match, multiline_arg, status, exception, source_indent, background)
29
+ increment
30
+
31
+ case status
32
+ when :pending: pending!
33
+ when :failed:
34
+ failed!
35
+ print_scenario
36
+ when :undefined:
37
+ undefined!
38
+ print_scenario
39
+ end
40
+ end
41
+
42
+ def after_features(features)
43
+ @io.puts
44
+ @io.puts
45
+ clear_pretty_output
46
+ @pretty_printer.after_features(features)
47
+ print_pretty_output
48
+ end
49
+
50
+ def before_feature_element(feature_element)
51
+ clear_pretty_output
52
+ @pretty_printer.before_feature_element(feature_element)
53
+ end
54
+
55
+ def self.delegate_to_pretty_printer(*methods)
56
+ methods.each do |method|
57
+ define_method(method) do |*args|
58
+ @pretty_printer.send(method, *args)
59
+ end
60
+ end
61
+ end
62
+ delegate_to_pretty_printer :before_feature, :comment_line, :after_tags, :tag_name, :feature_name, :after_feature_element, :before_background, :after_background, :background_name, :before_examples_array, :examples_name, :before_outline_table, :after_outline_table, :scenario_name, :before_step, :before_step_result, :step_name, :py_string, :exception, :before_multiline_arg, :after_multiline_arg, :before_table_row, :after_table_row, :after_table_cell, :table_cell_value
63
+
64
+
65
+ private
66
+
67
+ def clear_pretty_output
68
+ @pretty_printer_io.truncate(0)
69
+ end
70
+
71
+ def print_pretty_output
72
+ @io.print @pretty_printer_io.string
73
+ end
74
+
75
+ def print_scenario
76
+ erase_current_line
77
+ print_pretty_output
78
+ @io.puts
79
+ end
80
+
81
+ def erase_current_line
82
+ @io.print "\e[K"
83
+ end
84
+
85
+ def increment
86
+ with_color do
87
+ @current += 1
88
+ # HACK: need to make sure the progress is printed, even when the bar hasn't changed
89
+ @progress_bar.instance_variable_set("@previous", 0)
90
+ @progress_bar.instance_variable_set("@title", "#{@current}/#{@total}")
91
+ @progress_bar.inc
92
+ end
93
+ @io.flush
94
+ end
95
+
96
+ # stolen from the html formatter
97
+ def get_step_count(features)
98
+ count = 0
99
+ features = features.instance_variable_get("@features")
100
+ features.each do |feature|
101
+ #get background steps
102
+ if feature.instance_variable_get("@background")
103
+ background = feature.instance_variable_get("@background")
104
+ background.init
105
+ background_steps = background.instance_variable_get("@steps").instance_variable_get("@steps")
106
+ count += background_steps.size
107
+ end
108
+ #get scenarios
109
+ feature.instance_variable_get("@feature_elements").each do |scenario|
110
+ scenario.init
111
+ #get steps
112
+ steps = scenario.instance_variable_get("@steps").instance_variable_get("@steps")
113
+ count += steps.size
114
+
115
+ #get example table
116
+ examples = scenario.instance_variable_get("@examples_array")
117
+ unless examples.nil?
118
+ examples.each do |example|
119
+ example_matrix = example.instance_variable_get("@outline_table").instance_variable_get("@cell_matrix")
120
+ count += example_matrix.size
121
+ end
122
+ end
123
+
124
+ #get multiline step tables
125
+ steps.each do |step|
126
+ multi_arg = step.instance_variable_get("@multiline_arg")
127
+ next if multi_arg.nil?
128
+ matrix = multi_arg.instance_variable_get("@cell_matrix")
129
+ count += matrix.size unless matrix.nil?
130
+ end
131
+ end
132
+ end
133
+ return count
134
+ end
135
+
136
+ def pending!
137
+ @error_state = :pending if @error_state == :passed
138
+ end
139
+
140
+ def undefined!
141
+ @error_state = :undefined unless @error_state == :failed
142
+ end
143
+
144
+ def failed!
145
+ @error_state = :failed
146
+ end
147
+
148
+ def with_color
149
+ @coloured_io.status = @error_state
150
+ yield
151
+ end
152
+
153
+ end
154
+
155
+ end
metadata ADDED
@@ -0,0 +1,81 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: cucumber_spinner
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 1
8
+ version: "0.1"
9
+ platform: ruby
10
+ authors:
11
+ - Tobias Kraze
12
+ autorequire:
13
+ bindir: bin
14
+ cert_chain: []
15
+
16
+ date: 2010-07-28 00:00:00 +02:00
17
+ default_executable:
18
+ dependencies:
19
+ - !ruby/object:Gem::Dependency
20
+ name: rtui
21
+ prerelease: false
22
+ requirement: &id001 !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ segments:
27
+ - 0
28
+ - 2
29
+ - 2
30
+ version: 0.2.2
31
+ type: :runtime
32
+ version_requirements: *id001
33
+ description: Formatter for cucumber like the RSpecSpinner for RSpec. Shows a progress bar on the command line and prints failing scenarios immediately.
34
+ email: tobias.kraze@makandra.de
35
+ executables: []
36
+
37
+ extensions: []
38
+
39
+ extra_rdoc_files:
40
+ - README.rdoc
41
+ files:
42
+ - MIT-LICENSE
43
+ - README.rdoc
44
+ - Rakefile
45
+ - VERSION
46
+ - cucumber_spinner.gemspec
47
+ - lib/cucumber_spinner.rb
48
+ - lib/cucumber_spinner/formatted_io.rb
49
+ - lib/cucumber_spinner/progress_bar_formatter.rb
50
+ has_rdoc: true
51
+ homepage: http://github.com/makandra/cucumber_spinner
52
+ licenses: []
53
+
54
+ post_install_message:
55
+ rdoc_options:
56
+ - --charset=UTF-8
57
+ require_paths:
58
+ - lib
59
+ required_ruby_version: !ruby/object:Gem::Requirement
60
+ requirements:
61
+ - - ">="
62
+ - !ruby/object:Gem::Version
63
+ segments:
64
+ - 0
65
+ version: "0"
66
+ required_rubygems_version: !ruby/object:Gem::Requirement
67
+ requirements:
68
+ - - ">="
69
+ - !ruby/object:Gem::Version
70
+ segments:
71
+ - 0
72
+ version: "0"
73
+ requirements: []
74
+
75
+ rubyforge_project:
76
+ rubygems_version: 1.3.6
77
+ signing_key:
78
+ specification_version: 3
79
+ summary: Progress bar formatter for cucumber, shows failing scenarios immediately.
80
+ test_files: []
81
+