Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Added 'No One' if a person with a blank name enters.

  • Loading branch information...
commit 5d9b833edffd3bbf3259e649baed1eb8c539b3c4 1 parent 01e580e
@jyurek authored
Showing with 31 additions and 15 deletions.
  1. +4 −1 player.rb
  2. +27 −14 test/player_test.rb
View
5 player.rb
@@ -1,4 +1,5 @@
require 'ostruct'
+begin; require 'win32ole'; rescue LoadError; puts "Test Mode"; end
class Player
@@ -87,7 +88,9 @@ def self.run config
new(config).ensuring_connection do |player|
player.detect_user!
sleep 0.5
- player.play_for(player.last_access_user.Name) if player.should_play?
+ name = player.last_access_user.Name
+ name = name.empty? ? "No One" : name
+ player.play_for(name) if player.should_play?
end
end
View
41 test/player_test.rb
@@ -27,20 +27,33 @@ class PlayerTest < Test::Unit::TestCase
returns(["songs/Moe Syzslak.mp3"])
end
- should "detect users and play while ensuing a connection when run" do
- @player.last_access_user = OpenStruct.new(:Name => "Moe Syzslak")
- @player.stubs(:ensuring_connection).yields(@player)
- @player.stubs(:detect_user!)
- @player.stubs(:should_play?).returns(true)
- @player.stubs(:play_for)
- Player.stubs(:new).returns(@player)
-
- Player.run(config)
-
- assert_received(@player, :ensuring_connection)
- assert_received(@player, :detect_user!)
- assert_received(@player, :should_play?)
- assert_received(@player, :play_for){|p| p.with("Moe Syzslak") }
+ context "detect users and play while ensuing a connection when run" do
+ setup do
+ @player.last_access_user = OpenStruct.new(:Name => "Moe Syzslak")
+ @player.stubs(:ensuring_connection).yields(@player)
+ @player.stubs(:detect_user!)
+ @player.stubs(:should_play?).returns(true)
+ @player.stubs(:play_for)
+ Player.stubs(:new).returns(@player)
+ end
+
+ should "call the right things" do
+ Player.run(config)
+ assert_received(@player, :ensuring_connection)
+ assert_received(@player, :detect_user!)
+ assert_received(@player, :should_play?)
+ end
+
+ should "play the right song when the person has a name" do
+ Player.run(config)
+ assert_received(@player, :play_for){|p| p.with("Moe Syzslak") }
+ end
+
+ should "play the right song when the person does not have a name" do
+ @player.last_access_user = OpenStruct.new(:Name => "")
+ Player.run(config)
+ assert_received(@player, :play_for){|p| p.with("No One") }
+ end
end
context "changing connection possibilities" do
Please sign in to comment.
Something went wrong with that request. Please try again.