Skip to content

Instantly share code, notes, and snippets.

@andersr
Last active December 25, 2015 02:39
Show Gist options
  • Save andersr/6904165 to your computer and use it in GitHub Desktop.
Save andersr/6904165 to your computer and use it in GitHub Desktop.
jukebox_spec.rb
require 'simplecov'
SimpleCov.start
require 'json'
require 'rspec'
require_relative 'spec_helper'
require_relative 'jukebox'
require_relative 'song'
#use this song data for your tests
songs = [
"The Phoenix - 1901",
"Tokyo Police Club - Wait Up",
"Sufjan Stevens - Too Much",
"The Naked and the Famous - Young Blood",
"(Far From) Home - Tiga",
"The Cults - Abducted",
"The Phoenix - Consolation Prizes"
]
describe Song do
it 'should have a name' do
@song = Song.new("Michael Jackson - Thriller")
@song.name.should eq("Michael Jackson - Thriller")
end
end
describe Jukebox do
before :each do
@songs = songs.collect do |song|
Song.new(song)
end
@jukebox = Jukebox.new(@songs)
end
describe "Turning on the Jukebox" do
it 'should allow for turning on the jukebox so it is ready to accept commands' do
@jukebox.on?.should eq true
end
end
describe "Jukebox controls" do
it 'should allow for viewing help information' do
@jukebox.command("help").should eq ("Please select help, list, exit, or play.")
end
it 'should allow for listing all songs that can be played' do
@jukebox.command("list").should eq ("1 The Phoenix - 1901\n2 Tokyo Police Club - Wait Up\n3 Sufjan Stevens - Too Much\n4 The Naked and the Famous - Young Blood\n5 (Far From) Home - Tiga\n6 The Cults - Abducted\n7 The Phoenix - Consolation Prizes\n")
end
it 'should allow for playing a song in the list' do
@jukebox.command("play 2").should eq ("now playing 2")
end
it 'should respond to an invalid command' do
@jukebox.command("sfusdfjkaf").should eq("invalid command")
end
it 'should allow for exiting the jukebox' do
@jukebox.exit.should eq("Goodbye, thanks for listening!")
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment