spec/shared/scrapify.rb in scrapify-0.0.7 vs spec/shared/scrapify.rb in scrapify-0.0.8
- old
+ new
@@ -17,11 +17,11 @@
<ol>
</span>
<span class='references'><ol><li></li></ol></span
</li>
<li>
- <a>veg supreme</a><input value="veg.jpg">
+ <a>veg<br/>supreme</a><input value="veg.jpg">
<span class='price'>(2.34)</span>
<span class='ingredients'>
<ol>
<li>contains mushroom</li>
<li>contains jalapeno</li>
@@ -60,11 +60,11 @@
it "should store url" do
klass_or_object.url.should == @pizza_url
end
it "should parse html and fetch attributes using css" do
- klass_or_object.name_values.should == ['chicken supreme', 'veg supreme', 'pepperoni', 'chicken golden delight']
+ klass_or_object.name_values.should == ['chicken supreme', "veg\nsupreme", 'pepperoni', 'chicken golden delight']
end
it "should parse html and fetch attributes using xpath" do
klass_or_object.image_url_values.should == ['chicken.jpg', 'veg.jpg', 'pepperoni.jpg', 'golden.jpg']
end
@@ -83,10 +83,14 @@
it "should strip content" do
klass_or_object.first.name.should == 'chicken supreme'
end
+ it "should replace br with newline" do
+ klass_or_object.all[1].name.should == "veg\nsupreme"
+ end
+
describe "cache headers" do
it "should return the http headers" do
klass_or_object.http_cache_header.should == {
"cache-control" => "private, s-maxage=0, max-age=0, must-revalidate",
"age" => 51592,
@@ -118,20 +122,20 @@
end
describe "last" do
it "should fetch last matching element" do
last_pizza = klass_or_object.last
- last_pizza.name.should == 'chicken golden delight'
+ last_pizza.name.should == "chicken golden delight"
last_pizza.image_url.should == 'golden.jpg'
end
end
describe "all" do
it "should fetch all objects" do
pizzas = klass_or_object.all
pizzas.size.should == 4
- pizzas.map(&:name).should == ['chicken supreme', 'veg supreme', 'pepperoni', 'chicken golden delight']
+ pizzas.map(&:name).should == ['chicken supreme', "veg\nsupreme", 'pepperoni', 'chicken golden delight']
pizzas.map(&:image_url).should == ['chicken.jpg', 'veg.jpg', 'pepperoni.jpg', 'golden.jpg']
end
end
describe "count" do
@@ -167,12 +171,28 @@
it "should convert array to json" do
pizzas = klass_or_object.all
pizzas.to_json.should == [
{name: "chicken supreme", image_url: "chicken.jpg", price: '1.23', ingredients: ['corn', 'tomato'], :ingredient_urls => []},
- {name: "veg supreme", image_url: "veg.jpg", price: '2.34', ingredients: ['mushroom', 'jalapeno'], :ingredient_urls => []},
+ {name: "veg\nsupreme", image_url: "veg.jpg", price: '2.34', ingredients: ['mushroom', 'jalapeno'], :ingredient_urls => []},
{name: "pepperoni", image_url: "pepperoni.jpg", price: '3.45', ingredients: [], :ingredient_urls => []},
{name: "chicken golden delight", image_url: "golden.jpg", price: '4.56', ingredients: [], :ingredient_urls => ['chicken.html', 'delight.html']},
].to_json
end
+ end
+
+ it_behaves_like '#finder', klass_or_object, :name => 'chicken golden delight'
+ it_behaves_like '#finder', klass_or_object, :image_url => 'golden.jpg'
+ it_behaves_like '#finder', klass_or_object, :price => '4.56'
+ it_behaves_like '#finder', klass_or_object, :ingredient_urls => ['chicken.html', 'delight.html']
+ it_behaves_like '#finder', klass_or_object, :name => 'chicken golden delight', :image_url => 'golden.jpg', :price => '4.56', :ingredient_urls => ['chicken.html', 'delight.html']
+
+ it 'should return empty array if object is not found' do
+ klass_or_object.where(:name => 'does not exist').should be_empty
+ end
+
+ it 'should throw exception if attribute is not defined' do
+ lambda {
+ klass_or_object.where(:some_attribute => 'chicken golden delight')
+ }.should raise_error(Scrapify::AttributeDoesNotExist)
end
end