discourse/spec/components/oneboxer/amazon_onebox_spec.rb

43 lines
1.4 KiB
Ruby
Raw Normal View History

# encoding: utf-8
require 'spec_helper'
require 'oneboxer'
require 'oneboxer/amazon_onebox'
describe Oneboxer::AmazonOnebox do
before(:each) do
@o = Oneboxer::AmazonOnebox.new("http://www.amazon.com/Ruby-Programming-Language-David-Flanagan/dp/0596516177")
FakeWeb.register_uri(:get, @o.translate_url, response: fixture_file('oneboxer/amazon.response'))
end
2013-02-26 00:42:20 +08:00
it "translates the URL" do
@o.translate_url.should == "http://www.amazon.com/gp/aw/d/0596516177"
end
2013-02-26 00:42:20 +08:00
it "generates the expected onebox for Amazon" do
@o.onebox.should match_html expected_amazon_result
end
2013-02-26 00:42:20 +08:00
private
def expected_amazon_result
<<EXPECTED
<div class='onebox-result'>
<div class='source'>
<div class='info'>
2013-04-08 08:24:12 +08:00
<a href='http://www.amazon.com/Ruby-Programming-Language-David-Flanagan/dp/0596516177' class="track-link" target="_blank">
<img class='favicon' src="/assets/favicons/amazon.png"> amazon.com
</a>
</div>
</div>
<div class='onebox-result-body'>
2013-10-05 00:49:39 +08:00
<img src="http://ecx.images-amazon.com/images/I/512Cx%2BnJK8L._BO2,204,203,200_PIsitb-sticker-arrow-click,TopRight,35,-76_AA300_SH20_OU01_.jpg" class="thumbnail">
<h3><a href="http://www.amazon.com/Ruby-Programming-Language-David-Flanagan/dp/0596516177" target="_blank">The Ruby Programming Language [Paperback]</a></h3>
</div>
<div class='clearfix'></div>
</div>
EXPECTED
end
2013-02-26 00:42:20 +08:00
end