spec/weary/request_spec.rb in weary-1.0.1 vs spec/weary/request_spec.rb in weary-1.1.0

- old
+ new

@@ -1,8 +1,12 @@ require 'spec_helper' describe Weary::Request do + it_behaves_like "a Requestable" do + subject { described_class.new "http://github.com/api/v2/json/repos/show/mwunsch/weary" } + end + describe "#uri" do subject { described_class.new "http://github.com/api/v2/json/repos/show/mwunsch/weary" } it_behaves_like "a URI" do let(:uri) { subject.uri } @@ -95,20 +99,10 @@ describe "#headers" do subject { described_class.new "http://github.com/api/v2/json/repos/show/mwunsch/weary" } let(:hash) { {'User-Agent' => Weary::USER_AGENTS['Lynx 2.8.4rel.1 on Linux']} } - it "sets headers for the request" do - subject.headers(hash) - subject.instance_variable_get(:@headers).should eql hash - end - - it "gets previously set headers" do - subject.headers(hash) - subject.headers.should eql hash - end - it "updates the env with the Rack-friendly key" do subject.headers(hash) subject.env.should have_key('HTTP_USER_AGENT') end @@ -116,36 +110,20 @@ subject.headers(hash) subject.env['HTTP_USER_AGENT'].should eql(hash.values.first) end end - describe "#user_agent" do - subject { described_class.new "http://github.com/api/v2/json/repos/show/mwunsch/weary" } - let(:agent) { 'RSpec' } - - it "updates the #headers hash with a User-Agent" do - subject.user_agent agent - subject.headers.should have_key 'User-Agent' - end - - it "sets the user agent for the headers" do - subject.user_agent agent - subject.headers['User-Agent'].should be agent - end - end - describe "#params" do it "sets the query string for a GET request" do req = described_class.new "http://api.twitter.com/version/users/show.json" req.params :screen_name => 'markwunsch' req.uri.query.should eql "screen_name=markwunsch" end it "sets the rack input for a POST request" do req = described_class.new "https://api.github.com/gists", "POST" - req.params :public => true, - :files => { "file1.txt" => { :content => "String file contents"}} + req.params :public => true req.env['rack.input'].read.should eql req.params end it "adds a Middleware to the stack for the Content-Type and Length" do req = described_class.new "https://api.github.com/gists", "POST" @@ -194,24 +172,10 @@ req.oauth *cred req.oauth.should be_true end end - describe "#adapter" do - subject { described_class.new "http://github.com/api/v2/json/repos/show/mwunsch/weary" } - - it "sets a new adapter to set the connection" do - klass = Class.new { include Weary::Adapter } - subject.adapter(klass) - subject.adapter.should be klass - end - - it "defaults to the Net::HTTP adapter" do - subject.adapter.should be Weary::Adapter::NetHttp - end - end - describe "#perform" do subject do url = "http://github.com/api/v2/json/repos/show/mwunsch/weary" described_class.new url end @@ -231,10 +195,10 @@ code.should be >= 100 end end describe "#use" do - it "adds a middleware to the stack" do + it "runs middleware through the calling stack" do req = described_class.new "http://github.com/api/v2/json/repos/show/mwunsch/weary" req.adapter(Class.new { include Weary::Adapter }) # Rack::Runtime sets an "X-Runtime" response header # http://rack.rubyforge.org/doc/Rack/Runtime.html req.use Rack::Runtime, "RSpec" \ No newline at end of file