nyan-cat-formatter 0.0.3 → 0.0.4
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.
- data/LICENSE.md +20 -0
- data/README.md +2 -0
- data/lib/nyan_cat_formatter.rb +39 -65
- data/lib/rspec1.rb +61 -0
- data/lib/rspec2.rb +45 -0
- data/nyan-cat-formatter.gemspec +1 -1
- data/spec/nyan_cat_formatter_spec.rb +10 -2
- metadata +32 -50
data/LICENSE.md
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2011 Matt Sears
|
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/README.md
CHANGED
@@ -12,6 +12,8 @@ This is my take on the Nyan Cat RSpec Formatter. It simply creates a rainbow tra
|
|
12
12
|
|
13
13
|
The rainbow changes colors as it runs. See it in action [here](http://vimeo.com/32424001).
|
14
14
|
|
15
|
+
Works with RSpec 1.3 and RSpec 2.
|
16
|
+
|
15
17
|
```
|
16
18
|
rspec --format NyanCatFormatter
|
17
19
|
```
|
data/lib/nyan_cat_formatter.rb
CHANGED
@@ -1,7 +1,17 @@
|
|
1
1
|
# -*- coding: utf-8 -*-
|
2
|
-
require 'rspec/core/formatters/base_text_formatter'
|
3
2
|
|
4
|
-
|
3
|
+
rspec_bin = $0.split('/').last
|
4
|
+
if rspec_bin == 'rspec'
|
5
|
+
['rspec2','rspec/core/formatters/base_text_formatter'].each {|f| require f}
|
6
|
+
parent_class = RSpec::Core::Formatters::BaseTextFormatter
|
7
|
+
rspec_module = RSpec2
|
8
|
+
elsif rspec_bin == 'spec'
|
9
|
+
['spec', 'rspec1', 'spec/runner/formatter/base_text_formatter'].each {|f| require f}
|
10
|
+
parent_class = Spec::Runner::Formatter::BaseTextFormatter
|
11
|
+
rspec_module = RSpec1
|
12
|
+
end
|
13
|
+
|
14
|
+
NyanCatFormatter = Class.new(parent_class) do
|
5
15
|
|
6
16
|
ESC = "\e["
|
7
17
|
NND = "#{ESC}0m"
|
@@ -11,77 +21,27 @@ class NyanCatFormatter < RSpec::Core::Formatters::BaseTextFormatter
|
|
11
21
|
ERROR = '!'
|
12
22
|
PENDING = '+'
|
13
23
|
|
14
|
-
|
15
|
-
|
16
|
-
def start(example_count)
|
17
|
-
super(example_count)
|
18
|
-
@current, @color_index, @passing_count = 0,0,0
|
19
|
-
@example_results = []
|
20
|
-
end
|
21
|
-
|
22
|
-
def example_passed(example)
|
23
|
-
super(example)
|
24
|
-
tick PASS
|
25
|
-
end
|
24
|
+
include rspec_module
|
26
25
|
|
27
|
-
|
28
|
-
|
29
|
-
@pending_count =+1
|
30
|
-
tick PENDING
|
31
|
-
end
|
32
|
-
|
33
|
-
def example_failed(example)
|
34
|
-
super(example)
|
35
|
-
@failure_count =+1
|
36
|
-
tick FAIL
|
37
|
-
end
|
38
|
-
|
39
|
-
def start_dump
|
40
|
-
@current = @example_count
|
41
|
-
end
|
42
|
-
|
43
|
-
def dump_summary(duration, example_count, failure_count, pending_count)
|
44
|
-
dump_profile if profile_examples? && failure_count == 0
|
45
|
-
summary = "\nNyan Cat flew #{format_seconds(duration)} seconds".split(//).map { |c| rainbowify(c) }
|
46
|
-
output.puts summary.join
|
47
|
-
output.puts colorise_summary(summary_line(example_count, failure_count, pending_count))
|
48
|
-
|
49
|
-
if respond_to?(:dump_commands_to_rerun_failed_examples)
|
50
|
-
dump_commands_to_rerun_failed_examples
|
51
|
-
end
|
52
|
-
end
|
53
|
-
|
54
|
-
def dump_failures
|
55
|
-
#no op
|
56
|
-
end
|
26
|
+
attr_reader :current, :example_results, :color_index, :pending_count,
|
27
|
+
:failure_count, :example_count
|
57
28
|
|
58
29
|
# Increments the example count and displays the current progress
|
59
30
|
#
|
60
31
|
# @returns nothing
|
61
32
|
def tick(mark = PASS)
|
62
33
|
@example_results << mark
|
63
|
-
@current =
|
34
|
+
@current = (@current > @example_count) ? @example_count : @current + 1
|
64
35
|
dump_progress
|
65
36
|
end
|
66
37
|
|
67
|
-
# Creates a rainbow trail
|
68
|
-
#
|
69
|
-
# @return [String] the sprintf format of the Nyan cat
|
70
|
-
def nyan_trail
|
71
|
-
marks = @example_results.map{ |mark| highlight(mark) }
|
72
|
-
marks.shift(current_width - terminal_width) if current_width > terminal_width
|
73
|
-
nyan_cat_lines = nyan_cat.split("\n").each_with_index.map do |line, index|
|
74
|
-
format("%s#{line}", marks.join)
|
75
|
-
end.join("\n")
|
76
|
-
end
|
77
|
-
|
78
38
|
# Determine which Ascii Nyan Cat to display. If tests are complete,
|
79
39
|
# Nyan Cat goes to sleep. If there are failing or pending examples,
|
80
40
|
# Nyan Cat is concerned.
|
81
41
|
#
|
82
42
|
# @return [String] Nyan Cat
|
83
43
|
def nyan_cat
|
84
|
-
if @failure_count > 0 || @pending_count > 0
|
44
|
+
if @failure_count.to_i > 0 || @pending_count.to_i > 0
|
85
45
|
ascii_cat('o')[@color_index%2].join("\n") #'~|_(o.o)'
|
86
46
|
elsif (@current == @example_count)
|
87
47
|
ascii_cat('-')[@color_index%2].join("\n") # '~|_(-.-)'
|
@@ -133,11 +93,24 @@ class NyanCatFormatter < RSpec::Core::Formatters::BaseTextFormatter
|
|
133
93
|
#
|
134
94
|
# @return [Array]
|
135
95
|
def scoreboard
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
96
|
+
@pending_examples ||= []
|
97
|
+
@failed_examples ||= []
|
98
|
+
padding = @example_count.to_s.length
|
99
|
+
[ @current.to_s.rjust(padding),
|
100
|
+
green((@current - @pending_examples.size - @failed_examples.size).to_s.rjust(padding)),
|
101
|
+
yellow(@pending_count.to_s.rjust(padding)),
|
102
|
+
red(@failure_count.to_s.rjust(padding)) ]
|
103
|
+
end
|
104
|
+
|
105
|
+
# Creates a rainbow trail
|
106
|
+
#
|
107
|
+
# @return [String] the sprintf format of the Nyan cat
|
108
|
+
def nyan_trail
|
109
|
+
marks = @example_results.map{ |mark| highlight(mark) }
|
110
|
+
marks.shift(current_width - terminal_width) if current_width >= terminal_width
|
111
|
+
nyan_cat_lines = nyan_cat.split("\n").each_with_index.map do |line, index|
|
112
|
+
format("%s#{line}", marks.join)
|
113
|
+
end.join("\n")
|
141
114
|
end
|
142
115
|
|
143
116
|
# Ascii version of Nyan cat. Two cats in the array allow Nyan to animate running.
|
@@ -187,9 +160,10 @@ class NyanCatFormatter < RSpec::Core::Formatters::BaseTextFormatter
|
|
187
160
|
# @return [String]
|
188
161
|
def highlight(mark = PASS)
|
189
162
|
case mark
|
190
|
-
when PASS;
|
191
|
-
when FAIL;
|
192
|
-
when ERROR;
|
163
|
+
when PASS; rainbowify PASS_ARY[@color_index%2]
|
164
|
+
when FAIL; "\e[31m#{mark}\e[0m"
|
165
|
+
when ERROR; "\e[33m#{mark}\e[0m"
|
166
|
+
when PENDING; "\e[33m#{mark}\e[0m"
|
193
167
|
else mark
|
194
168
|
end
|
195
169
|
end
|
data/lib/rspec1.rb
ADDED
@@ -0,0 +1,61 @@
|
|
1
|
+
module RSpec1
|
2
|
+
|
3
|
+
def start(example_count)
|
4
|
+
super(example_count)
|
5
|
+
@example_count = example_count
|
6
|
+
@current = @color_index = @passing_count = @failure_count = @pending_count = 0
|
7
|
+
@example_results = []
|
8
|
+
end
|
9
|
+
|
10
|
+
def example_passed(example)
|
11
|
+
super
|
12
|
+
@passing_count += 1
|
13
|
+
tick PASS
|
14
|
+
end
|
15
|
+
|
16
|
+
def example_pending(example, message = nil)
|
17
|
+
super
|
18
|
+
@pending_count =+1
|
19
|
+
tick PENDING
|
20
|
+
end
|
21
|
+
|
22
|
+
def example_failed(example, counter = nil, failure = nil)
|
23
|
+
super
|
24
|
+
@failure_count =+1
|
25
|
+
tick FAIL
|
26
|
+
end
|
27
|
+
|
28
|
+
def start_dump
|
29
|
+
@current = @example_count
|
30
|
+
end
|
31
|
+
|
32
|
+
def dump_pending
|
33
|
+
output.puts "\e[0;33m"
|
34
|
+
super
|
35
|
+
end
|
36
|
+
|
37
|
+
def dump_failure(*args)
|
38
|
+
output.puts "\e[0;31m"
|
39
|
+
super
|
40
|
+
end
|
41
|
+
|
42
|
+
def dump_summary(duration, example_count, failure_count, pending_count)
|
43
|
+
@output.puts "\nNyan Cat flew #{duration} seconds\n".each_char.map {|c| rainbowify(c)}.join
|
44
|
+
summary = "#{example_count} example#{'s' unless example_count == 1}, #{failure_count} failure#{'s' unless failure_count == 1}"
|
45
|
+
summary << ", #{pending_count} pending" if pending_count > 0
|
46
|
+
|
47
|
+
if failure_count == 0
|
48
|
+
@output.puts red(summary)
|
49
|
+
elsif pending_count > 0
|
50
|
+
@output.puts yellow(summary)
|
51
|
+
else
|
52
|
+
@output.puts green(summary)
|
53
|
+
end
|
54
|
+
@output.flush
|
55
|
+
end
|
56
|
+
|
57
|
+
def dump_failures
|
58
|
+
#no op
|
59
|
+
end
|
60
|
+
|
61
|
+
end
|
data/lib/rspec2.rb
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
module RSpec2
|
2
|
+
|
3
|
+
def start(example_count)
|
4
|
+
super(example_count)
|
5
|
+
@current = @color_index = @passing_count = 0
|
6
|
+
@example_results = []
|
7
|
+
end
|
8
|
+
|
9
|
+
def example_passed(example)
|
10
|
+
super(example)
|
11
|
+
tick PASS
|
12
|
+
end
|
13
|
+
|
14
|
+
def example_pending(example)
|
15
|
+
super(example)
|
16
|
+
@pending_count =+1
|
17
|
+
tick PENDING
|
18
|
+
end
|
19
|
+
|
20
|
+
def example_failed(example)
|
21
|
+
super(example)
|
22
|
+
@failure_count =+1
|
23
|
+
tick FAIL
|
24
|
+
end
|
25
|
+
|
26
|
+
def start_dump
|
27
|
+
@current = @example_count
|
28
|
+
end
|
29
|
+
|
30
|
+
def dump_summary(duration, example_count, failure_count, pending_count)
|
31
|
+
dump_profile if profile_examples? && failure_count == 0
|
32
|
+
summary = "\nNyan Cat flew #{format_seconds(duration)} seconds".split(//).map { |c| rainbowify(c) }
|
33
|
+
output.puts summary.join
|
34
|
+
output.puts colorise_summary(summary_line(example_count, failure_count, pending_count))
|
35
|
+
|
36
|
+
if respond_to?(:dump_commands_to_rerun_failed_examples)
|
37
|
+
dump_commands_to_rerun_failed_examples
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def dump_failures
|
42
|
+
#no op
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
data/nyan-cat-formatter.gemspec
CHANGED
@@ -4,10 +4,18 @@ require 'stringio'
|
|
4
4
|
describe NyanCatFormatter do
|
5
5
|
|
6
6
|
before do
|
7
|
+
rspec_bin = $0.split('/').last
|
7
8
|
@output = StringIO.new
|
8
|
-
|
9
|
+
if rspec_bin == 'rspec'
|
10
|
+
@formatter = NyanCatFormatter.new(@output)
|
11
|
+
@example = RSpec::Core::ExampleGroup.describe.example
|
12
|
+
else
|
13
|
+
formatter_options = OpenStruct.new(:colour => true, :dry_run => false, :autospec => nil)
|
14
|
+
@formatter = NyanCatFormatter.new(formatter_options, @output)
|
15
|
+
@example = Spec::Example::ExampleProxy.new("should pass")
|
16
|
+
@formatter.instance_variable_set(:@example_group, OpenStruct.new(:description => "group"))
|
17
|
+
end
|
9
18
|
@formatter.start(2)
|
10
|
-
@example = RSpec::Core::ExampleGroup.describe.example
|
11
19
|
sleep(0.1) # Just to slow it down a little :-)
|
12
20
|
end
|
13
21
|
|
metadata
CHANGED
@@ -1,89 +1,71 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: nyan-cat-formatter
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.4
|
5
5
|
prerelease:
|
6
|
-
segments:
|
7
|
-
- 0
|
8
|
-
- 0
|
9
|
-
- 3
|
10
|
-
version: 0.0.3
|
11
6
|
platform: ruby
|
12
|
-
authors:
|
7
|
+
authors:
|
13
8
|
- Matt Sears
|
14
9
|
autorequire:
|
15
10
|
bindir: bin
|
16
11
|
cert_chain: []
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
- !ruby/object:Gem::Dependency
|
12
|
+
date: 2011-12-08 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
21
15
|
name: rspec
|
22
|
-
|
23
|
-
requirement: &id001 !ruby/object:Gem::Requirement
|
16
|
+
requirement: &70322272045780 !ruby/object:Gem::Requirement
|
24
17
|
none: false
|
25
|
-
requirements:
|
26
|
-
- -
|
27
|
-
- !ruby/object:Gem::Version
|
28
|
-
|
29
|
-
segments:
|
30
|
-
- 0
|
31
|
-
version: "0"
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
32
22
|
type: :development
|
33
|
-
|
34
|
-
|
35
|
-
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *70322272045780
|
25
|
+
description: ! 'Nyan Cat inspired RSpec formatter! '
|
26
|
+
email:
|
36
27
|
- matt@mattsears.com
|
37
28
|
executables: []
|
38
|
-
|
39
29
|
extensions: []
|
40
|
-
|
41
30
|
extra_rdoc_files: []
|
42
|
-
|
43
|
-
files:
|
31
|
+
files:
|
44
32
|
- .gitignore
|
45
33
|
- .rspec
|
46
34
|
- .rvmrc
|
47
35
|
- Gemfile
|
36
|
+
- LICENSE.md
|
48
37
|
- README.md
|
49
38
|
- Rakefile
|
50
39
|
- lib/nyan_cat_formatter.rb
|
40
|
+
- lib/rspec1.rb
|
41
|
+
- lib/rspec2.rb
|
51
42
|
- nyan-cat-formatter.gemspec
|
52
43
|
- spec/nyan_cat_formatter_spec.rb
|
53
44
|
- spec/spec_helper.rb
|
54
45
|
homepage: http://mtts.rs/nyancat
|
55
46
|
licenses: []
|
56
|
-
|
57
47
|
post_install_message:
|
58
48
|
rdoc_options: []
|
59
|
-
|
60
|
-
require_paths:
|
49
|
+
require_paths:
|
61
50
|
- lib
|
62
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
51
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
63
52
|
none: false
|
64
|
-
requirements:
|
65
|
-
- -
|
66
|
-
- !ruby/object:Gem::Version
|
67
|
-
|
68
|
-
|
69
|
-
- 0
|
70
|
-
version: "0"
|
71
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
53
|
+
requirements:
|
54
|
+
- - ! '>='
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
version: '0'
|
57
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
72
58
|
none: false
|
73
|
-
requirements:
|
74
|
-
- -
|
75
|
-
- !ruby/object:Gem::Version
|
76
|
-
|
77
|
-
segments:
|
78
|
-
- 0
|
79
|
-
version: "0"
|
59
|
+
requirements:
|
60
|
+
- - ! '>='
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: '0'
|
80
63
|
requirements: []
|
81
|
-
|
82
64
|
rubyforge_project: nyan-cat-formatter
|
83
65
|
rubygems_version: 1.8.10
|
84
66
|
signing_key:
|
85
67
|
specification_version: 3
|
86
68
|
summary: Nyan Cat inspired RSpec formatter!
|
87
|
-
test_files:
|
69
|
+
test_files:
|
88
70
|
- spec/nyan_cat_formatter_spec.rb
|
89
71
|
- spec/spec_helper.rb
|