smooth-jazz-nyan-cat-formatter 0.1.3 → 0.1.5

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/.gitignore CHANGED
@@ -1,4 +1,5 @@
1
1
  *.gem
2
+ .idea
2
3
  .bundle
3
4
  Gemfile.lock
4
5
  pkg/*
data/README.md CHANGED
@@ -1,12 +1,7 @@
1
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
2
  ========
3
3
 
4
- ```
5
- -_-_-_-_-_-_-_,------,
6
- _-_-_-_-_-_-_-| /\_/\
7
- -_-_-_-_-_-_-~|__( ^ .^)
8
- _-_-_-_-_-_-_-"" ""
9
- ```
4
+ ![NYAN](nyan_example.gif)
10
5
 
11
6
  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
7
 
@@ -28,9 +23,11 @@ so that you won't have to specify the `--format` option everytime you run the co
28
23
 
29
24
  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
25
 
31
- group :test do
32
- gem "nyan-cat-formatter"
33
- end
26
+ ```ruby
27
+ group :test do
28
+ gem "nyan-cat-formatter"
29
+ end
30
+ ```
34
31
 
35
32
  And then run `bundle install`.
36
33
 
@@ -75,6 +72,20 @@ Then run `rspec spec` and enjoy Nyan Cat formatted text output accompanied by th
75
72
 
76
73
  **This currently only works on Mac OS X or on Linux (if you have mpg321 or mpg123 installed).**
77
74
 
75
+ Using the Nyan Cat Wide Formatter
76
+ ---------------------------------
77
+
78
+ The classic Nyan Cat Formatter uses a terminal column per test. One
79
+ test, and single step that the cat goes ahead. The **Nyan Cat Wide
80
+ Formatter**, instead, uses the whole terminal width, so the cat will
81
+ always end up reaching the end of the terminal.
82
+
83
+ Simple use it by configuring it as the RSpec formatter:
84
+
85
+ ```
86
+ --format NyanCatWideFormatter
87
+ ```
88
+
78
89
  Contributing
79
90
  ----------
80
91
 
@@ -88,5 +99,4 @@ Once you've made your great commits:
88
99
 
89
100
  Author
90
101
  ----------
91
- [Matt Sears](https://wwww.mattsears.com) :: @mattsears
92
-
102
+ [Matt Sears](http://www.mattsears.com) :: @mattsears
Binary file
data/demo.rb CHANGED
File without changes
@@ -85,9 +85,14 @@ NyanCatFormatter = Class.new(parent_class) do
85
85
  #
86
86
  # @return [Fixnum]
87
87
  def current_width
88
- padding = @example_count.to_s.length * 2 + 6
89
- cat_length = nyan_cat.split("\n").group_by(&:size).max.first
90
- padding + @current + cat_length
88
+ padding_width + @current + cat_length
89
+ end
90
+
91
+ # Gets the padding for the current example count
92
+ #
93
+ # @return [Fixnum]
94
+ def padding_width
95
+ @example_count.to_s.length * 2 + 6
91
96
  end
92
97
 
93
98
  # A Unix trick using stty to get the console columns
@@ -111,9 +116,9 @@ NyanCatFormatter = Class.new(parent_class) do
111
116
  @failed_examples ||= []
112
117
  padding = @example_count.to_s.length
113
118
  [ @current.to_s.rjust(padding),
114
- green((@current - @pending_examples.size - @failed_examples.size).to_s.rjust(padding)),
115
- yellow(@pending_examples.size.to_s.rjust(padding)),
116
- red(@failed_examples.size.to_s.rjust(padding)),
119
+ success_color((@current - @pending_examples.size - @failed_examples.size).to_s.rjust(padding)),
120
+ pending_color(@pending_examples.size.to_s.rjust(padding)),
121
+ failure_color(@failed_examples.size.to_s.rjust(padding)),
117
122
  "".rjust(padding),
118
123
  "".rjust(padding) ]
119
124
  end
@@ -122,7 +127,7 @@ NyanCatFormatter = Class.new(parent_class) do
122
127
  #
123
128
  # @return [String] the sprintf format of the Nyan cat
124
129
  def nyan_trail
125
- nyan_cat_lines = nyan_cat.split("\n").each_with_index.map do |line, index|
130
+ nyan_cat.split("\n").each_with_index.map do |line, index|
126
131
  @color_index = @current%8
127
132
  marks = @example_results.map{ |mark| highlight(mark, index) }
128
133
  marks.shift(current_width - terminal_width) if current_width >= terminal_width
@@ -234,5 +239,13 @@ NyanCatFormatter = Class.new(parent_class) do
234
239
  def failed_or_pending?
235
240
  (@failure_count.to_i > 0 || @pending_count.to_i > 0)
236
241
  end
242
+
243
+ # Returns the cat length
244
+ #
245
+ # @returns [Fixnum]
246
+ def cat_length
247
+ #TODO this is gross
248
+ nyan_cat.split("\n").group_by(&:size).max.first
249
+ end
237
250
  end
238
251
 
@@ -49,11 +49,11 @@ module RSpec1
49
49
  summary << ", #{pending_count} pending" if pending_count > 0
50
50
 
51
51
  if failure_count == 0
52
- @output.puts red(summary)
52
+ @output.puts failure_color(summary)
53
53
  elsif pending_count > 0
54
- @output.puts yellow(summary)
54
+ @output.puts pending_color(summary)
55
55
  else
56
- @output.puts green(summary)
56
+ @output.puts success_color(summary)
57
57
  end
58
58
  @output.flush
59
59
  end
@@ -2,6 +2,9 @@
2
2
  require 'nyan_cat_formatter'
3
3
 
4
4
  class NyanCatMusicFormatter < NyanCatFormatter
5
+ MUSIC_LENGTH = 27.06 # seconds
6
+ # TODO make it work with variable length songs
7
+
5
8
  def osx?
6
9
  platform.downcase.include?("darwin")
7
10
  end
@@ -32,25 +35,40 @@ class NyanCatMusicFormatter < NyanCatFormatter
32
35
 
33
36
  def start input
34
37
  super
35
- kernel.system("afplay #{nyan_mp3} &") if osx?
36
- play_on_linux if linux?
38
+ t = Thread.new do
39
+ loop do
40
+ if osx?
41
+ kernel.system("afplay #{nyan_mp3} &")
42
+ elsif linux?
43
+ play_on_linux
44
+ end
45
+ Thread.current["started_playing"] ||= true
46
+ sleep MUSIC_LENGTH
47
+ end
48
+ end
49
+ until t["started_playing"]
50
+ sleep 0.001
51
+ end
37
52
  end
38
53
 
39
54
  def kill_music
40
55
  if File.exists? nyan_mp3
41
- system("killall -9 afplay &>/dev/null") if osx?
42
- kill_music_on_linux if linux?
56
+ if osx?
57
+ system("killall -9 afplay &>/dev/null")
58
+ elsif linux?
59
+ kill_music_on_linux
60
+ end
43
61
  end
44
62
  end
45
63
 
46
64
  private
47
-
65
+
48
66
  def play_on_linux
49
67
  kernel.system("[ -e #{nyan_mp3} ] && type mpg321 &>/dev/null && mpg321 #{nyan_mp3} &>/dev/null &") if kernel.system('which mpg321 &>/dev/null && type mpg321 &>/dev/null')
50
68
  kernel.system("[ -e #{nyan_mp3} ] && type mpg123 &>/dev/null && mpg123 #{nyan_mp3} &>/dev/null &") if kernel.system('which mpg123 &>/dev/null && type mpg123 &>/dev/null')
51
69
  end
52
70
 
53
- def kill_music_on_linux
71
+ def kill_music_on_linux
54
72
  system("killall -9 mpg321 &>/dev/null") if kernel.system("which mpg321 &>/dev/null && type mpg321 &>/dev/null")
55
73
  system("killall -9 mpg123 &>/dev/null") if kernel.system("which mpg123 &>/dev/null && type mpg123 &>/dev/null")
56
74
  end
@@ -0,0 +1,19 @@
1
+ # -*- coding: utf-8 -*-
2
+ require 'nyan_cat_formatter'
3
+
4
+ NyanCatWideFormatter = Class.new(NyanCatFormatter) do
5
+ def example_width(example = current)
6
+ net_width_for(example) - net_width_for(example - 1)
7
+ end
8
+
9
+ def net_width_for(example)
10
+ @net_width ||= {}
11
+
12
+ @net_width[example] ||= begin
13
+ return 0 if example < 0
14
+ net_width = terminal_width - padding_width - cat_length
15
+ rough_example_width = (net_width * example.to_f / @example_count.to_f)
16
+ rough_example_width.round
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,3 @@
1
+ module SmoothJazzNyanCatFormatter
2
+ VERSION = "0.1.5"
3
+ end
@@ -1,8 +1,9 @@
1
1
  $:.push File.expand_path("../lib", __FILE__)
2
+ require 'smooth_jazz_nyan_cat_formatter/version'
2
3
 
3
4
  Gem::Specification.new do |s|
4
5
  s.name = "smooth-jazz-nyan-cat-formatter"
5
- s.version = "0.1.3"
6
+ s.version = SmoothJazzNyanCatFormatter::VERSION
6
7
  s.authors = ["Ryan Spore"]
7
8
  s.email = ["ry@nspore.com"]
8
9
  s.summary = %q{Nyan Cat inspired RSpec formatter! Now with more Jazz! }
@@ -13,8 +14,8 @@ Gem::Specification.new do |s|
13
14
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
14
15
  s.require_paths = ["lib"]
15
16
 
16
- # specify any dependencies here; for example:
17
- s.add_development_dependency "rake"
18
- s.add_development_dependency "rspec"
19
17
  s.add_dependency "rspec-instafail"
18
+
19
+ s.add_development_dependency "rspec"
20
+ s.add_development_dependency "rake"
20
21
  end
Binary file
@@ -107,7 +107,7 @@ describe NyanCatFormatter do
107
107
  ' "" "" '
108
108
  ].join("\n")
109
109
  end
110
-
110
+
111
111
  it 'should call instafail.example_failed' do
112
112
  @formatter.instafail.should_receive(:example_failed).with(@example)
113
113
  @formatter.example_failed(@example)
@@ -190,7 +190,7 @@ describe NyanCatFormatter do
190
190
  @formatter.format_duration(987.34).should eq("16 minutes and 27.34 seconds")
191
191
  end
192
192
  end
193
-
193
+
194
194
  describe '#instafail' do
195
195
  it 'should be an instance of RSpec::Instafail' do
196
196
  @formatter.instafail.should be_instance_of(RSpec::Instafail)
@@ -0,0 +1,44 @@
1
+ require 'spec_helper'
2
+ require 'stringio'
3
+ require 'nyan_cat_wide_formatter'
4
+
5
+ describe NyanCatWideFormatter do
6
+ before do
7
+ @output = StringIO.new
8
+ @formatter = NyanCatWideFormatter.new(@output)
9
+ end
10
+
11
+ describe "cat situation" do
12
+ before do
13
+ @formatter.stub!(:terminal_width).and_return(100)
14
+ @formatter.stub!(:cat_length).and_return(11)
15
+ @whole_net_width = 100 - 2*2 - 6 - 11
16
+ end
17
+
18
+ context "for 35 examples" do
19
+ before do
20
+ @formatter.start(35)
21
+ end
22
+
23
+ it "should calculate the net width for example 3" do
24
+ @formatter.net_width_for(3).should == (@whole_net_width * 3.0 / 35.0).round
25
+ end
26
+
27
+ it "should calculate the net width for example 30" do
28
+ @formatter.net_width_for(5).should == (@whole_net_width * 5.0 / 35.0).round
29
+ end
30
+ end
31
+
32
+ context "for 50 examples" do
33
+ before { @formatter.start(50) }
34
+
35
+ it "should calculate the net width for example 1" do
36
+ @formatter.net_width_for(1).should == (@whole_net_width * 1.0 / 50.0).round
37
+ end
38
+
39
+ it "should calculate the net width for example 25" do
40
+ @formatter.net_width_for(25).should == (@whole_net_width * 25.0 / 50.0).round
41
+ end
42
+ end
43
+ end
44
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: smooth-jazz-nyan-cat-formatter
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.5
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,17 +9,17 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-02-06 00:00:00.000000000 Z
12
+ date: 2013-04-19 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
- name: rake
15
+ name: rspec-instafail
16
16
  requirement: !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
20
20
  - !ruby/object:Gem::Version
21
21
  version: '0'
22
- type: :development
22
+ type: :runtime
23
23
  prerelease: false
24
24
  version_requirements: !ruby/object:Gem::Requirement
25
25
  none: false
@@ -44,14 +44,14 @@ dependencies:
44
44
  - !ruby/object:Gem::Version
45
45
  version: '0'
46
46
  - !ruby/object:Gem::Dependency
47
- name: rspec-instafail
47
+ name: rake
48
48
  requirement: !ruby/object:Gem::Requirement
49
49
  none: false
50
50
  requirements:
51
51
  - - ! '>='
52
52
  - !ruby/object:Gem::Version
53
53
  version: '0'
54
- type: :runtime
54
+ type: :development
55
55
  prerelease: false
56
56
  version_requirements: !ruby/object:Gem::Requirement
57
57
  none: false
@@ -83,12 +83,17 @@ files:
83
83
  - lib/nyan_cat_formatter/rspec1.rb
84
84
  - lib/nyan_cat_formatter/rspec2.rb
85
85
  - lib/nyan_cat_music_formatter.rb
86
+ - lib/nyan_cat_wide_formatter.rb
86
87
  - lib/smooth_jazz_nyan_cat_formatter.rb
88
+ - lib/smooth_jazz_nyan_cat_formatter/version.rb
87
89
  - lib/smooth_jazz_nyan_cat_music_formatter.rb
88
90
  - lib/smooth_jazzy.rb
89
91
  - nyan-cat-formatter.gemspec
92
+ - nyan_example.gif
93
+ - projectFilesBackup/.idea/nyan-cat-formatter.iml
90
94
  - spec/nyan_cat_formatter_spec.rb
91
95
  - spec/nyan_cat_music_formatter_spec.rb
96
+ - spec/nyan_cat_wide_formatter_spec.rb
92
97
  - spec/padded_string_io_spec.rb
93
98
  - spec/smooth_jazz_nyan_cat_formatter_spec.rb
94
99
  - spec/smooth_jazz_nyan_cat_music_formatter_spec.rb
@@ -120,6 +125,7 @@ summary: Nyan Cat inspired RSpec formatter! Now with more Jazz!
120
125
  test_files:
121
126
  - spec/nyan_cat_formatter_spec.rb
122
127
  - spec/nyan_cat_music_formatter_spec.rb
128
+ - spec/nyan_cat_wide_formatter_spec.rb
123
129
  - spec/padded_string_io_spec.rb
124
130
  - spec/smooth_jazz_nyan_cat_formatter_spec.rb
125
131
  - spec/smooth_jazz_nyan_cat_music_formatter_spec.rb