spec/hallon/search_spec.rb in hallon-0.8.0 vs spec/hallon/search_spec.rb in hallon-0.9.0

- old
+ new

@@ -1,12 +1,10 @@ describe Hallon::Search do subject { search } let(:search) do - mock_session do - Spotify.should_receive(:search_create).and_return(mock_search) - Hallon::Search.new("my query") - end + Spotify.registry_add 'spotify:search:my query', mock_search + mock_session { Hallon::Search.new("my query") } end describe ".new" do it "should have some sane defaults" do Spotify.should_receive(:search_create).with(session.pointer, "my query", 0, 25, 0, 25, 0, 25, anything, anything).and_return(mock_search) @@ -24,44 +22,49 @@ :artists => 6 } mock_session { Hallon::Search.new("my query", my_params) } end + + it "should raise an error if the search failed" do + Spotify.should_receive(:search_create).and_return(null_pointer) + expect { mock_session { Hallon::Search.new("omgwtfbbq") } }.to raise_error(/search (.*?) failed/) + end end describe ".genres" do subject { Hallon::Search.genres } it { should include :jazz } it { should be_a Array } it { should_not be_empty } end - describe ".search" do + describe ".radio" do subject do - Spotify.should_receive(:radio_search_create).and_return(mock_search) + Spotify.registry_add 'spotify:radio:00002200:1990-2010', mock_search + mock_session { Hallon::Search.radio(1990..2010, :jazz, :punk) } + end - mock_session do - search = Hallon::Search.radio(1990..2010, :jazz, :punk) - end + it "should raise an error on invalid genres" do + Spotify.should_not_receive(:radio_search_create) + expect { Hallon::Search.radio(1990..2010, :bogus, :jazz) }.to raise_error(ArgumentError, /bogus/) end - it "should simply ignore invalid genres" do - mock_session do - Spotify.should_receive(:radio_search_create).and_return(mock_search) - expect { Hallon::Search.radio(1990..2010, :bogus, :hocum) }.to_not raise_error - end + it "should raise an error if the search failed" do + Spotify.should_receive(:radio_search_create).and_return(null_pointer) + expect { mock_session { Hallon::Search.radio(1990..1990) } }.to raise_error(/search failed/) end it { should be_loaded } - its(:error) { should eq :ok } + its(:status) { should eq :ok } its('tracks.size') { should eq 2 } # ^ should be enough end it { should be_a Hallon::Observable } it { should be_loaded } - its(:error) { should eq :ok } + its(:status) { should eq :ok } its(:query) { should eq "my query" } its(:did_you_mean) { should eq "another thing" } its('tracks.size') { should eq 2 } its('tracks.to_a') { should eq instantiate(Hallon::Track, mock_track, mock_track_two) }