minitest-sound 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 212568b0e34e78cfe338fe4ff324f470ba6e61b1
4
+ data.tar.gz: 7909390584699ea974654f47bb82ccb436e65af0
5
+ SHA512:
6
+ metadata.gz: aa9bf46d9123d9e342babfb5e506388996c363ad0f27ba3414a5b6f9684d8d0b00b4645b904eb942b943a16dd32fc73a94ce69662ee20326a7b1a011129aba97
7
+ data.tar.gz: f1a4c7e2d6e06b912125b57016612b5b1116bc3c45534b376c96df99588ed3ae437158fefa06c7a7eddffd0e55669145f7e10d1ea8ebcba51f44feed24108f99
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in minitest-sound.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 yuuji.yaginuma
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,41 @@
1
+ # Minitest::Sound
2
+
3
+ minitest-sound plays sound when test finished.
4
+
5
+ ## Requirements
6
+
7
+ * `mpg123`
8
+ * `minitest ~> 5.0`
9
+
10
+ ## Installation
11
+
12
+ Add this line to your application's Gemfile:
13
+
14
+ gem 'minitest-sound', github: 'y-yagi/minitest-sound'
15
+
16
+ And then execute:
17
+
18
+ $ bundle
19
+
20
+ ## Usage
21
+
22
+ ```ruby
23
+ require 'minitest/sound'
24
+
25
+ Minitest::Sound.success = 'xxx.mp3' # Sound file which does play when a test succeeded.
26
+ Minitest::Sound.failure = 'xxx.mp3' # Sound file which does play when a test failed.
27
+ Minitest::Sound.during_test = 'xxx.mp3' # Sound file which does play during test.
28
+ ```
29
+
30
+ ## Contributing
31
+
32
+ 1. Fork it ( https://github.com/y-yagi/minitest-sound/fork )
33
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
34
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
35
+ 4. Push to the branch (`git push origin my-new-feature`)
36
+ 5. Create a new Pull Request
37
+
38
+ ## TODO
39
+
40
+ * Add test
41
+ * Support soundcloud api
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ task :default => :test
5
+ Rake::TestTask.new do |t|
6
+ t.pattern = "test/**/*_test.rb"
7
+ t.verbose = true
8
+ end
@@ -0,0 +1,7 @@
1
+ require_relative 'sound/reporter'
2
+
3
+ module Minitest
4
+ def self.plugin_minitest_sound_init(opts)
5
+ self.reporter << Minitest::Sound::Reporter.new
6
+ end
7
+ end
@@ -0,0 +1,8 @@
1
+ require 'minitest'
2
+ module Minitest
3
+ module Sound
4
+ class << self
5
+ attr_accessor :success, :failure, :during_test
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,44 @@
1
+ module Minitest
2
+ module Sound
3
+ class Player
4
+ def initialize(success: nil, failure: nil, during_test: nil)
5
+ @success_sound = success
6
+ @failure_sound = failure
7
+ @during_test_sound = during_test
8
+ @during_test_pid = nil
9
+ end
10
+
11
+ def play(file: file, sync: true)
12
+ return if file.nil? || file.empty?
13
+
14
+ pid = spawn("mpg123 #{file}", err: '/dev/null')
15
+ Process.waitpid(pid) if sync
16
+ pid
17
+ rescue Errno::ENOENT
18
+ $stderr.puts message
19
+ end
20
+
21
+ def play_success_sound(sync = true)
22
+ play(file: @success_sound, sync: sync)
23
+ end
24
+
25
+ def play_failure_sound(sync = true)
26
+ play(file: @failure_sound, sync: sync)
27
+ end
28
+
29
+ def play_during_test_sound(sync = false)
30
+ @during_test_pid = play(file: @during_test_sound, sync: sync)
31
+ end
32
+
33
+ def stop_during_test_sound
34
+ return unless @during_test_pid
35
+ Process.kill('SIGINT', @during_test_pid)
36
+ end
37
+
38
+ def message
39
+ 'warning: minitest-sound use "mpg123". Please install "mpg123".'
40
+ end
41
+ end
42
+ end
43
+ end
44
+
@@ -0,0 +1,26 @@
1
+ require_relative 'player'
2
+
3
+ module Minitest
4
+ module Sound
5
+ class Reporter < StatisticsReporter
6
+ def initialize(io = $stdout, options = {})
7
+ super(io, options)
8
+ @player = Minitest::Sound::Player.new(
9
+ success: Minitest::Sound.success, failure: Minitest::Sound.failure,
10
+ during_test: Minitest::Sound.during_test,
11
+ )
12
+ end
13
+
14
+ def start
15
+ super
16
+ @player.play_during_test_sound
17
+ end
18
+
19
+ def report
20
+ super
21
+ @player.stop_during_test_sound
22
+ (errors == 0 && failures == 0) ? @player.play_success_sound : @player.play_failure_sound
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,5 @@
1
+ module Minitest
2
+ module Sound
3
+ VERSION = "0.0.2"
4
+ end
5
+ end
@@ -0,0 +1,24 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'minitest/sound/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "minitest-sound"
8
+ spec.version = Minitest::Sound::VERSION
9
+ spec.authors = ["Yuji Yaginuma"]
10
+ spec.email = ["yuuji.yaginuma@gmail.com"]
11
+ spec.summary = %q{Play a sound when test finished}
12
+ spec.homepage = "https://github.com/y-yagi/minitest-sound"
13
+ spec.license = "MIT"
14
+
15
+ spec.files = `git ls-files -z`.split("\x0")
16
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
17
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
18
+ spec.require_paths = ["lib"]
19
+
20
+ spec.add_dependency 'minitest', '>= 5.0'
21
+ spec.add_development_dependency "bundler", "~> 1.6"
22
+ spec.add_development_dependency "rake"
23
+ spec.add_development_dependency "sys-proctable"
24
+ end
Binary file
Binary file
Binary file
@@ -0,0 +1,60 @@
1
+ require_relative 'test_helper'
2
+ require 'sys/proctable'
3
+ include Sys
4
+
5
+ module MinitestSoundTest
6
+ class PlayerTest < MiniTest::Test
7
+ def setup
8
+ @fixtures_directory = File.expand_path('../fixtures', __FILE__)
9
+ end
10
+
11
+ def test_do_nothing_when_unset_success
12
+ player = Minitest::Sound::Player.new
13
+ player.play_success_sound
14
+ assert_equal(false, play_sound?)
15
+ end
16
+
17
+ def test_play_success_sound_when_set_success
18
+ success_sound = File.join(@fixtures_directory, 'success.mp3')
19
+ player = Minitest::Sound::Player.new(success: success_sound)
20
+ pid = player.play_success_sound(false)
21
+ assert_equal(true, play_sound?(success_sound))
22
+ Process.kill('SIGINT', pid)
23
+ end
24
+
25
+ def test_do_nothing_when_unset_failure
26
+ player = Minitest::Sound::Player.new
27
+ player.play_failure_sound
28
+ assert_equal(false, play_sound?)
29
+ end
30
+
31
+ def test_play_failure_sound_when_set_faiure
32
+ failure_sound = File.join(@fixtures_directory, 'failure.mp3')
33
+ player = Minitest::Sound::Player.new(failure: failure_sound)
34
+ pid = player.play_failure_sound(false)
35
+ assert_equal(true, play_sound?(failure_sound))
36
+ Process.kill('SIGINT', pid)
37
+ end
38
+
39
+ def test_output_errmsg_when_donot_install_mpg123
40
+ original_path = ENV['PATH']
41
+ ENV['PATH'] = ''
42
+
43
+ success_sound = File.join(@fixtures_directory, 'success.mp3')
44
+ player = Minitest::Sound::Player.new(success: success_sound)
45
+
46
+ out, err = capture_io { player.play_success_sound }
47
+ assert_equal(%Q(warning: minitest-sound use "mpg123". Please install "mpg123".\n), err)
48
+ ensure
49
+ ENV['PATH'] = original_path
50
+ end
51
+
52
+ private
53
+ def play_sound?(file = nil)
54
+ processes = ProcTable.ps.select{|s| s.comm == 'mpg123'}
55
+ return false if processes.empty?
56
+
57
+ processes.any?{|p| p.cmdline == "mpg123 #{file}"}
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,5 @@
1
+ require 'minitest/autorun'
2
+ require 'minitest/mock'
3
+ require 'minitest/sound'
4
+ require 'minitest/sound/player'
5
+ require 'minitest/sound/reporter'
metadata ADDED
@@ -0,0 +1,121 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: minitest-sound
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - Yuji Yaginuma
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-06-27 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: minitest
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '5.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '5.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.6'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.6'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: sys-proctable
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description:
70
+ email:
71
+ - yuuji.yaginuma@gmail.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".gitignore"
77
+ - Gemfile
78
+ - LICENSE.txt
79
+ - README.md
80
+ - Rakefile
81
+ - lib/minitest/minitest_sound_plugin.rb
82
+ - lib/minitest/sound.rb
83
+ - lib/minitest/sound/player.rb
84
+ - lib/minitest/sound/reporter.rb
85
+ - lib/minitest/sound/version.rb
86
+ - minitest-sound.gemspec
87
+ - test/fixtures/during_test.mp3
88
+ - test/fixtures/failure.mp3
89
+ - test/fixtures/success.mp3
90
+ - test/player_test.rb
91
+ - test/test_helper.rb
92
+ homepage: https://github.com/y-yagi/minitest-sound
93
+ licenses:
94
+ - MIT
95
+ metadata: {}
96
+ post_install_message:
97
+ rdoc_options: []
98
+ require_paths:
99
+ - lib
100
+ required_ruby_version: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - ">="
103
+ - !ruby/object:Gem::Version
104
+ version: '0'
105
+ required_rubygems_version: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - ">="
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ requirements: []
111
+ rubyforge_project:
112
+ rubygems_version: 2.2.2
113
+ signing_key:
114
+ specification_version: 4
115
+ summary: Play a sound when test finished
116
+ test_files:
117
+ - test/fixtures/during_test.mp3
118
+ - test/fixtures/failure.mp3
119
+ - test/fixtures/success.mp3
120
+ - test/player_test.rb
121
+ - test/test_helper.rb