spec/robut-rdio_spec.rb in robut-rdio-0.1.0 vs spec/robut-rdio_spec.rb in robut-rdio-0.1.2
- old
+ new
@@ -1,101 +1,244 @@
-require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
+require 'spec_helper'
-# Wherein we test legacy code, and hopefully refactor and remove this file
-describe "RobutRdio Super Integration Test" do
- let(:plugin) do plugin = Robut::Plugin::Rdio.new(nil)
- def plugin.nick
- "dj"
- end
-
-
- plugin.stub(:reply){|msg|
- @reply = msg
+describe Robut::Plugin::Rdio do
+
+ subject {
+ connection = double("connection")
+ connection.stub_chain(:config, :nick) { "dj" }
+ connection.stub(:store).and_return(store)
+ connection.stub(:reply).and_return(nil)
+ Robut::Plugin::Rdio.new connection
}
-
- plugin
- end
-
- def say(msg)
- plugin.handle(Time.now, 'foo bar', msg)
- end
-
- describe "searching for tracks" do
-
-
- it 'should make an rdio search' do
- stub_search('neil young', ['harvest', 'after the gold rush'])
- say('@dj find neil young')
- @reply.should == "result: harvest\nresult: after the gold rush\n"
+
+ let(:sender) { "sender" }
+
+ let!(:store) { {} }
+
+ let(:time) { Time.now }
+
+ describe "#usage" do
+
+ # Though it is acceptable for the plugin to return a String here,
+ # it is important that we return an Enumerable list of instruction examples
+ # as we have so many different commands.
+ it "should return a list of commands on how to use the plugin" do
+ subject.usage.should be_kind_of(Enumerable)
end
-
- def stub_search(mock_query, results)
- plugin.stub(:search).with(['', mock_query]){results}
- results.each do |result|
- plugin.stub(:format_result).with(result, anything()){"result: #{result}"}
- end
- end
-
end
+
+ describe "Routing Methods" do
+
+ describe "#play?", :method => :play? do
+
+ it_should_behave_like "a routing method"
- describe 'queuing tracks' do
-
- describe 'when there is a search result' do
- before do
- plugin.stub(:result_at){|i| i.to_s}
- plugin.stub(:queue){|result| @queued = result}
- plugin.stub(:has_results?){true}
- plugin.stub(:has_result?){true}
+ let(:valid_requests) do
+ [
+ # play keyword
+ "play 0",
+ "play 999999",
+ [ "play", "0" ],
+ # result keyword
+ "result1",
+ "result 1",
+ [ "result 0"],
+ # multiple tracks
+ "play 1, 2, 3",
+ "play 1 2 3",
+ "play 1 - 3",
+ "play 1-3",
+ # all tracks
+ "play all"
+ ]
end
- it 'should queue the track at the given position with "play <number>"' do
- say '@dj play 1'
- @queued.should == '1'
-
- say '@dj 8'
- @queued.should == '8'
+ let(:invalid_requests) do
+ [
+ "play Abba",
+ "play ",
+ [ "play", "three-eleven" ]
+ ]
end
end
-
- describe 'when there are no search results' do
- before do
- plugin.stub(:has_results?){false}
+
+ describe "search?", :method => :search? do
+
+ it_should_behave_like "a routing method"
+
+ let(:valid_requests) do
+ [
+ "find the beatles",
+ "do you have any grey poupon",
+ [ "find", "breeders" ],
+ "do you have Weezer",
+ "find finding nemo"
+ ]
end
- it 'should say there are no results' do
- say '@dj play 9'
- @reply.should == "I don't have any search results"
+ let(:invalid_requests) do
+ [
+ "play Abba",
+ "play ",
+ [ "play", "three-eleven" ]
+ ]
end
+
end
-
- describe 'when there are results but not at the requested index' do
- before do
- plugin.stub(:has_results?){true}
- plugin.stub(:has_result?).with(5){false}
+
+ describe "#search_and_play?", :method => :search_and_play? do
+
+ it_should_behave_like "a routing method"
+
+ let(:valid_requests) do
+ [
+ "play the beatles",
+ [ "play", "breeders" ],
+ "play doh re me ...",
+ "play me a song mister piano man"
+ ]
end
- it 'should say the result does not exist' do
- say '@dj play 5'
- @reply.should == "I don't have that result"
+
+ let(:invalid_requests) do
+ [
+ "play",
+ "find this and play it for me",
+ " play even with that space at the start",
+ [ "plato", "first", "album" ]
+ ]
end
+
end
+
+ describe "#command?", :method => :command? do
+
+ it_should_behave_like "a routing method"
+
+ let(:valid_requests) do
+ [
+ "play",
+ "pause",
+ "unpause",
+ "next",
+ "restart",
+ "back",
+ "clear",
+ [ "play" ]
+ ]
+ end
+
+ let(:invalid_requests) do
+ [
+ " play",
+ "play ",
+ "player",
+ "play-pause",
+ "clearing house"
+ ]
+ end
+
+ end
+
end
-
- describe "I'm feeling lucky play/search" do
- end
+ describe "#handle" do
+
+ it "should create a communication channel with the music server" do
+
+ subject.should_receive(:establish_server_callbacks!).and_return(nil)
+ subject.handle(time,"","")
+
+ end
- describe 'running commands' do
- before do
- plugin.stub(:run_command){|command| @command = command}
+ context "when not sent to the agent" do
+
+ let(:message) { "This message does not mention the dj" }
+
+ it "should perform no action" do
+
+ subject.should_not_receive(:play?)
+ subject.handle(time,sender,message)
+
+ end
+
end
+
+ context "when sent to the agent" do
+
+ context "when it is a play request" do
+
+ let(:message) { "@dj play 0" }
+
+ it_should_behave_like "a successfully routed action",
+ :route => :play?, :action => :play_result, :parameters => 0
+
+ end
+
+ context "when it is a multiple play request" do
+
+ let(:message) { "@dj play 1, 4 5-7" }
+
+ it_should_behave_like "a successfully routed action",
+ :route => :play?, :action => :play_result, :parameters => [1,4,5,6,7]
+
+ end
+
+ context "when it is a search and play request" do
+
+ let(:message) { "@dj play the misfits" }
- %w{play unpause pause next restart back clear}.each do |command|
- it "should run #{command}" do
- say("@dj #{command}")
- @command.should == command
+ context "when the search returns a result" do
+
+ it_should_behave_like "a successfully routed action",
+ :route => :search_and_play?, :action => :search_and_play_result,
+ :parameters => "the misfits", :returning => true
+
+ end
+
+ context "when the search result does not return a result" do
+
+ before :each do
+ subject.should_receive(:reply).with("I couldn't find 'the misfits' on Rdio.")
+ end
+
+ it_should_behave_like "a successfully routed action",
+ :route => :search_and_play?, :action => :search_and_play_result, :parameters => "the misfits"
+
+ end
+
end
+
+ context "when it is a search request" do
+
+ let(:message) { "@dj find the partridge family" }
+
+ it_should_behave_like "a successfully routed action",
+ :route => :search?, :action => :find, :parameters => "the partridge family"
+
+ end
+
+ context "when it is a skip album request" do
+
+ let(:message) { "skip album @dj" }
+
+ it_should_behave_like "a successfully routed action",
+ :route => :skip_album?, :action => :run_command, :parameters => "next_album"
+
+ end
+
+ context "when it is command" do
+
+ let(:message) { "@dj pause" }
+
+ it_should_behave_like "a successfully routed action",
+ :route => :command?, :action => :run_command, :parameters => "pause"
+
+ end
+
end
+
+
end
-
+
end