spec/models/artist_spec.rb in musicbrainz-0.7.7 vs spec/models/artist_spec.rb in musicbrainz-0.8.0
- old
+ new
@@ -1,59 +1,90 @@
-# -*- encoding: utf-8 -*-
-
require "spec_helper"
describe MusicBrainz::Artist do
- it "gets no exception while loading artist info" do
- lambda {
- MusicBrainz::Artist.find('69b39eab-6577-46a4-a9f5-817839092033')
- }.should_not raise_error(Exception)
- end
+ describe '.search' do
+ before(:each) {
+ mock url: 'http://musicbrainz.org/ws/2/artist?query=artist:"Kasabian"&limit=10',
+ fixture: 'artist/search_kasabian.xml'
+ }
+ let(:matches) {
+ MusicBrainz::Artist.search('Kasabian')
+ }
- it "gets correct instance" do
- artist = MusicBrainz::Artist.find_by_name('Kasabian')
- artist.should be_an_instance_of(MusicBrainz::Artist)
- end
+ it "searches artist by name" do
+ expect(matches).to_not be_empty
+ expect(matches.first[:name]).to eq("Kasabian")
+ end
- it "searches artist by name" do
- matches = MusicBrainz::Artist.search('Kasabian')
- matches.length.should be > 0
- matches.first[:name].should == "Kasabian"
+ it "should return search results in the right order and pass back the correct score" do
+ expect(matches.length).to be >= 2
+ expect(matches[0][:score]).to eq 100
+ expect(matches[0][:id]).to eq "69b39eab-6577-46a4-a9f5-817839092033"
+ expect(matches[1][:score]).to eq 73
+ expect(matches[1][:id]).to eq "d76aed40-1332-44db-9b19-aee7ec17464b"
+ end
end
- it "should return search results in the right order and pass back the correct score" do
- response = File.open(File.join(File.dirname(__FILE__), "../fixtures/artist/search.xml")).read
- MusicBrainz::Client.any_instance.stub(:get_contents).with('http://musicbrainz.org/ws/2/artist?query=artist:"Chris+Martin"&limit=10').
- and_return({ status: 200, body: response})
-
- matches = MusicBrainz::Artist.search('Chris Martin')
+ describe '.find' do
+ before(:each) {
+ mock url: 'http://musicbrainz.org/ws/2/artist/69b39eab-6577-46a4-a9f5-817839092033?inc=url-rels',
+ fixture: 'artist/find_69b39eab-6577-46a4-a9f5-817839092033.xml'
+ }
+ let(:artist) {
+ MusicBrainz::Artist.find('69b39eab-6577-46a4-a9f5-817839092033')
+ }
- matches[0][:score].should == 100
- matches[0][:id].should == "90fff570-a4ef-4cd4-ba21-e00c7261b05a"
- matches[1][:score].should == 100
- matches[1][:id].should == "b732a912-af95-472c-be52-b14610734c64"
+ it "gets no exception while loading artist info" do
+ expect{ artist }.to_not raise_error(Exception)
+ expect(artist.id).to eq '69b39eab-6577-46a4-a9f5-817839092033'
+ expect(artist.name).to eq 'Kasabian'
+ end
end
- it "gets correct result by name" do
- artist = MusicBrainz::Artist.find_by_name('Kasabian')
- artist.id.should == "69b39eab-6577-46a4-a9f5-817839092033"
- end
+ describe '.find_by_name' do
+ before(:each) {
+ mock url: 'http://musicbrainz.org/ws/2/artist?query=artist:"Kasabian"&limit=10',
+ fixture: 'artist/search_kasabian.xml'
+ mock url: 'http://musicbrainz.org/ws/2/artist/69b39eab-6577-46a4-a9f5-817839092033?inc=url-rels',
+ fixture: 'artist/find_69b39eab-6577-46a4-a9f5-817839092033.xml'
+ }
+ let(:artist) {
+ MusicBrainz::Artist.find_by_name('Kasabian')
+ }
- it "gets correct artist data" do
- artist = MusicBrainz::Artist.find_by_name('Kasabian')
- artist.id.should == "69b39eab-6577-46a4-a9f5-817839092033"
- artist.type.should == "Group"
- artist.name.should == "Kasabian"
- artist.country.should == "GB"
- artist.date_begin.year.should == 1999
- end
+ it "gets correct instance" do
+ expect(artist).to be_instance_of(MusicBrainz::Artist)
+ end
- it "gets correct artist's release groups" do
- release_groups = MusicBrainz::Artist.find_by_name('Kasabian').release_groups
- release_groups.length.should be >= 16
- release_groups.first.id.should == "533cbc5f-ec7e-32ab-95f3-8d1f804a5176"
- release_groups.first.type.should == "Single"
- release_groups.first.title.should == "Club Foot"
- release_groups.first.first_release_date.should == Date.new(2004, 5, 10)
- release_groups.first.urls[:discogs].should == 'http://www.discogs.com/master/125150'
+ it "gets correct result by name" do
+ expect(artist.id).to eq "69b39eab-6577-46a4-a9f5-817839092033"
+ end
+
+ it "gets correct artist data" do
+ expect(artist.id).to eq "69b39eab-6577-46a4-a9f5-817839092033"
+ expect(artist.type).to eq "Group"
+ expect(artist.name).to eq "Kasabian"
+ expect(artist.country).to eq "GB"
+ expect(artist.date_begin.year).to eq 1997
+ end
+
+ describe '#release_groups' do
+ before(:each) {
+ mock url: 'http://musicbrainz.org/ws/2/release-group?artist=69b39eab-6577-46a4-a9f5-817839092033&inc=url-rels',
+ fixture: 'artist/release_groups_69b39eab-6577-46a4-a9f5-817839092033.xml'
+ }
+ let(:release_groups) {
+ artist.release_groups
+ }
+
+ it "gets correct artist's release groups" do
+ release_groups = MusicBrainz::Artist.find_by_name('Kasabian').release_groups
+ expect(release_groups.length).to be >= 16
+ expect(release_groups.first.id).to eq "5547285f-578f-3236-85aa-b65cc0923b58"
+ expect(release_groups.first.type).to eq "Single"
+ expect(release_groups.first.title).to eq "Reason Is Treason"
+ expect(release_groups.first.first_release_date).to eq Date.new(2004, 2, 23)
+ expect(release_groups.first.urls[:discogs]).to eq 'https://www.discogs.com/master/125172'
+ end
+ end
end
end