# encoding: utf-8
require "spec_helper"
module Sucker
describe Response do
use_vcr_cassette "unit/sucker/response", :record => :new_episodes
let(:asins) { ["0816614024", "0143105825"] }
let(:response) do
worker = Sucker.new(
:locale => "us",
:key => amazon["key"],
:secret => amazon["secret"])
worker << {
"Operation" => "ItemLookup",
"IdType" => "ASIN",
"ResponseGroup" => ["ItemAttributes", "OfferFull"],
"ItemId" => asins }
worker.get
end
context ".new" do
it "sets the response body" do
response.body.should be_an_instance_of String
end
it "sets the response code" do
response.code.should == 200
end
it "sets the response time" do
response.time.should be_an_instance_of Float
end
end
context "#xml" do
it "returns a Nokogiri document" do
response.xml.should be_an_instance_of Nokogiri::XML::Document
end
end
context "#find" do
it "returns an array of matching nodes" do
node = response.find("ItemAttributes")
node.map { |book| book["ISBN"] }.should eql asins
end
it "returns an empty array if there are no matches" do
node = response.find("Foo")
node.should eql []
end
it "yields to a block if given one" do
has_yielded = false
response.find("ItemAttributes") do |item|
has_yielded = true
item.should be_an_instance_of Hash
end
has_yielded.should be_true
end
end
context "#to_hash" do
it "returns a hash" do
response.to_hash.should be_an_instance_of Hash
end
it "converts a content hash to string" do
response.body = "