less brittle specs to os-specific line endings

This commit is contained in:
Régis Hanol 2013-06-13 11:09:11 +02:00
parent b027f7d8da
commit 2e2553c18c
7 changed files with 13 additions and 13 deletions

View File

@ -15,7 +15,7 @@ describe Oneboxer::AmazonOnebox do
end end
it "generates the expected onebox for Amazon" do it "generates the expected onebox for Amazon" do
@o.onebox.should == expected_amazon_result @o.onebox.should match_html expected_amazon_result
end end
private private

View File

@ -11,7 +11,7 @@ describe Oneboxer::AndroidAppStoreOnebox do
end end
it "generates the expected onebox for Android App Store" do it "generates the expected onebox for Android App Store" do
@o.onebox.should == expected_android_app_store_result @o.onebox.should match_html expected_android_app_store_result
end end
private private

View File

@ -11,7 +11,7 @@ describe Oneboxer::AppleAppOnebox do
end end
it "generates the expected onebox for Apple app" do it "generates the expected onebox for Apple app" do
@o.onebox.should == expected_apple_app_result @o.onebox.should match_html expected_apple_app_result
end end
private private

View File

@ -11,7 +11,7 @@ describe Oneboxer::FlickrOnebox do
end end
it "generates the expected onebox for Flickr" do it "generates the expected onebox for Flickr" do
@o.onebox.should == expected_flickr_result @o.onebox.should match_html expected_flickr_result
end end
private private

View File

@ -13,19 +13,19 @@ describe Oneboxer::RottentomatoesOnebox do
it 'generates the expected onebox for a fresh movie' do it 'generates the expected onebox for a fresh movie' do
o = Oneboxer::RottentomatoesOnebox.new('http://www.rottentomatoes.com/m/mud_2012/') o = Oneboxer::RottentomatoesOnebox.new('http://www.rottentomatoes.com/m/mud_2012/')
FakeWeb.register_uri(:get, o.translate_url, response: fixture_file('oneboxer/rottentomatoes_fresh.response')) FakeWeb.register_uri(:get, o.translate_url, response: fixture_file('oneboxer/rottentomatoes_fresh.response'))
expect(o.onebox).to eq(expected_fresh_result) o.onebox.should match_html expected_fresh_result
end end
it 'generates the expected onebox for a rotten movie' do it 'generates the expected onebox for a rotten movie' do
o = Oneboxer::RottentomatoesOnebox.new('http://www.rottentomatoes.com/m/the_big_wedding_2013/') o = Oneboxer::RottentomatoesOnebox.new('http://www.rottentomatoes.com/m/the_big_wedding_2013/')
FakeWeb.register_uri(:get, o.translate_url, response: fixture_file('oneboxer/rottentomatoes_rotten.response')) FakeWeb.register_uri(:get, o.translate_url, response: fixture_file('oneboxer/rottentomatoes_rotten.response'))
expect(o.onebox).to eq(expected_rotten_result) o.onebox.should match_html expected_rotten_result
end end
it 'generates the expected onebox for a movie with an incomplete description' do it 'generates the expected onebox for a movie with an incomplete description' do
o = Oneboxer::RottentomatoesOnebox.new('http://www.rottentomatoes.com/m/gunde_jaari_gallanthayyinde/') o = Oneboxer::RottentomatoesOnebox.new('http://www.rottentomatoes.com/m/gunde_jaari_gallanthayyinde/')
FakeWeb.register_uri(:get, o.translate_url, response: fixture_file('oneboxer/rottentomatoes_incomplete.response')) FakeWeb.register_uri(:get, o.translate_url, response: fixture_file('oneboxer/rottentomatoes_incomplete.response'))
expect(o.onebox).to eq(expected_incomplete_result) o.onebox.should match_html expected_incomplete_result
end end
private private

View File

@ -10,7 +10,7 @@ describe Oneboxer::WikipediaOnebox do
o = Oneboxer::WikipediaOnebox.new('http://en.wikipedia.org/wiki/Ruby') o = Oneboxer::WikipediaOnebox.new('http://en.wikipedia.org/wiki/Ruby')
FakeWeb.register_uri(:get, o.translate_url, response: fixture_file('oneboxer/wikipedia.response')) FakeWeb.register_uri(:get, o.translate_url, response: fixture_file('oneboxer/wikipedia.response'))
FakeWeb.register_uri(:get, 'http://en.m.wikipedia.org/wiki/Ruby', response: fixture_file('oneboxer/wikipedia_redirected.response')) FakeWeb.register_uri(:get, 'http://en.m.wikipedia.org/wiki/Ruby', response: fixture_file('oneboxer/wikipedia_redirected.response'))
o.onebox.should == expected_wikipedia_result o.onebox.should match_html expected_wikipedia_result
end end
it "accepts .com extention" do it "accepts .com extention" do

View File

@ -1,17 +1,17 @@
require 'nokogiri/xml/parse_options' require 'nokogiri/xml/parse_options'
RSpec::Matchers.define :match_html do |expected| RSpec::Matchers.define :match_html do |expected|
match do |actual| match do |actual|
a = make_canonical_html expected a = make_canonical_html(expected).to_html.gsub("\r\n", "\n")
b = make_canonical_html actual b = make_canonical_html(actual).to_html.gsub("\r\n", "\n")
a.to_html == b.to_html a == b
end end
failure_message_for_should do |actual| failure_message_for_should do |actual|
"after sanitizing for extra white space and compactness, expected #{actual} to match #{expected}" "after sanitizing for extra white space and compactness, expected:\n#{actual}\n to match:\n#{expected}"
end end
failure_message_for_should_not do |actual| failure_message_for_should_not do |actual|
"after sanitizing for extra white space and compactness, expected #{actual} not to match #{expected}" "after sanitizing for extra white space and compactness, expected:\n#{actual}\n not to match:\n#{expected}"
end end
def make_canonical_html(html) def make_canonical_html(html)