spec/unit/sucker/response_spec.rb in sucker-0.7.0 vs spec/unit/sucker/response_spec.rb in sucker-0.7.1
- old
+ new
@@ -35,41 +35,49 @@
it "returns a Nokogiri document" do
@response.xml.should be_an_instance_of Nokogiri::XML::Document
end
end
- context "#to_h" do
+ context "#node" do
+ it "returns a collection of hashified nodes" do
+ response = @response.node("ItemAttributes")
+ response.map { |book| book["ISBN"] }.should eql @asins
+ end
+
+ it "returns an empty array if there are no matches" do
+ response = @response.node("Foo")
+ response.should eql []
+ end
+ end
+
+ context "#to_hash" do
it "returns a hash" do
- @response.to_h.should be_an_instance_of Hash
+ @response.to_hash.should be_an_instance_of Hash
end
it "converts a content hash to string" do
@response.body = "<book><title>A Thousand Plateaus</title></book>"
- @response.to_h["book"]["title"].should be_an_instance_of String
+ @response.to_hash["book"]["title"].should be_an_instance_of String
end
- it "is aliased as to_hash" do
- @response.to_hash.should eql @response.to_h
+ it "is aliased as to_h" do
+ @response.should respond_to :to_h
+ @response.to_h.should eql @response.to_hash
end
- it "parses document for a node name and returns a collection of hashified nodes" do
- response = @response.to_hash("ItemAttributes")
- response.map { |book| book["ISBN"] }.should eql @asins
- end
-
it "renders French" do
@response.body = "<Title>L'archéologie du savoir</Title>"
- @response.to_h["Title"].should eql "L'archéologie du savoir"
+ @response.to_hash["Title"].should eql "L'archéologie du savoir"
end
it "renders German" do
@response.body = "<Title>Kafka: Für eine kleine Literatur</Title>"
- @response.to_h["Title"].should eql "Kafka: Für eine kleine Literatur"
+ @response.to_hash["Title"].should eql "Kafka: Für eine kleine Literatur"
end
it "renders Japanese" do
@response.body = "<Title>スティーブ・ジョブズ 驚異のプレゼン―人々を惹きつける18の法則</Title>"
- @response.to_h["Title"].should eql "スティーブ・ジョブズ 驚異のプレゼン―人々を惹きつける18の法則"
+ @response.to_hash["Title"].should eql "スティーブ・ジョブズ 驚異のプレゼン―人々を惹きつける18の法則"
end
end
end
end