Gem is rewrapped with Bundler instead of Jeweler. All tests are using RSpec. Reorganized lib structure. Tests are fixed.
This commit is contained in:
@@ -1,51 +0,0 @@
|
||||
require 'spec_helper'
|
||||
|
||||
describe MusicBrainz do
|
||||
|
||||
describe '.cache_contents', :vcr do
|
||||
let(:cache_path) { File.join(File.dirname(__FILE__), '../../tmp/rspec_test/musicbrainz') }
|
||||
let(:response) { ::StringIO.new('<?xml version="1.0" encoding="UTF-8"?><metadata xmlns="http://musicbrainz.org/ns/mmd-2.0#"><artist type="Group" id="69b39eab-6577-46a4-a9f5-817839092033"><name>Kasabian</name><sort-name>Kasabian</sort-name><country>GB</country><life-span><begin>1999</begin></life-span><relation-list target-type="url"><relation type="allmusic"><target>http://allmusic.com/artist/p678134</target></relation><relation type="wikipedia"><target>http://en.wikipedia.org/wiki/Kasabian</target></relation><relation type="microblog"><target>http://twitter.com/kasabianhq</target></relation><relation type="BBC Music page"><target>http://www.bbc.co.uk/music/artists/69b39eab-6577-46a4-a9f5-817839092033</target></relation><relation type="discogs"><target>http://www.discogs.com/artist/Kasabian</target></relation><relation type="social network"><target>http://www.facebook.com/kasabian</target></relation><relation type="IMDb"><target>http://www.imdb.com/name/nm1868442/</target></relation><relation type="official homepage"><target>http://www.kasabian.co.uk/</target></relation><relation type="myspace"><target>http://www.myspace.com/kasabian</target></relation><relation type="youtube"><target>http://www.youtube.com/kasabianvevo</target></relation><relation type="youtube"><target>http://www.youtube.com/user/KasabianTour</target></relation></relation-list></artist></metadata>') }
|
||||
|
||||
before(:each) do
|
||||
MusicBrainz.clear_cache
|
||||
end
|
||||
|
||||
after(:each) do
|
||||
MusicBrainz.clear_cache
|
||||
end
|
||||
|
||||
context 'with cache enabled' do
|
||||
it 'calls get contents only once when requesting the resource twice' do
|
||||
MusicBrainz.cache_path = cache_path
|
||||
MusicBrainz.stub(:get_contents).and_return(response)
|
||||
MusicBrainz.should_receive(:get_contents).once
|
||||
mbid = '69b39eab-6577-46a4-a9f5-817839092033'
|
||||
File.exist?("#{cache_path}/artist/#{mbid}?inc=url-rels").should be_false
|
||||
artist = MusicBrainz::Artist.find(mbid)
|
||||
artist.should be_a_kind_of(MusicBrainz::Artist)
|
||||
|
||||
File.exist?("#{cache_path}/artist/#{mbid}?inc=url-rels").should be_true
|
||||
artist = MusicBrainz::Artist.find(mbid)
|
||||
artist.should be_a_kind_of(MusicBrainz::Artist)
|
||||
end
|
||||
end
|
||||
|
||||
context 'with cache disabled' do
|
||||
it 'calls get contents twice when requesting the resource twice' do
|
||||
MusicBrainz.cache_path = nil
|
||||
MusicBrainz.stub(:get_contents).and_return(response)
|
||||
MusicBrainz.should_receive(:get_contents).twice
|
||||
mbid = '69b39eab-6577-46a4-a9f5-817839092033'
|
||||
File.exist?("#{cache_path}/artist/#{mbid}?inc=url-rels").should be_false
|
||||
artist = MusicBrainz::Artist.find(mbid)
|
||||
artist.should be_a_kind_of(MusicBrainz::Artist)
|
||||
|
||||
File.exist?("#{cache_path}/artist/#{mbid}?inc=url-rels").should be_false
|
||||
response.rewind
|
||||
MusicBrainz.stub(:get_contents).and_return(response)
|
||||
artist = MusicBrainz::Artist.find(mbid)
|
||||
artist.should be_a_kind_of(MusicBrainz::Artist)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -1,44 +1,49 @@
|
||||
require 'spec_helper'
|
||||
require "spec_helper"
|
||||
|
||||
describe "artist" do
|
||||
it "return valid instance", :vcr do
|
||||
artist = MusicBrainz::Artist.find('69b39eab-6577-46a4-a9f5-817839092033')
|
||||
artist.should be_a_kind_of(MusicBrainz::Artist)
|
||||
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
|
||||
|
||||
it "search by name", :vcr do
|
||||
|
||||
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
|
||||
matches = MusicBrainz::Artist.search('Kasabian')
|
||||
matches.should have_at_least(1).item
|
||||
matches.first[:name].should eql('Kasabian')
|
||||
matches.length.should be > 0
|
||||
matches.first[:name].should == "Kasabian"
|
||||
end
|
||||
|
||||
it "finds name first than alias" do
|
||||
matches = MusicBrainz::Artist.search('Chris Martin')
|
||||
matches.length.should be > 0
|
||||
matches.first[:name].should == "Chris Martin"
|
||||
end
|
||||
|
||||
it "gets correct result by name" do
|
||||
artist = MusicBrainz::Artist.find_by_name('Kasabian')
|
||||
artist.id.should == "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.should == "1999"
|
||||
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 == Time.utc(2004, 5, 10)
|
||||
end
|
||||
#
|
||||
# should "get correct result by name" do
|
||||
# @artist = MusicBrainz::Artist.find_by_name('Kasabian')
|
||||
# assert_equal("69b39eab-6577-46a4-a9f5-817839092033", @artist.id)
|
||||
# end
|
||||
#
|
||||
# setup do
|
||||
# @artist = MusicBrainz::Artist.find('69b39eab-6577-46a4-a9f5-817839092033')
|
||||
# end
|
||||
#
|
||||
# should "return valid instance" do
|
||||
# assert_instance_of(MusicBrainz::Artist, @artist)
|
||||
# end
|
||||
#
|
||||
# should "contain correct data" do
|
||||
# assert_equal("69b39eab-6577-46a4-a9f5-817839092033", @artist.id)
|
||||
# assert_equal("Group", @artist.type)
|
||||
# assert_equal("Kasabian", @artist.name)
|
||||
# assert_equal("GB", @artist.country)
|
||||
# assert_equal("1999", @artist.date_begin)
|
||||
# end
|
||||
#
|
||||
# should "load release groups" do
|
||||
# release_groups = @artist.release_groups
|
||||
# assert_operator(16, :<=, release_groups.length)
|
||||
# assert_equal('533cbc5f-ec7e-32ab-95f3-8d1f804a5176', release_groups.first.id)
|
||||
# assert_equal('Single', release_groups.first.type)
|
||||
# assert_equal('Club Foot', release_groups.first.title)
|
||||
# assert_equal(Time.utc(2004, 5, 10), release_groups.first.first_release_date)
|
||||
# end
|
||||
end
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
require "spec_helper"
|
||||
|
||||
describe MusicBrainz::ReleaseGroup do
|
||||
it "gets no exception while loading release group info" do
|
||||
lambda {
|
||||
MusicBrainz::ReleaseGroup.find("6f33e0f0-cde2-38f9-9aee-2c60af8d1a61")
|
||||
}.should_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)
|
||||
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 == Time.utc(2006, 8, 28)
|
||||
end
|
||||
|
||||
it "gets correct release group's releases" do
|
||||
releases = MusicBrainz::ReleaseGroup.find("6f33e0f0-cde2-38f9-9aee-2c60af8d1a61").releases
|
||||
releases.length.should be >= 5
|
||||
releases.first.id.should == "2225dd4c-ae9a-403b-8ea0-9e05014c778f"
|
||||
releases.first.status.should == "Official"
|
||||
releases.first.title.should == "Empire"
|
||||
releases.first.date.should == Time.utc(2006, 8, 28)
|
||||
releases.first.country.should == "GB"
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,32 @@
|
||||
require "spec_helper"
|
||||
|
||||
describe MusicBrainz::Release do
|
||||
it "gets no exception while loading release info" do
|
||||
lambda {
|
||||
MusicBrainz::Release.find("2225dd4c-ae9a-403b-8ea0-9e05014c778f")
|
||||
}.should_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)
|
||||
end
|
||||
|
||||
it "gets correct release data" do
|
||||
release = MusicBrainz::Release.find("2225dd4c-ae9a-403b-8ea0-9e05014c778f")
|
||||
release.id.should == "2225dd4c-ae9a-403b-8ea0-9e05014c778f"
|
||||
release.title.should == "Empire"
|
||||
release.status.should == "Official"
|
||||
release.date.should == Time.utc(2006, 8, 28)
|
||||
release.country.should == "GB"
|
||||
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
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,21 @@
|
||||
require "spec_helper"
|
||||
|
||||
describe MusicBrainz::Track do
|
||||
it "gets no exception while loading release info" do
|
||||
lambda {
|
||||
MusicBrainz::Track.find("b3015bab-1540-4d4e-9f30-14872a1525f7")
|
||||
}.should_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)
|
||||
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
|
||||
end
|
||||
end
|
||||
+6
-24
@@ -1,29 +1,11 @@
|
||||
require 'simplecov'
|
||||
require "rubygems"
|
||||
require "bundler/setup"
|
||||
require "ap"
|
||||
|
||||
if ENV["COVERAGE"]
|
||||
SimpleCov.start do
|
||||
add_filter '/gems/'
|
||||
add_filter '/test/'
|
||||
add_filter '/spec/'
|
||||
end
|
||||
end
|
||||
|
||||
require 'rubygems'
|
||||
require 'bundler'
|
||||
begin
|
||||
Bundler.setup(:default, :development)
|
||||
rescue Bundler::BundlerError => e
|
||||
$stderr.puts e.message
|
||||
$stderr.puts "Run `bundle install` to install missing gems"
|
||||
exit e.status_code
|
||||
end
|
||||
require "vcr"
|
||||
require "musicbrainz"
|
||||
|
||||
# HTTPI.log = false
|
||||
Dir[File.dirname(__FILE__)+"/../lib/*.rb"].each{ |f| require f }
|
||||
Dir[File.dirname(__FILE__)+"/../spec/support/*.rb"].each{ |f| require f }
|
||||
MusicBrainz::Tools::Cache.cache_path = "tmp/cache"
|
||||
|
||||
RSpec.configure do |config|
|
||||
config.mock_with :rspec
|
||||
end
|
||||
# Configuration is not currently necessary
|
||||
end
|
||||
|
||||
@@ -1,13 +0,0 @@
|
||||
VCR.config do |c|
|
||||
c.cassette_library_dir = File.join(File.dirname(__FILE__), '..', '..', 'tmp', 'vcr')
|
||||
c.stub_with :webmock
|
||||
c.default_cassette_options = { :record => :new_episodes }
|
||||
end
|
||||
|
||||
RSpec.configure do |c|
|
||||
c.treat_symbols_as_metadata_keys_with_true_values = true
|
||||
c.around(:each, :vcr) do |example|
|
||||
name = example.metadata[:full_description].gsub(/\s/, '_')
|
||||
VCR.use_cassette(name) { example.call }
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,71 @@
|
||||
require "spec_helper"
|
||||
|
||||
describe MusicBrainz::Tools::Cache do
|
||||
before(:all) do
|
||||
@old_cache_path = MusicBrainz::Tools::Cache.cache_path
|
||||
@tmp_cache_path = File.join(File.dirname(__FILE__), '../../tmp/cache/tools')
|
||||
end
|
||||
|
||||
after(:all) do
|
||||
MusicBrainz::Tools::Cache.cache_path = @old_cache_path
|
||||
end
|
||||
|
||||
before(:each) do
|
||||
@test_response = ::StringIO.new('<?xml version="1.0" encoding="UTF-8"?>'+
|
||||
'<metadata xmlns="http://musicbrainz.org/ns/mmd-2.0#">'+
|
||||
'<artist type="Group" id="69b39eab-6577-46a4-a9f5-817839092033">'+
|
||||
'<name>Kasabian</name><sort-name>Kasabian</sort-name><country>GB</country>'+
|
||||
'<life-span><begin>1999</begin></life-span><relation-list target-type="url">'+
|
||||
'<relation type="allmusic"><target>http://allmusic.com/artist/p678134</target>'+
|
||||
'</relation><relation type="wikipedia"><target>http://en.wikipedia.org/wiki/Kasabian</target>'+
|
||||
'</relation><relation type="microblog"><target>http://twitter.com/kasabianhq</target>'+
|
||||
'</relation><relation type="BBC Music page"><target>'+
|
||||
'http://www.bbc.co.uk/music/artists/69b39eab-6577-46a4-a9f5-817839092033</target></relation>'+
|
||||
'<relation type="discogs"><target>http://www.discogs.com/artist/Kasabian</target></relation>'+
|
||||
'<relation type="social network"><target>http://www.facebook.com/kasabian</target></relation>'+
|
||||
'<relation type="IMDb"><target>http://www.imdb.com/name/nm1868442/</target></relation>'+
|
||||
'<relation type="official homepage"><target>http://www.kasabian.co.uk/</target></relation>'+
|
||||
'<relation type="myspace"><target>http://www.myspace.com/kasabian</target></relation>'+
|
||||
'<relation type="youtube"><target>http://www.youtube.com/kasabianvevo</target></relation>'+
|
||||
'<relation type="youtube"><target>http://www.youtube.com/user/KasabianTour</target></relation>'+
|
||||
'</relation-list></artist></metadata>')
|
||||
end
|
||||
|
||||
context "with cache enabled" do
|
||||
it "calls get contents only once when requesting the resource twice" do
|
||||
MusicBrainz::Tools::Cache.cache_path = @tmp_cache_path
|
||||
MusicBrainz::Tools::Proxy.stub(:get_contents).and_return(@test_response)
|
||||
MusicBrainz::Tools::Proxy.should_receive(:get_contents).once
|
||||
mbid = "69b39eab-6577-46a4-a9f5-817839092033"
|
||||
|
||||
File.exist?("#{@tmp_cache_path}/artist/#{mbid}?inc=url-rels").should be_false
|
||||
artist = MusicBrainz::Artist.find(mbid)
|
||||
artist.should be_a_kind_of(MusicBrainz::Artist)
|
||||
|
||||
File.exist?("#{@tmp_cache_path}/artist/#{mbid}?inc=url-rels").should be_true
|
||||
artist = MusicBrainz::Artist.find(mbid)
|
||||
artist.should be_a_kind_of(MusicBrainz::Artist)
|
||||
|
||||
MusicBrainz::Tools::Cache.clear_cache
|
||||
end
|
||||
end
|
||||
|
||||
context "with cache disabled" do
|
||||
it "calls get contents twice when requesting the resource twice" do
|
||||
MusicBrainz::Tools::Cache.cache_path = nil
|
||||
MusicBrainz::Tools::Proxy.stub(:get_contents).and_return(@test_response)
|
||||
MusicBrainz::Tools::Proxy.should_receive(:get_contents).twice
|
||||
mbid = "69b39eab-6577-46a4-a9f5-817839092033"
|
||||
|
||||
File.exist?("#{@tmp_cache_path}/artist/#{mbid}?inc=url-rels").should be_false
|
||||
artist = MusicBrainz::Artist.find(mbid)
|
||||
artist.should be_a_kind_of(MusicBrainz::Artist)
|
||||
|
||||
File.exist?("#{@tmp_cache_path}/artist/#{mbid}?inc=url-rels").should be_false
|
||||
@test_response.rewind
|
||||
MusicBrainz.stub(:get_contents).and_return(@test_response)
|
||||
artist = MusicBrainz::Artist.find(mbid)
|
||||
artist.should be_a_kind_of(MusicBrainz::Artist)
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user