smooth-jazz-nyan-cat-formatter 0.1.1

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.
@@ -0,0 +1,4 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format SmoothJazzNyanCatMusicFormatter
data/.rvmrc ADDED
@@ -0,0 +1 @@
1
+ rvm 1.9.3@nyan-cat-formatter --create
@@ -0,0 +1,5 @@
1
+ rvm:
2
+ - 1.8.7
3
+ - 1.9.2
4
+ - 1.9.3
5
+ - ree
@@ -0,0 +1,4 @@
1
+ 0.0.7 - June 26, 2012
2
+ -------------------------
3
+ * Fixed failure and pending counting bug.
4
+ * Change the summary tag line to read "You've Nyaned for ... seconds"
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in nyan-cat-formatter.gemspec
4
+ gemspec
@@ -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.
@@ -0,0 +1,92 @@
1
+ Nyan Cat RSpec Formatter [![Build Status](https://secure.travis-ci.org/mattsears/nyan-cat-formatter.png)](http://travis-ci.org/mattsears/nyan-cat-formatter)
2
+ ========
3
+
4
+ ```
5
+ -_-_-_-_-_-_-_,------,
6
+ _-_-_-_-_-_-_-| /\_/\
7
+ -_-_-_-_-_-_-~|__( ^ .^)
8
+ _-_-_-_-_-_-_-"" ""
9
+ ```
10
+
11
+ This is my take on the Nyan Cat RSpec Formatter. It simply creates a rainbow trail of test results. It also counts the number of examples as they execute and highlights failed and pending specs.
12
+
13
+ The rainbow changes colors as it runs. See it in action [here](http://vimeo.com/32424001).
14
+
15
+ Works with RSpec 1.3 and RSpec 2.
16
+
17
+ Using Nyan Cat
18
+ ---------------
19
+
20
+ You can either specify the formatting when using the `rspec` command:
21
+
22
+ rspec --format NyanCatFormatter
23
+
24
+ Or add `--format NyanCatFormatter` to a `.rspec` file placed in your project's root directory,
25
+ so that you won't have to specify the `--format` option everytime you run the command.
26
+
27
+ ###Using with Bundler
28
+
29
+ To use Nyan Cat with a project that uses Bundler (Rails or Sinatra f.e.) you need to add Nyan Cat dependecy to your Gemfile:
30
+
31
+ group :test do
32
+ gem "nyan-cat-formatter"
33
+ end
34
+
35
+ And then run `bundle install`.
36
+
37
+ Installing it
38
+ -------------
39
+
40
+ ```
41
+ $ gem install nyan-cat-formatter
42
+ ```
43
+
44
+ If you want to use Nyan Cat as your default formatter, simply put the options in your .rspec file:
45
+
46
+ ```
47
+ --format NyanCatFormatter
48
+ ```
49
+
50
+ Playing the Nyan Cat song
51
+ -------------------------
52
+
53
+ You can then enjoy playback in two ways:
54
+
55
+ **1. Play the song only when desired using a command line option:**
56
+
57
+ Use the following command to run your specs:
58
+
59
+ ```
60
+ $ rspec spec -f NyanCatMusicFormatter
61
+ ```
62
+
63
+ And enjoy the site of Nyan Cat running across your terminal to the Nyan Cat song!
64
+
65
+ **2. Play the song by default when you run your specs:**
66
+
67
+ Make sure your .rspec file in your application's root directory contains the following:
68
+
69
+ ```
70
+ --color
71
+ --format NyanCatMusicFormatter
72
+ ```
73
+
74
+ Then run `rspec spec` and enjoy Nyan Cat formatted text output accompanied by the Nyan Cat song by default!
75
+
76
+ **This currently only works on Mac OS X or on Linux (if you have mpg321 installed).**
77
+
78
+ Contributing
79
+ ----------
80
+
81
+ Once you've made your great commits:
82
+
83
+ 1. Fork Nyan Cat
84
+ 2. Create a topic branch - git checkout -b my_branch
85
+ 3. Push to your branch - git push origin my_branch
86
+ 4. Create a Pull Request from your branch
87
+ 5. That's it!
88
+
89
+ Author
90
+ ----------
91
+ [Matt Sears](https://wwww.mattsears.com) :: @mattsears
92
+
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+
3
+ task :default => :spec
4
+
5
+ require 'rspec/core/rake_task'
6
+ RSpec::Core::RakeTask.new
Binary file
data/demo.rb ADDED
@@ -0,0 +1,30 @@
1
+ require_relative 'spec/spec_helper'
2
+ require 'stringio'
3
+
4
+ describe NyanCatFormatter do
5
+
6
+ before do
7
+ @output = StringIO.new
8
+ @formatter = NyanCatFormatter.new(@output)
9
+ @formatter.start(2)
10
+ @example = RSpec::Core::ExampleGroup.describe.example
11
+
12
+ @samples = [0,0,0,0,0,0,0,0,0,0,0,1,
13
+ 0]
14
+
15
+ sleep(0.1) # Just to slow it down a little :-)
16
+ end
17
+
18
+ 100.times do |index|
19
+ it "should perform passing specs" do
20
+ @formatter.current.should == @samples.sample
21
+ end
22
+
23
+ it "should perform pending specs" do
24
+ if @samples.sample == 1
25
+ pending
26
+ end
27
+ end
28
+ end
29
+
30
+ end
@@ -0,0 +1,237 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ require 'nyan_cat_formatter/padded_string_io'
4
+
5
+ rspec_bin = $0.split('/').last
6
+ if rspec_bin == 'spec'
7
+ ['spec', 'nyan_cat_formatter/rspec1', 'spec/runner/formatter/base_text_formatter'].each {|f| require f}
8
+ parent_class = Spec::Runner::Formatter::BaseTextFormatter
9
+ rspec_module = RSpec1
10
+ else
11
+ ['nyan_cat_formatter/rspec2', 'rspec/core/formatters/base_text_formatter'].each {|f| require f}
12
+ parent_class = RSpec::Core::Formatters::BaseTextFormatter
13
+ rspec_module = RSpec2
14
+ end
15
+
16
+ NyanCatFormatter = Class.new(parent_class) do
17
+
18
+ ESC = "\e["
19
+ NND = "#{ESC}0m"
20
+ PASS = '='
21
+ PASS_ARY = ['-', '-', '_', '_', '-', '-', '‾', '‾']
22
+ FAIL = '*'
23
+ ERROR = '!'
24
+ PENDING = '+'
25
+
26
+ include rspec_module
27
+
28
+ attr_reader :current, :example_results, :color_index, :pending_count,
29
+ :failure_count, :example_count
30
+
31
+ def initialize(args)
32
+ super PaddedStringIO.new(terminal_width)
33
+ end
34
+
35
+ # Increments the example count and displays the current progress
36
+ #
37
+ # @returns nothing
38
+ def tick(mark = PASS)
39
+ @example_results << mark
40
+ @current = (@current > @example_count) ? @example_count : @current + 1
41
+ dump_progress
42
+ end
43
+
44
+ # Determine which Ascii Nyan Cat to display. If tests are complete,
45
+ # Nyan Cat goes to sleep. If there are failing or pending examples,
46
+ # Nyan Cat is concerned.
47
+ #
48
+ # @return [String] Nyan Cat
49
+ def nyan_cat
50
+ if self.failed_or_pending? && self.finished?
51
+ ascii_cat('x')[@color_index/2%2].join("\n") #'~|_(x.x)'
52
+ elsif self.failed_or_pending?
53
+ ascii_cat('o')[@color_index/2%2].join("\n") #'~|_(o.o)'
54
+ elsif self.finished?
55
+ ascii_cat('-')[@color_index/2%2].join("\n") # '~|_(-.-)'
56
+ else
57
+ ascii_cat('^')[@color_index/2%2].join("\n") # '~|_(^.^)'
58
+ end
59
+ end
60
+
61
+ # Displays the current progress in all Nyan Cat glory
62
+ #
63
+ # @return nothing
64
+ def dump_progress
65
+ padding = @example_count.to_s.length * 2 + 2
66
+ line = nyan_trail.split("\n").each_with_index.inject([]) do |result, (trail, index)|
67
+ value = "#{scoreboard[index]}/#{@example_count}:"
68
+ value = " " * value.length if scoreboard[index].strip == ""
69
+ result << format("%s %s", value, trail)
70
+ end.join("\n")
71
+ output.print line + eol
72
+ end
73
+
74
+ # Determines how we end the trail line. If complete, return a newline etc.
75
+ #
76
+ # @return [String]
77
+ def eol
78
+ return "\n" if @current == @example_count
79
+ length = (nyan_cat.split("\n").length - 1)
80
+ length > 0 ? format("\e[1A" * length + "\r") : "\r"
81
+ end
82
+
83
+ # Calculates the current flight length
84
+ #
85
+ # @return [Fixnum]
86
+ def current_width
87
+ padding = @example_count.to_s.length * 2 + 6
88
+ cat_length = nyan_cat.split("\n").group_by(&:size).max.first
89
+ padding + @current + cat_length
90
+ end
91
+
92
+ # A Unix trick using stty to get the console columns
93
+ #
94
+ # @return [Fixnum]
95
+ def terminal_width
96
+ if defined? JRUBY_VERSION
97
+ default_width = 80
98
+ else
99
+ default_width = `stty size`.split.map { |x| x.to_i }.reverse.first - 1
100
+ end
101
+ @terminal_width ||= default_width
102
+ end
103
+
104
+ # Creates a data store of pass, failed, and pending example results
105
+ # We have to pad the results here because sprintf can't properly pad color
106
+ #
107
+ # @return [Array]
108
+ def scoreboard
109
+ @pending_examples ||= []
110
+ @failed_examples ||= []
111
+ padding = @example_count.to_s.length
112
+ [ @current.to_s.rjust(padding),
113
+ green((@current - @pending_examples.size - @failed_examples.size).to_s.rjust(padding)),
114
+ yellow(@pending_examples.size.to_s.rjust(padding)),
115
+ red(@failed_examples.size.to_s.rjust(padding)),
116
+ "".rjust(padding),
117
+ "".rjust(padding) ]
118
+ end
119
+
120
+ # Creates a rainbow trail
121
+ #
122
+ # @return [String] the sprintf format of the Nyan cat
123
+ def nyan_trail
124
+ nyan_cat_lines = nyan_cat.split("\n").each_with_index.map do |line, index|
125
+ @color_index = @current%8
126
+ marks = @example_results.map{ |mark| highlight(mark, index) }
127
+ marks.shift(current_width - terminal_width) if current_width >= terminal_width
128
+ format("%s#{line}", marks.join)
129
+ end.join("\n")
130
+ end
131
+
132
+ # Ascii version of Nyan cat. Two cats in the array allow Nyan to animate running.
133
+ #
134
+ # @param o [String] Nyan's eye
135
+ # @return [Array] Nyan cats
136
+ def ascii_cat(o = '^')
137
+ [[ "----------",
138
+ "_,------, ",
139
+ "_| /\\_/\\ ",
140
+ "~|_( #{o} .#{o}) ",
141
+ " \"\" \"\" ",
142
+ "----------"
143
+ ],
144
+ [ "----------",
145
+ "_,------, ",
146
+ "_| /\\_/\\",
147
+ "^|__( #{o} .#{o}) ",
148
+ " \"\" \"\" ",
149
+ "----------"
150
+ ]]
151
+ end
152
+
153
+ # Colorizes the string with raindow colors of the rainbow
154
+ #
155
+ # @params string [String]
156
+ # @return [String]
157
+ def rainbowify(string)
158
+ c = colors[@color_index % colors.size]
159
+ @color_index += 1
160
+ colorize(string, c)
161
+ end
162
+
163
+ def rgb(r,g,b)
164
+ 16+r*36+g*6+b
165
+ end
166
+
167
+ def colorize(string, color)
168
+ "#{ESC}38;5;#{color}m#{string}#{NND}"
169
+ end
170
+
171
+ # Calculates the colors of the rainbow
172
+ #
173
+ # @return [Array]
174
+ def colors
175
+ @colors ||= (0...(6 * 7)).map do |n|
176
+ pi_3 = Math::PI / 3
177
+ n *= 1.0 / 6
178
+ r = (3 * Math.sin(n ) + 3).to_i
179
+ g = (3 * Math.sin(n + 2 * pi_3) + 3).to_i
180
+ b = (3 * Math.sin(n + 4 * pi_3) + 3).to_i
181
+ 36 * r + 6 * g + b + 16
182
+ end
183
+ end
184
+
185
+ def trail_colors
186
+ return [rgb(5,0,0),
187
+ rgb(5,2,0),
188
+ rgb(5,5,0),
189
+ rgb(0,5,0),
190
+ rgb(0,0,5),
191
+ rgb(1,0,5)]
192
+ end
193
+
194
+ # Determines how to color the example. If pass, it is rainbowified, otherwise
195
+ # we assign red if failed or yellow if an error occurred.
196
+ #
197
+ # @return [String]
198
+ def highlight(mark = PASS, index = 0)
199
+ @color_index += 1
200
+ case mark
201
+ when PASS; colorize PASS_ARY[@color_index%8], trail_colors[index]
202
+ when FAIL; "\e[31m#{mark}\e[0m"
203
+ when ERROR; "\e[33m#{mark}\e[0m"
204
+ when PENDING; "\e[33m#{mark}\e[0m"
205
+ else mark
206
+ end
207
+ end
208
+
209
+ # Converts a float of seconds into a minutes/seconds string
210
+ #
211
+ # @return [String]
212
+ def format_duration(duration)
213
+ seconds = ((duration % 60) * 100.0).round / 100.0 # 1.8.7 safe .round(2)
214
+ seconds = seconds.to_i if seconds.to_i == seconds # drop that zero if it's not needed
215
+
216
+ message = "#{seconds} second#{seconds == 1 ? "" : "s"}"
217
+ message = "#{(duration / 60).to_i} minute#{(duration / 60).to_i == 1 ? "" : "s"} and " + message if duration >= 60
218
+
219
+ message
220
+ end
221
+
222
+
223
+ # Determines if the specs have completed
224
+ #
225
+ # @returns [Boolean] true if finished; false otherwise
226
+ def finished?
227
+ (@current == @example_count)
228
+ end
229
+
230
+ # Determines if the any specs failed or are in pending state
231
+ #
232
+ # @returns [Boolean] true if failed or pending; false otherwise
233
+ def failed_or_pending?
234
+ (@failure_count.to_i > 0 || @pending_count.to_i > 0)
235
+ end
236
+ end
237
+
@@ -0,0 +1,20 @@
1
+ class PaddedStringIO
2
+ def initialize(terminal_size)
3
+ @output = $stdout
4
+ @terminal_size = terminal_size
5
+ end
6
+
7
+ def puts(output_strings = '')
8
+ unless output_strings.is_a?(Array)
9
+ output_strings = [output_strings]
10
+ end
11
+ output_strings.each do |output_string|
12
+ @output.puts output_string.ljust(@terminal_size)
13
+ # super 'foo'
14
+ end
15
+ end
16
+
17
+ def method_missing(*args)
18
+ @output.send(*args)
19
+ end
20
+ end
@@ -0,0 +1,64 @@
1
+ require 'rspec/instafail'
2
+
3
+ module RSpec1
4
+
5
+ def start(example_count)
6
+ super(example_count)
7
+ @example_count = example_count
8
+ @current = @color_index = @passing_count = @failure_count = @pending_count = 0
9
+ @example_results = []
10
+ end
11
+
12
+ def example_passed(example)
13
+ super
14
+ @passing_count += 1
15
+ tick PASS
16
+ end
17
+
18
+ def example_pending(example, message = nil)
19
+ super
20
+ @pending_count =+1
21
+ tick PENDING
22
+ end
23
+
24
+ def example_failed(example, counter = nil, failure = nil)
25
+ super
26
+ @failure_count =+1
27
+ tick FAIL
28
+ instafail.example_failed(example)
29
+ end
30
+
31
+ def start_dump
32
+ @current = @example_count
33
+ end
34
+
35
+ def dump_pending
36
+ output.puts "\e[0;33m"
37
+ super
38
+ end
39
+
40
+ def dump_failure(*args)
41
+ output.puts "\e[0;31m"
42
+ super
43
+ end
44
+
45
+ def dump_summary(duration, example_count, failure_count, pending_count)
46
+ NyanCatMusicFormatter.new(NyanCatFormatter).kill_music if NyanCatMusicFormatter
47
+ @output.puts "\nYou've Nyaned for #{format_duration(duration)}\n".each_char.map {|c| rainbowify(c)}.join
48
+ summary = "#{example_count} example#{'s' unless example_count == 1}, #{failure_count} failure#{'s' unless failure_count == 1}"
49
+ summary << ", #{pending_count} pending" if pending_count > 0
50
+
51
+ if failure_count == 0
52
+ @output.puts red(summary)
53
+ elsif pending_count > 0
54
+ @output.puts yellow(summary)
55
+ else
56
+ @output.puts green(summary)
57
+ end
58
+ @output.flush
59
+ end
60
+
61
+ def instafail
62
+ @instafail ||= RSpec::Instafail.new(output)
63
+ end
64
+ end
@@ -0,0 +1,72 @@
1
+ require 'rspec/instafail'
2
+
3
+ module RSpec2
4
+
5
+ def start(example_count)
6
+ super(example_count)
7
+ @current = @color_index = @passing_count = 0
8
+ @example_results = []
9
+ end
10
+
11
+ def example_passed(example)
12
+ super(example)
13
+ tick PASS
14
+ end
15
+
16
+ def example_pending(example)
17
+ super(example)
18
+ @pending_count +=1
19
+ tick PENDING
20
+ end
21
+
22
+ def example_failed(example)
23
+ super(example)
24
+ @failure_count +=1
25
+ instafail.example_failed(example)
26
+ tick FAIL
27
+ end
28
+
29
+ def start_dump
30
+ @current = @example_count
31
+ end
32
+
33
+ def dump_failures
34
+ nil
35
+ end
36
+
37
+ def dump_summary(duration, example_count, failure_count, pending_count)
38
+ NyanCatMusicFormatter.new(NyanCatFormatter).kill_music if NyanCatMusicFormatter
39
+ dump_profile if profile_examples? && failure_count == 0
40
+ summary = "\nYou've Nyaned for #{format_duration(duration)}\n".split(//).map { |c| rainbowify(c) }
41
+ output.puts summary.join
42
+ output.puts colorise_summary(summary_line(example_count, failure_count, pending_count))
43
+ if respond_to?(:dump_commands_to_rerun_failed_examples)
44
+ dump_commands_to_rerun_failed_examples
45
+ end
46
+ end
47
+
48
+ def instafail
49
+ @instafail ||= RSpec::Instafail.new(output)
50
+ end
51
+ end
52
+
53
+ =begin
54
+ module RSpec
55
+ module Core
56
+ module Formatters
57
+ class BaseTextFormatter < BaseFormatter
58
+ def dump_failure(example, index)
59
+ output.puts "#{short_padding}#{index.next}) #{example.full_description} "
60
+ exception = example.execution_result[:exception]
61
+ output.puts "#{long_padding}#{red("Failure/Error:")} #{red(read_failed_line(exception, example).strip)} "
62
+ output.puts "#{long_padding}#{red(exception.class.name << ":")} " unless exception.class.name =~ /RSpec/
63
+ exception.message.to_s.split("\n").each { |line| output.puts "#{long_padding} #{red(line)} " } if exception.message
64
+ if shared_group = find_shared_group(example)
65
+ dump_shared_failure_info(shared_group)
66
+ end
67
+ end
68
+ end
69
+ end
70
+ end
71
+ end
72
+ =end
@@ -0,0 +1,45 @@
1
+ # -*- coding: utf-8 -*-
2
+ require 'nyan_cat_formatter'
3
+
4
+ class NyanCatMusicFormatter < NyanCatFormatter
5
+ def osx?
6
+ platform.downcase.include?("darwin")
7
+ end
8
+
9
+ def linux?
10
+ platform.downcase.include?('linux')
11
+ end
12
+
13
+ def kernel=(kernel)
14
+ @kernel = kernel
15
+ end
16
+
17
+ def kernel
18
+ @kernel ||= Kernel
19
+ end
20
+
21
+ def platform=(platform)
22
+ @platform = platform
23
+ end
24
+
25
+ def platform
26
+ @platform ||= RUBY_PLATFORM
27
+ end
28
+
29
+ def nyan_mp3
30
+ File.expand_path('../../data/nyan-cat.mp3', __FILE__)
31
+ end
32
+
33
+ def start input
34
+ super
35
+ kernel.system("afplay #{nyan_mp3} &") if osx?
36
+ kernel.system("[ -e #{nyan_mp3} ] && type mpg321 &>/dev/null && mpg321 #{nyan_mp3} &>/dev/null &") if linux?
37
+ end
38
+
39
+ def kill_music
40
+ if File.exists? nyan_mp3
41
+ system("killall -9 afplay &>/dev/null") if osx?
42
+ system("killall -9 mpg321 &>/dev/null") if linux?
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,7 @@
1
+ # -*- coding: utf-8 -*-
2
+ require 'smooth_jazzy'
3
+ require 'nyan_cat_formatter'
4
+
5
+ class SmoothJazzNyanCatFormatter < NyanCatFormatter
6
+ include SmoothJazzy
7
+ end
@@ -0,0 +1,11 @@
1
+ # -*- coding: utf-8 -*-
2
+ require 'smooth_jazzy'
3
+ require 'nyan_cat_music_formatter'
4
+
5
+ class SmoothJazzNyanCatMusicFormatter < NyanCatMusicFormatter
6
+ include SmoothJazzy
7
+
8
+ def nyan_mp3
9
+ File.expand_path('../../data/smooth-jazz-nyan-cat.mp3', __FILE__)
10
+ end
11
+ end
@@ -0,0 +1,29 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ module SmoothJazzy
4
+ # Ascii version of Nyan cat. Two cats in the array allow Nyan to animate running.
5
+ #
6
+ # @param o [String] Nyan's eye
7
+ # @return [Array] Nyan cats
8
+ def ascii_cat(o = '^')
9
+ if o=='^'
10
+ face = '⌐■.■'
11
+ else
12
+ face = "#{o} .#{o}"
13
+ end
14
+ [[ "----------",
15
+ "_,------, ",
16
+ "_| /\\_/\\ ",
17
+ "~|_( #{face}) ",
18
+ " \"\" \"\" ",
19
+ "----------"
20
+ ],
21
+ [ "----------",
22
+ "_,------, ",
23
+ "_| /\\_/\\",
24
+ "^|__( #{face}) ",
25
+ " \"\" \"\" ",
26
+ "----------"
27
+ ]]
28
+ end
29
+ end
@@ -0,0 +1,20 @@
1
+ $:.push File.expand_path("../lib", __FILE__)
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = "smooth-jazz-nyan-cat-formatter"
5
+ s.version = "0.1.1"
6
+ s.authors = ["Ryan Spore"]
7
+ s.email = ["ry@nspore.com"]
8
+ s.summary = %q{Nyan Cat inspired RSpec formatter! Now with more Jazz! }
9
+ s.description = %q{Nyan Cat inspired RSpec formatter! Now with more Jazz! }
10
+
11
+ s.files = `git ls-files`.split("\n")
12
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
13
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
14
+ s.require_paths = ["lib"]
15
+
16
+ # specify any dependencies here; for example:
17
+ s.add_development_dependency "rake"
18
+ s.add_development_dependency "rspec"
19
+ s.add_dependency "rspec-instafail"
20
+ end
@@ -0,0 +1,199 @@
1
+ require 'spec_helper'
2
+ require 'stringio'
3
+
4
+ describe NyanCatFormatter do
5
+
6
+ before do
7
+ rspec_bin = $0.split('/').last
8
+ @output = StringIO.new
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
18
+ @formatter.start(2)
19
+ sleep(0.1) # Just to slow it down a little :-)
20
+ end
21
+
22
+ describe 'passed, pending and failed' do
23
+
24
+ before do
25
+ @formatter.stub!(:tick)
26
+ end
27
+
28
+ describe 'example_passed' do
29
+
30
+ it 'should call the increment method' do
31
+ @formatter.should_receive :tick
32
+ @formatter.example_passed(@example)
33
+ end
34
+
35
+ it 'should relax Nyan Cat' do
36
+ @formatter.example_passed(@example)
37
+ @formatter.nyan_cat.should include [
38
+ '_,------, ',
39
+ '_| /\_/\ ',
40
+ '~|_( ^ .^) ',
41
+ ' "" "" '
42
+ ].join("\n")
43
+ end
44
+
45
+ it 'should update the scoreboard' do
46
+ @formatter.scoreboard.size.should == 6
47
+ end
48
+
49
+ end
50
+
51
+ describe 'example_pending' do
52
+
53
+ it 'should call the tick method' do
54
+ @formatter.should_receive :tick
55
+ @formatter.example_pending(@example)
56
+ end
57
+
58
+ it 'should increment the pending count' do
59
+ lambda { @formatter.example_pending(@example)}.
60
+ should change(@formatter, :pending_count).by(1)
61
+ end
62
+
63
+ it 'should alert Nyan Cat' do
64
+ @formatter.example_pending(@example)
65
+ @formatter.nyan_cat.should include [
66
+ '_,------, ',
67
+ '_| /\_/\ ',
68
+ '~|_( o .o) ',
69
+ ' "" "" '
70
+ ].join("\n")
71
+ end
72
+
73
+ end
74
+
75
+ describe 'example_failed' do
76
+ before do
77
+ @formatter.instafail.stub!(:example_failed)
78
+ end
79
+
80
+ it 'should call the increment method' do
81
+ @formatter.should_receive :tick
82
+ @formatter.example_failed(@example)
83
+ end
84
+
85
+ it 'should increment the failure count' do
86
+ lambda { @formatter.example_failed(@example)}.
87
+ should change(@formatter, :failure_count).by(1)
88
+ end
89
+
90
+ it 'should alert Nyan Cat' do
91
+ @formatter.example_failed(@example)
92
+ @formatter.nyan_cat.should include [
93
+ '_,------, ',
94
+ '_| /\_/\ ',
95
+ '~|_( o .o) ',
96
+ ' "" "" '
97
+ ].join("\n")
98
+ end
99
+
100
+ it 'should kill nyan if the specs are finished' do
101
+ @formatter.example_failed(@example)
102
+ @formatter.stub(:finished?).and_return(true)
103
+ @formatter.nyan_cat.should include [
104
+ '_,------, ',
105
+ '_| /\_/\ ',
106
+ '~|_( x .x) ',
107
+ ' "" "" '
108
+ ].join("\n")
109
+ end
110
+
111
+ it 'should call instafail.example_failed' do
112
+ @formatter.instafail.should_receive(:example_failed).with(@example)
113
+ @formatter.example_failed(@example)
114
+ end
115
+ end
116
+ end
117
+
118
+ describe 'tick' do
119
+
120
+ before do
121
+ @formatter.stub!(:current).and_return(1)
122
+ @formatter.stub!(:example_count).and_return(2)
123
+ @formatter.tick
124
+ end
125
+
126
+ it 'should increment the current' do
127
+ @formatter.current.should == 1
128
+ end
129
+
130
+ it 'should store the marks in an array' do
131
+ @formatter.example_results.should include('=')
132
+ end
133
+
134
+ end
135
+
136
+ describe 'rainbowify' do
137
+
138
+ it 'should increment the color index count' do
139
+ lambda { @formatter.rainbowify('=') }.should change(@formatter, :color_index).by(1)
140
+ end
141
+
142
+ end
143
+
144
+ describe 'highlight' do
145
+
146
+ it 'should rainbowify passing examples' do
147
+ @formatter.highlight('=').should == "\e[38;5;196m-\e[0m"
148
+ end
149
+
150
+ it 'should mark failing examples as red' do
151
+ @formatter.highlight('*').should == "\e[31m*\e[0m"
152
+ end
153
+
154
+ it 'should mark pending examples as yellow' do
155
+ @formatter.highlight('!').should == "\e[33m!\e[0m"
156
+ end
157
+
158
+ end
159
+
160
+ describe 'start' do
161
+
162
+ it 'should set the total amount of specs' do
163
+ @formatter.example_count.should == 2
164
+ end
165
+
166
+ it 'should set the current to 0' do
167
+ @formatter.current.should == 0
168
+ end
169
+
170
+ end
171
+
172
+ describe "#format_duration" do
173
+ it "should return just seconds for sub 60 seconds" do
174
+ @formatter.format_duration(5.3).should eq("5.3 seconds")
175
+ end
176
+
177
+ it "should remove that extra zero if it is not needed" do
178
+ @formatter.format_duration(1.0).should eq("1 second")
179
+ end
180
+
181
+ it "should plurlaize seconds" do
182
+ @formatter.format_duration(1.1).should eq("1.1 seconds")
183
+ end
184
+
185
+ it "add a minute if it is just over 60 seconds" do
186
+ @formatter.format_duration(63.2543456456).should eq("1 minute and 3.25 seconds")
187
+ end
188
+
189
+ it "should pluralize minutes" do
190
+ @formatter.format_duration(987.34).should eq("16 minutes and 27.34 seconds")
191
+ end
192
+ end
193
+
194
+ describe '#instafail' do
195
+ it 'should be an instance of RSpec::Instafail' do
196
+ @formatter.instafail.should be_instance_of(RSpec::Instafail)
197
+ end
198
+ end
199
+ end
@@ -0,0 +1,74 @@
1
+ require 'spec_helper'
2
+ require 'stringio'
3
+ require 'nyan_cat_music_formatter'
4
+
5
+ describe NyanCatMusicFormatter do
6
+ let(:path_to_mp3) { NyanCatMusicFormatter.new(stdout).nyan_mp3 }
7
+ let(:stdout) { StringIO.new }
8
+ let(:formatter) { described_class.new stdout }
9
+ let(:mock_kernel) { MockKernel.new }
10
+
11
+ before { formatter.kernel = mock_kernel }
12
+
13
+ describe 'kernel' do
14
+ it 'defaults to Kernel' do
15
+ described_class.new(stdout).kernel.should == Kernel
16
+ end
17
+
18
+ it 'can be set' do
19
+ formatter = described_class.new stdout
20
+ formatter.kernel = 'something else'
21
+ formatter.kernel.should == 'something else'
22
+ end
23
+ end
24
+
25
+ describe 'platform' do
26
+ it 'defaults to RUBY_PLATFORM' do
27
+ described_class.new(stdout).platform.should eq RUBY_PLATFORM
28
+ end
29
+
30
+ it 'can be set' do
31
+ formatter = described_class.new stdout
32
+ formatter.platform = 'something else'
33
+ formatter.platform.should == 'something else'
34
+ end
35
+ end
36
+
37
+ describe 'start' do
38
+ it 'sets the total amount of specs' do
39
+ formatter.start 3
40
+ formatter.example_count.should == 3
41
+ end
42
+
43
+ it 'sets the current to 0' do
44
+ formatter.start 3
45
+ formatter.current.should == 0
46
+ end
47
+
48
+ context 'when on OS X' do
49
+ before { formatter.platform = 'darwin' }
50
+
51
+ it 'plays the song in the background' do
52
+ formatter.start 3
53
+ mock_kernel.seen.should include "afplay #{path_to_mp3} &"
54
+ end
55
+ end
56
+
57
+ context 'when on linux' do
58
+ before { formatter.platform = 'linux'}
59
+ it 'plays the song for linux too' do
60
+ formatter.start 10
61
+ mock_kernel.seen.any? { |entry| entry. end_with? "mpg321 #{path_to_mp3} &>/dev/null &" }.should be
62
+ end
63
+ end
64
+
65
+ context 'when not on OS X' do
66
+ before { formatter.platform = 'windows' }
67
+
68
+ it 'does not play the song' do
69
+ formatter.start 4
70
+ mock_kernel.seen.should be_empty
71
+ end
72
+ end
73
+ end
74
+ end
@@ -0,0 +1,44 @@
1
+ # -*- coding: utf-8 -*-
2
+ require 'spec_helper'
3
+ require 'stringio'
4
+
5
+ describe SmoothJazzNyanCatFormatter do
6
+ before do
7
+ rspec_bin = $0.split('/').last
8
+ @output = StringIO.new
9
+ if rspec_bin == 'rspec'
10
+ @formatter = SmoothJazzNyanCatFormatter.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 = SmoothJazzNyanCatFormatter.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
18
+ @formatter.start(2)
19
+ end
20
+
21
+ describe 'inherited behavior' do
22
+ it 'should inherit from the NyanCatMusicFormatter' do
23
+ @formatter.should be_a(NyanCatFormatter)
24
+ end
25
+ end
26
+
27
+ describe 'passed, pending and failed' do
28
+ before do
29
+ @formatter.stub!(:tick)
30
+ end
31
+
32
+ describe 'example_passed' do
33
+ it 'should relax Nyan Cat' do
34
+ @formatter.example_passed(@example)
35
+ @formatter.nyan_cat.should include [
36
+ '_,------, ',
37
+ '_| /\_/\ ',
38
+ '~|_( ⌐■.■) ',
39
+ ' "" "" '
40
+ ].join("\n")
41
+ end
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,60 @@
1
+ # -*- coding: utf-8 -*-
2
+ require 'spec_helper'
3
+ require 'stringio'
4
+ require 'smooth_jazz_nyan_cat_music_formatter'
5
+
6
+ describe SmoothJazzNyanCatMusicFormatter do
7
+ let(:path_to_mp3) { @formatter.nyan_mp3 }
8
+ let(:stdout) { StringIO.new }
9
+ let(:mock_kernel) { MockKernel.new }
10
+
11
+ before do
12
+ @formatter = nil
13
+ rspec_bin = $0.split('/').last
14
+ if rspec_bin == 'rspec'
15
+ @formatter = SmoothJazzNyanCatMusicFormatter.new(stdout)
16
+ @example = RSpec::Core::ExampleGroup.describe.example
17
+ else
18
+ formatter_options = OpenStruct.new(:colour => true, :dry_run => false, :autospec => nil)
19
+ @formatter = SmoothJazzNyanCatMusicFormatter.new(formatter_options, stdout)
20
+ @example = Spec::Example::ExampleProxy.new("should pass")
21
+ @formatter.instance_variable_set(:@example_group, OpenStruct.new(:description => "group"))
22
+ end
23
+ @formatter.start(2)
24
+ @formatter.kernel = mock_kernel
25
+ end
26
+
27
+ describe 'inherited behavior' do
28
+ it 'should inherit from the NyanCatMusicFormatter' do
29
+ @formatter.should be_a(NyanCatFormatter)
30
+ @formatter.should be_a(NyanCatMusicFormatter)
31
+ end
32
+ end
33
+
34
+ describe 'start' do
35
+ context 'when on OS X' do
36
+ before { @formatter.platform = 'darwin' }
37
+
38
+ it 'plays the song in the background' do
39
+ @formatter.start 3
40
+ mock_kernel.seen.should include "afplay #{path_to_mp3} &"
41
+ end
42
+ end
43
+ end
44
+
45
+ describe 'example_passed' do
46
+ before do
47
+ @formatter.stub!(:tick)
48
+ end
49
+
50
+ it 'should relax Nyan Cat' do
51
+ @formatter.example_passed(@example)
52
+ @formatter.nyan_cat.should include [
53
+ '_,------, ',
54
+ '_| /\_/\ ',
55
+ '~|_( ⌐■.■) ',
56
+ ' "" "" '
57
+ ].join("\n")
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,15 @@
1
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
2
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
3
+ require 'nyan_cat_formatter'
4
+ require 'smooth_jazz_nyan_cat_formatter'
5
+ require 'rspec/instafail'
6
+
7
+ class MockKernel
8
+ def system(string)
9
+ seen << string
10
+ end
11
+
12
+ def seen
13
+ @seen ||= []
14
+ end
15
+ end
metadata ADDED
@@ -0,0 +1,124 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: smooth-jazz-nyan-cat-formatter
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Ryan Spore
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-10-03 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rake
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: rspec
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: rspec-instafail
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :runtime
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ description: ! 'Nyan Cat inspired RSpec formatter! Now with more Jazz! '
63
+ email:
64
+ - ry@nspore.com
65
+ executables: []
66
+ extensions: []
67
+ extra_rdoc_files: []
68
+ files:
69
+ - .gitignore
70
+ - .rspec
71
+ - .rvmrc
72
+ - .travis.yml
73
+ - CHANGELOG.md
74
+ - Gemfile
75
+ - LICENSE.md
76
+ - README.md
77
+ - Rakefile
78
+ - data/nyan-cat.mp3
79
+ - data/smooth-jazz-nyan-cat.mp3
80
+ - demo.rb
81
+ - lib/nyan_cat_formatter.rb
82
+ - lib/nyan_cat_formatter/padded_string_io.rb
83
+ - lib/nyan_cat_formatter/rspec1.rb
84
+ - lib/nyan_cat_formatter/rspec2.rb
85
+ - lib/nyan_cat_music_formatter.rb
86
+ - lib/smooth_jazz_nyan_cat_formatter.rb
87
+ - lib/smooth_jazz_nyan_cat_music_formatter.rb
88
+ - lib/smooth_jazzy.rb
89
+ - nyan-cat-formatter.gemspec
90
+ - spec/nyan_cat_formatter_spec.rb
91
+ - spec/nyan_cat_music_formatter_spec.rb
92
+ - spec/smooth_jazz_nyan_cat_formatter_spec.rb
93
+ - spec/smooth_jazz_nyan_cat_music_formatter_spec.rb
94
+ - spec/spec_helper.rb
95
+ homepage:
96
+ licenses: []
97
+ post_install_message:
98
+ rdoc_options: []
99
+ require_paths:
100
+ - lib
101
+ required_ruby_version: !ruby/object:Gem::Requirement
102
+ none: false
103
+ requirements:
104
+ - - ! '>='
105
+ - !ruby/object:Gem::Version
106
+ version: '0'
107
+ required_rubygems_version: !ruby/object:Gem::Requirement
108
+ none: false
109
+ requirements:
110
+ - - ! '>='
111
+ - !ruby/object:Gem::Version
112
+ version: '0'
113
+ requirements: []
114
+ rubyforge_project:
115
+ rubygems_version: 1.8.24
116
+ signing_key:
117
+ specification_version: 3
118
+ summary: Nyan Cat inspired RSpec formatter! Now with more Jazz!
119
+ test_files:
120
+ - spec/nyan_cat_formatter_spec.rb
121
+ - spec/nyan_cat_music_formatter_spec.rb
122
+ - spec/smooth_jazz_nyan_cat_formatter_spec.rb
123
+ - spec/smooth_jazz_nyan_cat_music_formatter_spec.rb
124
+ - spec/spec_helper.rb