Created
January 9, 2015 22:16
-
-
Save postazure/7e2f4c6716c0f14c2474 to your computer and use it in GitHub Desktop.
Rough Tests for Yelp Crawler (Health Score)
This file contains hidden or 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
require "spec_helper" | |
require "noko_converter" | |
require "business" | |
require "Nokogiri" | |
require "RestClient" | |
describe Business do | |
let(:source) {"http://www.yelp.com/biz/fat-angel-san-francisco"} | |
it "name" do | |
source_html = RestClient.get(source, user_agent: "Chrome") | |
noko = Nokogiri::HTML(source_html) | |
biz = Business.new(noko) | |
biz_name = biz.name | |
expect(biz_name).to eq "Fat Angel" | |
end | |
it "health_score" do | |
source_html = RestClient.get(source, user_agent: "Chrome") | |
noko = Nokogiri::HTML(source_html) | |
biz = Business.new(noko) | |
biz_health = biz.health_score | |
expect(biz_health).to eq 98 | |
end | |
it "related businesses" do | |
source_html = RestClient.get(source, user_agent: "Chrome") | |
noko = Nokogiri::HTML(source_html) | |
biz = Business.new(noko) | |
biz_related = biz.related | |
expect(biz_related.count).to eq 3 | |
end | |
it "related businesses are business" do | |
source_html = RestClient.get(source, user_agent: "Chrome") | |
noko = Nokogiri::HTML(source_html) | |
biz = Business.new(noko) | |
biz_related_url = biz.related | |
expect(biz_related_url.first).to eq "http://www.yelp.com/biz/the-social-study-san-francisco?page_src=related_bizes" | |
end | |
it "related urls are valid" do | |
source_html = RestClient.get(source, user_agent: "Chrome") | |
noko = Nokogiri::HTML(source_html) | |
biz = Business.new(noko) | |
biz_related_url = biz.related.first | |
related_source_html = RestClient.get(biz_related_url, user_agent: "Chrome") | |
related_noko = Nokogiri::HTML(related_source_html) | |
related_biz = Business.new(related_noko) | |
related_biz_name = related_biz.name | |
expect(related_biz_name).to eq "The Social Study" | |
end | |
end |
This file contains hidden or 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
require "spec_helper" | |
require "noko_converter" | |
require "crawler" | |
require "Business" | |
require "Nokogiri" | |
require "RestClient" | |
describe Crawler do | |
let(:url) {"http://www.yelp.com/biz/fat-angel-san-francisco"} | |
it "returns Rickybobby (HS 91)" do | |
crawler = Crawler.new(url) | |
hs_biz = crawler.health_score(91) | |
expect(hs_biz.name).to eq "Rickybobby" | |
end | |
end |
This file contains hidden or 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
require "spec_helper" | |
require "noko_converter" | |
require "Business" | |
require "Nokogiri" | |
require "RestClient" | |
describe NokoConverter do | |
let(:source) {"http://www.yelp.com/biz/fat-angel-san-francisco"} | |
it "convert page" do | |
noko = NokoConverter.new(source) | |
biz = noko.to_biz | |
expect(biz.name).to include "Fat Angel" | |
end | |
it "gets related biz name" do | |
noko = NokoConverter.new(source) | |
biz = noko.to_biz | |
r_biz = NokoConverter.new(biz.related[0]) | |
r_biz = r_biz.to_biz | |
expect(r_biz.name).to eq "The Social Study" | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment