Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Modernize, clean up some bitrot

  • Loading branch information...
commit 1488c7f4a7dbb355ad6d339662f012a2c50cbd7e 1 parent 9e0bc2e
@paul paul authored
View
1  .gitignore
@@ -3,3 +3,4 @@ pkg/*
doc/*
.yardoc
\#*\#
+Gemfile.lock
View
15 Gemfile
@@ -0,0 +1,15 @@
+# A sample Gemfile
+source "http://rubygems.org"
+
+gem 'httpauth'
+
+
+group :development do
+ gem "fakeweb"
+ gem "rspec"
+ gem "echoe"
+ gem "yard"
+ gem "sinatra"
+end
+
+# vim: ft=ruby
View
20 Rakefile
@@ -1,6 +1,6 @@
require 'rubygems'
require 'rake'
-require 'lib/resourceful'
+require './lib/resourceful'
begin
require 'echoe'
@@ -27,15 +27,15 @@ desc 'Run all acceptance specs'
Spec::Rake::SpecTask.new(:spec) do |t|
t.spec_opts << '--options' << 'spec/spec.opts' if File.exists?('spec/spec.opts')
t.libs << 'lib'
- t.spec_files = FileList['spec/**/*_spec.rb']
+ t.spec_files = FileList['spec/**/*_spec.rb']
end
-namespace :spec do
+namespace :spec do
desc 'Run all acceptance specs'
Spec::Rake::SpecTask.new(:acceptance) do |t|
t.spec_opts << '--options' << 'spec/spec.opts' if File.exists?('spec/spec.opts')
t.libs << 'lib'
- t.spec_files = FileList['spec/acceptance/*_spec.rb']
+ t.spec_files = FileList['spec/acceptance/*_spec.rb']
end
desc 'Run all unit specs'
@@ -44,19 +44,19 @@ namespace :spec do
t.libs << 'lib'
t.spec_files = FileList['spec/**/*_spec.rb'] - (FileList['spec/acceptance/*_spec.rb'] + FileList['spec/simple_sinatra_server_spec.rb'] )
end
-
+
desc 'Run the specs for the server'
Spec::Rake::SpecTask.new('server') do |t|
t.spec_opts << '--options' << 'spec/spec.opts' if File.exists?('spec/spec.opts')
t.libs << 'lib'
- t.spec_files = FileList['spec/simple_sinatra_server_spec.rb']
+ t.spec_files = FileList['spec/simple_sinatra_server_spec.rb']
end
end
-task :server do
- begin
- require 'spec/simple_sinatra_server'
- desc "Run the sinatra echo server, with loggin"
+task :server do
+ begin
+ require './spec/simple_sinatra_server'
+ desc "Run the sinatra echo server, with loggin"
task :server do
Sinatra::Default.set(
:run => true,
View
2  lib/resourceful.rb
@@ -21,6 +21,6 @@ module Resourceful
# Resourceful is a library that provides a high level HTTP interface.
module Resourceful
- VERSION = "1.0.1"
+ VERSION = "1.1.0"
RESOURCEFUL_USER_AGENT_TOKEN = "Resourceful/#{VERSION}(Ruby/#{RUBY_VERSION})"
end
View
2  spec/acceptance/authorization_spec.rb
@@ -1,5 +1,5 @@
-require File.dirname(__FILE__) + '/../spec_helper'
+require 'spec_helper'
require 'resourceful'
describe Resourceful do
View
2  spec/acceptance/caching_spec.rb
@@ -1,5 +1,5 @@
-require File.dirname(__FILE__) + '/../spec_helper'
+require 'spec_helper'
require 'resourceful'
require 'addressable/template'
View
2  spec/acceptance/header_spec.rb
@@ -1,4 +1,4 @@
-require File.dirname(__FILE__) + '/../spec_helper'
+require 'spec_helper'
require 'resourceful'
describe Resourceful do
View
2  spec/acceptance/redirecting_spec.rb
@@ -1,5 +1,5 @@
-require File.dirname(__FILE__) + '/../spec_helper'
+require 'spec_helper'
require 'resourceful'
describe Resourceful do
View
2  spec/acceptance/resource_spec.rb
@@ -1,5 +1,5 @@
-require File.dirname(__FILE__) + '/../spec_helper'
+require 'spec_helper'
require 'resourceful'
describe Resourceful do
View
2  spec/acceptance/resourceful_spec.rb
@@ -1,5 +1,5 @@
-require File.dirname(__FILE__) + '/../spec_helper'
+require 'spec_helper'
require 'resourceful'
describe Resourceful do
View
22 spec/resourceful/header_spec.rb
@@ -1,17 +1,17 @@
-require File.dirname(__FILE__) + "/../spec_helper.rb"
+require "spec_helper.rb"
module Resourceful
- describe Header do
+ describe Header do
def self.should_support_header(name)
const_name = name.upcase.gsub('-', '_')
meth_name = name.downcase.gsub('-', '_')
eval <<-RUBY
- it "should have constant `#{const_name}` for header `#{name}`" do
+ it "should have constant `#{const_name}` for header `#{name}`" do
Resourceful::Header::#{const_name}.should == '#{name}'
end
- it "should have accessor method `#{meth_name}` for header `#{name}`" do
+ it "should have accessor method `#{meth_name}` for header `#{name}`" do
Resourceful::Header.new.should respond_to(:#{meth_name})
end
@@ -68,18 +68,18 @@ def self.should_support_header(name)
should_support_header('WWW-Authenticate')
- it "should be instantiatable w/ single valued header fields" do
+ it "should be instantiatable w/ single valued header fields" do
Header.new('Host' => 'foo.example').
host.should eql('foo.example')
end
- it "should gracefully handle repeated values for single valued header fields" do
+ it "should gracefully handle repeated values for single valued header fields" do
lambda {
Header.new('Host' => ['foo.example', 'bar.example'])
}.should raise_error(ArgumentError, 'Host field may only have one value')
end
- it "should provide #each_fields to iterate through all header fields and values as strings" do
+ it "should provide #each_fields to iterate through all header fields and values as strings" do
field_names = []
Header.new('Accept' => "this", :content_type => "that", 'pragma' => 'test').each_field do |fname, _|
field_names << fname
@@ -91,7 +91,7 @@ def self.should_support_header(name)
field_names.should have(3).items
end
- it "should provide #to_hash as a way to dump the header fields" do
+ it "should provide #to_hash as a way to dump the header fields" do
Header.new('Accept' => "this", :content_type => "that", 'date' => 'today').to_hash.tap do |h|
h.should have_pair('Accept', ['this'])
h.should have_pair('Content-Type', 'that')
@@ -125,12 +125,12 @@ def self.should_support_header(name)
accept.should eql(['application/foo', 'application/bar'])
end
- it "should be instantiatable w/ multi-valued header fields w/ one value" do
+ it "should be instantiatable w/ multi-valued header fields w/ one value" do
Header.new('Accept' => 'application/foo').
accept.should eql(['application/foo'])
end
- it "should provide values to #each_field as a comma separated string" do
+ it "should provide values to #each_field as a comma separated string" do
Header.new('Accept' => ['this', 'that']).each_field do |fname, fval|
fval.should == 'this, that'
end
@@ -148,6 +148,6 @@ def self.should_support_header(name)
header_hash.has_key?(name)
header_hash[name] == value
end
- end
+ end
end
end
View
22 spec/resourceful/http_accessor_spec.rb
@@ -1,52 +1,52 @@
-require File.dirname(__FILE__) + "/../spec_helper"
+require "spec_helper"
require "resourceful/http_accessor"
module Resourceful
- describe HttpAccessor do
- describe "instantiation" do
- it "should accept logger option" do
+ describe HttpAccessor do
+ describe "instantiation" do
+ it "should accept logger option" do
test_logger = stub('logger', :debug => false)
ha = HttpAccessor.new(:logger => test_logger)
ha.logger.should equal(test_logger)
end
- it "should accept array user_agent option" do
+ it "should accept array user_agent option" do
ha = HttpAccessor.new(:user_agent => ['foo/3.2', 'bar/1.0'])
ha.user_agent_string.should match(/^foo\/3.2 bar\/1.0 Resourceful/)
end
- it "should accept string user_agent option" do
+ it "should accept string user_agent option" do
ha = HttpAccessor.new(:user_agent => 'foo')
ha.user_agent_string.should match(/^foo Resourceful/)
end
- it "should accept cache_manager option" do
+ it "should accept cache_manager option" do
test_cache_manager = stub('cache_manager', :debug => false)
ha = HttpAccessor.new(:cache_manager => test_cache_manager)
ha.cache_manager.should equal(test_cache_manager)
end
- it "should accept http_adapter option" do
+ it "should accept http_adapter option" do
test_http_adapter = stub('http_adapter', :debug => false)
ha = HttpAccessor.new(:http_adapter => test_http_adapter)
ha.http_adapter.should equal(test_http_adapter)
end
- it "should accept authenticator option" do
+ it "should accept authenticator option" do
test_authenticator = stub('authenticator', :debug => false)
ha = HttpAccessor.new(:authenticator => test_authenticator)
# cannot really be tested safely so we just rely on the fact that the option was accepted
end
- it "should accept authenticators option" do
+ it "should accept authenticators option" do
test_authenticator1 = stub('authenticator1', :debug => false)
test_authenticator2 = stub('authenticator2', :debug => false)
ha = HttpAccessor.new(:authenticator => [test_authenticator1, test_authenticator2])
# cannot really be tested safely so we just rely on the fact that the option was accepted
end
- it "should reject unrecognized options" do
+ it "should reject unrecognized options" do
lambda {
HttpAccessor.new(:not_a_valid_option => "this")
}.should raise_error(ArgumentError)
View
30 spec/resourceful/multipart_form_data_spec.rb
@@ -1,32 +1,32 @@
-require File.dirname(__FILE__) + "/../spec_helper"
+require "spec_helper"
require 'tempfile'
require "resourceful/multipart_form_data.rb"
describe Resourceful::MultipartFormData do
- before do
+ before do
@form_data = Resourceful::MultipartFormData.new
end
- it "should know its content-type" do
+ it "should know its content-type" do
@form_data.content_type.should match(/^multipart\/form-data/i)
end
- it "should know its boundary string" do
+ it "should know its boundary string" do
@form_data.content_type.should match(/; boundary=[0-9A-Za-z]{10,}/i)
end
- describe "with simple parameters" do
+ describe "with simple parameters" do
- it "should all simple parameters to be added" do
+ it "should all simple parameters to be added" do
@form_data.add(:foo, "testing")
end
- it "should render a multipart form-data document when #read is called" do
+ it "should render a multipart form-data document when #read is called" do
@form_data.add('foo', 'bar')
@form_data.add('baz', 'this')
-
+
boundary = /boundary=(\w+)/.match(@form_data.content_type)[1]
@form_data.read.should eql(<<MPFD[0..-2])
--#{boundary}\r
@@ -42,23 +42,23 @@
end
- describe "with file parameter" do
- it "should add file parameters to be added" do
+ describe "with file parameter" do
+ it "should add file parameters to be added" do
Tempfile.open('resourceful-post-file-tests') do |file_to_upload|
file_to_upload << "This is a test"
file_to_upload.flush
-
+
@form_data.add_file(:foo, file_to_upload.path)
end
end
- it "should render a multipart form-data document when #read is called" do
+ it "should render a multipart form-data document when #read is called" do
Tempfile.open('resourceful-post-file-tests') do |file_to_upload|
file_to_upload << "This is a test"
file_to_upload.flush
-
+
@form_data.add_file(:foo, file_to_upload.path)
-
+
boundary = /boundary=(\w+)/.match(@form_data.content_type)[1]
@form_data.read.should eql(<<MPFD[0..-2])
--#{boundary}\r
@@ -70,7 +70,7 @@
MPFD
end
-
+
end
end
end
View
14 spec/resourceful/resource_spec.rb
@@ -1,20 +1,20 @@
-require File.dirname(__FILE__) + "/../spec_helper"
+require "spec_helper"
module Resourceful
- describe Resource do
- before do
+ describe Resource do
+ before do
@http_adapter = stub(:http_adapter)
http = Resourceful::HttpAccessor.new(:http_adapter => @http_adapter)
@resource = http.resource('http://foo.example')
end
-
- describe "POSTing" do
- it "should use bodies content type as the request content-type if it is known" do
+
+ describe "POSTing" do
+ it "should use bodies content type as the request content-type if it is known" do
@http_adapter.should_receive(:make_request).with(anything, anything, anything, hash_including('Content-Type' => 'application/x-special-type')).and_return([200, {}, ""])
body = stub(:body, :content_type => 'application/x-special-type', :read => "hello there")
@resource.post(body)
end
end
-
+
end
end
View
18 spec/resourceful/response_spec.rb
@@ -1,47 +1,47 @@
-require File.dirname(__FILE__) + "/../spec_helper"
+require "spec_helper"
require 'resourceful/response'
require 'resourceful/header'
module Resourceful
- describe Response do
-
- it "should know when it is expired" do
+ describe Response do
+
+ it "should know when it is expired" do
resp = Response.new(nil, nil, Header.new('Cache-Control' => 'max-age=2', 'Date' => (Time.now - 2).httpdate), nil)
resp.request_time = Time.now
resp.expired?.should be_true
end
- it "should know when it is not expired" do
+ it "should know when it is not expired" do
resp = Response.new(nil, nil, Header.new('Cache-Control' => 'max-age=1', 'Date' => Time.now.httpdate), nil)
resp.request_time = Time.now
resp.expired?.should be_false
end
- it "know when it is stale due to expiration" do
+ it "know when it is stale due to expiration" do
resp = Response.new(nil, nil, Header.new('Cache-Control' => 'max-age=1', 'Date' => (Time.now - 2).httpdate), nil)
resp.request_time = Time.now
resp.stale?.should be_true
end
- it "know when it is stale due to no-cache" do
+ it "know when it is stale due to no-cache" do
resp = Response.new(nil, nil, Header.new('Cache-Control' => 'no-cache', 'Date' => Time.now.httpdate), nil)
resp.request_time = Time.now
resp.stale?.should be_true
end
- it "know when it is stale due to must-revalidate" do
+ it "know when it is stale due to must-revalidate" do
resp = Response.new(nil, nil, Header.new('Cache-Control' => 'must-revalidate', 'Date' => Time.now.httpdate), nil)
resp.request_time = Time.now
resp.stale?.should be_true
end
- it "know when it is not stale" do
+ it "know when it is not stale" do
resp = Response.new(nil, nil, Header.new('Cache-Control' => 'max-age=1', 'Date' => Time.now.httpdate), nil)
resp.request_time = Time.now
View
26 spec/resourceful/urlencoded_form_data_spec.rb
@@ -1,43 +1,43 @@
-require File.dirname(__FILE__) + "/../spec_helper"
+require "spec_helper"
require 'tempfile'
require "resourceful/urlencoded_form_data.rb"
describe Resourceful::UrlencodedFormData do
- before do
+ before do
@form_data = Resourceful::UrlencodedFormData.new
end
- it "should know its content-type" do
+ it "should know its content-type" do
@form_data.content_type.should match(/^application\/x-www-form-urlencoded$/i)
end
- describe "instantiation" do
- it "should be creatable with hash" do
+ describe "instantiation" do
+ it "should be creatable with hash" do
Resourceful::UrlencodedFormData.new(:foo => 'testing').read.should eql("foo=testing")
end
end
- describe "with simple parameters" do
- it "should all simple parameters to be added" do
+ describe "with simple parameters" do
+ it "should all simple parameters to be added" do
@form_data.add(:foo, "testing")
end
- it "should render a multipart form-data document when #read is called" do
+ it "should render a multipart form-data document when #read is called" do
@form_data.add('foo', 'bar')
@form_data.add('baz', 'this')
-
+
@form_data.read.should eql("foo=bar&baz=this")
end
- it "should escape character in values that are unsafe" do
+ it "should escape character in values that are unsafe" do
@form_data.add('foo', 'this & that')
-
+
@form_data.read.should eql("foo=this+%26+that")
end
- it "should escape character in names that are unsafe" do
- @form_data.add('foo=bar', 'this')
+ it "should escape character in names that are unsafe" do
+ @form_data.add('foo=bar', 'this')
@form_data.read.should eql("foo%3Dbar=this")
end
end
View
40 spec/resourceful_spec.rb
@@ -1,79 +1,79 @@
-require File.dirname(__FILE__) + "/spec_helper.rb"
+require "spec_helper"
-describe Resourceful do
- it "should have a default accessor" do
+describe Resourceful do
+ it "should have a default accessor" do
Resourceful.default_accessor.should be_kind_of Resourceful::HttpAccessor
end
- it "should delegate request making (minimal)" do
+ it "should delegate request making (minimal)" do
stub_resource = mock(:resource)
Resourceful.default_accessor.should_receive(:resource).with( 'http://foo.invalid/bar').and_return(stub_resource)
stub_resource.should_receive(:request).with(:get, nil, {})
-
+
Resourceful.request(:get, 'http://foo.invalid/bar')
end
- it "should delegate request making (with header)" do
+ it "should delegate request making (with header)" do
stub_resource = mock(:resource)
Resourceful.default_accessor.should_receive(:resource).with( 'http://foo.invalid/bar').and_return(stub_resource)
stub_resource.should_receive(:request).with(:get, nil, {:accept => :json})
-
+
Resourceful.request(:get, 'http://foo.invalid/bar', :accept => :json)
end
- it "should delegate request making (with body)" do
+ it "should delegate request making (with body)" do
stub_resource = mock(:resource)
Resourceful.default_accessor.should_receive(:resource).with( 'http://foo.invalid/bar').and_return(stub_resource)
stub_resource.should_receive(:request).with(:get, 'body', {})
-
+
Resourceful.request(:get, 'http://foo.invalid/bar', {}, 'body')
end
- it "should allow convenient get requests" do
+ it "should allow convenient get requests" do
stub_resource = mock(:resource)
Resourceful.default_accessor.should_receive(:resource).with( 'http://foo.invalid/bar').and_return(stub_resource)
stub_resource.should_receive(:request).with(:get, nil, :header_marker)
-
+
Resourceful.get 'http://foo.invalid/bar', :header_marker
end
- it "should allow convenient head requests" do
+ it "should allow convenient head requests" do
stub_resource = mock(:resource)
Resourceful.default_accessor.should_receive(:resource).with( 'http://foo.invalid/bar').and_return(stub_resource)
stub_resource.should_receive(:request).with(:head, nil, :header_marker)
-
+
Resourceful.head 'http://foo.invalid/bar', :header_marker
end
- it "should allow convenient delete requests" do
+ it "should allow convenient delete requests" do
stub_resource = mock(:resource)
Resourceful.default_accessor.should_receive(:resource).with( 'http://foo.invalid/bar').and_return(stub_resource)
stub_resource.should_receive(:request).with(:delete, nil, :header_marker)
-
+
Resourceful.delete 'http://foo.invalid/bar', :header_marker
end
- it "should allow convenient post requests" do
+ it "should allow convenient post requests" do
stub_resource = mock(:resource)
Resourceful.default_accessor.should_receive(:resource).with( 'http://foo.invalid/bar').and_return(stub_resource)
stub_resource.should_receive(:request).with(:post, :body_marker, :header_marker)
-
+
Resourceful.post 'http://foo.invalid/bar', :body_marker, :header_marker
end
- it "should allow convenient put requests" do
+ it "should allow convenient put requests" do
stub_resource = mock(:resource)
Resourceful.default_accessor.should_receive(:resource).with( 'http://foo.invalid/bar').and_return(stub_resource)
stub_resource.should_receive(:request).with(:put, :body_marker, :header_marker)
-
+
Resourceful.put 'http://foo.invalid/bar', :body_marker, :header_marker
end
it "should allow new authenticators to be added to default accessor" do
Resourceful.default_accessor.should_receive(:add_authenticator).with(:my_authentcator_marker)
-
+
Resourceful.add_authenticator(:my_authentcator_marker)
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.