-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6 from tsigo/vcr
Spec reorganization and updating
- Loading branch information
Showing
16 changed files
with
212 additions
and
1,998 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
spec/support/cassettes |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
require 'spec_helper' | ||
|
||
module RapGenius | ||
describe Annotation, vcr: {cassette_name: "big-sean-annotation"} do | ||
|
||
let(:annotation) { described_class.new(id: "2092393") } | ||
subject { annotation } | ||
|
||
its(:id) { should eq "2092393" } | ||
its(:url) { should eq "http://rapgenius.com/2092393" } | ||
its(:song) { should be_a Song } | ||
its(:song_url) { should eq "http://rapgenius.com/Big-sean-control-lyrics" } | ||
|
||
describe "#lyric" do | ||
it "should have the correct lyric" do | ||
annotation.lyric.should eq "You gon' get this rain like it's May weather," | ||
end | ||
end | ||
|
||
describe "#explanation" do | ||
it "should have the correct explanation" do | ||
annotation.explanation.should include "making it rain" | ||
end | ||
end | ||
|
||
describe '.find' do | ||
it "returns a new instance at the specified path" do | ||
i = described_class.find("foobar") | ||
i.should be_an Annotation | ||
i.id.should eq "foobar" | ||
end | ||
end | ||
|
||
context "with additional parameters passed into the constructor" do | ||
let(:annotation) { described_class.new(id: "5678", lyric: "foo") } | ||
|
||
its(:id) { should eq "5678" } | ||
its(:lyric) { should eq "foo" } | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
require 'spec_helper' | ||
|
||
class ScraperTester | ||
include RapGenius::Scraper | ||
end | ||
|
||
module RapGenius | ||
describe Scraper do | ||
|
||
let(:scraper) { ScraperTester.new } | ||
|
||
describe "#url=" do | ||
it "forms the URL with the base URL, if the current path is relative" do | ||
scraper.url = "foobar" | ||
scraper.url.should include RapGenius::Scraper::BASE_URL | ||
end | ||
|
||
it "leaves the URL as it is if already complete" do | ||
scraper.url = "http://foobar.com/baz" | ||
scraper.url.should eq "http://foobar.com/baz" | ||
end | ||
end | ||
|
||
describe "#document" do | ||
before do | ||
scraper.url = "http://foo.bar/" | ||
end | ||
|
||
context "with a successful request" do | ||
before do | ||
stub_request(:get, "http://foo.bar").to_return({body: 'ok', status: 200}) | ||
end | ||
|
||
it "returns a Nokogiri document object" do | ||
scraper.document.should be_a Nokogiri::HTML::Document | ||
end | ||
|
||
it "contains the tags in page received back from the HTTP request" do | ||
scraper.document.css('body').length.should eq 1 | ||
end | ||
end | ||
|
||
context "with a failed request" do | ||
before do | ||
stub_request(:get, "http://foo.bar").to_return({body: '', status: 404}) | ||
end | ||
|
||
it "raises a ScraperError" do | ||
expect { scraper.document }.to raise_error(RapGenius::ScraperError) | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
require 'spec_helper' | ||
|
||
module RapGenius | ||
describe Song do | ||
context "given Big Sean's Control", vcr: {cassette_name: "big-sean-control-lyrics"} do | ||
subject { described_class.new("Big-sean-control-lyrics") } | ||
|
||
its(:url) { should eq "http://rapgenius.com/Big-sean-control-lyrics" } | ||
its(:title) { should eq "Control" } | ||
its(:artist) { should eq "Big Sean" } | ||
its(:description) { should include "blew up the Internet" } | ||
its(:full_artist) { should include "(Ft. Jay Electronica & Kendrick Lamar)"} | ||
|
||
describe "#images" do | ||
it "should be an Array" do | ||
subject.images.should be_an Array | ||
end | ||
|
||
it "should include Big Sean's picture" do | ||
subject.images.should include "http://s3.amazonaws.com/rapgenius/1375029260_Big%20Sean.png" | ||
end | ||
end | ||
|
||
describe "#annotations" do | ||
it "should be an Array of Annotation objects" do | ||
subject.annotations.should be_an Array | ||
subject.annotations.first.should be_a Annotation | ||
end | ||
|
||
it "should be of a valid length" do | ||
# Annotations get added and removed from the live site; we want our | ||
# count to be somewhat accurate, within reason. | ||
subject.annotations.length.should be_within(15).of(130) | ||
end | ||
end | ||
end | ||
|
||
describe '.find' do | ||
it "returns a new instance at the specified path" do | ||
i = described_class.find("foobar") | ||
i.should be_a Song | ||
i.url.should eq 'http://rapgenius.com/foobar' | ||
end | ||
end | ||
end | ||
end |
Oops, something went wrong.