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

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -73,7 +73,7 @@ Make sure your .rspec file in your application's root directory contains the fol
73
73
 
74
74
  Then run `rspec spec` and enjoy Nyan Cat formatted text output accompanied by the Nyan Cat song by default!
75
75
 
76
- **This currently only works on Mac OS X or on Linux (if you have mpg321 installed).**
76
+ **This currently only works on Mac OS X or on Linux (if you have mpg321 or mpg123 installed).**
77
77
 
78
78
  Contributing
79
79
  ----------
data/demo.rb CHANGED
@@ -9,8 +9,8 @@ describe NyanCatFormatter do
9
9
  @formatter.start(2)
10
10
  @example = RSpec::Core::ExampleGroup.describe.example
11
11
 
12
- @samples = [0,0,0,0,0,0,0,0,0,0,0,1,
13
- 0]
12
+ @samples = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,
13
+ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]
14
14
 
15
15
  sleep(0.1) # Just to slow it down a little :-)
16
16
  end
@@ -29,7 +29,7 @@ NyanCatFormatter = Class.new(parent_class) do
29
29
  :failure_count, :example_count
30
30
 
31
31
  def initialize(args)
32
- super PaddedStringIO.new(terminal_width)
32
+ super PaddedStringIO.new
33
33
  end
34
34
 
35
35
  # Increments the example count and displays the current progress
@@ -76,8 +76,9 @@ NyanCatFormatter = Class.new(parent_class) do
76
76
  # @return [String]
77
77
  def eol
78
78
  return "\n" if @current == @example_count
79
- length = (nyan_cat.split("\n").length - 1)
80
- length > 0 ? format("\e[1A" * length + "\r") : "\r"
79
+ number_of_lines = (nyan_cat.split("\n").length - 1)
80
+ move_cursor_up = "\e[1A"
81
+ number_of_lines > 0 ? format(move_cursor_up * number_of_lines + "\r") : "\r"
81
82
  end
82
83
 
83
84
  # Calculates the current flight length
@@ -96,7 +97,7 @@ NyanCatFormatter = Class.new(parent_class) do
96
97
  if defined? JRUBY_VERSION
97
98
  default_width = 80
98
99
  else
99
- default_width = `stty size`.split.map { |x| x.to_i }.reverse.first - 1
100
+ default_width = `stty size`.split[-1].to_i - 1
100
101
  end
101
102
  @terminal_width ||= default_width
102
103
  end
@@ -1,19 +1,17 @@
1
1
  class PaddedStringIO
2
- def initialize(terminal_size)
2
+ def initialize
3
3
  @output = $stdout
4
- @terminal_size = terminal_size
5
4
  end
6
-
5
+
7
6
  def puts(output_strings = '')
8
7
  unless output_strings.is_a?(Array)
9
8
  output_strings = [output_strings]
10
9
  end
11
- output_strings.each do |output_string|
12
- @output.puts output_string.ljust(@terminal_size)
13
- # super 'foo'
10
+ output_strings.each do |output_string|
11
+ @output.puts output_string + "\e[0K"
14
12
  end
15
13
  end
16
-
14
+
17
15
  def method_missing(*args)
18
16
  @output.send(*args)
19
17
  end
@@ -43,7 +43,7 @@ module RSpec1
43
43
  end
44
44
 
45
45
  def dump_summary(duration, example_count, failure_count, pending_count)
46
- NyanCatMusicFormatter.new(NyanCatFormatter).kill_music if NyanCatMusicFormatter
46
+ NyanCatMusicFormatter.new(NyanCatFormatter).kill_music if defined?(NyanCatMusicFormatter)
47
47
  @output.puts "\nYou've Nyaned for #{format_duration(duration)}\n".each_char.map {|c| rainbowify(c)}.join
48
48
  summary = "#{example_count} example#{'s' unless example_count == 1}, #{failure_count} failure#{'s' unless failure_count == 1}"
49
49
  summary << ", #{pending_count} pending" if pending_count > 0
@@ -35,7 +35,7 @@ module RSpec2
35
35
  end
36
36
 
37
37
  def dump_summary(duration, example_count, failure_count, pending_count)
38
- NyanCatMusicFormatter.new(NyanCatFormatter).kill_music if NyanCatMusicFormatter
38
+ NyanCatMusicFormatter.new(NyanCatFormatter).kill_music if defined?(NyanCatMusicFormatter)
39
39
  dump_profile if profile_examples? && failure_count == 0
40
40
  summary = "\nYou've Nyaned for #{format_duration(duration)}\n".split(//).map { |c| rainbowify(c) }
41
41
  output.puts summary.join
@@ -49,24 +49,3 @@ module RSpec2
49
49
  @instafail ||= RSpec::Instafail.new(output)
50
50
  end
51
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
@@ -33,13 +33,26 @@ class NyanCatMusicFormatter < NyanCatFormatter
33
33
  def start input
34
34
  super
35
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?
36
+ play_on_linux if linux?
37
37
  end
38
38
 
39
39
  def kill_music
40
40
  if File.exists? nyan_mp3
41
41
  system("killall -9 afplay &>/dev/null") if osx?
42
- system("killall -9 mpg321 &>/dev/null") if linux?
42
+ kill_music_on_linux if linux?
43
43
  end
44
44
  end
45
+
46
+ private
47
+
48
+ def play_on_linux
49
+ 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
+ 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
+ end
52
+
53
+ def kill_music_on_linux
54
+ system("killall -9 mpg321 &>/dev/null") if kernel.system("which mpg321 &>/dev/null && type mpg321 &>/dev/null")
55
+ system("killall -9 mpg123 &>/dev/null") if kernel.system("which mpg123 &>/dev/null && type mpg123 &>/dev/null")
56
+ end
57
+
45
58
  end
@@ -2,7 +2,7 @@ $:.push File.expand_path("../lib", __FILE__)
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = "smooth-jazz-nyan-cat-formatter"
5
- s.version = "0.1.1"
5
+ s.version = "0.1.3"
6
6
  s.authors = ["Ryan Spore"]
7
7
  s.email = ["ry@nspore.com"]
8
8
  s.summary = %q{Nyan Cat inspired RSpec formatter! Now with more Jazz! }
@@ -59,6 +59,7 @@ describe NyanCatMusicFormatter do
59
59
  it 'plays the song for linux too' do
60
60
  formatter.start 10
61
61
  mock_kernel.seen.any? { |entry| entry. end_with? "mpg321 #{path_to_mp3} &>/dev/null &" }.should be
62
+ mock_kernel.seen.any? { |entry| entry. end_with? "mpg123 #{path_to_mp3} &>/dev/null &" }.should be
62
63
  end
63
64
  end
64
65
 
@@ -0,0 +1,11 @@
1
+ require 'spec_helper'
2
+
3
+ describe PaddedStringIO do
4
+ let(:subject) { PaddedStringIO.new }
5
+
6
+ it 'every puts clears the line to the right so no cat parts show up' do
7
+ arg = "this is a test string"
8
+ $stdout.should_receive(:puts).with(arg + "\e[0K")
9
+ subject.puts(arg)
10
+ end
11
+ 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.1
4
+ version: 0.1.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-10-03 00:00:00.000000000 Z
12
+ date: 2013-02-06 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rake
@@ -89,6 +89,7 @@ files:
89
89
  - nyan-cat-formatter.gemspec
90
90
  - spec/nyan_cat_formatter_spec.rb
91
91
  - spec/nyan_cat_music_formatter_spec.rb
92
+ - spec/padded_string_io_spec.rb
92
93
  - spec/smooth_jazz_nyan_cat_formatter_spec.rb
93
94
  - spec/smooth_jazz_nyan_cat_music_formatter_spec.rb
94
95
  - spec/spec_helper.rb
@@ -119,6 +120,7 @@ summary: Nyan Cat inspired RSpec formatter! Now with more Jazz!
119
120
  test_files:
120
121
  - spec/nyan_cat_formatter_spec.rb
121
122
  - spec/nyan_cat_music_formatter_spec.rb
123
+ - spec/padded_string_io_spec.rb
122
124
  - spec/smooth_jazz_nyan_cat_formatter_spec.rb
123
125
  - spec/smooth_jazz_nyan_cat_music_formatter_spec.rb
124
126
  - spec/spec_helper.rb