Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,3 @@ pkg
bin
.bundle
*.rbc
Gemfile.lock
8 changes: 6 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@ rvm:
- "1.9.2"
- "1.9.3"
- "2.0.0"
- "2.1.2"
- jruby-18mode # JRuby in 1.8 mode
- jruby-19mode # JRuby in 1.9 mode
- rbx-18mode
- rbx-19mode
- rbx-2
before_install:
- gem update --system
install: "bundle install"
script: "bundle exec rspec"
29 changes: 1 addition & 28 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,29 +1,2 @@
source "http://rubygems.org"
source 'http://rubygems.org'
gemspec

ruby_version = Gem::Version.new(RUBY_VERSION.dup)
ruby_19 = Gem::Version.new('1.9')
ruby_20 = Gem::Version.new('2.0')

group :optional do
gem 'rack-cache', :require => 'rack/cache'
gem 'rack-contrib', :require => 'rack/contrib'
end

group :test do
gem 'rake'
gem 'sinatra', :require => 'sinatra/base'
gem 'rspec', '>=2.0.0'
gem 'realweb'

if ruby_version >= ruby_20
gem 'em-synchrony'
elsif ruby_version >= ruby_19
gem 'debugger' if RUBY_ENGINE == 'ruby'
gem 'em-synchrony'
else
gem 'ruby-debug'
gem 'mongrel'
gem 'cgi_multipart_eof_fix'
end
end
67 changes: 67 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
PATH
remote: .
specs:
rack-client (0.4.3.pre)
rack (>= 1.0.0)

GEM
remote: http://rubygems.org/
specs:
addressable (2.3.6)
cookiejar (0.3.2)
diff-lcs (1.2.5)
em-http-request (1.1.2)
addressable (>= 2.3.4)
cookiejar
em-socksify (>= 0.3)
eventmachine (>= 1.0.3)
http_parser.rb (>= 0.6.0)
em-socksify (0.3.0)
eventmachine (>= 1.0.0.beta.4)
em-synchrony (1.0.3)
eventmachine (>= 1.0.0.beta.1)
ethon (0.7.1)
ffi (>= 1.3.0)
eventmachine (1.0.3)
excon (0.39.5)
faraday (0.9.0)
multipart-post (>= 1.2, < 3)
ffi (1.9.3)
http_parser.rb (0.6.0)
json (1.8.1)
multipart-post (2.0.0)
rack (1.5.2)
rack-protection (1.5.3)
rack
realweb (1.0.1)
rack (>= 1.1.0)
rspec (2.99.0)
rspec-core (~> 2.99.0)
rspec-expectations (~> 2.99.0)
rspec-mocks (~> 2.99.0)
rspec-core (2.99.1)
rspec-expectations (2.99.2)
diff-lcs (>= 1.1.3, < 2.0)
rspec-mocks (2.99.2)
sinatra (1.4.5)
rack (~> 1.4)
rack-protection (~> 1.4)
tilt (~> 1.3, >= 1.3.4)
tilt (1.4.1)
typhoeus (0.6.9)
ethon (>= 0.7.1)

PLATFORMS
ruby

DEPENDENCIES
em-http-request (~> 1.1.2)
em-synchrony (~> 1.0.3)
excon (~> 0.39.5)
faraday (~> 0.9.0)
json (~> 1.8.1)
rack-client!
realweb (~> 1.0.1)
rspec (~> 2.99.0)
sinatra (~> 1.4.5)
typhoeus (~> 0.6.9)
3 changes: 2 additions & 1 deletion lib/rack/client/adapter/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ def request(method, url, headers = {}, body = nil)
if block_given?
call(build_env(method.upcase, url, headers, body)) {|tuple| yield *tuple }
else
return *call(build_env(method.upcase, url, headers, body))
env = build_env(method.upcase, url, headers, body)
return *call(env)
end
end

Expand Down
24 changes: 18 additions & 6 deletions rack-client.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,23 @@ Gem::Specification.new do |s|
s.description = s.summary
s.files = %w[History.txt LICENSE README.textile Rakefile] + Dir["lib/**/*.rb"] + Dir["demo/**/*.rb"]

s.add_dependency 'rack', '>=1.0.0'
s.add_dependency('rack', '>= 1.0.0')

s.add_development_dependency 'excon'
s.add_development_dependency 'em-http-request'
s.add_development_dependency 'typhoeus'
s.add_development_dependency 'json'
s.add_development_dependency 'faraday', '>= 0.9.0.rc1'
s.add_development_dependency('excon', '~> 0.39.5')
s.add_development_dependency('em-http-request', '~> 1.1.2')
s.add_development_dependency('faraday', '~> 0.9.0')
s.add_development_dependency('json', '~> 1.8.1')
s.add_development_dependency('realweb', '~> 1.0.1')
s.add_development_dependency('rspec', '~> 2.99.0')
s.add_development_dependency('sinatra', '~> 1.4.5')
s.add_development_dependency('typhoeus', '~> 0.6.9')


if RUBY_VERSION >= '1.9'
s.add_development_dependency('em-synchrony', '~> 1.0.3')
elsif RUBY_VERSION < '1.9'
s.add_development_dependency('mongrel', '~> 1.1.5')
s.add_development_dependency('ruby-debug', '~> 0.10.4')
s.add_development_dependency('cgi_multipart_eof_fix', '~> 2.5.0')
end
end
40 changes: 20 additions & 20 deletions spec/adapter/faraday_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,115 +20,115 @@
describe 'GET' do

it 'retrieves the response body' do
conn.get('echo').body.should == 'get'
expect(conn.get('echo').body).to eq('get')
end

it 'send url encoded params' do
conn.get('echo', :name => 'zack').body.should == %(get ?{"name"=>"zack"})
expect(conn.get('echo', :name => 'zack').body).to eq(%(get ?{"name"=>"zack"}))
end

it 'retrieves the response headers' do
response = conn.get('echo')

response.headers['Content-Type'].should =~ %r{text/plain}
response.headers['content-type'].should =~ %r{text/plain}
expect(response.headers['Content-Type']).to match(%r{text/plain})
expect(response.headers['content-type']).to match(%r{text/plain})
end

it 'handles headers with multiple values' do
conn.get('multi').headers['set-cookie'].should == 'one, two'
expect(conn.get('multi').headers['set-cookie']).to eq('one, two')
end

it 'with body' do
response = conn.get('echo') do |req|
req.body = {'bodyrock' => true}
end

response.body.should == %(get {"bodyrock"=>"true"})
expect(response.body).to eq(%(get {"bodyrock"=>"true"}))
end

it 'sends user agent' do
response = conn.get('echo_header', {:name => 'user-agent'}, :user_agent => 'Agent Faraday')
response.body.should == 'Agent Faraday'
expect(response.body).to eq('Agent Faraday')
end

end

describe 'POST' do

it 'send url encoded params' do
conn.post('echo', :name => 'zack').body.should == %(post {"name"=>"zack"})
expect(conn.post('echo', :name => 'zack').body).to eq(%(post {"name"=>"zack"}))
end

it 'send url encoded nested params' do
response = conn.post('echo', 'name' => {'first' => 'zack'})
response.body.should == %(post {"name"=>{"first"=>"zack"}})
expect(response.body).to eq(%(post {"name"=>{"first"=>"zack"}}))
end

it 'retrieves the response headers' do
conn.post('echo').headers['content-type'].should =~ %r{text/plain}
expect(conn.post('echo').headers['content-type']).to match(%r{text/plain})
end

it 'sends files' do
response = conn.post('file') do |req|
req.body = {'uploaded_file' => Faraday::UploadIO.new(__FILE__, 'text/x-ruby')}
end

response.body.should == 'file faraday_spec.rb text/x-ruby'
expect(response.body).to eq('file faraday_spec.rb text/x-ruby')
end

end

describe 'PUT' do

it 'send url encoded params' do
conn.put('echo', :name => 'zack').body.should == %(put {"name"=>"zack"})
expect(conn.put('echo', :name => 'zack').body).to eq(%(put {"name"=>"zack"}))
end

it 'send url encoded nested params' do
response = conn.put('echo', 'name' => {'first' => 'zack'})
response.body.should == %(put {"name"=>{"first"=>"zack"}})
expect(response.body).to eq(%(put {"name"=>{"first"=>"zack"}}))
end

it 'retrieves the response headers' do
conn.put('echo').headers['content-type'].should =~ %r{text/plain}
expect(conn.put('echo').headers['content-type']).to match(%r{text/plain})
end

end

describe 'PATCH' do

it 'send url encoded params' do
conn.patch('echo', :name => 'zack').body.should == %(patch {"name"=>"zack"})
expect(conn.patch('echo', :name => 'zack').body).to eq(%(patch {"name"=>"zack"}))
end

end

describe 'OPTIONS' do

specify { conn.run_request(:options, 'echo', nil, {}).body.should == 'options' }
specify { expect(conn.run_request(:options, 'echo', nil, {}).body).to eq('options') }

end

describe 'HEAD' do

it 'retrieves no response body' do
conn.head('echo').body.should == ''
expect(conn.head('echo').body).to eq('')
end

it 'retrieves the response headers' do
conn.head('echo').headers['content-type'].should =~ %r{text/plain}
expect(conn.head('echo').headers['content-type']).to match(%r{text/plain})
end

end

describe 'DELETE' do

it 'retrieves the response headers' do
conn.delete('echo').headers['content-type'].should =~ %r{text/plain}
expect(conn.delete('echo').headers['content-type']).to match(%r{text/plain})
end

it 'retrieves the body' do
conn.delete('echo').body.should == %(delete)
expect(conn.delete('echo').body).to eq(%(delete))
end

end
Expand Down
20 changes: 10 additions & 10 deletions spec/adapter/simple_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

it 'will be rackified (e.g. HTTP_*)' do
client = Rack::Client::Simple.new(app)
client.get('/', 'X-Foo' => 'bar').body.should == 'bar'
expect(client.get('/', 'X-Foo' => 'bar').body).to eq('bar')
end
end

Expand All @@ -16,12 +16,12 @@

it 'adds the user agent header to requests' do
client = Rack::Client::Simple.new(app)
client.get('/hitme').body.should == "rack-client #{Rack::Client::VERSION} (app: Proc)"
expect(client.get('/hitme').body).to eq("rack-client #{Rack::Client::VERSION} (app: Proc)")
end

it 'can be overridden' do
client = Rack::Client::Simple.new(app)
client.get('/foo', 'User-Agent' => 'IE6').body.should == 'IE6'
expect(client.get('/foo', 'User-Agent' => 'IE6').body).to eq('IE6')
end
end

Expand All @@ -30,17 +30,17 @@

it 'adds the host as the hostname of REQUEST_URI' do
client = Rack::Client::Simple.new(app, 'http://example.org/')
client.get('/foo').body.should == 'example.org'
expect(client.get('/foo').body).to eq('example.org')
end

it 'adds the host and port for explicit ports in the REQUEST_URI' do
client = Rack::Client::Simple.new(app, 'http://example.org:81/')
client.get('/foo').body.should == 'example.org:81'
expect(client.get('/foo').body).to eq('example.org:81')
end

it 'can be overridden' do
client = Rack::Client::Simple.new(app, 'http://example.org/')
client.get('/foo', 'Host' => '127.0.0.1').body.should == '127.0.0.1'
expect(client.get('/foo', 'Host' => '127.0.0.1').body).to eq('127.0.0.1')
end
end

Expand All @@ -49,17 +49,17 @@

it 'uses the base uri if the url is relative' do
client = Rack::Client::Simple.new(app, 'http://example.org/')
client.get('/foo').body.should == 'http://example.org/foo'
expect(client.get('/foo').body).to eq('http://example.org/foo')
end

it 'does not use the base uri if the url is absolute' do
client = Rack::Client::Simple.new(app, 'http://example.org/')
client.get('http://example.com/bar').body.should == 'http://example.com/bar'
expect(client.get('http://example.com/bar').body).to eq('http://example.com/bar')
end

it 'should accept a URI as the url' do
client = Rack::Client::Simple.new(app, 'http://example.org/')
client.get(URI('http://example.com/bar')).body.should == 'http://example.com/bar'
expect(client.get(URI('http://example.com/bar')).body).to eq('http://example.com/bar')
end
end

Expand All @@ -76,7 +76,7 @@ def call(env)
end

client = klass.new(lambda {|_| [500, {}, ['FAIL']] })
client.get('/').body.should == 'Hello Middleware!'
expect(client.get('/').body).to eq('Hello Middleware!')
end
end
end
Loading