nyan-cat-formatter 0.6.0 → 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,5 @@
1
+ before_install: gem install bundler
2
+
1
3
  rvm:
2
4
  - 1.8.7
3
5
  - 1.9.2
@@ -6,5 +8,4 @@ rvm:
6
8
  - ree
7
9
  gemfile:
8
10
  - Gemfile
9
- - gemfiles/rspec1.gemfile
10
11
  - gemfiles/rspec2.gemfile
data/Rakefile CHANGED
@@ -1,6 +1,8 @@
1
+ require 'bundler/setup'
1
2
  require "bundler/gem_tasks"
2
3
 
3
- task :default => :spec
4
-
5
4
  require 'rspec/core/rake_task'
6
5
  RSpec::Core::RakeTask.new
6
+
7
+ desc 'Default: run the rspec examples'
8
+ task :default => :spec
@@ -0,0 +1,12 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ rake (10.1.1)
5
+ rspec (1.3.2)
6
+
7
+ PLATFORMS
8
+ ruby
9
+
10
+ DEPENDENCIES
11
+ rake
12
+ rspec (~> 1)
@@ -0,0 +1,19 @@
1
+ GEM
2
+ specs:
3
+ diff-lcs (1.2.5)
4
+ rake (10.1.1)
5
+ rspec (2.14.1)
6
+ rspec-core (~> 2.14.0)
7
+ rspec-expectations (~> 2.14.0)
8
+ rspec-mocks (~> 2.14.0)
9
+ rspec-core (2.14.7)
10
+ rspec-expectations (2.14.3)
11
+ diff-lcs (>= 1.1.3, < 2.0)
12
+ rspec-mocks (2.14.4)
13
+
14
+ PLATFORMS
15
+ ruby
16
+
17
+ DEPENDENCIES
18
+ rake
19
+ rspec (~> 2.14)
@@ -0,0 +1,10 @@
1
+ module NyanCatFormat
2
+ module Verbose
3
+ def progress_lines
4
+ [
5
+ format("%-#{terminal_width}s", finished? ? '' : "running: #{example_name}"),
6
+ ].concat(super)
7
+ end
8
+
9
+ end
10
+ end
@@ -46,12 +46,17 @@ module NyanCat
46
46
  #
47
47
  # @return nothing
48
48
  def dump_progress
49
+ output.print(progress_lines.join("\n") + eol)
50
+ end
51
+
52
+ def progress_lines
49
53
  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
54
+ [
55
+ nyan_trail.split("\n").each_with_index.inject([]) do |result, (trail, index)|
56
+ value = "#{scoreboard[index]}/#{@example_count}:"
57
+ result << format("%s %s", value, trail)
58
+ end
59
+ ].flatten
55
60
  end
56
61
 
57
62
  # Determines how we end the trail line. If complete, return a newline etc.
@@ -59,7 +64,7 @@ module NyanCat
59
64
  # @return [String]
60
65
  def eol
61
66
  return "\n" if @current == @example_count
62
- length = (nyan_cat.split("\n").length - 1)
67
+ length = progress_lines.length - 1
63
68
  length > 0 ? format("\e[1A" * length + "\r") : "\r"
64
69
  end
65
70
 
@@ -1,12 +1,19 @@
1
1
  class RSpec2 < RSpec::Core::Formatters::BaseTextFormatter
2
2
  include NyanCat::Common
3
3
 
4
+ attr_reader :example_name
5
+
4
6
  def start(example_count)
5
7
  super(example_count)
6
8
  @current = @color_index = @passing_count = 0
7
9
  @example_results = []
8
10
  end
9
11
 
12
+ def example_started(example)
13
+ super(example)
14
+ @example_name = example.full_description
15
+ end
16
+
10
17
  def example_passed(example)
11
18
  super(example)
12
19
  tick PASS
@@ -4,7 +4,9 @@ require 'ostruct'
4
4
  class RSpec3 < RSpec::Core::Formatters::BaseTextFormatter
5
5
  include NyanCat::Common
6
6
 
7
- RSpec::Core::Formatters.register self, :example_passed, :example_pending,
7
+ attr_reader :example_name
8
+
9
+ RSpec::Core::Formatters.register self, :example_started, :example_passed, :example_pending,
8
10
  :example_failed, :start_dump, :start
9
11
 
10
12
  def initialize(output)
@@ -23,6 +25,13 @@ class RSpec3 < RSpec::Core::Formatters::BaseTextFormatter
23
25
  @example_results = []
24
26
  end
25
27
 
28
+ def example_started(notification)
29
+ if notification.respond_to?(:example)
30
+ notification = notification.example
31
+ end
32
+ @example_name = notification.full_description
33
+ end
34
+
26
35
  def example_passed(notification)
27
36
  tick PASS
28
37
  end
@@ -0,0 +1,7 @@
1
+ # -*- coding: utf-8 -*-
2
+ require 'nyan_cat_formatter'
3
+ require 'nyan_cat_format/verbose'
4
+
5
+ NyanCatVerboseFormatter = Class.new(NyanCatFormatter) do
6
+ include NyanCatFormat::Verbose
7
+ end
@@ -4,4 +4,9 @@ require 'nyan_cat_format/wide'
4
4
 
5
5
  NyanCatWideFormatter = Class.new(NyanCatFormatter) do
6
6
  include NyanCatFormat::Wide
7
+
8
+ rspec_3_or_greater = Gem::Version.new(RSpec::Core::Version::STRING).release >= Gem::Version.new('3.0.0')
9
+
10
+ RSpec::Core::Formatters.register(self, :example_passed, :example_pending,
11
+ :example_failed, :start_dump, :start) if rspec_3_or_greater
7
12
  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.6.0"
5
+ s.version = "0.7.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,14 @@ describe NyanCatFormatter do
16
16
  @formatter.instance_variable_set(:@example_group, OpenStruct.new(:description => "group"))
17
17
  end
18
18
  @formatter.start(2)
19
- sleep(0.1) # Just to slow it down a little :-)
19
+ @formatter.example_started(@example)
20
+ end
21
+
22
+ shared_examples 'a test' do
23
+ it 'should call the increment method' do
24
+ expect(@formatter).to receive(:tick)
25
+ @formatter.example_passed(@example)
26
+ end
20
27
  end
21
28
 
22
29
  describe 'passed, pending and failed' do
@@ -26,11 +33,7 @@ describe NyanCatFormatter do
26
33
  end
27
34
 
28
35
  describe 'example_passed' do
29
-
30
- it 'should call the increment method' do
31
- expect(@formatter).to receive(:tick)
32
- @formatter.example_passed(@example)
33
- end
36
+ it_behaves_like 'a test'
34
37
 
35
38
  it 'should relax Nyan Cat' do
36
39
  @formatter.example_passed(@example)
@@ -48,11 +51,7 @@ describe NyanCatFormatter do
48
51
  end
49
52
 
50
53
  describe 'example_pending' do
51
-
52
- it 'should call the tick method' do
53
- expect(@formatter).to receive(:tick)
54
- @formatter.example_pending(@example)
55
- end
54
+ it_behaves_like 'a test'
56
55
 
57
56
  it 'should increment the pending count' do
58
57
  expect {
@@ -73,11 +72,7 @@ describe NyanCatFormatter do
73
72
  end
74
73
 
75
74
  describe 'example_failed' do
76
-
77
- it 'should call the increment method' do
78
- expect(@formatter).to receive(:tick)
79
- @formatter.example_failed(@example)
80
- end
75
+ it_behaves_like 'a test'
81
76
 
82
77
  it 'should increment the failure count' do
83
78
  expect {
@@ -0,0 +1,29 @@
1
+ require 'spec_helper'
2
+ require 'stringio'
3
+ require 'nyan_cat_verbose_formatter'
4
+
5
+ describe NyanCatVerboseFormatter do
6
+ before(:all) do
7
+ @output = StringIO.new
8
+ @formatter = described_class.new(@output)
9
+ end
10
+
11
+ before(:each) do
12
+ @formatter.start(1)
13
+ end
14
+
15
+ it 'displays "running" line with name of test on the first line' do
16
+ expect(@formatter.progress_lines.first).to include('running: ')
17
+ end
18
+
19
+ context 'this was the last test' do
20
+ before(:each) do
21
+ allow(@formatter).to receive(:finished?).and_return(true)
22
+ end
23
+
24
+ it 'should display an empty first line' do
25
+ expect(@formatter.progress_lines.first.scan(/[^ ]/)).to be_empty
26
+ end
27
+ end
28
+
29
+ end
@@ -15,6 +15,16 @@ describe NyanCatWideFormatter do
15
15
  @whole_net_width = 100 - 2*2 - 6 - 11
16
16
  end
17
17
 
18
+ context "for rspec 3" do
19
+ context "to avoid deprecation warnings" do
20
+ it "registers a nyan cat wide formatter compatible with rspec 3 format" do
21
+ if Gem::Version.new(RSpec::Core::Version::STRING).release >= Gem::Version.new('3.0.0')
22
+ expect(RSpec::Core::Formatters::Loader.formatters.keys).to include(NyanCatWideFormatter)
23
+ end
24
+ end
25
+ end
26
+ end
27
+
18
28
  context "for 35 examples" do
19
29
  before do
20
30
  @formatter.start(35)
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.6.0
4
+ version: 0.7.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: 2014-03-22 00:00:00.000000000 Z
12
+ date: 2014-05-31 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
@@ -74,8 +74,11 @@ files:
74
74
  - data/nyan-cat.mp3
75
75
  - demo.rb
76
76
  - gemfiles/rspec1
77
+ - gemfiles/rspec1.lock
77
78
  - gemfiles/rspec2
79
+ - gemfiles/rspec2.lock
78
80
  - lib/nyan_cat_format/music.rb
81
+ - lib/nyan_cat_format/verbose.rb
79
82
  - lib/nyan_cat_format/wide.rb
80
83
  - lib/nyan_cat_formatter.rb
81
84
  - lib/nyan_cat_formatter/common.rb
@@ -83,12 +86,14 @@ files:
83
86
  - lib/nyan_cat_formatter/rspec2.rb
84
87
  - lib/nyan_cat_formatter/rspec3.rb
85
88
  - lib/nyan_cat_music_formatter.rb
89
+ - lib/nyan_cat_verbose_formatter.rb
86
90
  - lib/nyan_cat_wide_formatter.rb
87
91
  - lib/nyan_cat_wide_music_formatter.rb
88
92
  - nyan-cat-formatter.gemspec
89
93
  - nyan_example.gif
90
94
  - spec/nyan_cat_formatter_spec.rb
91
95
  - spec/nyan_cat_music_formatter_spec.rb
96
+ - spec/nyan_cat_verbose_formatter_spec.rb
92
97
  - spec/nyan_cat_wide_formatter_spec.rb
93
98
  - spec/spec_helper.rb
94
99
  homepage: https://github.com/mattsears/nyan-cat-formatter
@@ -118,6 +123,7 @@ summary: Nyan Cat inspired RSpec formatter!
118
123
  test_files:
119
124
  - spec/nyan_cat_formatter_spec.rb
120
125
  - spec/nyan_cat_music_formatter_spec.rb
126
+ - spec/nyan_cat_verbose_formatter_spec.rb
121
127
  - spec/nyan_cat_wide_formatter_spec.rb
122
128
  - spec/spec_helper.rb
123
129
  has_rdoc: