1
0
Fork 0

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

View File

@ -19,4 +19,5 @@ Gem::Specification.new do |gem|
gem.add_development_dependency('rspec') gem.add_development_dependency('rspec')
gem.add_development_dependency('awesome_print') gem.add_development_dependency('awesome_print')
gem.add_development_dependency('rake', '~> 10.4.0') gem.add_development_dependency('rake', '~> 10.4.0')
gem.add_development_dependency('pry')
end end

View File

@ -16,7 +16,7 @@ describe MusicBrainz::Bindings::Relations do
</relation-list></artist>} </relation-list></artist>}
) )
described_class.parse(xml.xpath('./artist'))[:urls][:social_network].should == 'https://plus.google.com/+Madonna' expect(described_class.parse(xml.xpath('./artist'))[:urls][:social_network]).to eq 'https://plus.google.com/+Madonna'
end end
end end
@ -33,7 +33,7 @@ describe MusicBrainz::Bindings::Relations do
</relation-list></artist>} </relation-list></artist>}
) )
described_class.parse(xml.xpath('./artist'))[:urls][:social_network].should == [ expect(described_class.parse(xml.xpath('./artist'))[:urls][:social_network]).to eq [
'https://plus.google.com/+Madonna', 'https://www.facebook.com/madonna' 'https://plus.google.com/+Madonna', 'https://www.facebook.com/madonna'
] ]
end end

View File

@ -4,14 +4,20 @@ require "spec_helper"
describe MusicBrainz::Bindings::ReleaseGroupSearch do describe MusicBrainz::Bindings::ReleaseGroupSearch do
describe '.parse' do describe '.parse' do
let(:response) {
'<metadata xmlns="http://musicbrainz.org/ns/mmd-2.0#" xmlns:ext="http://musicbrainz.org/ns/ext#-2.0"><release-group-list><release-group id="246bc928-2dc8-35ba-80ee-7a0079de1632" type="Single" ext:score="100"><title>Empire</title></release-group></release-group-list></metadata>'
}
let(:metadata) {
described_class.parse(Nokogiri::XML.parse(response).remove_namespaces!.xpath('/metadata'))
}
it "gets correct release group data" do it "gets correct release group data" do
response = '<metadata xmlns="http://musicbrainz.org/ns/mmd-2.0#" xmlns:ext="http://musicbrainz.org/ns/ext#-2.0"><release-group-list><release-group id="246bc928-2dc8-35ba-80ee-7a0079de1632" type="Single" ext:score="100"><title>Empire</title></release-group></release-group-list></metadata>' expect(metadata).to eq([
described_class.parse(Nokogiri::XML.parse(response).remove_namespaces!.xpath('/metadata')).should == [
{ {
id: '246bc928-2dc8-35ba-80ee-7a0079de1632', mbid: '246bc928-2dc8-35ba-80ee-7a0079de1632', id: '246bc928-2dc8-35ba-80ee-7a0079de1632', mbid: '246bc928-2dc8-35ba-80ee-7a0079de1632',
title: 'Empire', type: 'Single', score: 100 title: 'Empire', type: 'Single', score: 100
} }
] ])
end end
end end
end end

View File

@ -10,7 +10,7 @@ describe MusicBrainz::Bindings::Release do
it 'returns CD' do it 'returns CD' do
response = '<release><medium-list count="1"><medium><format>CD</format></medium></medium-list></release>' response = '<release><medium-list count="1"><medium><format>CD</format></medium></medium-list></release>'
xml = Nokogiri::XML.parse(response) xml = Nokogiri::XML.parse(response)
described_class.parse(xml)[:format].should == 'CD' expect(described_class.parse(xml)[:format]).to eq 'CD'
end end
end end
@ -18,7 +18,7 @@ describe MusicBrainz::Bindings::Release do
it 'returns 2xCD' do it 'returns 2xCD' do
response = '<release><medium-list count="2"><medium><format>CD</format><track-list count="11" /></medium><medium><title>bonus disc</title><format>CD</format></medium></medium-list></release>' response = '<release><medium-list count="2"><medium><format>CD</format><track-list count="11" /></medium><medium><title>bonus disc</title><format>CD</format></medium></medium-list></release>'
xml = Nokogiri::XML.parse(response) xml = Nokogiri::XML.parse(response)
described_class.parse(xml)[:format].should == '2xCD' expect(described_class.parse(xml)[:format]).to eq '2xCD'
end end
end end
@ -26,7 +26,7 @@ describe MusicBrainz::Bindings::Release do
it 'returns DVD + CD' do it 'returns DVD + CD' do
response = '<release><medium-list count="2"><medium><format>DVD</format></medium><medium><format>CD</format></medium></medium-list></release>' response = '<release><medium-list count="2"><medium><format>DVD</format></medium><medium><format>CD</format></medium></medium-list></release>'
xml = Nokogiri::XML.parse(response) xml = Nokogiri::XML.parse(response)
described_class.parse(xml)[:format].should == 'DVD + CD' expect(described_class.parse(xml)[:format]).to eq 'DVD + CD'
end end
end end
@ -34,7 +34,7 @@ describe MusicBrainz::Bindings::Release do
it 'returns 2xCD + DVD' do it 'returns 2xCD + DVD' do
response = '<release><medium-list count="2"><medium><format>CD</format></medium><medium><format>CD</format></medium><medium><format>DVD</format></medium></medium-list></release>' response = '<release><medium-list count="2"><medium><format>CD</format></medium><medium><format>CD</format></medium><medium><format>DVD</format></medium></medium-list></release>'
xml = Nokogiri::XML.parse(response) xml = Nokogiri::XML.parse(response)
described_class.parse(xml)[:format].should == '2xCD + DVD' expect(described_class.parse(xml)[:format]).to eq '2xCD + DVD'
end end
end end
end end

View File

@ -6,7 +6,7 @@ describe MusicBrainz::Bindings::TrackSearch do
describe '.parse' do describe '.parse' do
it "gets correct Track (really recording) data" do it "gets correct Track (really recording) data" do
response = '<metadata xmlns="http://musicbrainz.org/ns/mmd-2.0#" xmlns:ext="http://musicbrainz.org/ns/ext#-2.0"><recording-list offset="0" count="1"><recording id="0b382a13-32f0-4743-9248-ba5536a6115e" ext:score="100"><title>King Fred</title><artist-credit><name-credit><artist id="f52f7a92-d495-4d32-89e7-8b1e5b8541c8"><name>Too Much Joy</name></artist></name-credit></artist-credit><release-list><release id="8442e42b-c40a-4817-89a0-dbe663c94d2d"><title>Green Eggs and Crack</title></release></release-list></recording></recording-list></metadata>' response = '<metadata xmlns="http://musicbrainz.org/ns/mmd-2.0#" xmlns:ext="http://musicbrainz.org/ns/ext#-2.0"><recording-list offset="0" count="1"><recording id="0b382a13-32f0-4743-9248-ba5536a6115e" ext:score="100"><title>King Fred</title><artist-credit><name-credit><artist id="f52f7a92-d495-4d32-89e7-8b1e5b8541c8"><name>Too Much Joy</name></artist></name-credit></artist-credit><release-list><release id="8442e42b-c40a-4817-89a0-dbe663c94d2d"><title>Green Eggs and Crack</title></release></release-list></recording></recording-list></metadata>'
described_class.parse(Nokogiri::XML.parse(response).remove_namespaces!.xpath('/metadata')).should == [ expect(described_class.parse(Nokogiri::XML.parse(response).remove_namespaces!.xpath('/metadata'))).to eq [
{ {
id: '0b382a13-32f0-4743-9248-ba5536a6115e', mbid: '0b382a13-32f0-4743-9248-ba5536a6115e', id: '0b382a13-32f0-4743-9248-ba5536a6115e', mbid: '0b382a13-32f0-4743-9248-ba5536a6115e',
title: 'King Fred', artist: 'Too Much Joy', releases: ['Green Eggs and Crack'], score: 100 title: 'King Fred', artist: 'Too Much Joy', releases: ['Green Eggs and Crack'], score: 100

View File

@ -4,9 +4,8 @@ require "ostruct"
require "spec_helper" require "spec_helper"
describe MusicBrainz::ClientModules::CachingProxy do describe MusicBrainz::ClientModules::CachingProxy do
let(:old_cache_path){ File.join(File.dirname(__FILE__), '..', '..', 'tmp', 'spec_cache') }
let(:tmp_cache_path){ File.join(File.dirname(__FILE__), '..', '..', 'tmp', 'cache_module_spec_cache') }
let(:test_mbid){ "69b39eab-6577-46a4-a9f5-817839092033" } let(:test_mbid){ "69b39eab-6577-46a4-a9f5-817839092033" }
let(:tmp_cache_path){ File.join(File.dirname(__FILE__), '..', '..', 'tmp', 'cache_module_spec_cache') }
let(:test_cache_file){ "#{tmp_cache_path}/03/48/ec/6c2bee685d9a96f95ed46378f624714e7a4650b0d44c1a8eee5bac2480.xml" } let(:test_cache_file){ "#{tmp_cache_path}/03/48/ec/6c2bee685d9a96f95ed46378f624714e7a4650b0d44c1a8eee5bac2480.xml" }
let(:test_response_file){ File.join(File.dirname(__FILE__), "../fixtures/kasabian.xml") } let(:test_response_file){ File.join(File.dirname(__FILE__), "../fixtures/kasabian.xml") }
let(:test_response){ File.open(test_response_file).read } let(:test_response){ File.open(test_response_file).read }
@ -15,8 +14,12 @@ describe MusicBrainz::ClientModules::CachingProxy do
MusicBrainz.config.cache_path = File.join(File.dirname(__FILE__), '..', '..', 'tmp', 'cache_module_spec_cache') MusicBrainz.config.cache_path = File.join(File.dirname(__FILE__), '..', '..', 'tmp', 'cache_module_spec_cache')
end end
before do
File.delete(test_cache_file) if File.exist?(test_cache_file)
end
after(:all) do after(:all) do
MusicBrainz.config.cache_path = old_cache_path MusicBrainz.config.cache_path = File.join(File.dirname(__FILE__), '..', '..', 'tmp', 'spec_cache')
MusicBrainz.config.perform_caching = true MusicBrainz.config.perform_caching = true
MusicBrainz.config.query_interval = 1.5 MusicBrainz.config.query_interval = 1.5
end end
@ -24,16 +27,16 @@ describe MusicBrainz::ClientModules::CachingProxy do
context "with cache enabled" do context "with cache enabled" do
it "calls http only once when requesting the resource twice" do it "calls http only once when requesting the resource twice" do
MusicBrainz.config.perform_caching = true MusicBrainz.config.perform_caching = true
File.exist?(test_cache_file).should be_false expect(File).to_not exist(test_cache_file)
# Stubbing # Stubbing
MusicBrainz.client.http.stub(:get).and_return(OpenStruct.new(status: 200, body: test_response)) allow(MusicBrainz.client.http).to receive(:get).and_return(OpenStruct.new(status: 200, body: test_response))
MusicBrainz.client.http.should_receive(:get).once expect(MusicBrainz.client.http).to receive(:get).once
2.times do 2.times do
artist = MusicBrainz::Artist.find(test_mbid) artist = MusicBrainz::Artist.find(test_mbid)
artist.should be_a_kind_of(MusicBrainz::Artist) expect(artist).to be_kind_of(MusicBrainz::Artist)
File.exist?(test_cache_file).should be_true expect(File).to exist(test_cache_file)
end end
MusicBrainz.client.clear_cache MusicBrainz.client.clear_cache
@ -43,19 +46,19 @@ describe MusicBrainz::ClientModules::CachingProxy do
context "with cache disabled" do context "with cache disabled" do
it "calls http twice when requesting the resource twice" do it "calls http twice when requesting the resource twice" do
MusicBrainz.config.perform_caching = false MusicBrainz.config.perform_caching = false
File.exist?(test_cache_file).should be_false expect(File).to_not exist(test_cache_file)
# Hacking for test performance purposes # Hacking for test performance purposes
MusicBrainz.config.query_interval = 0.0 MusicBrainz.config.query_interval = 0.0
# Stubbing # Stubbing
MusicBrainz.client.http.stub(:get).and_return(OpenStruct.new(status: 200, body: test_response)) allow(MusicBrainz.client.http).to receive(:get).and_return(OpenStruct.new(status: 200, body: test_response))
MusicBrainz.client.http.should_receive(:get).twice expect(MusicBrainz.client.http).to receive(:get).twice
2.times do 2.times do
artist = MusicBrainz::Artist.find(test_mbid) artist = MusicBrainz::Artist.find(test_mbid)
artist.should be_a_kind_of(MusicBrainz::Artist) expect(artist).to be_kind_of(MusicBrainz::Artist)
File.exist?(test_cache_file).should be_false expect(File).to_not exist(test_cache_file)
end end
end end
end end

View File

@ -18,15 +18,15 @@ describe MusicBrainz::Deprecated::CacheConfig do
it "allows deprecated use of cache_path" do it "allows deprecated use of cache_path" do
MusicBrainz.config.cache_path = "test1" MusicBrainz.config.cache_path = "test1"
MusicBrainz::Tools::Cache.cache_path.should == "test1" expect(MusicBrainz::Tools::Cache.cache_path).to eq "test1"
MusicBrainz.cache_path.should == "test1" expect(MusicBrainz.cache_path).to eq "test1"
end end
it "allows deprecated use of cache_path=" do it "allows deprecated use of cache_path=" do
MusicBrainz::Tools::Cache.cache_path = "test2" MusicBrainz::Tools::Cache.cache_path = "test2"
MusicBrainz.config.cache_path.should == "test2" expect(MusicBrainz.config.cache_path).to eq "test2"
MusicBrainz.cache_path = "test3" MusicBrainz.cache_path = "test3"
MusicBrainz.config.cache_path.should == "test3" expect(MusicBrainz.config.cache_path).to eq "test3"
end end
end end

View File

@ -18,15 +18,15 @@ describe MusicBrainz::Deprecated::ProxyConfig do
it "allows deprecated use of query_interval" do it "allows deprecated use of query_interval" do
MusicBrainz.config.query_interval = 2 MusicBrainz.config.query_interval = 2
MusicBrainz::Tools::Proxy.query_interval.should == 2 expect(MusicBrainz::Tools::Proxy.query_interval).to eq 2
MusicBrainz.query_interval.should == 2 expect(MusicBrainz.query_interval).to eq 2
end end
it "allows deprecated use of query_interval=" do it "allows deprecated use of query_interval=" do
MusicBrainz::Tools::Proxy.query_interval = 3 MusicBrainz::Tools::Proxy.query_interval = 3
MusicBrainz.config.query_interval.should == 3 expect(MusicBrainz.config.query_interval).to eq 3
MusicBrainz.query_interval = 4 MusicBrainz.query_interval = 4
MusicBrainz.config.query_interval.should == 4 expect(MusicBrainz.config.query_interval).to eq 4
end end
end end

View File

@ -4,56 +4,57 @@ require "spec_helper"
describe MusicBrainz::Artist do describe MusicBrainz::Artist do
it "gets no exception while loading artist info" do it "gets no exception while loading artist info" do
lambda { expect {
MusicBrainz::Artist.find('69b39eab-6577-46a4-a9f5-817839092033') MusicBrainz::Artist.find('69b39eab-6577-46a4-a9f5-817839092033')
}.should_not raise_error(Exception) }.to_not raise_error(Exception)
end end
it "gets correct instance" do it "gets correct instance" do
artist = MusicBrainz::Artist.find_by_name('Kasabian') artist = MusicBrainz::Artist.find_by_name('Kasabian')
artist.should be_an_instance_of(MusicBrainz::Artist) expect(artist).to be_instance_of(MusicBrainz::Artist)
end end
it "searches artist by name" do it "searches artist by name" do
matches = MusicBrainz::Artist.search('Kasabian') matches = MusicBrainz::Artist.search('Kasabian')
matches.length.should be > 0 expect(matches).to_not be_empty
matches.first[:name].should == "Kasabian" expect(matches.first[:name]).to eq("Kasabian")
end end
it "should return search results in the right order and pass back the correct score" do 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 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'). allow_any_instance_of(MusicBrainz::Client).to receive(:get_contents)
and_return({ status: 200, body: response}) .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 = MusicBrainz::Artist.search('Chris Martin')
matches[0][:score].should == 100 expect(matches[0][:score]).to eq 100
matches[0][:id].should == "90fff570-a4ef-4cd4-ba21-e00c7261b05a" expect(matches[0][:id]).to eq "90fff570-a4ef-4cd4-ba21-e00c7261b05a"
matches[1][:score].should == 100 expect(matches[1][:score]).to eq 100
matches[1][:id].should == "b732a912-af95-472c-be52-b14610734c64" expect(matches[1][:id]).to eq "b732a912-af95-472c-be52-b14610734c64"
end end
it "gets correct result by name" do it "gets correct result by name" do
artist = MusicBrainz::Artist.find_by_name('Kasabian') 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 end
it "gets correct artist data" do it "gets correct artist data" do
artist = MusicBrainz::Artist.find_by_name('Kasabian') 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"
artist.type.should == "Group" expect(artist.type).to eq "Group"
artist.name.should == "Kasabian" expect(artist.name).to eq "Kasabian"
artist.country.should == "GB" expect(artist.country).to eq "GB"
artist.date_begin.year.should == 1999 expect(artist.date_begin.year).to eq 1997
end end
it "gets correct artist's release groups" do it "gets correct artist's release groups" do
release_groups = MusicBrainz::Artist.find_by_name('Kasabian').release_groups release_groups = MusicBrainz::Artist.find_by_name('Kasabian').release_groups
release_groups.length.should be >= 16 expect(release_groups.length).to be >= 16
release_groups.first.id.should == "533cbc5f-ec7e-32ab-95f3-8d1f804a5176" expect(release_groups.first.id).to eq "533cbc5f-ec7e-32ab-95f3-8d1f804a5176"
release_groups.first.type.should == "Single" expect(release_groups.first.type).to eq "Single"
release_groups.first.title.should == "Club Foot" expect(release_groups.first.title).to eq "Club Foot"
release_groups.first.first_release_date.should == Date.new(2004, 5, 10) expect(release_groups.first.first_release_date).to eq Date.new(2004, 5, 10)
release_groups.first.urls[:discogs].should == 'http://www.discogs.com/master/125150' expect(release_groups.first.urls[:discogs]).to eq 'http://www.discogs.com/master/125150'
end end
end end

View File

@ -10,7 +10,7 @@ describe MusicBrainz::BaseModel do
response = '<release-group><first-release-date></first-release-date></release-group>' response = '<release-group><first-release-date></first-release-date></release-group>'
xml = Nokogiri::XML.parse(response) xml = Nokogiri::XML.parse(response)
release_group = MusicBrainz::ReleaseGroup.new MusicBrainz::Bindings::ReleaseGroup.parse(xml) 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
end end
@ -19,7 +19,7 @@ describe MusicBrainz::BaseModel do
response = '<release-group><first-release-date>1995</first-release-date></release-group>' response = '<release-group><first-release-date>1995</first-release-date></release-group>'
xml = Nokogiri::XML.parse(response) xml = Nokogiri::XML.parse(response)
release_group = MusicBrainz::ReleaseGroup.new MusicBrainz::Bindings::ReleaseGroup.parse(xml) 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
end end
@ -28,7 +28,7 @@ describe MusicBrainz::BaseModel do
response = '<release-group><first-release-date>1995-04</first-release-date></release-group>' response = '<release-group><first-release-date>1995-04</first-release-date></release-group>'
xml = Nokogiri::XML.parse(response) xml = Nokogiri::XML.parse(response)
release_group = MusicBrainz::ReleaseGroup.new MusicBrainz::Bindings::ReleaseGroup.parse(xml) 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
@ -37,7 +37,7 @@ describe MusicBrainz::BaseModel do
response = '<release-group><first-release-date>1995-04-30</first-release-date></release-group>' response = '<release-group><first-release-date>1995-04-30</first-release-date></release-group>'
xml = Nokogiri::XML.parse(response) xml = Nokogiri::XML.parse(response)
release_group = MusicBrainz::ReleaseGroup.new MusicBrainz::Bindings::ReleaseGroup.parse(xml) 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

View File

@ -5,23 +5,23 @@ require "spec_helper"
describe MusicBrainz::ReleaseGroup do describe MusicBrainz::ReleaseGroup do
describe '.find' do describe '.find' do
it "gets no exception while loading release group info" do it "gets no exception while loading release group info" do
lambda { expect {
MusicBrainz::ReleaseGroup.find("6f33e0f0-cde2-38f9-9aee-2c60af8d1a61") MusicBrainz::ReleaseGroup.find("6f33e0f0-cde2-38f9-9aee-2c60af8d1a61")
}.should_not raise_error(Exception) }.to_not raise_error(Exception)
end end
it "gets correct instance" do it "gets correct instance" do
release_group = MusicBrainz::ReleaseGroup.find("6f33e0f0-cde2-38f9-9aee-2c60af8d1a61") 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 end
it "gets correct release group data" do it "gets correct release group data" do
release_group = MusicBrainz::ReleaseGroup.find("6f33e0f0-cde2-38f9-9aee-2c60af8d1a61") release_group = MusicBrainz::ReleaseGroup.find("6f33e0f0-cde2-38f9-9aee-2c60af8d1a61")
release_group.id.should == "6f33e0f0-cde2-38f9-9aee-2c60af8d1a61" expect(release_group.id).to eq "6f33e0f0-cde2-38f9-9aee-2c60af8d1a61"
release_group.type.should == "Album" expect(release_group.type).to eq "Album"
release_group.title.should == "Empire" expect(release_group.title).to eq "Empire"
release_group.first_release_date.should == Date.new(2006, 8, 28) expect(release_group.first_release_date).to eq Date.new(2006, 8, 28)
release_group.urls[:wikipedia].should == 'http://en.wikipedia.org/wiki/Empire_(Kasabian_album)' expect(release_group.urls[:wikipedia]).to eq 'http://en.wikipedia.org/wiki/Empire_(Kasabian_album)'
end end
end end
@ -29,22 +29,23 @@ describe MusicBrainz::ReleaseGroup do
context 'without type filter' do context 'without type filter' do
it "searches release group by artist name and title" 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 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'). allow_any_instance_of(MusicBrainz::Client).to receive(:get_contents)
and_return({ status: 200, body: response}) .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 = MusicBrainz::ReleaseGroup.search('Kasabian', 'Empire')
matches.length.should be > 0 expect(matches.length).to be > 0
matches.first[:title].should == 'Empire' expect(matches.first[:title]).to eq 'Empire'
matches.first[:type].should == 'Album' expect(matches.first[:type]).to eq 'Album'
end end
end end
context 'with type filter' do context 'with type filter' do
it "searches release group by artist name and title" do it "searches release group by artist name and title" do
matches = MusicBrainz::ReleaseGroup.search('Kasabian', 'Empire', 'Album') matches = MusicBrainz::ReleaseGroup.search('Kasabian', 'Empire', 'Album')
matches.length.should be > 0 expect(matches.length).to be > 0
matches.first[:title].should == 'Empire' expect(matches.first[:title]).to eq 'Empire'
matches.first[:type].should == 'Album' expect(matches.first[:type]).to eq 'Album'
end end
end end
end end
@ -52,34 +53,38 @@ describe MusicBrainz::ReleaseGroup do
describe '.find_by_artist_and_title' do describe '.find_by_artist_and_title' do
it "gets first release group by artist name 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 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'). allow_any_instance_of(MusicBrainz::Client).to receive(:get_contents)
and_return({ status: 200, body: response}) .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 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'). allow_any_instance_of(MusicBrainz::Client).to receive(:get_contents)
and_return({ status: 200, body: response}) .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 = 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
end end
describe '#releases' do describe '#releases' do
it "gets correct release group's 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'). allow_any_instance_of(MusicBrainz::Client).to receive(:get_contents)
and_return({ status: 200, body: File.open(File.join(File.dirname(__FILE__), "../fixtures/release_group/entity.xml")).read}) .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'). allow_any_instance_of(MusicBrainz::Client).to receive(:get_contents)
and_return({ status: 200, body: File.open(File.join(File.dirname(__FILE__), "../fixtures/release/list.xml")).read}) .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 = MusicBrainz::ReleaseGroup.find("6f33e0f0-cde2-38f9-9aee-2c60af8d1a61").releases
releases.length.should be >= 5 expect(releases.length).to be >= 5
releases.first.id.should == "30d5e730-ce0a-464d-93e1-7d76e4bb3e31" expect(releases.first.id).to eq "30d5e730-ce0a-464d-93e1-7d76e4bb3e31"
releases.first.status.should == "Official" expect(releases.first.status).to eq "Official"
releases.first.title.should == "Empire" expect(releases.first.title).to eq "Empire"
releases.first.date.should == Date.new(2006, 8, 28) expect(releases.first.date).to eq Date.new(2006, 8, 28)
releases.first.country.should == "GB" expect(releases.first.country).to eq "GB"
releases.first.type.should == "Album" expect(releases.first.type).to eq "Album"
end end
end end
end end

View File

@ -4,35 +4,35 @@ require "spec_helper"
describe MusicBrainz::Release do describe MusicBrainz::Release do
it "gets no exception while loading release info" do it "gets no exception while loading release info" do
lambda { expect {
MusicBrainz::Release.find("2225dd4c-ae9a-403b-8ea0-9e05014c778f") MusicBrainz::Release.find("2225dd4c-ae9a-403b-8ea0-9e05014c778f")
}.should_not raise_error(Exception) }.to_not raise_error(Exception)
end end
it "gets correct instance" do it "gets correct instance" do
release = MusicBrainz::Release.find("2225dd4c-ae9a-403b-8ea0-9e05014c778f") 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 end
it "gets correct release data" do it "gets correct release data" do
release = MusicBrainz::Release.find("b94cb547-cf7a-4357-894c-53c3bf33b093") release = MusicBrainz::Release.find("b94cb547-cf7a-4357-894c-53c3bf33b093")
release.id.should == "b94cb547-cf7a-4357-894c-53c3bf33b093" expect(release.id).to eq "b94cb547-cf7a-4357-894c-53c3bf33b093"
release.title.should == "Humanoid" expect(release.title).to eq "Humanoid"
release.status.should == "Official" expect(release.status).to eq "Official"
release.date.should == Date.new(2009, 10, 6) expect(release.date).to eq Date.new(2009, 10, 6)
release.country.should == "US" expect(release.country).to eq "US"
release.asin.should == 'B002NOYX6I' expect(release.asin).to eq 'B002NOYX6I'
release.barcode.should == '602527197692' expect(release.barcode).to eq '602527197692'
release.quality.should == 'normal' expect(release.quality).to eq 'normal'
release.type.should == 'Album' expect(release.type).to eq 'Album'
end end
it "gets correct release tracks" do it "gets correct release tracks" do
tracks = MusicBrainz::Release.find("2225dd4c-ae9a-403b-8ea0-9e05014c778f").tracks tracks = MusicBrainz::Release.find("2225dd4c-ae9a-403b-8ea0-9e05014c778f").tracks
tracks.length.should == 11 expect(tracks.length).to eq 11
tracks.first.position.should == 1 expect(tracks.first.position).to eq 1
tracks.first.recording_id.should == "b3015bab-1540-4d4e-9f30-14872a1525f7" expect(tracks.first.recording_id).to eq "b3015bab-1540-4d4e-9f30-14872a1525f7"
tracks.first.title.should == "Empire" expect(tracks.first.title).to eq "Empire"
tracks.first.length.should == 233013 expect(tracks.first.length).to eq 233013
end end
end end

View File

@ -4,20 +4,20 @@ require "spec_helper"
describe MusicBrainz::Track do describe MusicBrainz::Track do
it "gets no exception while loading release info" do it "gets no exception while loading release info" do
lambda { expect {
MusicBrainz::Track.find("b3015bab-1540-4d4e-9f30-14872a1525f7") MusicBrainz::Track.find("b3015bab-1540-4d4e-9f30-14872a1525f7")
}.should_not raise_error(Exception) }.to_not raise_error(Exception)
end end
it "gets correct instance" do it "gets correct instance" do
track = MusicBrainz::Track.find("b3015bab-1540-4d4e-9f30-14872a1525f7") 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 end
it "gets correct track data" do it "gets correct track data" do
track = MusicBrainz::Track.find("b3015bab-1540-4d4e-9f30-14872a1525f7") track = MusicBrainz::Track.find("b3015bab-1540-4d4e-9f30-14872a1525f7")
track.recording_id.should == "b3015bab-1540-4d4e-9f30-14872a1525f7" expect(track.recording_id).to eq "b3015bab-1540-4d4e-9f30-14872a1525f7"
track.title.should == "Empire" expect(track.title).to eq "Empire"
track.length.should == 233013 expect(track.length).to eq 233013
end end
end end

View File

@ -1,6 +1,7 @@
require "rubygems" require "rubygems"
require "bundler/setup" require "bundler/setup"
require "musicbrainz" require "musicbrainz"
require "pry"
RSpec.configure do |c| RSpec.configure do |c|
c.order = 'random' c.order = 'random'