spec/sucker/response_spec.rb in sucker-1.3.0 vs spec/sucker/response_spec.rb in sucker-1.3.1

- old
+ new

@@ -46,10 +46,33 @@ response.should have_errors end end end + describe "#each" do + context "when a block is given" do + it "yields each match to a block" do + has_yielded = false + + response.each("ItemAttributes") do |item| + has_yielded = true + item.should be_an_instance_of Hash + end + + has_yielded.should be_true + end + end + + context "when no block is given" do + it "raises error" do + expect do + response.each("ItemAttributes") + end.to raise_error(LocalJumpError) + end + end + end + describe '#find' do context 'when there are matches' do it 'returns an array of matching nodes' do response.find('ASIN').should eql asins end @@ -57,9 +80,27 @@ context 'when there are no matches' do it 'returns an empty array' do node = response.find('Foo') node.should eql [] + end + end + end + + describe "#map" do + context "when a block is given" do + it "yields each match to a block and maps returned values" do + titles = response.map("ItemAttributes") { |item| item["Title"] } + + titles.count.should eql 2 + end + end + + context "when no block is given" do + it "raises error" do + expect do + response.map("ItemAttributes") + end.to raise_error(LocalJumpError) end end end describe '#[]' do