musicbrainz 0.7.7 → 0.8.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (57) hide show
  1. checksums.yaml +7 -0
  2. data/.github/workflows/test.yml +26 -0
  3. data/.gitignore +2 -2
  4. data/Gemfile +11 -0
  5. data/Gemfile.lock +54 -0
  6. data/LICENSE +2 -2
  7. data/README.md +21 -10
  8. data/lib/musicbrainz/bindings/artist.rb +0 -1
  9. data/lib/musicbrainz/bindings/artist_search.rb +0 -1
  10. data/lib/musicbrainz/bindings/discid_releases.rb +13 -0
  11. data/lib/musicbrainz/bindings/recording.rb +19 -0
  12. data/lib/musicbrainz/bindings/{track_search.rb → recording_search.rb} +1 -2
  13. data/lib/musicbrainz/bindings/relations.rb +1 -2
  14. data/lib/musicbrainz/bindings/release_group_search.rb +0 -1
  15. data/lib/musicbrainz/client_modules/caching_proxy.rb +27 -13
  16. data/lib/musicbrainz/models/base_model.rb +12 -2
  17. data/lib/musicbrainz/models/recording.rb +20 -0
  18. data/lib/musicbrainz/models/release.rb +8 -1
  19. data/lib/musicbrainz/models/track.rb +0 -4
  20. data/lib/musicbrainz/version.rb +1 -1
  21. data/lib/musicbrainz.rb +4 -1
  22. data/musicbrainz.gemspec +3 -6
  23. data/spec/bindings/recording_search_spec.rb +48 -0
  24. data/spec/bindings/relations_spec.rb +45 -26
  25. data/spec/bindings/release_group_search_spec.rb +24 -6
  26. data/spec/bindings/release_spec.rb +94 -18
  27. data/spec/client_modules/cache_spec.rb +18 -17
  28. data/spec/deprecated/cache_config_spec.rb +4 -6
  29. data/spec/deprecated/proxy_config_spec.rb +4 -6
  30. data/spec/fixtures/artist/find_69b39eab-6577-46a4-a9f5-817839092033.xml +168 -0
  31. data/spec/fixtures/artist/release_groups_69b39eab-6577-46a4-a9f5-817839092033.xml +412 -0
  32. data/spec/fixtures/artist/search_kasabian.xml +104 -0
  33. data/spec/fixtures/recording/find_b3015bab-1540-4d4e-9f30-14872a1525f7.xml +8 -0
  34. data/spec/fixtures/recording/search_bound_for_the_floor_local_h.xml +647 -0
  35. data/spec/fixtures/release/find_2225dd4c-ae9a-403b-8ea0-9e05014c778f.xml +44 -0
  36. data/spec/fixtures/release/find_2225dd4c-ae9a-403b-8ea0-9e05014c778f_tracks.xml +151 -0
  37. data/spec/fixtures/release/find_b94cb547-cf7a-4357-894c-53c3bf33b093.xml +52 -0
  38. data/spec/fixtures/release/find_by_discid_pmzhT6ZlFiwSRCdVwV0eqire5_Y-.xml +141 -0
  39. data/spec/fixtures/release/list_6f33e0f0-cde2-38f9-9aee-2c60af8d1a61.xml +344 -0
  40. data/spec/fixtures/release_group/search_kasabian_empire_album.xml +117 -0
  41. data/spec/models/artist_spec.rb +77 -46
  42. data/spec/models/base_model_spec.rb +50 -22
  43. data/spec/models/recording_spec.rb +42 -0
  44. data/spec/models/release_group_spec.rb +61 -55
  45. data/spec/models/release_spec.rb +63 -28
  46. data/spec/models/track_spec.rb +19 -15
  47. data/spec/spec_helper.rb +7 -7
  48. data/spec/support/mock_helpers.rb +13 -0
  49. metadata +55 -93
  50. data/.rspec +0 -1
  51. data/.travis.yml +0 -4
  52. data/spec/bindings/track_search_spec.rb +0 -17
  53. data/spec/fixtures/artist/search.xml +0 -67
  54. data/spec/fixtures/kasabian.xml +0 -1
  55. data/spec/fixtures/release/list.xml +0 -344
  56. /data/spec/fixtures/release_group/{entity.xml → find_6f33e0f0-cde2-38f9-9aee-2c60af8d1a61.xml} +0 -0
  57. /data/spec/fixtures/release_group/{search.xml → search_kasabian_empire.xml} +0 -0
@@ -1,45 +1,73 @@
1
- # -*- encoding: utf-8 -*-
2
-
3
1
  require "spec_helper"
4
2
 
5
3
  describe MusicBrainz::BaseModel do
6
4
  describe '#validate_type' do
7
5
  describe 'Date' do
6
+ let(:xml) {
7
+ Nokogiri::XML.parse(response)
8
+ }
9
+ let(:bindings) {
10
+ MusicBrainz::Bindings::ReleaseGroup.parse(xml)
11
+ }
12
+ let(:release_group) {
13
+ MusicBrainz::ReleaseGroup.new(bindings)
14
+ }
15
+
8
16
  context 'nil value' do
17
+ let(:response) {
18
+ <<-XML
19
+ <release-group>
20
+ <first-release-date></first-release-date>
21
+ </release-group>
22
+ XML
23
+ }
24
+
9
25
  it 'returns 2030-12-31' do
10
- response = '<release-group><first-release-date></first-release-date></release-group>'
11
- xml = Nokogiri::XML.parse(response)
12
- release_group = MusicBrainz::ReleaseGroup.new MusicBrainz::Bindings::ReleaseGroup.parse(xml)
13
- release_group.first_release_date.should == Date.new(2030, 12, 31)
26
+ expect(release_group.first_release_date).to eq Date.new(2030, 12, 31)
14
27
  end
15
28
  end
16
-
29
+
17
30
  context 'year only' do
31
+ let(:response) {
32
+ <<-XML
33
+ <release-group>
34
+ <first-release-date>1995</first-release-date>
35
+ </release-group>
36
+ XML
37
+ }
38
+
18
39
  it 'returns 1995-12-31' do
19
- response = '<release-group><first-release-date>1995</first-release-date></release-group>'
20
- xml = Nokogiri::XML.parse(response)
21
- release_group = MusicBrainz::ReleaseGroup.new MusicBrainz::Bindings::ReleaseGroup.parse(xml)
22
- release_group.first_release_date.should == Date.new(1995, 12, 31)
40
+ expect(release_group.first_release_date).to eq Date.new(1995, 12, 31)
23
41
  end
24
42
  end
25
-
43
+
26
44
  context 'year and month only' do
45
+ let(:response) {
46
+ <<-XML
47
+ <release-group>
48
+ <first-release-date>1995-04</first-release-date>
49
+ </release-group>
50
+ XML
51
+ }
52
+
27
53
  it 'returns 1995-04-30' do
28
- response = '<release-group><first-release-date>1995-04</first-release-date></release-group>'
29
- xml = Nokogiri::XML.parse(response)
30
- release_group = MusicBrainz::ReleaseGroup.new MusicBrainz::Bindings::ReleaseGroup.parse(xml)
31
- release_group.first_release_date.should == Date.new(1995, 4, 30)
54
+ expect(release_group.first_release_date).to eq Date.new(1995, 4, 30)
32
55
  end
33
56
  end
34
-
57
+
35
58
  context 'year, month and day' do
59
+ let(:response) {
60
+ <<-XML
61
+ <release-group>
62
+ <first-release-date>1995-04-30</first-release-date>
63
+ </release-group>
64
+ XML
65
+ }
66
+
36
67
  it 'returns 1995-04-30' do
37
- response = '<release-group><first-release-date>1995-04-30</first-release-date></release-group>'
38
- xml = Nokogiri::XML.parse(response)
39
- release_group = MusicBrainz::ReleaseGroup.new MusicBrainz::Bindings::ReleaseGroup.parse(xml)
40
- release_group.first_release_date.should == Date.new(1995, 4, 30)
68
+ expect(release_group.first_release_date).to eq Date.new(1995, 4, 30)
41
69
  end
42
70
  end
43
71
  end
44
72
  end
45
- end
73
+ end
@@ -0,0 +1,42 @@
1
+ require "spec_helper"
2
+
3
+ describe MusicBrainz::Recording do
4
+ describe '.find' do
5
+ before(:each) {
6
+ mock url: 'http://musicbrainz.org/ws/2/recording/b3015bab-1540-4d4e-9f30-14872a1525f7?',
7
+ fixture: 'recording/find_b3015bab-1540-4d4e-9f30-14872a1525f7.xml'
8
+ }
9
+ let(:recording) {
10
+ MusicBrainz::Recording.find("b3015bab-1540-4d4e-9f30-14872a1525f7")
11
+ }
12
+
13
+ it "gets no exception while loading release info" do
14
+ expect{ recording }.to_not raise_error(Exception)
15
+ end
16
+
17
+ it "gets correct instance" do
18
+ expect(recording).to be_an_instance_of(MusicBrainz::Recording)
19
+ end
20
+
21
+ it "gets correct track data" do
22
+ expect(recording.title).to eq "Empire"
23
+ end
24
+ end
25
+
26
+ describe '.search' do
27
+ before(:each) {
28
+ mock url: 'http://musicbrainz.org/ws/2/recording?query=recording:"Bound+for+the+floor" AND artist:"Local+H"&limit=10',
29
+ fixture: 'recording/search_bound_for_the_floor_local_h.xml'
30
+ }
31
+ let(:matches) {
32
+ MusicBrainz::Recording.search('Bound for the floor', 'Local H')
33
+ }
34
+
35
+ it "searches tracks (aka recordings) by artist name and title" do
36
+ expect(matches).to_not be_empty
37
+ expect(matches.first[:id]).to eq 'bb940e26-4265-4909-b128-4906d8b1079e'
38
+ expect(matches.first[:title]).to eq "Bound for the Floor"
39
+ expect(matches.first[:artist]).to eq "Local H"
40
+ end
41
+ end
42
+ end
@@ -1,85 +1,91 @@
1
- # -*- encoding: utf-8 -*-
2
-
3
1
  require "spec_helper"
4
2
 
5
3
  describe MusicBrainz::ReleaseGroup do
4
+ before(:each) {
5
+ mock url: 'http://musicbrainz.org/ws/2/release-group/6f33e0f0-cde2-38f9-9aee-2c60af8d1a61?inc=url-rels',
6
+ fixture: 'release_group/find_6f33e0f0-cde2-38f9-9aee-2c60af8d1a61.xml'
7
+
8
+ mock url: 'http://musicbrainz.org/ws/2/release-group?query=artist:"Kasabian" AND releasegroup:"Empire"&limit=10',
9
+ fixture: 'release_group/search_kasabian_empire.xml'
10
+
11
+ mock url: 'http://musicbrainz.org/ws/2/release-group?query=artist:"Kasabian" AND releasegroup:"Empire" AND type:"Album"&limit=10',
12
+ fixture: 'release_group/search_kasabian_empire_album.xml'
13
+
14
+ mock url: 'http://musicbrainz.org/ws/2/release?release-group=6f33e0f0-cde2-38f9-9aee-2c60af8d1a61&inc=media+release-groups&limit=100',
15
+ fixture: 'release/list_6f33e0f0-cde2-38f9-9aee-2c60af8d1a61.xml'
16
+ }
17
+
6
18
  describe '.find' do
19
+ let(:release_group) {
20
+ MusicBrainz::ReleaseGroup.find("6f33e0f0-cde2-38f9-9aee-2c60af8d1a61")
21
+ }
22
+
7
23
  it "gets no exception while loading release group info" do
8
- lambda {
9
- MusicBrainz::ReleaseGroup.find("6f33e0f0-cde2-38f9-9aee-2c60af8d1a61")
10
- }.should_not raise_error(Exception)
24
+ expect { release_group }.to_not raise_error(Exception)
11
25
  end
12
-
26
+
13
27
  it "gets correct instance" do
14
- release_group = MusicBrainz::ReleaseGroup.find("6f33e0f0-cde2-38f9-9aee-2c60af8d1a61")
15
- release_group.should be_an_instance_of(MusicBrainz::ReleaseGroup)
28
+ expect(release_group).to be_an_instance_of(MusicBrainz::ReleaseGroup)
16
29
  end
17
-
30
+
18
31
  it "gets correct release group data" do
19
- release_group = MusicBrainz::ReleaseGroup.find("6f33e0f0-cde2-38f9-9aee-2c60af8d1a61")
20
- release_group.id.should == "6f33e0f0-cde2-38f9-9aee-2c60af8d1a61"
21
- release_group.type.should == "Album"
22
- release_group.title.should == "Empire"
23
- release_group.first_release_date.should == Date.new(2006, 8, 28)
24
- release_group.urls[:wikipedia].should == 'http://en.wikipedia.org/wiki/Empire_(Kasabian_album)'
32
+ expect(release_group.id).to eq "6f33e0f0-cde2-38f9-9aee-2c60af8d1a61"
33
+ expect(release_group.type).to eq "Album"
34
+ expect(release_group.title).to eq "Empire"
35
+ expect(release_group.first_release_date).to eq Date.new(2006, 8, 28)
36
+ expect(release_group.urls[:wikipedia]).to eq 'http://en.wikipedia.org/wiki/Empire_(Kasabian_album)'
25
37
  end
26
38
  end
27
-
39
+
28
40
  describe '.search' do
29
41
  context 'without type filter' do
42
+ let(:matches) {
43
+ MusicBrainz::ReleaseGroup.search('Kasabian', 'Empire')
44
+ }
45
+
30
46
  it "searches release group by artist name and title" do
31
- response = File.open(File.join(File.dirname(__FILE__), "../fixtures/release_group/search.xml")).read
32
- MusicBrainz::Client.any_instance.stub(:get_contents).with('http://musicbrainz.org/ws/2/release-group?query=artist:"Kasabian" AND releasegroup:"Empire"&limit=10').
33
- and_return({ status: 200, body: response})
34
-
35
- matches = MusicBrainz::ReleaseGroup.search('Kasabian', 'Empire')
36
- matches.length.should be > 0
37
- matches.first[:title].should == 'Empire'
38
- matches.first[:type].should == 'Album'
47
+ expect(matches.length).to be > 0
48
+ expect(matches.first[:title]).to eq 'Empire'
49
+ expect(matches.first[:type]).to eq 'Album'
39
50
  end
40
51
  end
41
-
52
+
42
53
  context 'with type filter' do
54
+ let(:matches) {
55
+ MusicBrainz::ReleaseGroup.search('Kasabian', 'Empire', 'Album')
56
+ }
57
+
43
58
  it "searches release group by artist name and title" do
44
- matches = MusicBrainz::ReleaseGroup.search('Kasabian', 'Empire', 'Album')
45
- matches.length.should be > 0
46
- matches.first[:title].should == 'Empire'
47
- matches.first[:type].should == 'Album'
59
+ expect(matches.length).to be > 0
60
+ expect(matches.first[:title]).to eq 'Empire'
61
+ expect(matches.first[:type]).to eq 'Album'
48
62
  end
49
63
  end
50
64
  end
51
-
65
+
52
66
  describe '.find_by_artist_and_title' do
67
+ let(:release_group) {
68
+ MusicBrainz::ReleaseGroup.find_by_artist_and_title('Kasabian', 'Empire')
69
+ }
70
+
53
71
  it "gets first release group by artist name and title" do
54
- response = File.open(File.join(File.dirname(__FILE__), "../fixtures/release_group/search.xml")).read
55
- MusicBrainz::Client.any_instance.stub(:get_contents).with('http://musicbrainz.org/ws/2/release-group?query=artist:"Kasabian" AND releasegroup:"Empire"&limit=10').
56
- and_return({ status: 200, body: response})
57
-
58
- response = File.open(File.join(File.dirname(__FILE__), "../fixtures/release_group/entity.xml")).read
59
- MusicBrainz::Client.any_instance.stub(:get_contents).with('http://musicbrainz.org/ws/2/release-group/6f33e0f0-cde2-38f9-9aee-2c60af8d1a61?inc=url-rels').
60
- and_return({ status: 200, body: response})
61
-
62
- release_group = MusicBrainz::ReleaseGroup.find_by_artist_and_title('Kasabian', 'Empire')
63
- release_group.id.should == '6f33e0f0-cde2-38f9-9aee-2c60af8d1a61'
72
+ expect(release_group.id).to eq '6f33e0f0-cde2-38f9-9aee-2c60af8d1a61'
64
73
  end
65
74
  end
66
-
75
+
67
76
  describe '#releases' do
77
+ let(:releases) {
78
+ MusicBrainz::ReleaseGroup.find("6f33e0f0-cde2-38f9-9aee-2c60af8d1a61").releases
79
+ }
80
+
68
81
  it "gets correct release group's releases" do
69
- MusicBrainz::Client.any_instance.stub(:get_contents).with('http://musicbrainz.org/ws/2/release-group/6f33e0f0-cde2-38f9-9aee-2c60af8d1a61?inc=url-rels').
70
- and_return({ status: 200, body: File.open(File.join(File.dirname(__FILE__), "../fixtures/release_group/entity.xml")).read})
71
-
72
- 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').
73
- and_return({ status: 200, body: File.open(File.join(File.dirname(__FILE__), "../fixtures/release/list.xml")).read})
74
-
75
- releases = MusicBrainz::ReleaseGroup.find("6f33e0f0-cde2-38f9-9aee-2c60af8d1a61").releases
76
- releases.length.should be >= 5
77
- releases.first.id.should == "30d5e730-ce0a-464d-93e1-7d76e4bb3e31"
78
- releases.first.status.should == "Official"
79
- releases.first.title.should == "Empire"
80
- releases.first.date.should == Date.new(2006, 8, 28)
81
- releases.first.country.should == "GB"
82
- releases.first.type.should == "Album"
82
+ expect(releases.length).to be >= 5
83
+ expect(releases.first.id).to eq "2225dd4c-ae9a-403b-8ea0-9e05014c778f"
84
+ expect(releases.first.status).to eq "Official"
85
+ expect(releases.first.title).to eq "Empire"
86
+ expect(releases.first.date).to eq Date.new(2006, 8, 28)
87
+ expect(releases.first.country).to eq "GB"
88
+ expect(releases.first.type).to eq "Album"
83
89
  end
84
90
  end
85
91
  end
@@ -1,38 +1,73 @@
1
- # -*- encoding: utf-8 -*-
2
-
3
1
  require "spec_helper"
4
2
 
5
3
  describe MusicBrainz::Release do
6
- it "gets no exception while loading release info" do
7
- lambda {
8
- MusicBrainz::Release.find("2225dd4c-ae9a-403b-8ea0-9e05014c778f")
9
- }.should_not raise_error(Exception)
10
- end
4
+ before(:each) {
5
+ mock url: 'http://musicbrainz.org/ws/2/release/2225dd4c-ae9a-403b-8ea0-9e05014c778f?inc=media+release-groups',
6
+ fixture: 'release/find_2225dd4c-ae9a-403b-8ea0-9e05014c778f.xml'
7
+
8
+ mock url: 'http://musicbrainz.org/ws/2/release/2225dd4c-ae9a-403b-8ea0-9e05014c778f?inc=recordings+media&limit=100',
9
+ fixture: 'release/find_2225dd4c-ae9a-403b-8ea0-9e05014c778f_tracks.xml'
10
+
11
+ mock url: 'http://musicbrainz.org/ws/2/release/b94cb547-cf7a-4357-894c-53c3bf33b093?inc=media+release-groups',
12
+ fixture: 'release/find_b94cb547-cf7a-4357-894c-53c3bf33b093.xml'
13
+
14
+ mock url: 'http://musicbrainz.org/ws/2/discid/pmzhT6ZlFiwSRCdVwV0eqire5_Y-?',
15
+ fixture: 'release/find_by_discid_pmzhT6ZlFiwSRCdVwV0eqire5_Y-.xml'
16
+ }
11
17
 
12
- it "gets correct instance" do
13
- release = MusicBrainz::Release.find("2225dd4c-ae9a-403b-8ea0-9e05014c778f")
14
- release.should be_an_instance_of(MusicBrainz::Release)
18
+ describe '.find' do
19
+ let(:release) {
20
+ MusicBrainz::Release.find("b94cb547-cf7a-4357-894c-53c3bf33b093")
21
+ }
22
+
23
+ it "gets no exception while loading release info" do
24
+ expect { release }.to_not raise_error(Exception)
25
+ end
26
+
27
+ it "gets correct instance" do
28
+ expect(release).to be_an_instance_of(MusicBrainz::Release)
29
+ end
30
+
31
+ it "gets correct release data" do
32
+ expect(release.id).to eq "b94cb547-cf7a-4357-894c-53c3bf33b093"
33
+ expect(release.title).to eq "Humanoid"
34
+ expect(release.status).to eq "Official"
35
+ expect(release.date).to eq Date.new(2009, 10, 6)
36
+ expect(release.country).to eq "US"
37
+ expect(release.asin).to eq 'B002NOYX6I'
38
+ expect(release.barcode).to eq '602527197692'
39
+ expect(release.quality).to eq 'normal'
40
+ expect(release.type).to eq 'Album'
41
+ end
15
42
  end
16
43
 
17
- it "gets correct release data" do
18
- release = MusicBrainz::Release.find("b94cb547-cf7a-4357-894c-53c3bf33b093")
19
- release.id.should == "b94cb547-cf7a-4357-894c-53c3bf33b093"
20
- release.title.should == "Humanoid"
21
- release.status.should == "Official"
22
- release.date.should == Date.new(2009, 10, 6)
23
- release.country.should == "US"
24
- release.asin.should == 'B002NOYX6I'
25
- release.barcode.should == '602527197692'
26
- release.quality.should == 'normal'
27
- release.type.should == 'Album'
44
+ describe '#tracks' do
45
+ let(:release) {
46
+ MusicBrainz::Release.find("2225dd4c-ae9a-403b-8ea0-9e05014c778f")
47
+ }
48
+ let(:tracks) {
49
+ release.tracks
50
+ }
51
+
52
+ it "gets correct release tracks" do
53
+ expect(tracks.length).to eq 11
54
+ expect(tracks.first.position).to eq 1
55
+ expect(tracks.first.recording_id).to eq "b3015bab-1540-4d4e-9f30-14872a1525f7"
56
+ expect(tracks.first.title).to eq "Empire"
57
+ expect(tracks.first.length).to eq 233013
58
+ end
28
59
  end
29
60
 
30
- it "gets correct release tracks" do
31
- tracks = MusicBrainz::Release.find("2225dd4c-ae9a-403b-8ea0-9e05014c778f").tracks
32
- tracks.length.should == 11
33
- tracks.first.position.should == 1
34
- tracks.first.recording_id.should == "b3015bab-1540-4d4e-9f30-14872a1525f7"
35
- tracks.first.title.should == "Empire"
36
- tracks.first.length.should == 233013
61
+ describe '.find_by_discid' do
62
+ let(:releases) {
63
+ MusicBrainz::Release.find_by_discid("pmzhT6ZlFiwSRCdVwV0eqire5_Y-")
64
+ }
65
+
66
+ it "gets a list of matching releases for a discid" do
67
+ expect(releases.length).to eq 2
68
+ expect(releases.first.id).to eq "7a31cd5f-6a57-4fca-a731-c521df1d3b78"
69
+ expect(releases.first.title).to eq "Kveikur"
70
+ expect(releases.first.asin).to eq "B00C1GBOU6"
71
+ end
37
72
  end
38
73
  end
@@ -1,23 +1,27 @@
1
- # -*- encoding: utf-8 -*-
2
-
3
1
  require "spec_helper"
4
2
 
5
3
  describe MusicBrainz::Track do
6
- it "gets no exception while loading release info" do
7
- lambda {
4
+ describe '.find' do
5
+ before(:each) {
6
+ mock url: 'http://musicbrainz.org/ws/2/recording/b3015bab-1540-4d4e-9f30-14872a1525f7?',
7
+ fixture: 'recording/find_b3015bab-1540-4d4e-9f30-14872a1525f7.xml'
8
+ }
9
+ let(:track) {
8
10
  MusicBrainz::Track.find("b3015bab-1540-4d4e-9f30-14872a1525f7")
9
- }.should_not raise_error(Exception)
10
- end
11
+ }
11
12
 
12
- it "gets correct instance" do
13
- track = MusicBrainz::Track.find("b3015bab-1540-4d4e-9f30-14872a1525f7")
14
- track.should be_an_instance_of(MusicBrainz::Track)
15
- end
13
+ it "gets no exception while loading release info" do
14
+ expect { track }.to_not raise_error(Exception)
15
+ end
16
+
17
+ it "gets correct instance" do
18
+ expect(track).to be_an_instance_of(MusicBrainz::Track)
19
+ end
16
20
 
17
- it "gets correct track data" do
18
- track = MusicBrainz::Track.find("b3015bab-1540-4d4e-9f30-14872a1525f7")
19
- track.recording_id.should == "b3015bab-1540-4d4e-9f30-14872a1525f7"
20
- track.title.should == "Empire"
21
- track.length.should == 233013
21
+ it "gets correct track data" do
22
+ expect(track.recording_id).to eq "b3015bab-1540-4d4e-9f30-14872a1525f7"
23
+ expect(track.title).to eq "Empire"
24
+ expect(track.length).to eq 233013
25
+ end
22
26
  end
23
27
  end
data/spec/spec_helper.rb CHANGED
@@ -1,19 +1,19 @@
1
1
  require "rubygems"
2
2
  require "bundler/setup"
3
3
  require "musicbrainz"
4
+ require "pry"
5
+ require "awesome_print"
6
+ require_relative 'support/mock_helpers'
4
7
 
5
8
  RSpec.configure do |c|
9
+ include MockHelpers
10
+
6
11
  c.order = 'random'
12
+ c.color = true
7
13
  end
8
14
 
9
15
  MusicBrainz.configure do |c|
10
- test_email = `git config user.email`.chomp
11
- test_email = "magnolia_fan@me.com" if test_email.empty?
12
-
13
16
  c.app_name = "MusicBrainzGemTestSuite"
14
17
  c.app_version = MusicBrainz::VERSION
15
- c.contact = test_email
16
-
17
- c.cache_path = File.join(File.dirname(__FILE__), '..', 'tmp', 'spec_cache')
18
- c.perform_caching = true
18
+ c.contact = "root@localhost"
19
19
  end
@@ -0,0 +1,13 @@
1
+ module MockHelpers
2
+ def mock(url:, fixture:)
3
+ allow_any_instance_of(MusicBrainz::Client).to receive(:get_contents)
4
+ .with(url)
5
+ .and_return({ status: 200, body: read_fixture(fixture)})
6
+ end
7
+
8
+ def read_fixture(name)
9
+ spec_path = File.join(File.dirname(__FILE__), "..")
10
+ file_path = File.join(spec_path, "fixtures", name)
11
+ File.open(file_path).read
12
+ end
13
+ end