rspec_spinner 0.4.5

Sign up to get free protection for your applications and to get access to all the features.
data/History.txt ADDED
@@ -0,0 +1,4 @@
1
+ == 0.0.1 2008-12-18
2
+
3
+ * 1 major enhancement:
4
+ * Initial release
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2008 Nicholas A. Evans, Marcos Piccinini
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.
data/Manifest.txt ADDED
@@ -0,0 +1,18 @@
1
+ History.txt
2
+ MIT-LICENSE
3
+ Manifest.txt
4
+ PostInstall.txt
5
+ README.rdoc
6
+ Rakefile
7
+ lib/rspec_spinner.rb
8
+ lib/rspec_spinner/bar.rb
9
+ lib/rspec_spinner/base.rb
10
+ lib/rspec_spinner/spinner.rb
11
+ rspec_spinner.gemspec
12
+ script/console
13
+ script/destroy
14
+ script/generate
15
+ spec/rspec_spinner_spec.rb
16
+ spec/spec.opts
17
+ spec/spec_helper.rb
18
+ tasks/rspec.rake
data/PostInstall.txt ADDED
@@ -0,0 +1,21 @@
1
+ == TO USE:
2
+
3
+ Require RspecSpinner on spec/spec_helper.rb:
4
+
5
+ require 'spec'
6
+ require 'rspec_spinner'
7
+ ...
8
+
9
+
10
+ Change your spec.opts --formatter to "spinner":
11
+
12
+ --formatter RspecSpinner::Bar
13
+
14
+ or:
15
+
16
+ --formatter RspecSpinner::Spinner
17
+
18
+
19
+ Have fun!
20
+
21
+ http://github.com/nofxx/rspec_spinner
data/README.rdoc ADDED
@@ -0,0 +1,59 @@
1
+ = rspec-spinner
2
+
3
+ * http://github.com/nofxx/rspec-spinner
4
+
5
+ Adds an extra formatter that looks like this:
6
+
7
+ Foo::Error ......
8
+ SLOW SPEC: 10.0314 Foo should raise Bar
9
+ PENDING SPEC: Foo should get Bar
10
+ 891/1808: 49% |======================= | ETA: 00:00:21
11
+
12
+
13
+ Or this:
14
+
15
+ 46% \ ETA: 00:00:23
16
+
17
+
18
+ No dots and Fs, just what you need to know: FAILURES, PENDINGS and SLOW ones.
19
+
20
+
21
+ == INSTALL:
22
+
23
+ sudo gem install rspec_spinner
24
+
25
+
26
+ == TO USE:
27
+
28
+ Require RspecSpinner on spec/spec_helper.rb:
29
+
30
+ require 'spec'
31
+ require 'rspec_spinner'
32
+ ...
33
+
34
+
35
+ Change your spec.opts --formatter to:
36
+
37
+ --formatter RspecSpinner::Bar
38
+
39
+ or:
40
+
41
+ --formatter RspecSpinner::Spinner
42
+
43
+
44
+ Have fun!
45
+
46
+
47
+ == REQUIREMENTS:
48
+
49
+ * rspec
50
+ * rtui (http://github.com/nofxx/rtui)
51
+
52
+
53
+ == LICENSE:
54
+
55
+ (The MIT License)
56
+
57
+ Based on the Advanced Progress Bar by Nicholas A. Evans
58
+
59
+ Copyright (c) 2008 Marcos Piccinini
data/Rakefile ADDED
@@ -0,0 +1,32 @@
1
+ %w[rubygems rake rake/clean fileutils newgem rubigen].each { |f| require f }
2
+ require File.dirname(__FILE__) + '/lib/rspec_spinner'
3
+
4
+ # Generate all the Rake tasks
5
+ # Run 'rake -T' to see list of generated tasks (from gem root directory)
6
+ $hoe = Hoe.new('rspec_spinner', RspecSpinner::VERSION) do |p|
7
+ p.developer('Marcos Piccinini', 'x@nofxx.com')
8
+ p.summary = "Some extra formatters for rspec"
9
+ p.description = "Some extra formatters for rspec"
10
+ p.url = "http://github.com/nofxx/postgis_adapter"
11
+ p.changes = p.paragraphs_of("History.txt", 0..1).join("\n\n")
12
+ p.post_install_message = 'PostInstall.txt'
13
+ p.rubyforge_name = p.name # TODO this is default value
14
+ p.extra_deps = [
15
+ ['rspec','>=1.1.11'],
16
+ ['rtui','>= 0.1.8']
17
+ ]
18
+ p.extra_dev_deps = [
19
+ ['newgem', ">= #{::Newgem::VERSION}"]
20
+ ]
21
+
22
+ p.clean_globs |= %w[**/.DS_Store tmp *.log]
23
+ path = (p.rubyforge_name == p.name) ? p.rubyforge_name : "\#{p.rubyforge_name}/\#{p.name}"
24
+ p.remote_rdoc_dir = File.join(path.gsub(/^#{p.rubyforge_name}\/?/,''), 'rdoc')
25
+ p.rsync_args = '-av --delete --ignore-errors'
26
+ end
27
+
28
+ require 'newgem/tasks' # load /tasks/*.rake
29
+ Dir['tasks/**/*.rake'].each { |t| load t }
30
+
31
+ # TODO - want other tests/tasks run by default? Add them to the list
32
+ # task :default => [:spec, :features]
@@ -0,0 +1,16 @@
1
+ module RspecSpinner
2
+ class Bar < RspecSpinnerBase
3
+
4
+
5
+ def start(example_count)
6
+ @current = 0
7
+ @total = example_count
8
+ @error_state = :all_passing
9
+ @pbar = Rtui::Progress.new("#{example_count} examples", example_count,
10
+ {:out => output})
11
+ end
12
+ end
13
+ end
14
+
15
+
16
+
@@ -0,0 +1,129 @@
1
+ require "spec/runner/formatter/base_text_formatter"
2
+ require "rubygems"
3
+ require "rtui"
4
+
5
+ module RspecSpinner
6
+ class RspecSpinnerBase < Spec::Runner::Formatter::BaseTextFormatter
7
+ # Threshold for slow specs, in seconds.
8
+ # Anything that takes longer than this will be printed out
9
+ #THRESHOLD = 0.25
10
+ THRESHOLD = 3.0
11
+
12
+ attr_reader :total, :current
13
+
14
+ def start(example_count)
15
+ @current = 0
16
+ # @subject = "oi"
17
+ @total = example_count
18
+ @error_state = :all_passing
19
+ @pbar = Rtui::Progress.new("#{example_count} examples", example_count,
20
+ {:out => output, :components => [:percentage, :spinner, :stat]})
21
+ @pbar.subject = "Starting..."
22
+ end
23
+
24
+ def example_started(example)
25
+ super
26
+ @start_time = Time.now
27
+ end
28
+
29
+ def example_passed(example)
30
+ print_warning_if_slow(example_group.description,
31
+ example.description,
32
+ Time.now - @start_time)
33
+ increment
34
+ end
35
+
36
+ # third param is optional, because earlier versions of rspec sent only two args
37
+ def example_pending(example, message, pending_caller=nil)
38
+ immediately_dump_pending(example.full_description, message, pending_caller)
39
+ mark_error_state_pending
40
+ increment
41
+ end
42
+
43
+ def example_failed(example, counter, failure)
44
+ immediately_dump_failure(counter, failure)
45
+ mark_error_state_failed
46
+ increment
47
+ end
48
+
49
+ def start_dump
50
+ @pbar.subject = ""
51
+ with_color do
52
+ @pbar.finish
53
+ end
54
+ output.flush
55
+ end
56
+
57
+ def dump_failure(*args)
58
+ # no-op; we summarized failures as we were running
59
+ end
60
+
61
+ def method_missing(sym, *args)
62
+ # ignore
63
+ end
64
+
65
+ # stolen and slightly modified from BaseTextFormatter#dump_failure
66
+ def immediately_dump_failure(counter, failure)
67
+ erase_current_line
68
+ output.puts
69
+ output.print "#{counter.to_s}) "
70
+ output.puts colourise("#{failure.header}\n#{failure.exception.message}", failure)
71
+ output.puts format_backtrace(failure.exception.backtrace)
72
+ output.puts
73
+ end
74
+
75
+ # stolen and modified from BaseTextFormatter#dump_pending
76
+ def immediately_dump_pending(desc, msg, called_from)
77
+ erase_current_line
78
+ output.puts yellow("PENDING SPEC:") + " #{desc} (#{msg})"
79
+ output.puts " Called from #{called_from}" if called_from
80
+ end
81
+
82
+ def increment
83
+ with_color do
84
+ @current += 1
85
+ # HACK: need to make sure the progress is printed, even when the bar hasn't changed
86
+ @pbar.instance_variable_set("@previous", 0)
87
+ @pbar.instance_variable_set("@title", "#{current}/#{total}")
88
+ @pbar.inc
89
+ # @pbar.subject = @subject if @subject
90
+ end
91
+ output.flush
92
+ end
93
+
94
+ ERROR_STATE_COLORS = {
95
+ :all_passing => "\e[32m", # green
96
+ :some_pending => "\e[33m", # yellow
97
+ :some_failed => "\e[31m", # red
98
+ }
99
+
100
+ def with_color
101
+ use_color = colour? && output_to_tty?
102
+ output.print ERROR_STATE_COLORS[@error_state] if use_color
103
+ yield
104
+ output.print "\e[0m" if use_color
105
+ end
106
+
107
+ def mark_error_state_failed
108
+ @error_state = :some_failed
109
+ end
110
+
111
+ def mark_error_state_pending
112
+ @error_state = :some_pending unless @error_state == :some_failed
113
+ end
114
+
115
+ def erase_current_line
116
+ output.print "\e[K"
117
+ end
118
+
119
+ def print_warning_if_slow(group, example, elapsed)
120
+ if elapsed > THRESHOLD
121
+ #mark_error_state(:pending)
122
+ erase_current_line
123
+ output.print yellow("SLOW SPEC: #{sprintf("%.4f", elapsed)} ")
124
+ output.print " #{group} #{example}"
125
+ output.puts
126
+ end
127
+ end
128
+ end
129
+ end
@@ -0,0 +1,18 @@
1
+ module RspecSpinner
2
+ class Spinner < RspecSpinnerBase
3
+
4
+
5
+ def start(example_count)
6
+ @current = 0
7
+ @total = example_count
8
+ @error_state = :all_passing
9
+ @pbar = Rtui::Progress.new("#{example_count} examples", example_count,
10
+ {:out => output, :components => [:percentage, :spinner, :subject, :stat]})
11
+ end
12
+
13
+ def example_started(example)
14
+ @pbar.subject = example.description
15
+ super
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,18 @@
1
+ $:.unshift(File.dirname(__FILE__)) unless
2
+ $:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
3
+ #require "spec/runner/options"
4
+ require "rspec_spinner/base"
5
+ require "rspec_spinner/spinner"
6
+ require "rspec_spinner/bar"
7
+
8
+ module RspecSpinner
9
+ VERSION = '0.4.5'
10
+ end
11
+
12
+ #module Spec
13
+ # module Runner
14
+ # class Options
15
+ # EXAMPLE_FORMATTERS.merge({ 'spinner' => ['spec/runner/formatter/spinner_formatter', 'Formatter::SpinnerFormatter'] })
16
+ # end
17
+ ## end
18
+ #end
@@ -0,0 +1,44 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = %q{rspec_spinner}
5
+ s.version = "0.4.5"
6
+
7
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
+ s.authors = ["Marcos Piccinini"]
9
+ s.date = %q{2008-12-21}
10
+ s.description = %q{Some extra formatters for rspec}
11
+ s.email = ["x@nofxx.com"]
12
+ s.extra_rdoc_files = ["History.txt", "Manifest.txt", "PostInstall.txt", "README.rdoc"]
13
+ s.files = ["History.txt", "MIT-LICENSE", "Manifest.txt", "PostInstall.txt", "README.rdoc", "Rakefile", "lib/rspec_spinner.rb", "lib/rspec_spinner/bar.rb", "lib/rspec_spinner/base.rb", "lib/rspec_spinner/spinner.rb", "rspec_spinner.gemspec", "script/console", "script/destroy", "script/generate", "spec/rspec_spinner_spec.rb", "spec/spec.opts", "spec/spec_helper.rb", "tasks/rspec.rake"]
14
+ s.has_rdoc = true
15
+ s.homepage = %q{http://github.com/nofxx/postgis_adapter}
16
+ s.post_install_message = %q{PostInstall.txt}
17
+ s.rdoc_options = ["--main", "README.rdoc"]
18
+ s.require_paths = ["lib"]
19
+ s.rubyforge_project = %q{rspec_spinner}
20
+ s.rubygems_version = %q{1.3.1}
21
+ s.summary = %q{Some extra formatters for rspec}
22
+
23
+ if s.respond_to? :specification_version then
24
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
25
+ s.specification_version = 2
26
+
27
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
28
+ s.add_runtime_dependency(%q<rspec>, [">= 1.1.11"])
29
+ s.add_runtime_dependency(%q<rtui>, [">= 0.1.8"])
30
+ s.add_development_dependency(%q<newgem>, [">= 1.2.1"])
31
+ s.add_development_dependency(%q<hoe>, [">= 1.8.0"])
32
+ else
33
+ s.add_dependency(%q<rspec>, [">= 1.1.11"])
34
+ s.add_dependency(%q<rtui>, [">= 0.1.8"])
35
+ s.add_dependency(%q<newgem>, [">= 1.2.1"])
36
+ s.add_dependency(%q<hoe>, [">= 1.8.0"])
37
+ end
38
+ else
39
+ s.add_dependency(%q<rspec>, [">= 1.1.11"])
40
+ s.add_dependency(%q<rtui>, [">= 0.1.8"])
41
+ s.add_dependency(%q<newgem>, [">= 1.2.1"])
42
+ s.add_dependency(%q<hoe>, [">= 1.8.0"])
43
+ end
44
+ end
data/script/console ADDED
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env ruby
2
+ # File: script/console
3
+ irb = RUBY_PLATFORM =~ /(:?mswin|mingw)/ ? 'irb.bat' : 'irb'
4
+
5
+ libs = " -r irb/completion"
6
+ # Perhaps use a console_lib to store any extra methods I may want available in the cosole
7
+ # libs << " -r #{File.dirname(__FILE__) + '/../lib/console_lib/console_logger.rb'}"
8
+ libs << " -r #{File.dirname(__FILE__) + '/../lib/rspec-spinner.rb'}"
9
+ puts "Loading rspec-spinner gem"
10
+ exec "#{irb} #{libs} --simple-prompt"
data/script/destroy ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+ APP_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..'))
3
+
4
+ begin
5
+ require 'rubigen'
6
+ rescue LoadError
7
+ require 'rubygems'
8
+ require 'rubigen'
9
+ end
10
+ require 'rubigen/scripts/destroy'
11
+
12
+ ARGV.shift if ['--help', '-h'].include?(ARGV[0])
13
+ RubiGen::Base.use_component_sources! [:rubygems, :newgem, :newgem_theme, :test_unit]
14
+ RubiGen::Scripts::Destroy.new.run(ARGV)
data/script/generate ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+ APP_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..'))
3
+
4
+ begin
5
+ require 'rubigen'
6
+ rescue LoadError
7
+ require 'rubygems'
8
+ require 'rubigen'
9
+ end
10
+ require 'rubigen/scripts/generate'
11
+
12
+ ARGV.shift if ['--help', '-h'].include?(ARGV[0])
13
+ RubiGen::Base.use_component_sources! [:rubygems, :newgem, :newgem_theme, :test_unit]
14
+ RubiGen::Scripts::Generate.new.run(ARGV)
@@ -0,0 +1,11 @@
1
+ require File.dirname(__FILE__) + '/spec_helper.rb'
2
+
3
+ # Time to add your specs!
4
+ # http://rspec.info/
5
+ describe "Place your specs here" do
6
+
7
+ it "find this spec in spec directory" do
8
+ violated "Be sure to write your specs"
9
+ end
10
+
11
+ end
data/spec/spec.opts ADDED
@@ -0,0 +1 @@
1
+ --colour
@@ -0,0 +1,10 @@
1
+ begin
2
+ require 'spec'
3
+ rescue LoadError
4
+ require 'rubygems'
5
+ gem 'rspec'
6
+ require 'spec'
7
+ end
8
+
9
+ $:.unshift(File.dirname(__FILE__) + '/../lib')
10
+ require 'rspec-spinner'
data/tasks/rspec.rake ADDED
@@ -0,0 +1,21 @@
1
+ begin
2
+ require 'spec'
3
+ rescue LoadError
4
+ require 'rubygems'
5
+ require 'spec'
6
+ end
7
+ begin
8
+ require 'spec/rake/spectask'
9
+ rescue LoadError
10
+ puts <<-EOS
11
+ To use rspec for testing you must install rspec gem:
12
+ gem install rspec
13
+ EOS
14
+ exit(0)
15
+ end
16
+
17
+ desc "Run the specs under spec/models"
18
+ Spec::Rake::SpecTask.new do |t|
19
+ t.spec_opts = ['--options', "spec/spec.opts"]
20
+ t.spec_files = FileList['spec/**/*_spec.rb']
21
+ end
metadata ADDED
@@ -0,0 +1,114 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rspec_spinner
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.4.5
5
+ platform: ruby
6
+ authors:
7
+ - Marcos Piccinini
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2008-12-21 00:00:00 -02:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: rspec
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: 1.1.11
24
+ version:
25
+ - !ruby/object:Gem::Dependency
26
+ name: rtui
27
+ type: :runtime
28
+ version_requirement:
29
+ version_requirements: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 0.1.8
34
+ version:
35
+ - !ruby/object:Gem::Dependency
36
+ name: newgem
37
+ type: :development
38
+ version_requirement:
39
+ version_requirements: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ version: 1.2.1
44
+ version:
45
+ - !ruby/object:Gem::Dependency
46
+ name: hoe
47
+ type: :development
48
+ version_requirement:
49
+ version_requirements: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: 1.8.0
54
+ version:
55
+ description: Some extra formatters for rspec
56
+ email:
57
+ - x@nofxx.com
58
+ executables: []
59
+
60
+ extensions: []
61
+
62
+ extra_rdoc_files:
63
+ - History.txt
64
+ - Manifest.txt
65
+ - PostInstall.txt
66
+ - README.rdoc
67
+ files:
68
+ - History.txt
69
+ - MIT-LICENSE
70
+ - Manifest.txt
71
+ - PostInstall.txt
72
+ - README.rdoc
73
+ - Rakefile
74
+ - lib/rspec_spinner.rb
75
+ - lib/rspec_spinner/bar.rb
76
+ - lib/rspec_spinner/base.rb
77
+ - lib/rspec_spinner/spinner.rb
78
+ - rspec_spinner.gemspec
79
+ - script/console
80
+ - script/destroy
81
+ - script/generate
82
+ - spec/rspec_spinner_spec.rb
83
+ - spec/spec.opts
84
+ - spec/spec_helper.rb
85
+ - tasks/rspec.rake
86
+ has_rdoc: true
87
+ homepage: http://github.com/nofxx/postgis_adapter
88
+ post_install_message: PostInstall.txt
89
+ rdoc_options:
90
+ - --main
91
+ - README.rdoc
92
+ require_paths:
93
+ - lib
94
+ required_ruby_version: !ruby/object:Gem::Requirement
95
+ requirements:
96
+ - - ">="
97
+ - !ruby/object:Gem::Version
98
+ version: "0"
99
+ version:
100
+ required_rubygems_version: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - ">="
103
+ - !ruby/object:Gem::Version
104
+ version: "0"
105
+ version:
106
+ requirements: []
107
+
108
+ rubyforge_project: rspec_spinner
109
+ rubygems_version: 1.3.1
110
+ signing_key:
111
+ specification_version: 2
112
+ summary: Some extra formatters for rspec
113
+ test_files: []
114
+