mirror of
https://github.com/rest-client/rest-client.git
synced 2022-11-09 13:49:40 -05:00
an assortment of fixes to make tests passing with recent versions of dependecnies
This commit is contained in:
parent
352d0a8488
commit
178a0d82c8
6 changed files with 32 additions and 24 deletions
24
Rakefile
24
Rakefile
|
@ -19,32 +19,32 @@ end
|
||||||
|
|
||||||
############################
|
############################
|
||||||
|
|
||||||
require 'spec/rake/spectask'
|
require "rspec/core/rake_task"
|
||||||
|
|
||||||
desc "Run all specs"
|
desc "Run all specs"
|
||||||
task :spec => ["spec:unit", "spec:integration"]
|
task :spec => ["spec:unit", "spec:integration"]
|
||||||
|
|
||||||
desc "Run unit specs"
|
desc "Run unit specs"
|
||||||
Spec::Rake::SpecTask.new('spec:unit') do |t|
|
RSpec::Core::RakeTask.new('spec:unit') do |t|
|
||||||
t.spec_opts = ['--colour --format progress --loadby mtime --reverse']
|
t.rspec_opts = ['--colour --format progress']
|
||||||
t.spec_files = FileList['spec/*_spec.rb']
|
t.pattern = 'spec/*_spec.rb'
|
||||||
end
|
end
|
||||||
|
|
||||||
desc "Run integration specs"
|
desc "Run integration specs"
|
||||||
Spec::Rake::SpecTask.new('spec:integration') do |t|
|
RSpec::Core::RakeTask.new('spec:integration') do |t|
|
||||||
t.spec_opts = ['--colour --format progress --loadby mtime --reverse']
|
t.rspec_opts = ['--colour --format progress']
|
||||||
t.spec_files = FileList['spec/integration/*_spec.rb']
|
t.pattern = 'spec/integration/*_spec.rb'
|
||||||
end
|
end
|
||||||
|
|
||||||
desc "Print specdocs"
|
desc "Print specdocs"
|
||||||
Spec::Rake::SpecTask.new(:doc) do |t|
|
RSpec::Core::RakeTask.new(:doc) do |t|
|
||||||
t.spec_opts = ["--format", "specdoc", "--dry-run"]
|
t.rspec_opts = ["--format", "specdoc", "--dry-run"]
|
||||||
t.spec_files = FileList['spec/*_spec.rb']
|
t.pattern = 'spec/*_spec.rb'
|
||||||
end
|
end
|
||||||
|
|
||||||
desc "Run all examples with RCov"
|
desc "Run all examples with RCov"
|
||||||
Spec::Rake::SpecTask.new('rcov') do |t|
|
RSpec::Core::RakeTask.new('rcov') do |t|
|
||||||
t.spec_files = FileList['spec/*_spec.rb']
|
t.pattern = 'spec/*_spec.rb'
|
||||||
t.rcov = true
|
t.rcov = true
|
||||||
t.rcov_opts = ['--exclude', 'examples']
|
t.rcov_opts = ['--exclude', 'examples']
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,9 +1,7 @@
|
||||||
def is_ruby_19?
|
def is_ruby_19?
|
||||||
RUBY_VERSION == '1.9.1' or RUBY_VERSION == '1.9.2'
|
RUBY_VERSION > '1.9'
|
||||||
end
|
end
|
||||||
|
|
||||||
Encoding.default_internal = Encoding.default_external = "ASCII-8BIT" if is_ruby_19?
|
|
||||||
|
|
||||||
require 'rubygems'
|
require 'rubygems'
|
||||||
|
|
||||||
begin
|
begin
|
||||||
|
|
|
@ -12,6 +12,8 @@ describe RestClient::Request do
|
||||||
expect { request.execute }.to_not raise_error
|
expect { request.execute }.to_not raise_error
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# This doesn't works any more (under 1.9.3 at the very least). Exceptions in verify_callback are ignored.
|
||||||
|
# see https://github.com/ruby/ruby/blob/trunk/ext/openssl/ossl.c#L237
|
||||||
it "is unsuccessful with an incorrect ca_file" do
|
it "is unsuccessful with an incorrect ca_file" do
|
||||||
request = RestClient::Request.new(
|
request = RestClient::Request.new(
|
||||||
:method => :get,
|
:method => :get,
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
# encoding: binary
|
||||||
require File.join(File.dirname(File.expand_path(__FILE__)), 'base')
|
require File.join(File.dirname(File.expand_path(__FILE__)), 'base')
|
||||||
|
|
||||||
describe RestClient::Payload do
|
describe RestClient::Payload do
|
||||||
|
@ -108,7 +109,7 @@ baz\r
|
||||||
Content-Disposition: form-data; name="foo"; filename="master_shake.jpg"\r
|
Content-Disposition: form-data; name="foo"; filename="master_shake.jpg"\r
|
||||||
Content-Type: image/jpeg\r
|
Content-Type: image/jpeg\r
|
||||||
\r
|
\r
|
||||||
#{IO.read(f.path)}\r
|
#{File.open(f.path, 'rb'){|bin| bin.read}}\r
|
||||||
--#{m.boundary}--\r
|
--#{m.boundary}--\r
|
||||||
EOS
|
EOS
|
||||||
end
|
end
|
||||||
|
@ -121,7 +122,7 @@ Content-Type: image/jpeg\r
|
||||||
Content-Disposition: form-data; filename="master_shake.jpg"\r
|
Content-Disposition: form-data; filename="master_shake.jpg"\r
|
||||||
Content-Type: image/jpeg\r
|
Content-Type: image/jpeg\r
|
||||||
\r
|
\r
|
||||||
#{IO.read(f.path)}\r
|
#{File.open(f.path, 'rb'){|bin| bin.read}}\r
|
||||||
--#{m.boundary}--\r
|
--#{m.boundary}--\r
|
||||||
EOS
|
EOS
|
||||||
end
|
end
|
||||||
|
@ -136,7 +137,7 @@ Content-Type: image/jpeg\r
|
||||||
Content-Disposition: form-data; name="foo"; filename="foo.txt"\r
|
Content-Disposition: form-data; name="foo"; filename="foo.txt"\r
|
||||||
Content-Type: text/plain\r
|
Content-Type: text/plain\r
|
||||||
\r
|
\r
|
||||||
#{IO.read(f.path)}\r
|
#{File.open(f.path, 'rb'){|bin| bin.read}}\r
|
||||||
--#{m.boundary}--\r
|
--#{m.boundary}--\r
|
||||||
EOS
|
EOS
|
||||||
end
|
end
|
||||||
|
@ -160,7 +161,7 @@ foo\r
|
||||||
Content-Disposition: form-data; name="foo[bar]"; filename="foo.txt"\r
|
Content-Disposition: form-data; name="foo[bar]"; filename="foo.txt"\r
|
||||||
Content-Type: text/plain\r
|
Content-Type: text/plain\r
|
||||||
\r
|
\r
|
||||||
#{IO.read(f.path)}\r
|
#{File.open(f.path, 'rb'){|bin| bin.read}}\r
|
||||||
--#{m.boundary}--\r
|
--#{m.boundary}--\r
|
||||||
EOS
|
EOS
|
||||||
end
|
end
|
||||||
|
@ -230,5 +231,14 @@ Content-Type: text/plain\r
|
||||||
it "should recognize other payloads that can be streamed" do
|
it "should recognize other payloads that can be streamed" do
|
||||||
RestClient::Payload.generate(StringIO.new('foo')).should be_kind_of(RestClient::Payload::Streamed)
|
RestClient::Payload.generate(StringIO.new('foo')).should be_kind_of(RestClient::Payload::Streamed)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# hashery gem introduces Hash#read convenience method. Existence of #read method used to determine of content is streameable :/
|
||||||
|
it "shouldn't treat hashes as streameable" do
|
||||||
|
RestClient::Payload.generate({"foo" => 'bar'}).should be_kind_of(RestClient::Payload::UrlEncoded)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
class HashMapForTesting < Hash
|
||||||
|
alias :read :[]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -111,8 +111,7 @@ describe RestClient::Request do
|
||||||
|
|
||||||
it "uses netrc credentials" do
|
it "uses netrc credentials" do
|
||||||
URI.stub!(:parse).and_return(mock('uri', :user => nil, :password => nil, :host => 'example.com'))
|
URI.stub!(:parse).and_return(mock('uri', :user => nil, :password => nil, :host => 'example.com'))
|
||||||
File.stub!(:stat).and_return(mock('stat', :mode => 0600))
|
Netrc.stub!(:read).and_return('example.com' => ['a', 'b'])
|
||||||
IO.stub!(:read).and_return("machine example.com login a password b")
|
|
||||||
@request.parse_url_with_auth('http://example.com/resource')
|
@request.parse_url_with_auth('http://example.com/resource')
|
||||||
@request.user.should == 'a'
|
@request.user.should == 'a'
|
||||||
@request.password.should == 'b'
|
@request.password.should == 'b'
|
||||||
|
@ -120,8 +119,7 @@ describe RestClient::Request do
|
||||||
|
|
||||||
it "uses credentials in the url in preference to netrc" do
|
it "uses credentials in the url in preference to netrc" do
|
||||||
URI.stub!(:parse).and_return(mock('uri', :user => 'joe%20', :password => 'pass1', :host => 'example.com'))
|
URI.stub!(:parse).and_return(mock('uri', :user => 'joe%20', :password => 'pass1', :host => 'example.com'))
|
||||||
File.stub!(:stat).and_return(mock('stat', :mode => 0600))
|
Netrc.stub!(:read).and_return('example.com' => ['a', 'b'])
|
||||||
IO.stub!(:read).and_return("machine example.com login a password b")
|
|
||||||
@request.parse_url_with_auth('http://joe%20:pass1@example.com/resource')
|
@request.parse_url_with_auth('http://joe%20:pass1@example.com/resource')
|
||||||
@request.user.should == 'joe '
|
@request.user.should == 'joe '
|
||||||
@request.password.should == 'pass1'
|
@request.password.should == 'pass1'
|
||||||
|
|
|
@ -91,7 +91,7 @@ describe RestClient::Response do
|
||||||
end
|
end
|
||||||
|
|
||||||
it "follows a redirection and keep the cookies" do
|
it "follows a redirection and keep the cookies" do
|
||||||
stub_request(:get, 'http://some/resource').to_return(:body => '', :status => 301, :headers => {'Set-Cookie' => CGI::Cookie.new('Foo', 'Bar'), 'Location' => 'http://new/resource', })
|
stub_request(:get, 'http://some/resource').to_return(:body => '', :status => 301, :headers => {'Set-Cookie' => 'Foo=Bar', 'Location' => 'http://new/resource', })
|
||||||
stub_request(:get, 'http://new/resource').with(:headers => {'Cookie' => 'Foo=Bar'}).to_return(:body => 'Qux')
|
stub_request(:get, 'http://new/resource').with(:headers => {'Cookie' => 'Foo=Bar'}).to_return(:body => 'Qux')
|
||||||
RestClient::Request.execute(:url => 'http://some/resource', :method => :get).body.should == 'Qux'
|
RestClient::Request.execute(:url => 'http://some/resource', :method => :get).body.should == 'Qux'
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue