Skip to content

Commit

Permalink
Add sound observer to prompt
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexB52 committed Nov 19, 2023
1 parent 4061fc2 commit 259e641
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 5 deletions.
4 changes: 3 additions & 1 deletion exe/retest
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,15 @@ if options.help?
return
end

repository = Retest::Repository.new(files: Retest::VersionControl.files)
prompt = Retest::Prompt.new
repository = Retest::Repository.new(files: Retest::VersionControl.files, prompt: prompt)
command = Retest::Command.for_options(options)
runner = Retest::Runners.runner_for(command.to_s)
sounds = Retest::Sounds.for(options)

sounds.play(:start)
runner.add_observer(sounds)
prompt.add_observer(sounds)

program = Retest::Program.new(
repository: repository,
Expand Down
5 changes: 5 additions & 0 deletions lib/retest/prompt.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
module Retest
class Prompt
include Observable

def self.ask_which_test_to_use(path, files)
new.ask_which_test_to_use(path, files)
end
Expand All @@ -15,6 +17,9 @@ def initialize(input: nil, output: nil)
end

def ask_which_test_to_use(path, files)
changed
notify_observers(:question)

output.puts(<<~QUESTION)
We found few tests matching: #{path}
Expand Down
13 changes: 9 additions & 4 deletions lib/retest/sounds.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ def play(sound)
['afplay', '/System/Library/Sounds/Funk.aiff']
when :start
['afplay', '/System/Library/Sounds/Blow.aiff']
when :question
['afplay', '/System/Library/Sounds/Glass.aiff']
else
raise ArgumentError.new("No sounds were found for type: #{sound}.")
end
Expand All @@ -40,15 +42,18 @@ def play(sound)
# List of Mac Audio Files:
# afplay /System/Library/Sounds/Basso.aiff
# afplay /System/Library/Sounds/Bottle.aiff
# afplay /System/Library/Sounds/Funk.aiff
# afplay /System/Library/Sounds/Hero.aiff
# afplay /System/Library/Sounds/Ping.aiff
# afplay /System/Library/Sounds/Purr.aiff
# afplay /System/Library/Sounds/Submarine.aiff
# afplay /System/Library/Sounds/Blow.aiff
# afplay /System/Library/Sounds/Frog.aiff
# afplay /System/Library/Sounds/Glass.aiff
# afplay /System/Library/Sounds/Morse.aiff
# afplay /System/Library/Sounds/Pop.aiff
# afplay /System/Library/Sounds/Sosumi.aiff
# afplay /System/Library/Sounds/Tink.aiff

# USED

# fail: afplay /System/Library/Sounds/Sosumi.aiff
# pass: afplay /System/Library/Sounds/Funk.aiff
# start: afplay /System/Library/Sounds/Blow.aiff
# question: afplay /System/Library/Sounds/Glass.aiff
18 changes: 18 additions & 0 deletions test/retest/sounds/mac_os_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,24 @@ def test_play_tests_fail

kernel.verify
end

def test_play_question
kernel = MiniTest::Mock.new
kernel.expect(:system, true, ['afplay', '/System/Library/Sounds/Glass.aiff'])

MacOS.new(kernel: kernel, thread: FakeThread).play(:question)

kernel.verify
end

def test_play_start
kernel = MiniTest::Mock.new
kernel.expect(:system, true, ['afplay', '/System/Library/Sounds/Blow.aiff'])

MacOS.new(kernel: kernel, thread: FakeThread).play(:start)

kernel.verify
end
end
end
end

0 comments on commit 259e641

Please sign in to comment.