Skip to content

Instantly share code, notes, and snippets.

@medwards
Created November 21, 2011 03:03
Show Gist options
  • Save medwards/1381493 to your computer and use it in GitHub Desktop.
Save medwards/1381493 to your computer and use it in GitHub Desktop.
how to pass tests yick
Might be bad bc I removed some other junk in the diff
diff --git a/lib/play.rb b/lib/play.rb
index e8e7ceb..7ddc757 100644
--- a/lib/play.rb
+++ b/lib/play.rb
@@ -76,14 +76,16 @@ module Play
# Returns the Client subclass that matches the client requested
# in the config subclass.
def self.client
+ if not :test
+ client_name = config['client']
+ else
+ client_name = 'test'
+ end
+ client_class = client_name.capitalize + 'Client'
require 'play/' + client_class.downcase
return Play.const_get(client_class)
rescue NameError
raise NotImplementedError,
"\"#{config['client']}\" is not a supported music client type."
end
end
@medwards
Copy link
Author

diff --git a/test/api_test.rb b/test/api_test.rb
index 4ace513..ad76383 100644
--- a/test/api_test.rb
+++ b/test/api_test.rb
@@ -1,4 +1,5 @@
require 'helper'
+require 'play/testclient'
include Rack::Test::Methods

def app
@@ -27,7 +28,7 @@ context "Api" do
end

test "/api/say" do

  • Play::Client.expects(:say).with("Holman is sexy").returns(true)
  • Play::TestClient.expects(:say).with("Holman is sexy").returns(true)
    get "/api/say", { :message => "Holman is sexy" }
    resp = parse_json(last_response.body.strip)
    assert_equal "Okay.", resp[:success]
    @@ -134,28 +135,28 @@ context "Api" do
    end

test "/api/volume" do

  • Play::Client.expects(:volume).with('3').returns(true)
  • Play::TestClient.expects(:volume).with('3').returns(true)
    post "/api/volume", {:level => 3}
    resp = parse_json(last_response.body.strip)
    assert_equal 'true', resp[:success]
    end

test "/api/volume with a float" do

  • Play::Client.expects(:volume).with("2.5").returns(true)
  • Play::TestClient.expects(:volume).with("2.5").returns(true)
    post "/api/volume", {:level => '2.5'}
    resp = parse_json(last_response.body.strip)
    assert_equal 'true', resp[:success]
    end

test "/api/pause" do

  • Play::Client.expects(:pause).returns(true)
  • Play::TestClient.expects(:pause).returns(true)
    post "/api/pause"
    resp = parse_json(last_response.body.strip)
    assert_equal 'true', resp[:success]
    end

test "/api/next" do

  • Play::Client.expects(:pause).times(2).returns(true)
  • Play::TestClient.expects(:pause).times(2).returns(true)
    post "/api/next"
    resp = parse_json(last_response.body.strip)
    assert_equal 'true', resp[:success]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment