2010-07-03 06:41:59 -04:00
|
|
|
require File.join( File.dirname(File.expand_path(__FILE__)), 'base')
|
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
|
|
|
|
RestClient::Request.should_receive(:execute).with(:method => :get, :url => 'http://some/resource', :headers => {})
|
|
|
|
RestClient.get('http://some/resource')
|
|
|
|
end
|
|
|
|
|
|
|
|
it "POST" do
|
|
|
|
RestClient::Request.should_receive(:execute).with(:method => :post, :url => 'http://some/resource', :payload => 'payload', :headers => {})
|
|
|
|
RestClient.post('http://some/resource', 'payload')
|
|
|
|
end
|
|
|
|
|
|
|
|
it "PUT" do
|
|
|
|
RestClient::Request.should_receive(:execute).with(:method => :put, :url => 'http://some/resource', :payload => 'payload', :headers => {})
|
|
|
|
RestClient.put('http://some/resource', 'payload')
|
|
|
|
end
|
|
|
|
|
|
|
|
it "DELETE" do
|
|
|
|
RestClient::Request.should_receive(:execute).with(:method => :delete, :url => 'http://some/resource', :headers => {})
|
|
|
|
RestClient.delete('http://some/resource')
|
|
|
|
end
|
|
|
|
|
|
|
|
it "HEAD" do
|
|
|
|
RestClient::Request.should_receive(:execute).with(:method => :head, :url => 'http://some/resource', :headers => {})
|
|
|
|
RestClient.head('http://some/resource')
|
|
|
|
end
|
2010-07-02 17:21:32 -04:00
|
|
|
|
|
|
|
it "OPTIONS" do
|
|
|
|
RestClient::Request.should_receive(:execute).with(:method => :options, :url => 'http://some/resource', :headers => {})
|
|
|
|
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 = []
|
|
|
|
log.should_receive(:<<).with('xyz')
|
|
|
|
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'
|
|
|
|
STDOUT.should_receive(:puts).with('xyz')
|
|
|
|
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'
|
|
|
|
STDERR.should_receive(:puts).with('xyz')
|
|
|
|
RestClient.log << 'xyz'
|
|
|
|
end
|
|
|
|
|
|
|
|
it "append the log to the requested filename" do
|
|
|
|
RestClient.log = '/tmp/restclient.log'
|
|
|
|
f = mock('file handle')
|
|
|
|
File.should_receive(:open).with('/tmp/restclient.log', 'a').and_yield(f)
|
|
|
|
f.should_receive(:puts).with('xyz')
|
|
|
|
RestClient.log << 'xyz'
|
2009-12-29 12:27:39 -05:00
|
|
|
end
|
|
|
|
end
|
2010-01-05 15:03:27 -05:00
|
|
|
|
2009-01-24 17:55:18 -05:00
|
|
|
end
|