spec/unit/sucker/request_spec.rb in sucker-0.9.2 vs spec/unit/sucker/request_spec.rb in sucker-1.0.0.beta.1

- old
+ new

@@ -1,126 +1,138 @@ +# encoding: utf-8 require "spec_helper" module Sucker describe Request do - before do - @worker = Sucker.new( + use_vcr_cassette "unit/sucker/request", :record => :new_episodes + + let(:worker) do + 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 include default_parameters + "Version" => Sucker::CURRENT_AMAZON_API_VERSION } + worker.parameters.should include default_parameters end end context "#<<" do it "merges a hash into the parameters" do - @worker << { "foo" => "bar" } - @worker.parameters["foo"].should eql "bar" + worker << { "foo" => "bar" } + worker.parameters["foo"].should eql "bar" end end + context "api_version" do + it "has a default value" do + worker.api_version.should_not be_nil + end + end + + context "#api_version=" do + it "sets the Amazon API version" do + worker.api_version = "foo" + worker.api_version.should eql "foo" + end + end + context "#associate_tag=" do it "sets the associate tag in the parameters" do - @worker.associate_tag = "foo" - @worker.parameters["AssociateTag"].should eql "foo" + worker.associate_tag = "foo" + worker.parameters["AssociateTag"].should eql "foo" end end context "#curl" do it "returns a cURL object" do - @worker.curl.should be_an_instance_of Curl::Easy + worker.curl.should be_an_instance_of Curl::Easy end it "configures the cURL object" do - @worker.curl.interface.should be_nil + worker.curl.interface.should be_nil - @worker.curl do |curl| + worker.curl do |curl| curl.interface = "eth1" end - @worker.curl.interface.should eql "eth1" + worker.curl.interface.should eql "eth1" end end context "#get" do - before do - Sucker.stub(@worker) - end - it "returns a Response object" do - @worker.get.class.ancestors.should include Sucker::Response + worker.get.class.ancestors.should include Sucker::Response end end context "#key=" do it "sets the Amazon AWS access key in the parameters" do - @worker.key = "foo" - @worker.parameters["AWSAccessKeyId"].should eql "foo" + 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 = worker.send(:build_query) query.should match /Service=([^&]+)&Timestamp=([^&]+)&Version=([^&]+)/ end it "sorts parameters" do - @worker.parameters["AAA"] = "foo" - query = @worker.send(:build_query) + worker.parameters["AAA"] = "foo" + query = worker.send(:build_query) 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) + worker.parameters["Foo"] = ["bar", "baz"] + query = worker.send(:build_query) query.should match /Foo=bar%2Cbaz/ end it "handles integer parameter values" do - @worker.parameters["Foo"] = 1 - query = @worker.send(:build_query) + worker.parameters["Foo"] = 1 + query = worker.send(:build_query) query.should match /Foo=1/ end it "handles floating-point parameter values" do - @worker.parameters["Foo"] = 1.0 - query = @worker.send(:build_query) + worker.parameters["Foo"] = 1.0 + query = worker.send(:build_query) query.should match /Foo=1/ end end context "#host" do it "returns a host" do - @worker.locale = "fr" - @worker.send(:host).should eql "ecs.amazonaws.fr" + 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 - query = @worker.send :build_signed_query + query = worker.send :build_signed_query query.should match /&Signature=.*/ end end context "#timestamp" do it "returns a timestamp" do - @worker.send(:timestamp)["Timestamp"].should match /^\d+-\d+-\d+T\d+:\d+:\d+Z$/ + 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.send(:uri).should be_an_instance_of URI::HTTP + worker.send(:uri).should be_an_instance_of URI::HTTP end end end end end