spec/unit/sucker/request_spec.rb in sucker-0.3.0 vs spec/unit/sucker/request_spec.rb in sucker-0.4.0

- old
+ new

@@ -1,19 +1,22 @@ require "spec_helper" module Sucker describe Request do before do - @worker = Sucker.new + @worker = Sucker.new( + :locale => "us", + :key => "key", + :secret => "secret") end context ".new" do it "sets default parameters" do default_parameters = { "Service" => "AWSECommerceService", "Version" => Sucker::AMAZON_API_VERSION } - @worker.parameters.should eql default_parameters + @worker.parameters.should include default_parameters end end context "#<<" do it "merges a hash into the parameters" do @@ -38,77 +41,66 @@ end end context "#get" do before do - @worker.locale = "us" - @worker.secret = "secret" - - curl = @worker.curl - curl.stub(:get).and_return(nil) - curl.stub!(:body_str).and_return(fixture("single_item_lookup.us")) + Sucker.stub(@worker) end it "returns a Response object" do - @worker.get.should be_an_instance_of Response + @worker.get.class.ancestors.should include Response end end context "#key=" do it "sets the Amazon AWS access key in the parameters" do - @worker.key = "key" - @worker.parameters["AWSAccessKeyId"].should eql "key" + @worker.key = "foo" + @worker.parameters["AWSAccessKeyId"].should eql "foo" end end context "private methods" do context "#build_query" do it "canonicalizes parameters" do query = @worker.send(:build_query) - query.should eql "Service=AWSECommerceService&Version=#{Sucker::AMAZON_API_VERSION}" + query.should match /Service=([^&]+)&Timestamp=([^&]+)&Version=([^&]+)/ end it "sorts parameters" do - @worker.parameters["Foo"] = "bar" + @worker.parameters["AAA"] = "foo" query = @worker.send(:build_query) - query.should match /^Foo=bar/ + query.should match /^AAA=foo/ end it "converts a parameter whose value is an array to a string" do @worker.parameters["Foo"] = ["bar", "baz"] query = @worker.send(:build_query) - query.should match /^Foo=bar%2Cbaz/ + query.should match /Foo=bar%2Cbaz/ end end context "#host" do it "returns a host" do - @worker.locale = "us" - @worker.send(:host).should eql "ecs.amazonaws.com" + @worker.locale = "fr" + @worker.send(:host).should eql "ecs.amazonaws.fr" end end context "#build_signed_query" do it "returns a signed query string" do - @worker.secret = "secret" - @worker.locale = "us" query = @worker.send :build_signed_query query.should match /&Signature=.*/ end end - context "#timestamp_parameters" do - it "upserts a timestamp to the parameters" do - @worker.send :timestamp_parameters - @worker.parameters["Timestamp"].should match /^\d+-\d+-\d+T\d+:\d+:\d+Z$/ + context "#timestamp" do + it "returns a timestamp" do + @worker.send(:timestamp)["Timestamp"].should match /^\d+-\d+-\d+T\d+:\d+:\d+Z$/ end end context "#uri" do it "returns the URI with which to query Amazon" do - @worker.key = "key" - @worker.locale = "us" - @worker.secret = "secret" @worker.send(:uri).should be_an_instance_of URI::HTTP end end end end