spec/hallon/user_spec.rb in hallon-0.15.0 vs spec/hallon/user_spec.rb in hallon-0.16.0
- old
+ new
@@ -1,80 +1,90 @@
# coding: utf-8
describe Hallon::User do
- it { described_class.should include Hallon::Loadable }
+ let(:user) do
+ Hallon::User.new(mock_users[:default])
+ end
+ let(:empty_user) do
+ Hallon::User.new(mock_users[:empty])
+ end
+
+ specify { user.should be_a Hallon::Loadable }
+
it_should_behave_like "a Linkable object" do
let(:spotify_uri) { "spotify:user:burgestrand" }
let(:custom_object) { "burgestrand" }
end
- describe "an instance" do
- let(:user) { Hallon::User.new(mock_user) }
+ describe "#loaded?" do
+ it "should return true as the user is loaded" do
+ user.should be_loaded
+ end
+ end
- describe "#loaded?" do
- it "should return true as the user is loaded" do
- user.should be_loaded
- end
+ describe "#name" do
+ it "should be the canonical name" do
+ user.name.should eq "burgestrand"
end
- describe "#name" do
- it "should be the canonical name" do
- user.name.should eq "burgestrand"
- end
+ it "returns an empty string if the name is not available" do
+ empty_user.name.should be_empty
end
+ end
- describe "#display_name" do
- it "should be the users’ display name" do
- user.display_name.should eq "Burgestrand"
- end
+ describe "#display_name" do
+ it "should be the users’ display name" do
+ user.display_name.should eq "Burgestrand"
end
- describe "#post" do
- let(:post) { mock_session { user.post(tracks) } }
- let(:tracks) { instantiate(Hallon::Track, mock_track, mock_track_two) }
+ it "returns an empty string if the display name is not available" do
+ empty_user.name.should be_empty
+ end
+ end
- it "should post to the correct user" do
- post.recipient_name.should eq user.name
- end
+ describe "#post" do
+ let(:post) { user.post(tracks) }
+ let(:tracks) { instantiate(Hallon::Track, mock_track, mock_track_two) }
- it "should post with the given message" do
- post.message.should be_nil
- stub_session { user.post("Hey ho!", tracks) }.message.should eq "Hey ho!"
- end
+ it "should post to the correct user" do
+ post.recipient_name.should eq user.name
+ end
- it "should return nil on failure" do
- stub_session { user.post([]).should be_nil }
- end
+ it "should post with the given message" do
+ post.message.should be_nil
+ user.post("Hey ho!", tracks).message.should eq "Hey ho!"
end
- describe "#starred" do
- let(:starred) { Hallon::Playlist.new("spotify:user:%s:starred" % user.name) }
+ it "should return nil on failure" do
+ user.post([]).should be_nil
+ end
+ end
- it "should return the users’ starred playlist" do
- session.login 'Kim', 'pass'
- session.should be_logged_in
- mock_session { user.starred.should eq starred }
- end
+ describe "#starred" do
+ let(:starred) { Hallon::Playlist.new("spotify:user:%s:starred" % user.name) }
- it "should return nil if not logged in" do
- session.should_not be_logged_in
- mock_session { user.starred.should be_nil }
- end
+ it "should return the users’ starred playlist" do
+ session.login 'Kim', 'pass'
+ session.should be_logged_in
+ user.starred.should eq starred
end
- describe "#published" do
- let(:published) { Hallon::PlaylistContainer.new(mock_container) }
+ it "should return nil if not available" do
+ empty_user.starred.should be_nil
+ end
+ end
- it "should return the playlist container of the user" do
- Spotify.registry_add("spotify:container:%s" % user.name, mock_container)
+ describe "#published" do
+ let(:published) { Hallon::PlaylistContainer.new(mock_container) }
- session.login('burgestrand', 'pass')
- mock_session { user.published.should eq published }
- end
+ it "should return the playlist container of the user" do
+ Spotify.registry_add("spotify:container:%s" % user.name, mock_container)
- it "should return nil if not logged in" do
- Spotify.should_receive(:session_publishedcontainer_for_user_create).and_return(null_pointer)
- mock_session { user.published.should be_nil }
- end
+ session.login('burgestrand', 'pass')
+ user.published.should eq published
+ end
+
+ it "should return nil if not logged in" do
+ empty_user.published.should be_nil
end
end
end