nyan-cat-formatter 0.5.2 → 0.6.0

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.
@@ -2,4 +2,9 @@ rvm:
2
2
  - 1.8.7
3
3
  - 1.9.2
4
4
  - 1.9.3
5
+ - 2.1.0
5
6
  - ree
7
+ gemfile:
8
+ - Gemfile
9
+ - gemfiles/rspec1.gemfile
10
+ - gemfiles/rspec2.gemfile
data/README.md CHANGED
@@ -7,7 +7,7 @@ This is my take on the Nyan Cat RSpec Formatter. It simply creates a rainbow tra
7
7
 
8
8
  The rainbow changes colors as it runs. See it in action [here](http://vimeo.com/32424001).
9
9
 
10
- Works with RSpec 1.3 and RSpec 2.
10
+ Works with RSpec 1.3, 2 and 3.
11
11
 
12
12
  Using Nyan Cat
13
13
  ---------------
@@ -0,0 +1,9 @@
1
+ source :rubygems
2
+
3
+ gem 'rspec', '~> 1'
4
+
5
+ group :development do
6
+ gem 'rake'
7
+ end
8
+
9
+ # vi:ft=ruby
@@ -0,0 +1,7 @@
1
+ gem 'rspec', '~> 2.14'
2
+
3
+ group :development do
4
+ gem 'rake'
5
+ end
6
+
7
+ #vi:ft=ruby
@@ -1,223 +1,20 @@
1
1
  # -*- coding: utf-8 -*-
2
2
 
3
+ require 'nyan_cat_formatter/common'
4
+
3
5
  rspec_bin = $0.split('/').last
4
6
  if rspec_bin == 'spec'
5
7
  ['spec', 'nyan_cat_formatter/rspec1', 'spec/runner/formatter/base_text_formatter'].each {|f| require f}
6
- parent_class = Spec::Runner::Formatter::BaseTextFormatter
7
- rspec_module = RSpec1
8
+ formatter = RSpec1
8
9
  else
9
- ['nyan_cat_formatter/rspec2', 'rspec/core/formatters/base_text_formatter'].each {|f| require f}
10
- parent_class = RSpec::Core::Formatters::BaseTextFormatter
11
- rspec_module = RSpec2
12
- end
13
-
14
- NyanCatFormatter = Class.new(parent_class) do
15
-
16
- ESC = "\e["
17
- NND = "#{ESC}0m"
18
- PASS = '='
19
- PASS_ARY = ['-', '_']
20
- FAIL = '*'
21
- ERROR = '!'
22
- PENDING = '+'
23
-
24
- include rspec_module
25
-
26
- attr_reader :current, :example_results, :color_index, :pending_count,
27
- :failure_count, :example_count
28
-
29
- # Increments the example count and displays the current progress
30
- #
31
- # @returns nothing
32
- def tick(mark = PASS)
33
- @example_results << mark
34
- @current = (@current > @example_count) ? @example_count : @current + 1
35
- dump_progress
36
- end
37
-
38
- # Determine which Ascii Nyan Cat to display. If tests are complete,
39
- # Nyan Cat goes to sleep. If there are failing or pending examples,
40
- # Nyan Cat is concerned.
41
- #
42
- # @return [String] Nyan Cat
43
- def nyan_cat
44
- if self.failed_or_pending? && self.finished?
45
- ascii_cat('x')[@color_index%2].join("\n") #'~|_(x.x)'
46
- elsif self.failed_or_pending?
47
- ascii_cat('o')[@color_index%2].join("\n") #'~|_(o.o)'
48
- elsif self.finished?
49
- ascii_cat('-')[@color_index%2].join("\n") # '~|_(-.-)'
50
- else
51
- ascii_cat('^')[@color_index%2].join("\n") # '~|_(^.^)'
52
- end
53
- end
54
-
55
- # Displays the current progress in all Nyan Cat glory
56
- #
57
- # @return nothing
58
- def dump_progress
59
- padding = @example_count.to_s.length * 2 + 2
60
- line = nyan_trail.split("\n").each_with_index.inject([]) do |result, (trail, index)|
61
- value = "#{scoreboard[index]}/#{@example_count}:"
62
- result << format("%s %s", value, trail)
63
- end.join("\n")
64
- output.print line + eol
65
- end
66
-
67
- # Determines how we end the trail line. If complete, return a newline etc.
68
- #
69
- # @return [String]
70
- def eol
71
- return "\n" if @current == @example_count
72
- length = (nyan_cat.split("\n").length - 1)
73
- length > 0 ? format("\e[1A" * length + "\r") : "\r"
74
- end
75
-
76
- # Calculates the current flight length
77
- #
78
- # @return [Fixnum]
79
- def current_width
80
- padding_width + example_width + cat_length
81
- end
82
-
83
- # Gets the padding for the current example count
84
- #
85
- # @return [Fixnum]
86
- def padding_width
87
- @example_count.to_s.length * 2 + 6
88
- end
89
-
90
- # A Unix trick using stty to get the console columns
91
- #
92
- # @return [Fixnum]
93
- def terminal_width
94
- if defined? JRUBY_VERSION
95
- default_width = 80
96
- else
97
- default_width = `stty size`.split.map { |x| x.to_i }.reverse.first - 1
98
- end
99
- @terminal_width ||= default_width
100
- end
101
-
102
- # Creates a data store of pass, failed, and pending example results
103
- # We have to pad the results here because sprintf can't properly pad color
104
- #
105
- # @return [Array]
106
- def scoreboard
107
- @pending_examples ||= []
108
- @failed_examples ||= []
109
- padding = @example_count.to_s.length
110
- [ @current.to_s.rjust(padding),
111
- success_color((@current - @pending_examples.size - @failed_examples.size).to_s.rjust(padding)),
112
- pending_color(@pending_examples.size.to_s.rjust(padding)),
113
- failure_color(@failed_examples.size.to_s.rjust(padding)) ]
114
- end
115
-
116
- # Creates a rainbow trail
117
- #
118
- # @return [String] the sprintf format of the Nyan cat
119
- def nyan_trail
120
- marks = @example_results.each_with_index.map{ |mark, i| highlight(mark) * example_width(i) }
121
- marks.shift(current_width - terminal_width) if current_width >= terminal_width
122
- nyan_cat_lines = nyan_cat.split("\n").each_with_index.map do |line, index|
123
- format("%s#{line}", marks.join)
124
- end.join("\n")
10
+ require 'rspec/core/formatters/base_text_formatter'
11
+ if Gem::Version.new(RSpec::Core::Version::STRING).release >= Gem::Version.new('3.0.0')
12
+ require 'nyan_cat_formatter/rspec3'
13
+ formatter = RSpec3
14
+ else
15
+ require 'nyan_cat_formatter/rspec2'
16
+ formatter = RSpec2
125
17
  end
126
-
127
- # Times a mark has to be repeated
128
- def example_width(item = 1)
129
- 1
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
- "~|_( #{o} .#{o}) ",
140
- " \"\" \"\" "
141
- ],
142
- [ "_,------, ",
143
- "_| /\\_/\\",
144
- "^|__( #{o} .#{o}) ",
145
- " \" \" \" \""
146
- ]]
147
- end
148
-
149
- # Colorizes the string with raindow colors of the rainbow
150
- #
151
- # @params string [String]
152
- # @return [String]
153
- def rainbowify(string)
154
- c = colors[@color_index % colors.size]
155
- @color_index += 1
156
- "#{ESC}38;5;#{c}m#{string}#{NND}"
157
- end
158
-
159
- # Calculates the colors of the rainbow
160
- #
161
- # @return [Array]
162
- def colors
163
- @colors ||= (0...(6 * 7)).map do |n|
164
- pi_3 = Math::PI / 3
165
- n *= 1.0 / 6
166
- r = (3 * Math.sin(n ) + 3).to_i
167
- g = (3 * Math.sin(n + 2 * pi_3) + 3).to_i
168
- b = (3 * Math.sin(n + 4 * pi_3) + 3).to_i
169
- 36 * r + 6 * g + b + 16
170
- end
171
- end
172
-
173
- # Determines how to color the example. If pass, it is rainbowified, otherwise
174
- # we assign red if failed or yellow if an error occurred.
175
- #
176
- # @return [String]
177
- def highlight(mark = PASS)
178
- case mark
179
- when PASS; rainbowify PASS_ARY[@color_index%2]
180
- when FAIL; "\e[31m#{mark}\e[0m"
181
- when ERROR; "\e[33m#{mark}\e[0m"
182
- when PENDING; "\e[33m#{mark}\e[0m"
183
- else mark
184
- end
185
- end
186
-
187
- # Converts a float of seconds into a minutes/seconds string
188
- #
189
- # @return [String]
190
- def format_duration(duration)
191
- seconds = ((duration % 60) * 100.0).round / 100.0 # 1.8.7 safe .round(2)
192
- seconds = seconds.to_i if seconds.to_i == seconds # drop that zero if it's not needed
193
-
194
- message = "#{seconds} second#{seconds == 1 ? "" : "s"}"
195
- message = "#{(duration / 60).to_i} minute#{(duration / 60).to_i == 1 ? "" : "s"} and " + message if duration >= 60
196
-
197
- message
198
- end
199
-
200
-
201
- # Determines if the specs have completed
202
- #
203
- # @returns [Boolean] true if finished; false otherwise
204
- def finished?
205
- (@current == @example_count)
206
- end
207
-
208
- # Determines if the any specs failed or are in pending state
209
- #
210
- # @returns [Boolean] true if failed or pending; false otherwise
211
- def failed_or_pending?
212
- (@failure_count.to_i > 0 || @pending_count.to_i > 0)
213
- end
214
-
215
- # Returns the cat length
216
- #
217
- # @returns [Fixnum]
218
- def cat_length
219
- nyan_cat.split("\n").group_by(&:size).max.first
220
- end
221
-
222
18
  end
223
19
 
20
+ NyanCatFormatter = formatter
@@ -0,0 +1,213 @@
1
+ # -*- coding: utf-8 -*-
2
+ module NyanCat
3
+ module Common
4
+ ESC = "\e["
5
+ NND = "#{ESC}0m"
6
+ PASS = '='
7
+ PASS_ARY = ['-', '_']
8
+ FAIL = '*'
9
+ ERROR = '!'
10
+ PENDING = '+'
11
+
12
+ def self.included(base)
13
+ base.class_eval do
14
+ attr_reader :current, :example_results, :color_index, :pending_count, :failure_count,
15
+ :example_count
16
+ end
17
+ end
18
+
19
+ # Increments the example count and displays the current progress
20
+ #
21
+ # @returns nothing
22
+ def tick(mark = PASS)
23
+ @example_results << mark
24
+ @current = (@current > @example_count) ? @example_count : @current + 1
25
+ dump_progress
26
+ end
27
+
28
+ # Determine which Ascii Nyan Cat to display. If tests are complete,
29
+ # Nyan Cat goes to sleep. If there are failing or pending examples,
30
+ # Nyan Cat is concerned.
31
+ #
32
+ # @return [String] Nyan Cat
33
+ def nyan_cat
34
+ if self.failed_or_pending? && self.finished?
35
+ ascii_cat('x')[@color_index%2].join("\n") #'~|_(x.x)'
36
+ elsif self.failed_or_pending?
37
+ ascii_cat('o')[@color_index%2].join("\n") #'~|_(o.o)'
38
+ elsif self.finished?
39
+ ascii_cat('-')[@color_index%2].join("\n") # '~|_(-.-)'
40
+ else
41
+ ascii_cat('^')[@color_index%2].join("\n") # '~|_(^.^)'
42
+ end
43
+ end
44
+
45
+ # Displays the current progress in all Nyan Cat glory
46
+ #
47
+ # @return nothing
48
+ def dump_progress
49
+ padding = @example_count.to_s.length * 2 + 2
50
+ line = nyan_trail.split("\n").each_with_index.inject([]) do |result, (trail, index)|
51
+ value = "#{scoreboard[index]}/#{@example_count}:"
52
+ result << format("%s %s", value, trail)
53
+ end.join("\n")
54
+ output.print line + eol
55
+ end
56
+
57
+ # Determines how we end the trail line. If complete, return a newline etc.
58
+ #
59
+ # @return [String]
60
+ def eol
61
+ return "\n" if @current == @example_count
62
+ length = (nyan_cat.split("\n").length - 1)
63
+ length > 0 ? format("\e[1A" * length + "\r") : "\r"
64
+ end
65
+
66
+ # Calculates the current flight length
67
+ #
68
+ # @return [Fixnum]
69
+ def current_width
70
+ # padding_width + example_width + cat_length
71
+ padding_width + (@current * example_width) + cat_length
72
+ end
73
+
74
+ # Gets the padding for the current example count
75
+ #
76
+ # @return [Fixnum]
77
+ def padding_width
78
+ @example_count.to_s.length * 2 + 6
79
+ end
80
+
81
+ # A Unix trick using stty to get the console columns
82
+ #
83
+ # @return [Fixnum]
84
+ def terminal_width
85
+ if defined? JRUBY_VERSION
86
+ default_width = 80
87
+ else
88
+ default_width = `stty size`.split.map { |x| x.to_i }.reverse.first - 1
89
+ end
90
+ @terminal_width ||= default_width
91
+ end
92
+
93
+ # Creates a data store of pass, failed, and pending example results
94
+ # We have to pad the results here because sprintf can't properly pad color
95
+ #
96
+ # @return [Array]
97
+ def scoreboard
98
+ @pending_examples ||= []
99
+ @failed_examples ||= []
100
+ padding = @example_count.to_s.length
101
+ [ @current.to_s.rjust(padding),
102
+ success_color((@current - @pending_examples.size - @failed_examples.size).to_s.rjust(padding)),
103
+ pending_color(@pending_examples.size.to_s.rjust(padding)),
104
+ failure_color(@failed_examples.size.to_s.rjust(padding)) ]
105
+ end
106
+
107
+ # Creates a rainbow trail
108
+ #
109
+ # @return [String] the sprintf format of the Nyan cat
110
+ def nyan_trail
111
+ marks = @example_results.each_with_index.map{ |mark, i| highlight(mark) * example_width(i) }
112
+ marks.shift(current_width - terminal_width) if current_width >= terminal_width
113
+ nyan_cat_lines = nyan_cat.split("\n").each_with_index.map do |line, index|
114
+ format("%s#{line}", marks.join)
115
+ end.join("\n")
116
+ end
117
+
118
+ # Times a mark has to be repeated
119
+ def example_width(item = 1)
120
+ 1
121
+ end
122
+
123
+ # Ascii version of Nyan cat. Two cats in the array allow Nyan to animate running.
124
+ #
125
+ # @param o [String] Nyan's eye
126
+ # @return [Array] Nyan cats
127
+ def ascii_cat(o = '^')
128
+ [[ "_,------, ",
129
+ "_| /\\_/\\ ",
130
+ "~|_( #{o} .#{o}) ",
131
+ " \"\" \"\" "
132
+ ],
133
+ [ "_,------, ",
134
+ "_| /\\_/\\",
135
+ "^|__( #{o} .#{o}) ",
136
+ " \" \" \" \""
137
+ ]]
138
+ end
139
+
140
+ # Colorizes the string with raindow colors of the rainbow
141
+ #
142
+ # @params string [String]
143
+ # @return [String]
144
+ def rainbowify(string)
145
+ c = colors[@color_index % colors.size]
146
+ @color_index += 1
147
+ "#{ESC}38;5;#{c}m#{string}#{NND}"
148
+ end
149
+
150
+ # Calculates the colors of the rainbow
151
+ #
152
+ # @return [Array]
153
+ def colors
154
+ @colors ||= (0...(6 * 7)).map do |n|
155
+ pi_3 = Math::PI / 3
156
+ n *= 1.0 / 6
157
+ r = (3 * Math.sin(n ) + 3).to_i
158
+ g = (3 * Math.sin(n + 2 * pi_3) + 3).to_i
159
+ b = (3 * Math.sin(n + 4 * pi_3) + 3).to_i
160
+ 36 * r + 6 * g + b + 16
161
+ end
162
+ end
163
+
164
+ # Determines how to color the example. If pass, it is rainbowified, otherwise
165
+ # we assign red if failed or yellow if an error occurred.
166
+ #
167
+ # @return [String]
168
+ def highlight(mark = PASS)
169
+ case mark
170
+ when PASS; rainbowify PASS_ARY[@color_index%2]
171
+ when FAIL; "\e[31m#{mark}\e[0m"
172
+ when ERROR; "\e[33m#{mark}\e[0m"
173
+ when PENDING; "\e[33m#{mark}\e[0m"
174
+ else mark
175
+ end
176
+ end
177
+
178
+ # Converts a float of seconds into a minutes/seconds string
179
+ #
180
+ # @return [String]
181
+ def format_duration(duration)
182
+ seconds = ((duration % 60) * 100.0).round / 100.0 # 1.8.7 safe .round(2)
183
+ seconds = seconds.to_i if seconds.to_i == seconds # drop that zero if it's not needed
184
+
185
+ message = "#{seconds} second#{seconds == 1 ? "" : "s"}"
186
+ message = "#{(duration / 60).to_i} minute#{(duration / 60).to_i == 1 ? "" : "s"} and " + message if duration >= 60
187
+
188
+ message
189
+ end
190
+
191
+
192
+ # Determines if the specs have completed
193
+ #
194
+ # @returns [Boolean] true if finished; false otherwise
195
+ def finished?
196
+ (@current == @example_count)
197
+ end
198
+
199
+ # Determines if the any specs failed or are in pending state
200
+ #
201
+ # @returns [Boolean] true if failed or pending; false otherwise
202
+ def failed_or_pending?
203
+ (@failure_count.to_i > 0 || @pending_count.to_i > 0)
204
+ end
205
+
206
+ # Returns the cat length
207
+ #
208
+ # @returns [Fixnum]
209
+ def cat_length
210
+ nyan_cat.split("\n").group_by(&:size).max.first
211
+ end
212
+ end
213
+ end
@@ -1,4 +1,5 @@
1
- module RSpec1
1
+ class RSpec1 < Spec::Runner::Formatter::BaseTextFormatter
2
+ include NyanCat::Common
2
3
 
3
4
  def start(example_count)
4
5
  super(example_count)
@@ -1,4 +1,5 @@
1
- module RSpec2
1
+ class RSpec2 < RSpec::Core::Formatters::BaseTextFormatter
2
+ include NyanCat::Common
2
3
 
3
4
  def start(example_count)
4
5
  super(example_count)
@@ -0,0 +1,69 @@
1
+ require "rspec/core/formatters/base_text_formatter"
2
+ require 'ostruct'
3
+
4
+ class RSpec3 < RSpec::Core::Formatters::BaseTextFormatter
5
+ include NyanCat::Common
6
+
7
+ RSpec::Core::Formatters.register self, :example_passed, :example_pending,
8
+ :example_failed, :start_dump, :start
9
+
10
+ def initialize(output)
11
+ super(output)
12
+ end
13
+
14
+ def start(notification)
15
+ # TODO: Lazy fix for specs.
16
+ if notification.kind_of?(Fixnum)
17
+ super(OpenStruct.new(:count => notification))
18
+ else
19
+ super(notification)
20
+ end
21
+
22
+ @current = @color_index = @passing_count = 0
23
+ @example_results = []
24
+ end
25
+
26
+ def example_passed(notification)
27
+ tick PASS
28
+ end
29
+
30
+ def example_pending(notification)
31
+ if notification.respond_to?(:example)
32
+ super(notification)
33
+ else
34
+ super(OpenStruct.new(:example => notification))
35
+ end
36
+
37
+ @pending_count += 1
38
+
39
+ tick PENDING
40
+ end
41
+
42
+ def example_failed(notification)
43
+ # TODO: Lazy fix for specs
44
+ if notification.respond_to?(:example)
45
+ super(notification)
46
+ else
47
+ super(OpenStruct.new(:example => notification))
48
+ end
49
+
50
+ @failure_count += 1
51
+ tick FAIL
52
+ end
53
+
54
+ def start_dump(notification)
55
+ @current = @example_count
56
+ end
57
+
58
+ def dump_summary(notification)
59
+ duration = notification.duration
60
+ failure_count = notification.failure_count
61
+ dump_profile if profile_examples? && failure_count == 0
62
+ summary = "\nYou've Nyaned for #{format_duration(duration)}\n".split(//).map { |c| rainbowify(c) }
63
+ output.puts summary.join
64
+ output.puts colorise_summary(notification)
65
+ if respond_to?(:dump_commands_to_rerun_failed_examples)
66
+ dump_commands_to_rerun_failed_examples
67
+ end
68
+ end
69
+ end
@@ -2,7 +2,7 @@ $:.push File.expand_path("../lib", __FILE__)
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = "nyan-cat-formatter"
5
- s.version = "0.5.2"
5
+ s.version = "0.6.0"
6
6
  s.authors = ["Matt Sears"]
7
7
  s.email = ["matt@mattsears.com"]
8
8
  s.homepage = "https://github.com/mattsears/nyan-cat-formatter"
@@ -16,7 +16,7 @@ Gem::Specification.new do |s|
16
16
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
17
17
  s.require_paths = ["lib"]
18
18
 
19
- s.add_dependency "rspec", ">= 2.13"
19
+ s.add_dependency "rspec", ">= 2.14.2", ">= 2.99.0.beta1", "< 4"
20
20
 
21
21
  s.add_development_dependency "rake"
22
22
  end
@@ -22,52 +22,52 @@ describe NyanCatFormatter do
22
22
  describe 'passed, pending and failed' do
23
23
 
24
24
  before do
25
- @formatter.stub(:tick)
25
+ allow(@formatter).to receive(:tick)
26
26
  end
27
27
 
28
28
  describe 'example_passed' do
29
29
 
30
30
  it 'should call the increment method' do
31
- @formatter.should_receive :tick
31
+ expect(@formatter).to receive(:tick)
32
32
  @formatter.example_passed(@example)
33
33
  end
34
34
 
35
35
  it 'should relax Nyan Cat' do
36
36
  @formatter.example_passed(@example)
37
- @formatter.nyan_cat.should == [
37
+ expect(@formatter.nyan_cat).to eq([
38
38
  '_,------, ',
39
39
  '_| /\_/\ ',
40
40
  '~|_( ^ .^) ',
41
41
  ' "" "" '
42
- ].join("\n")
42
+ ].join("\n"))
43
43
  end
44
44
 
45
45
  it 'should update the scoreboard' do
46
- @formatter.scoreboard.size.should == 4
46
+ expect(@formatter.scoreboard.size).to eq(4)
47
47
  end
48
-
49
48
  end
50
49
 
51
50
  describe 'example_pending' do
52
51
 
53
52
  it 'should call the tick method' do
54
- @formatter.should_receive :tick
53
+ expect(@formatter).to receive(:tick)
55
54
  @formatter.example_pending(@example)
56
55
  end
57
56
 
58
57
  it 'should increment the pending count' do
59
- lambda { @formatter.example_pending(@example)}.
60
- should change(@formatter, :pending_count).by(1)
58
+ expect {
59
+ @formatter.example_pending(@example)
60
+ }.to change(@formatter, :pending_count).by(1)
61
61
  end
62
62
 
63
63
  it 'should alert Nyan Cat' do
64
64
  @formatter.example_pending(@example)
65
- @formatter.nyan_cat.should == [
65
+ expect(@formatter.nyan_cat).to eq([
66
66
  '_,------, ',
67
67
  '_| /\_/\ ',
68
68
  '~|_( o .o) ',
69
69
  ' "" "" '
70
- ].join("\n")
70
+ ].join("\n"))
71
71
  end
72
72
 
73
73
  end
@@ -75,34 +75,35 @@ describe NyanCatFormatter do
75
75
  describe 'example_failed' do
76
76
 
77
77
  it 'should call the increment method' do
78
- @formatter.should_receive :tick
78
+ expect(@formatter).to receive(:tick)
79
79
  @formatter.example_failed(@example)
80
80
  end
81
81
 
82
82
  it 'should increment the failure count' do
83
- lambda { @formatter.example_failed(@example)}.
84
- should change(@formatter, :failure_count).by(1)
83
+ expect {
84
+ @formatter.example_failed(@example)
85
+ }.to change(@formatter, :failure_count).by(1)
85
86
  end
86
87
 
87
88
  it 'should alert Nyan Cat' do
88
89
  @formatter.example_failed(@example)
89
- @formatter.nyan_cat.should == [
90
+ expect(@formatter.nyan_cat).to eq([
90
91
  '_,------, ',
91
92
  '_| /\_/\ ',
92
93
  '~|_( o .o) ',
93
94
  ' "" "" '
94
- ].join("\n")
95
+ ].join("\n"))
95
96
  end
96
97
 
97
98
  it 'should kill nyan if the specs are finished' do
98
99
  @formatter.example_failed(@example)
99
- @formatter.stub(:finished?).and_return(true)
100
- @formatter.nyan_cat.should == [
100
+ allow(@formatter).to receive(:finished?).and_return(true)
101
+ expect(@formatter.nyan_cat).to eq([
101
102
  '_,------, ',
102
103
  '_| /\_/\ ',
103
104
  '~|_( x .x) ',
104
105
  ' "" "" '
105
- ].join("\n")
106
+ ].join("\n"))
106
107
  end
107
108
 
108
109
  end
@@ -111,17 +112,17 @@ describe NyanCatFormatter do
111
112
  describe 'tick' do
112
113
 
113
114
  before do
114
- @formatter.stub(:current).and_return(1)
115
- @formatter.stub(:example_count).and_return(2)
115
+ allow(@formatter).to receive(:current).and_return(1)
116
+ allow(@formatter).to receive(:example_count).and_return(2)
116
117
  @formatter.tick
117
118
  end
118
119
 
119
120
  it 'should increment the current' do
120
- @formatter.current.should == 1
121
+ expect(@formatter.current).to eql(1)
121
122
  end
122
123
 
123
124
  it 'should store the marks in an array' do
124
- @formatter.example_results.should include('=')
125
+ expect(@formatter.example_results).to include('=')
125
126
  end
126
127
 
127
128
  end
@@ -129,7 +130,9 @@ describe NyanCatFormatter do
129
130
  describe 'rainbowify' do
130
131
 
131
132
  it 'should increment the color index count' do
132
- lambda { @formatter.rainbowify('=') }.should change(@formatter, :color_index).by(1)
133
+ expect {
134
+ @formatter.rainbowify('=')
135
+ }.to change(@formatter, :color_index).by(1)
133
136
  end
134
137
 
135
138
  end
@@ -137,15 +140,15 @@ describe NyanCatFormatter do
137
140
  describe 'highlight' do
138
141
 
139
142
  it 'should rainbowify passing examples' do
140
- @formatter.highlight('=').should == "\e[38;5;154m-\e[0m"
143
+ expect(@formatter.highlight('=')).to eq("\e[38;5;154m-\e[0m")
141
144
  end
142
145
 
143
146
  it 'should mark failing examples as red' do
144
- @formatter.highlight('*').should == "\e[31m*\e[0m"
147
+ expect(@formatter.highlight('*')).to eq("\e[31m*\e[0m")
145
148
  end
146
149
 
147
150
  it 'should mark pending examples as yellow' do
148
- @formatter.highlight('!').should == "\e[33m!\e[0m"
151
+ expect(@formatter.highlight('!')).to eq("\e[33m!\e[0m")
149
152
  end
150
153
 
151
154
  end
@@ -153,34 +156,34 @@ describe NyanCatFormatter do
153
156
  describe 'start' do
154
157
 
155
158
  it 'should set the total amount of specs' do
156
- @formatter.example_count.should == 2
159
+ expect(@formatter.example_count).to eq(2)
157
160
  end
158
161
 
159
162
  it 'should set the current to 0' do
160
- @formatter.current.should == 0
163
+ expect(@formatter.current).to eq(0)
161
164
  end
162
165
 
163
166
  end
164
167
 
165
168
  describe "#format_duration" do
166
169
  it "should return just seconds for sub 60 seconds" do
167
- @formatter.format_duration(5.3).should eq("5.3 seconds")
170
+ expect(@formatter.format_duration(5.3)).to eq("5.3 seconds")
168
171
  end
169
172
 
170
173
  it "should remove that extra zero if it is not needed" do
171
- @formatter.format_duration(1.0).should eq("1 second")
174
+ expect(@formatter.format_duration(1.0)).to eq("1 second")
172
175
  end
173
176
 
174
177
  it "should plurlaize seconds" do
175
- @formatter.format_duration(1.1).should eq("1.1 seconds")
178
+ expect(@formatter.format_duration(1.1)).to eq("1.1 seconds")
176
179
  end
177
180
 
178
181
  it "add a minute if it is just over 60 seconds" do
179
- @formatter.format_duration(63.2543456456).should eq("1 minute and 3.25 seconds")
182
+ expect(@formatter.format_duration(63.2543456456)).to eq("1 minute and 3.25 seconds")
180
183
  end
181
184
 
182
185
  it "should pluralize minutes" do
183
- @formatter.format_duration(987.34).should eq("16 minutes and 27.34 seconds")
186
+ expect(@formatter.format_duration(987.34)).to eq("16 minutes and 27.34 seconds")
184
187
  end
185
188
  end
186
189
 
@@ -195,7 +198,7 @@ describe NyanCatFormatter do
195
198
 
196
199
  context "when in example #{i}" do
197
200
  it "should return 1 as the example width" do
198
- @formatter.example_width.should == 1
201
+ expect(@formatter.example_width).to eq(1)
199
202
  end
200
203
  end
201
204
  end
@@ -22,37 +22,37 @@ describe NyanCatMusicFormatter do
22
22
 
23
23
  describe 'kernel' do
24
24
  it 'defaults to Kernel' do
25
- described_class.new(stdout).kernel.should == Kernel
25
+ expect(described_class.new(stdout).kernel).to eq(Kernel)
26
26
  end
27
27
 
28
28
  it 'can be set' do
29
29
  formatter = described_class.new stdout
30
30
  formatter.kernel = 'something else'
31
- formatter.kernel.should == 'something else'
31
+ expect(formatter.kernel).to eq('something else')
32
32
  end
33
33
  end
34
34
 
35
35
  describe 'platform' do
36
36
  it 'defaults to RUBY_PLATFORM' do
37
- described_class.new(stdout).platform.should eq RUBY_PLATFORM
37
+ expect(described_class.new(stdout).platform).to eq(RUBY_PLATFORM)
38
38
  end
39
39
 
40
40
  it 'can be set' do
41
41
  formatter = described_class.new stdout
42
42
  formatter.platform = 'something else'
43
- formatter.platform.should == 'something else'
43
+ expect(formatter.platform).to eql('something else')
44
44
  end
45
45
  end
46
46
 
47
47
  describe 'start' do
48
48
  it 'sets the total amount of specs' do
49
49
  formatter.start 3
50
- formatter.example_count.should == 3
50
+ expect(formatter.example_count).to eql(3)
51
51
  end
52
52
 
53
53
  it 'sets the current to 0' do
54
54
  formatter.start 3
55
- formatter.current.should == 0
55
+ expect(formatter.current).to eql(0)
56
56
  end
57
57
 
58
58
  context 'when on OS X' do
@@ -60,7 +60,7 @@ describe NyanCatMusicFormatter do
60
60
 
61
61
  it 'plays the song in the background' do
62
62
  formatter.start 3
63
- mock_kernel.seen.should include "afplay #{path_to_mp3} &"
63
+ expect(mock_kernel.seen).to include("afplay #{path_to_mp3} &")
64
64
  end
65
65
  end
66
66
 
@@ -68,8 +68,12 @@ describe NyanCatMusicFormatter do
68
68
  before { formatter.platform = 'linux'}
69
69
  it 'plays the song for linux too' do
70
70
  formatter.start 10
71
- mock_kernel.seen.any? { |entry| entry. end_with? "mpg321 #{path_to_mp3} &>/dev/null &" }.should be
72
- mock_kernel.seen.any? { |entry| entry. end_with? "mpg123 #{path_to_mp3} &>/dev/null &" }.should be
71
+ expect {
72
+ mock_kernel.seen.any? { |entry| entry. end_with? "mpg321 #{path_to_mp3} &>/dev/null &" }
73
+ }.to be
74
+ expect {
75
+ mock_kernel.seen.any? { |entry| entry. end_with? "mpg123 #{path_to_mp3} &>/dev/null &" }
76
+ }.to be
73
77
  end
74
78
  end
75
79
 
@@ -78,7 +82,7 @@ describe NyanCatMusicFormatter do
78
82
 
79
83
  it 'does not play the song' do
80
84
  formatter.start 4
81
- mock_kernel.seen.should be_empty
85
+ expect(mock_kernel.seen).to be_empty
82
86
  end
83
87
  end
84
88
  end
@@ -10,8 +10,8 @@ describe NyanCatWideFormatter do
10
10
 
11
11
  describe "cat situation" do
12
12
  before do
13
- @formatter.stub(:terminal_width).and_return(100)
14
- @formatter.stub(:cat_length).and_return(11)
13
+ allow(@formatter).to receive(:terminal_width).and_return(100)
14
+ allow(@formatter).to receive(:cat_length).and_return(11)
15
15
  @whole_net_width = 100 - 2*2 - 6 - 11
16
16
  end
17
17
 
@@ -21,11 +21,11 @@ describe NyanCatWideFormatter do
21
21
  end
22
22
 
23
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
24
+ expect(@formatter.net_width_for(3)).to eql((@whole_net_width * 3.0 / 35.0).round)
25
25
  end
26
26
 
27
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
28
+ expect(@formatter.net_width_for(5)).to eql((@whole_net_width * 5.0 / 35.0).round)
29
29
  end
30
30
  end
31
31
 
@@ -33,11 +33,11 @@ describe NyanCatWideFormatter do
33
33
  before { @formatter.start(50) }
34
34
 
35
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
36
+ expect(@formatter.net_width_for(1)).to eql((@whole_net_width * 1.0 / 50.0).round)
37
37
  end
38
38
 
39
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
40
+ expect(@formatter.net_width_for(25)).to eql((@whole_net_width * 25.0 / 50.0).round)
41
41
  end
42
42
  end
43
43
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nyan-cat-formatter
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.2
4
+ version: 0.6.0
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: 2013-11-03 00:00:00.000000000 Z
12
+ date: 2014-03-22 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
@@ -18,7 +18,13 @@ dependencies:
18
18
  requirements:
19
19
  - - ! '>='
20
20
  - !ruby/object:Gem::Version
21
- version: '2.13'
21
+ version: 2.14.2
22
+ - - ! '>='
23
+ - !ruby/object:Gem::Version
24
+ version: 2.99.0.beta1
25
+ - - <
26
+ - !ruby/object:Gem::Version
27
+ version: '4'
22
28
  type: :runtime
23
29
  prerelease: false
24
30
  version_requirements: !ruby/object:Gem::Requirement
@@ -26,7 +32,13 @@ dependencies:
26
32
  requirements:
27
33
  - - ! '>='
28
34
  - !ruby/object:Gem::Version
29
- version: '2.13'
35
+ version: 2.14.2
36
+ - - ! '>='
37
+ - !ruby/object:Gem::Version
38
+ version: 2.99.0.beta1
39
+ - - <
40
+ - !ruby/object:Gem::Version
41
+ version: '4'
30
42
  - !ruby/object:Gem::Dependency
31
43
  name: rake
32
44
  requirement: !ruby/object:Gem::Requirement
@@ -61,11 +73,15 @@ files:
61
73
  - Rakefile
62
74
  - data/nyan-cat.mp3
63
75
  - demo.rb
76
+ - gemfiles/rspec1
77
+ - gemfiles/rspec2
64
78
  - lib/nyan_cat_format/music.rb
65
79
  - lib/nyan_cat_format/wide.rb
66
80
  - lib/nyan_cat_formatter.rb
81
+ - lib/nyan_cat_formatter/common.rb
67
82
  - lib/nyan_cat_formatter/rspec1.rb
68
83
  - lib/nyan_cat_formatter/rspec2.rb
84
+ - lib/nyan_cat_formatter/rspec3.rb
69
85
  - lib/nyan_cat_music_formatter.rb
70
86
  - lib/nyan_cat_wide_formatter.rb
71
87
  - lib/nyan_cat_wide_music_formatter.rb
@@ -104,3 +120,4 @@ test_files:
104
120
  - spec/nyan_cat_music_formatter_spec.rb
105
121
  - spec/nyan_cat_wide_formatter_spec.rb
106
122
  - spec/spec_helper.rb
123
+ has_rdoc: