Class: Minitest::Sound::Player

Inherits:
Object
  • Object
show all
Defined in:
lib/minitest/sound/player.rb

Instance Method Summary collapse

Constructor Details

#initialize(success: nil, failure: nil, during_test: nil) ⇒ Player

Returns a new instance of Player.



4
5
6
7
8
9
# File 'lib/minitest/sound/player.rb', line 4

def initialize(success: nil, failure: nil, during_test: nil)
  @success_sound = success
  @failure_sound = failure
  @during_test_sound = during_test
  @during_test_pid = nil
end

Instance Method Details

#messageObject



38
39
40
# File 'lib/minitest/sound/player.rb', line 38

def message
  'warning: minitest-sound use "mpg123". Please install "mpg123".'
end

#play(file: nil, sync: true) ⇒ Object



11
12
13
14
15
16
17
18
19
# File 'lib/minitest/sound/player.rb', line 11

def play(file: nil, sync: true)
  return if file.nil? || file.empty?

  pid = spawn("mpg123 #{file}", err: '/dev/null')
  Process.waitpid(pid) if sync
  pid
rescue Errno::ENOENT
  $stderr.puts message
end

#play_during_test_sound(sync = false) ⇒ Object



29
30
31
# File 'lib/minitest/sound/player.rb', line 29

def play_during_test_sound(sync = false)
  @during_test_pid = play(file: during_test_sound, sync: sync)
end

#play_failure_sound(sync = true) ⇒ Object



25
26
27
# File 'lib/minitest/sound/player.rb', line 25

def play_failure_sound(sync = true)
  play(file: failure_sound, sync: sync)
end

#play_success_sound(sync = true) ⇒ Object



21
22
23
# File 'lib/minitest/sound/player.rb', line 21

def play_success_sound(sync = true)
  play(file: success_sound, sync: sync)
end

#stop_during_test_soundObject



33
34
35
36
# File 'lib/minitest/sound/player.rb', line 33

def stop_during_test_sound
  return unless @during_test_pid
  Process.kill('SIGINT', @during_test_pid)
end