Class: RSpec::Sound::Player

Inherits:
Object
  • Object
show all
Defined in:
lib/rspec/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/rspec/sound/player.rb', line 4

def initialize(success: nil, failure: nil, during_test: nil)
  @success = success
  @failure = failure
  @during_test = during_test
  @sound_pid = nil
end

Instance Method Details

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



23
24
25
26
# File 'lib/rspec/sound/player.rb', line 23

def play(file: nil, sync: true)
  @sound_pid = spawn("mpg123 #{file}", err: '/dev/null')
  Process.waitpid(@sound_pid) if sync
end

#play_during_test(sync: false) ⇒ Object



11
12
13
# File 'lib/rspec/sound/player.rb', line 11

def play_during_test(sync: false)
  play(file: @during_test, sync: sync)
end

#play_failure(sync: true) ⇒ Object



19
20
21
# File 'lib/rspec/sound/player.rb', line 19

def play_failure(sync: true)
  play(file: @failure, sync: sync)
end

#play_success(sync: true) ⇒ Object



15
16
17
# File 'lib/rspec/sound/player.rb', line 15

def play_success(sync: true)
  play(file: @success, sync: sync)
end

#stopObject



28
29
30
# File 'lib/rspec/sound/player.rb', line 28

def stop
  Process.kill('SIGINT', @sound_pid)
end