rainbow_formatter 0.1.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+ require 'stringio'
5
+ require 'rainbow_insta_fail_formatter'
6
+
7
+ describe RainbowInstaFailFormatter do
8
+ before(:all) do
9
+ @output = StringIO.new
10
+ @formatter = described_class.new(@output)
11
+ end
12
+
13
+ before(:each) do
14
+ @formatter.start(1)
15
+ end
16
+
17
+ it 'displays failed tests immediately' do
18
+ example = double :example
19
+ expect(example).to receive(:fully_formatted).and_return('FAIL')
20
+ @formatter.example_failed(example)
21
+ expect(@output.string).to include('FAIL')
22
+ end
23
+ end
@@ -0,0 +1,122 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+ require 'stringio'
5
+ require 'fileutils'
6
+ require 'rainbow_music_formatter'
7
+
8
+ class MockKernel
9
+ def system(string)
10
+ seen << string
11
+ end
12
+
13
+ def spawn(string)
14
+ seen << string
15
+ rand(10_000)
16
+ end
17
+
18
+ def seen
19
+ @seen ||= []
20
+ end
21
+ end
22
+
23
+ describe RainbowMusicFormatter do
24
+ let(:path_to_mp3) { RainbowMusicFormatter.new(RainbowFormatter).rainbow_mp3 }
25
+ let(:stdout) { StringIO.new }
26
+ let(:formatter) { described_class.new stdout }
27
+ let(:mock_kernel) { MockKernel.new }
28
+
29
+ before { formatter.kernel = mock_kernel }
30
+
31
+ describe 'kernel' do
32
+ it 'defaults to Kernel' do
33
+ expect(described_class.new(stdout).kernel).to eq(Kernel)
34
+ end
35
+
36
+ it 'can be set' do
37
+ formatter = described_class.new stdout
38
+ formatter.kernel = 'something else'
39
+ expect(formatter.kernel).to eq('something else')
40
+ end
41
+ end
42
+
43
+ describe 'platform' do
44
+ it 'defaults to RUBY_PLATFORM' do
45
+ expect(described_class.new(stdout).platform).to eq(RUBY_PLATFORM)
46
+ end
47
+
48
+ it 'can be set' do
49
+ formatter = described_class.new stdout
50
+ formatter.platform = 'something else'
51
+ expect(formatter.platform).to eql('something else')
52
+ end
53
+ end
54
+
55
+ describe 'start' do
56
+ before do
57
+ allow(Process).to receive(:wait) { sleep 1 }
58
+ allow(Process).to receive(:kill).and_return(true)
59
+ end
60
+
61
+ it 'sets the total amount of specs' do
62
+ formatter.start 3
63
+ expect(formatter.example_count).to eql(3)
64
+ end
65
+
66
+ it 'sets the current to 0' do
67
+ formatter.start 3
68
+ expect(formatter.current).to eql(0)
69
+ end
70
+
71
+ context 'when on OS X' do
72
+ before { formatter.platform = 'darwin' }
73
+
74
+ it 'plays the song in the background' do
75
+ formatter.start 3
76
+ expect(mock_kernel.seen).to include("afplay #{path_to_mp3}")
77
+ end
78
+ end
79
+
80
+ context 'when on linux' do
81
+ before { formatter.platform = 'linux' }
82
+
83
+ it 'plays the song for linux too with mpg123 when available' do
84
+ allow(mock_kernel).to receive(:system).with(match(/which mpg123/)).and_return(true)
85
+ allow(mock_kernel).to receive(:system).with(match(/which mpg321/)).and_return(false)
86
+ formatter.start 10
87
+ expect(mock_kernel.seen.any? { |entry| entry. end_with? "mpg123 #{path_to_mp3} >/dev/null 2>&1" }).to be
88
+ end
89
+
90
+ it 'plays the song for linux too with mpg321 when available' do
91
+ allow(mock_kernel).to receive(:system).with(match(/which mpg321/)).and_return(true)
92
+ allow(mock_kernel).to receive(:system).with(match(/which mpg123/)).and_return(false)
93
+ formatter.start 10
94
+ expect(mock_kernel.seen.any? { |entry| entry. end_with? "mpg321 #{path_to_mp3} >/dev/null 2>&1" }).to be
95
+ end
96
+ end
97
+
98
+ context 'when on Windows' do
99
+ before { formatter.platform = 'windows' }
100
+
101
+ it 'does not play the song' do
102
+ formatter.start 4
103
+ expect(mock_kernel.seen).to be_empty
104
+ end
105
+ end
106
+
107
+ context 'when the music file does not exist' do
108
+ before do
109
+ FileUtils.mv path_to_mp3, "#{path_to_mp3}.tmp"
110
+ end
111
+
112
+ after do
113
+ FileUtils.mv "#{path_to_mp3}.tmp", path_to_mp3
114
+ end
115
+
116
+ it "won't try to play anything" do
117
+ formatter.start 42
118
+ expect(mock_kernel.seen).to be_empty
119
+ end
120
+ end
121
+ end
122
+ end
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+ require 'stringio'
5
+ require 'rainbow_verbose_formatter'
6
+
7
+ describe RainbowVerboseFormatter do
8
+ before(:all) do
9
+ @output = StringIO.new
10
+ @formatter = described_class.new(@output)
11
+ end
12
+
13
+ before(:each) do
14
+ @formatter.start(1)
15
+ end
16
+
17
+ it 'displays "running" line with name of test on the last line' do
18
+ expect(@formatter.progress_lines.last).to include('running: ')
19
+ end
20
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
4
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
5
+ require 'rainbow_formatter'
metadata ADDED
@@ -0,0 +1,129 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rainbow_formatter
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.5
5
+ platform: ruby
6
+ authors:
7
+ - Federico Farina
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2019-04-18 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rspec
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '3'
20
+ - - "<"
21
+ - !ruby/object:Gem::Version
22
+ version: '4'
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ version: '3'
30
+ - - "<"
31
+ - !ruby/object:Gem::Version
32
+ version: '4'
33
+ - !ruby/object:Gem::Dependency
34
+ name: pry
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ version: '0'
40
+ type: :development
41
+ prerelease: false
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: '0'
47
+ - !ruby/object:Gem::Dependency
48
+ name: rake
49
+ requirement: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ version: '0'
61
+ description: Customizable ascii-music RSpec formattter
62
+ email:
63
+ - federicojosefarina@gmail.com
64
+ executables: []
65
+ extensions: []
66
+ extra_rdoc_files: []
67
+ files:
68
+ - ".gitignore"
69
+ - ".rspec"
70
+ - ".rubocop.yml"
71
+ - ".ruby-version"
72
+ - CHANGELOG.md
73
+ - Gemfile
74
+ - LICENSE.md
75
+ - README.md
76
+ - Rakefile
77
+ - data/car.gif
78
+ - data/dog.gif
79
+ - data/monkey.gif
80
+ - data/tina_bike.gif
81
+ - data/tina_bike.mp3
82
+ - data/tina_dream.gif
83
+ - data/tina_dream.mp3
84
+ - demo.rb
85
+ - lib/formatter/common.rb
86
+ - lib/formatter/configuration.rb
87
+ - lib/formatter/custom/car.rb
88
+ - lib/formatter/custom/dog.rb
89
+ - lib/formatter/custom/monkey.rb
90
+ - lib/formatter/custom/tina_bike.rb
91
+ - lib/formatter/custom/tina_dream.rb
92
+ - lib/formatter/insta_fail.rb
93
+ - lib/formatter/music.rb
94
+ - lib/formatter/verbose.rb
95
+ - lib/formatter/version.rb
96
+ - lib/rainbow_formatter.rb
97
+ - lib/rainbow_insta_fail_formatter.rb
98
+ - lib/rainbow_music_formatter.rb
99
+ - lib/rainbow_verbose_formatter.rb
100
+ - rainbow_formatter.gemspec
101
+ - spec/rainbow_formatter_spec.rb
102
+ - spec/rainbow_insta_fail_formatter_spec.rb
103
+ - spec/rainbow_music_formatter_spec.rb
104
+ - spec/rainbow_verbose_formatter_spec.rb
105
+ - spec/spec_helper.rb
106
+ homepage: https://github.com/fedefa/rainbow-formatter
107
+ licenses:
108
+ - MIT
109
+ metadata: {}
110
+ post_install_message:
111
+ rdoc_options: []
112
+ require_paths:
113
+ - lib
114
+ required_ruby_version: !ruby/object:Gem::Requirement
115
+ requirements:
116
+ - - ">="
117
+ - !ruby/object:Gem::Version
118
+ version: '0'
119
+ required_rubygems_version: !ruby/object:Gem::Requirement
120
+ requirements:
121
+ - - ">="
122
+ - !ruby/object:Gem::Version
123
+ version: '0'
124
+ requirements: []
125
+ rubygems_version: 3.0.3
126
+ signing_key:
127
+ specification_version: 4
128
+ summary: Customizable RSpec formatter
129
+ test_files: []