2015-03-13 21:00:51 -04:00
|
|
|
require_relative '_lib'
|
2009-01-24 17:55:18 -05:00
|
|
|
|
|
|
|
describe RestClient do
|
2009-12-29 12:27:39 -05:00
|
|
|
describe "API" do
|
|
|
|
it "GET" do
|
2016-06-05 19:52:16 -04:00
|
|
|
expect(RestClient::Request).to receive(:execute).with(:method => :get, :url => 'http://some/resource', :headers => {})
|
2009-12-29 12:27:39 -05:00
|
|
|
RestClient.get('http://some/resource')
|
|
|
|
end
|
|
|
|
|
|
|
|
it "POST" do
|
2016-06-05 19:52:16 -04:00
|
|
|
expect(RestClient::Request).to receive(:execute).with(:method => :post, :url => 'http://some/resource', :payload => 'payload', :headers => {})
|
2009-12-29 12:27:39 -05:00
|
|
|
RestClient.post('http://some/resource', 'payload')
|
|
|
|
end
|
|
|
|
|
|
|
|
it "PUT" do
|
2016-06-05 19:52:16 -04:00
|
|
|
expect(RestClient::Request).to receive(:execute).with(:method => :put, :url => 'http://some/resource', :payload => 'payload', :headers => {})
|
2009-12-29 12:27:39 -05:00
|
|
|
RestClient.put('http://some/resource', 'payload')
|
|
|
|
end
|
|
|
|
|
2011-04-29 18:17:47 -04:00
|
|
|
it "PATCH" do
|
2016-06-05 19:52:16 -04:00
|
|
|
expect(RestClient::Request).to receive(:execute).with(:method => :patch, :url => 'http://some/resource', :payload => 'payload', :headers => {})
|
2011-04-29 18:17:47 -04:00
|
|
|
RestClient.patch('http://some/resource', 'payload')
|
|
|
|
end
|
|
|
|
|
2009-12-29 12:27:39 -05:00
|
|
|
it "DELETE" do
|
2016-06-05 19:52:16 -04:00
|
|
|
expect(RestClient::Request).to receive(:execute).with(:method => :delete, :url => 'http://some/resource', :headers => {})
|
2009-12-29 12:27:39 -05:00
|
|
|
RestClient.delete('http://some/resource')
|
|
|
|
end
|
|
|
|
|
|
|
|
it "HEAD" do
|
2016-06-05 19:52:16 -04:00
|
|
|
expect(RestClient::Request).to receive(:execute).with(:method => :head, :url => 'http://some/resource', :headers => {})
|
2009-12-29 12:27:39 -05:00
|
|
|
RestClient.head('http://some/resource')
|
|
|
|
end
|
2010-07-02 17:21:32 -04:00
|
|
|
|
|
|
|
it "OPTIONS" do
|
2016-06-05 19:52:16 -04:00
|
|
|
expect(RestClient::Request).to receive(:execute).with(:method => :options, :url => 'http://some/resource', :headers => {})
|
2010-07-02 17:21:32 -04:00
|
|
|
RestClient.options('http://some/resource')
|
|
|
|
end
|
2009-12-29 12:27:39 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
describe "logging" do
|
|
|
|
after do
|
|
|
|
RestClient.log = nil
|
|
|
|
end
|
|
|
|
|
2010-01-05 15:03:27 -05:00
|
|
|
it "uses << if the log is not a string" do
|
|
|
|
log = RestClient.log = []
|
2016-06-05 19:52:16 -04:00
|
|
|
expect(log).to receive(:<<).with('xyz')
|
2010-01-05 15:03:27 -05:00
|
|
|
RestClient.log << 'xyz'
|
2009-12-29 12:27:39 -05:00
|
|
|
end
|
|
|
|
|
2010-01-05 15:03:27 -05:00
|
|
|
it "displays the log to stdout" do
|
|
|
|
RestClient.log = 'stdout'
|
2016-06-05 19:52:16 -04:00
|
|
|
expect(STDOUT).to receive(:puts).with('xyz')
|
2010-01-05 15:03:27 -05:00
|
|
|
RestClient.log << 'xyz'
|
2009-12-29 12:27:39 -05:00
|
|
|
end
|
|
|
|
|
2010-01-05 15:03:27 -05:00
|
|
|
it "displays the log to stderr" do
|
|
|
|
RestClient.log = 'stderr'
|
2016-06-05 19:52:16 -04:00
|
|
|
expect(STDERR).to receive(:puts).with('xyz')
|
2010-01-05 15:03:27 -05:00
|
|
|
RestClient.log << 'xyz'
|
|
|
|
end
|
|
|
|
|
|
|
|
it "append the log to the requested filename" do
|
|
|
|
RestClient.log = '/tmp/restclient.log'
|
2013-07-26 23:09:42 -04:00
|
|
|
f = double('file handle')
|
2016-06-05 19:52:16 -04:00
|
|
|
expect(File).to receive(:open).with('/tmp/restclient.log', 'a').and_yield(f)
|
|
|
|
expect(f).to receive(:puts).with('xyz')
|
2010-01-05 15:03:27 -05:00
|
|
|
RestClient.log << 'xyz'
|
2009-12-29 12:27:39 -05:00
|
|
|
end
|
|
|
|
end
|
2010-01-05 15:03:27 -05:00
|
|
|
|
2014-03-06 21:18:07 -05:00
|
|
|
describe 'version' do
|
2017-04-28 01:21:47 -04:00
|
|
|
# test that there is a sane version number to avoid accidental 0.0.0 again
|
|
|
|
it 'has a version > 2.0.0.alpha, < 3.0' do
|
2014-03-06 21:18:07 -05:00
|
|
|
ver = Gem::Version.new(RestClient.version)
|
2017-04-28 01:21:47 -04:00
|
|
|
expect(Gem::Requirement.new('> 2.0.0.alpha', '< 3.0')).to be_satisfied_by(ver)
|
2014-03-06 21:18:07 -05:00
|
|
|
end
|
|
|
|
end
|
2009-01-24 17:55:18 -05:00
|
|
|
end
|