Update to use modern RSpec syntax and conventions

* Replace `should` syntax with `expect` syntax.
* Add pry as a development dependency.
* Fix failing specs.
This commit is contained in:
Jason Voegele
2015-03-13 15:39:11 -04:00
parent 4d12555c09
commit ad4a53f9ce
14 changed files with 155 additions and 138 deletions
+25 -24
View File
@@ -4,56 +4,57 @@ require "spec_helper"
describe MusicBrainz::Artist do
it "gets no exception while loading artist info" do
lambda {
expect {
MusicBrainz::Artist.find('69b39eab-6577-46a4-a9f5-817839092033')
}.should_not raise_error(Exception)
}.to_not raise_error(Exception)
end
it "gets correct instance" do
artist = MusicBrainz::Artist.find_by_name('Kasabian')
artist.should be_an_instance_of(MusicBrainz::Artist)
expect(artist).to be_instance_of(MusicBrainz::Artist)
end
it "searches artist by name" do
matches = MusicBrainz::Artist.search('Kasabian')
matches.length.should be > 0
matches.first[:name].should == "Kasabian"
expect(matches).to_not be_empty
expect(matches.first[:name]).to eq("Kasabian")
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})
allow_any_instance_of(MusicBrainz::Client).to receive(: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')
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"
expect(matches[0][:score]).to eq 100
expect(matches[0][:id]).to eq "90fff570-a4ef-4cd4-ba21-e00c7261b05a"
expect(matches[1][:score]).to eq 100
expect(matches[1][:id]).to eq "b732a912-af95-472c-be52-b14610734c64"
end
it "gets correct result by name" do
artist = MusicBrainz::Artist.find_by_name('Kasabian')
artist.id.should == "69b39eab-6577-46a4-a9f5-817839092033"
expect(artist.id).to eq "69b39eab-6577-46a4-a9f5-817839092033"
end
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
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
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'
expect(release_groups.length).to be >= 16
expect(release_groups.first.id).to eq "533cbc5f-ec7e-32ab-95f3-8d1f804a5176"
expect(release_groups.first.type).to eq "Single"
expect(release_groups.first.title).to eq "Club Foot"
expect(release_groups.first.first_release_date).to eq Date.new(2004, 5, 10)
expect(release_groups.first.urls[:discogs]).to eq 'http://www.discogs.com/master/125150'
end
end
+8 -8
View File
@@ -10,36 +10,36 @@ describe MusicBrainz::BaseModel do
response = '<release-group><first-release-date></first-release-date></release-group>'
xml = Nokogiri::XML.parse(response)
release_group = MusicBrainz::ReleaseGroup.new MusicBrainz::Bindings::ReleaseGroup.parse(xml)
release_group.first_release_date.should == Date.new(2030, 12, 31)
expect(release_group.first_release_date).to eq Date.new(2030, 12, 31)
end
end
context 'year only' do
it 'returns 1995-12-31' do
response = '<release-group><first-release-date>1995</first-release-date></release-group>'
xml = Nokogiri::XML.parse(response)
release_group = MusicBrainz::ReleaseGroup.new MusicBrainz::Bindings::ReleaseGroup.parse(xml)
release_group.first_release_date.should == Date.new(1995, 12, 31)
expect(release_group.first_release_date).to eq Date.new(1995, 12, 31)
end
end
context 'year and month only' do
it 'returns 1995-04-30' do
response = '<release-group><first-release-date>1995-04</first-release-date></release-group>'
xml = Nokogiri::XML.parse(response)
release_group = MusicBrainz::ReleaseGroup.new MusicBrainz::Bindings::ReleaseGroup.parse(xml)
release_group.first_release_date.should == Date.new(1995, 4, 30)
expect(release_group.first_release_date).to eq Date.new(1995, 4, 30)
end
end
context 'year, month and day' do
it 'returns 1995-04-30' do
response = '<release-group><first-release-date>1995-04-30</first-release-date></release-group>'
xml = Nokogiri::XML.parse(response)
release_group = MusicBrainz::ReleaseGroup.new MusicBrainz::Bindings::ReleaseGroup.parse(xml)
release_group.first_release_date.should == Date.new(1995, 4, 30)
expect(release_group.first_release_date).to eq Date.new(1995, 4, 30)
end
end
end
end
end
end
+48 -43
View File
@@ -5,81 +5,86 @@ require "spec_helper"
describe MusicBrainz::ReleaseGroup do
describe '.find' do
it "gets no exception while loading release group info" do
lambda {
expect {
MusicBrainz::ReleaseGroup.find("6f33e0f0-cde2-38f9-9aee-2c60af8d1a61")
}.should_not raise_error(Exception)
}.to_not raise_error(Exception)
end
it "gets correct instance" do
release_group = MusicBrainz::ReleaseGroup.find("6f33e0f0-cde2-38f9-9aee-2c60af8d1a61")
release_group.should be_an_instance_of(MusicBrainz::ReleaseGroup)
expect(release_group).to be_an_instance_of(MusicBrainz::ReleaseGroup)
end
it "gets correct release group data" do
release_group = MusicBrainz::ReleaseGroup.find("6f33e0f0-cde2-38f9-9aee-2c60af8d1a61")
release_group.id.should == "6f33e0f0-cde2-38f9-9aee-2c60af8d1a61"
release_group.type.should == "Album"
release_group.title.should == "Empire"
release_group.first_release_date.should == Date.new(2006, 8, 28)
release_group.urls[:wikipedia].should == 'http://en.wikipedia.org/wiki/Empire_(Kasabian_album)'
expect(release_group.id).to eq "6f33e0f0-cde2-38f9-9aee-2c60af8d1a61"
expect(release_group.type).to eq "Album"
expect(release_group.title).to eq "Empire"
expect(release_group.first_release_date).to eq Date.new(2006, 8, 28)
expect(release_group.urls[:wikipedia]).to eq 'http://en.wikipedia.org/wiki/Empire_(Kasabian_album)'
end
end
describe '.search' do
context 'without type filter' do
it "searches release group by artist name and title" do
response = File.open(File.join(File.dirname(__FILE__), "../fixtures/release_group/search.xml")).read
MusicBrainz::Client.any_instance.stub(:get_contents).with('http://musicbrainz.org/ws/2/release-group?query=artist:"Kasabian" AND releasegroup:"Empire"&limit=10').
and_return({ status: 200, body: response})
allow_any_instance_of(MusicBrainz::Client).to receive(:get_contents)
.with('http://musicbrainz.org/ws/2/release-group?query=artist:"Kasabian" AND releasegroup:"Empire"&limit=10')
.and_return({ status: 200, body: response})
matches = MusicBrainz::ReleaseGroup.search('Kasabian', 'Empire')
matches.length.should be > 0
matches.first[:title].should == 'Empire'
matches.first[:type].should == 'Album'
expect(matches.length).to be > 0
expect(matches.first[:title]).to eq 'Empire'
expect(matches.first[:type]).to eq 'Album'
end
end
context 'with type filter' do
it "searches release group by artist name and title" do
matches = MusicBrainz::ReleaseGroup.search('Kasabian', 'Empire', 'Album')
matches.length.should be > 0
matches.first[:title].should == 'Empire'
matches.first[:type].should == 'Album'
expect(matches.length).to be > 0
expect(matches.first[:title]).to eq 'Empire'
expect(matches.first[:type]).to eq 'Album'
end
end
end
describe '.find_by_artist_and_title' do
it "gets first release group by artist name and title" do
response = File.open(File.join(File.dirname(__FILE__), "../fixtures/release_group/search.xml")).read
MusicBrainz::Client.any_instance.stub(:get_contents).with('http://musicbrainz.org/ws/2/release-group?query=artist:"Kasabian" AND releasegroup:"Empire"&limit=10').
and_return({ status: 200, body: response})
allow_any_instance_of(MusicBrainz::Client).to receive(:get_contents)
.with('http://musicbrainz.org/ws/2/release-group?query=artist:"Kasabian" AND releasegroup:"Empire"&limit=10')
.and_return({ status: 200, body: response})
response = File.open(File.join(File.dirname(__FILE__), "../fixtures/release_group/entity.xml")).read
MusicBrainz::Client.any_instance.stub(:get_contents).with('http://musicbrainz.org/ws/2/release-group/6f33e0f0-cde2-38f9-9aee-2c60af8d1a61?inc=url-rels').
and_return({ status: 200, body: response})
allow_any_instance_of(MusicBrainz::Client).to receive(:get_contents)
.with('http://musicbrainz.org/ws/2/release-group/6f33e0f0-cde2-38f9-9aee-2c60af8d1a61?inc=url-rels')
.and_return({ status: 200, body: response})
release_group = MusicBrainz::ReleaseGroup.find_by_artist_and_title('Kasabian', 'Empire')
release_group.id.should == '6f33e0f0-cde2-38f9-9aee-2c60af8d1a61'
expect(release_group.id).to eq '6f33e0f0-cde2-38f9-9aee-2c60af8d1a61'
end
end
describe '#releases' do
it "gets correct release group's releases" do
MusicBrainz::Client.any_instance.stub(:get_contents).with('http://musicbrainz.org/ws/2/release-group/6f33e0f0-cde2-38f9-9aee-2c60af8d1a61?inc=url-rels').
and_return({ status: 200, body: File.open(File.join(File.dirname(__FILE__), "../fixtures/release_group/entity.xml")).read})
MusicBrainz::Client.any_instance.stub(:get_contents).with('http://musicbrainz.org/ws/2/release?release-group=6f33e0f0-cde2-38f9-9aee-2c60af8d1a61&inc=media+release-groups&limit=100').
and_return({ status: 200, body: File.open(File.join(File.dirname(__FILE__), "../fixtures/release/list.xml")).read})
allow_any_instance_of(MusicBrainz::Client).to receive(:get_contents)
.with('http://musicbrainz.org/ws/2/release-group/6f33e0f0-cde2-38f9-9aee-2c60af8d1a61?inc=url-rels')
.and_return({ status: 200, body: File.open(File.join(File.dirname(__FILE__), "../fixtures/release_group/entity.xml")).read})
allow_any_instance_of(MusicBrainz::Client).to receive(:get_contents)
.with('http://musicbrainz.org/ws/2/release?release-group=6f33e0f0-cde2-38f9-9aee-2c60af8d1a61&inc=media+release-groups&limit=100')
.and_return({ status: 200, body: File.open(File.join(File.dirname(__FILE__), "../fixtures/release/list.xml")).read})
releases = MusicBrainz::ReleaseGroup.find("6f33e0f0-cde2-38f9-9aee-2c60af8d1a61").releases
releases.length.should be >= 5
releases.first.id.should == "30d5e730-ce0a-464d-93e1-7d76e4bb3e31"
releases.first.status.should == "Official"
releases.first.title.should == "Empire"
releases.first.date.should == Date.new(2006, 8, 28)
releases.first.country.should == "GB"
releases.first.type.should == "Album"
expect(releases.length).to be >= 5
expect(releases.first.id).to eq "30d5e730-ce0a-464d-93e1-7d76e4bb3e31"
expect(releases.first.status).to eq "Official"
expect(releases.first.title).to eq "Empire"
expect(releases.first.date).to eq Date.new(2006, 8, 28)
expect(releases.first.country).to eq "GB"
expect(releases.first.type).to eq "Album"
end
end
end
+17 -17
View File
@@ -4,35 +4,35 @@ require "spec_helper"
describe MusicBrainz::Release do
it "gets no exception while loading release info" do
lambda {
expect {
MusicBrainz::Release.find("2225dd4c-ae9a-403b-8ea0-9e05014c778f")
}.should_not raise_error(Exception)
}.to_not raise_error(Exception)
end
it "gets correct instance" do
release = MusicBrainz::Release.find("2225dd4c-ae9a-403b-8ea0-9e05014c778f")
release.should be_an_instance_of(MusicBrainz::Release)
expect(release).to be_an_instance_of(MusicBrainz::Release)
end
it "gets correct release data" do
release = MusicBrainz::Release.find("b94cb547-cf7a-4357-894c-53c3bf33b093")
release.id.should == "b94cb547-cf7a-4357-894c-53c3bf33b093"
release.title.should == "Humanoid"
release.status.should == "Official"
release.date.should == Date.new(2009, 10, 6)
release.country.should == "US"
release.asin.should == 'B002NOYX6I'
release.barcode.should == '602527197692'
release.quality.should == 'normal'
release.type.should == 'Album'
expect(release.id).to eq "b94cb547-cf7a-4357-894c-53c3bf33b093"
expect(release.title).to eq "Humanoid"
expect(release.status).to eq "Official"
expect(release.date).to eq Date.new(2009, 10, 6)
expect(release.country).to eq "US"
expect(release.asin).to eq 'B002NOYX6I'
expect(release.barcode).to eq '602527197692'
expect(release.quality).to eq 'normal'
expect(release.type).to eq 'Album'
end
it "gets correct release tracks" do
tracks = MusicBrainz::Release.find("2225dd4c-ae9a-403b-8ea0-9e05014c778f").tracks
tracks.length.should == 11
tracks.first.position.should == 1
tracks.first.recording_id.should == "b3015bab-1540-4d4e-9f30-14872a1525f7"
tracks.first.title.should == "Empire"
tracks.first.length.should == 233013
expect(tracks.length).to eq 11
expect(tracks.first.position).to eq 1
expect(tracks.first.recording_id).to eq "b3015bab-1540-4d4e-9f30-14872a1525f7"
expect(tracks.first.title).to eq "Empire"
expect(tracks.first.length).to eq 233013
end
end
+6 -6
View File
@@ -4,20 +4,20 @@ require "spec_helper"
describe MusicBrainz::Track do
it "gets no exception while loading release info" do
lambda {
expect {
MusicBrainz::Track.find("b3015bab-1540-4d4e-9f30-14872a1525f7")
}.should_not raise_error(Exception)
}.to_not raise_error(Exception)
end
it "gets correct instance" do
track = MusicBrainz::Track.find("b3015bab-1540-4d4e-9f30-14872a1525f7")
track.should be_an_instance_of(MusicBrainz::Track)
expect(track).to be_an_instance_of(MusicBrainz::Track)
end
it "gets correct track data" do
track = MusicBrainz::Track.find("b3015bab-1540-4d4e-9f30-14872a1525f7")
track.recording_id.should == "b3015bab-1540-4d4e-9f30-14872a1525f7"
track.title.should == "Empire"
track.length.should == 233013
expect(track.recording_id).to eq "b3015bab-1540-4d4e-9f30-14872a1525f7"
expect(track.title).to eq "Empire"
expect(track.length).to eq 233013
end
end