1
0
Fork 0
mirror of https://github.com/rest-client/rest-client.git synced 2022-11-09 13:49:40 -05:00
rest-client--rest-client/spec/unit/restclient_spec.rb
Andy Brody 4971d1a6e1 Convert specs to RSpec 2.99.2 syntax with Transpec
This conversion is done by Transpec 3.2.2 with the following command:
    transpec

* 317 conversions
    from: obj.should
      to: expect(obj).to

* 160 conversions
    from: obj.stub(:message)
      to: allow(obj).to receive(:message)

* 100 conversions
    from: obj.should_receive(:message)
      to: expect(obj).to receive(:message)

* 30 conversions
    from: lambda { }.should
      to: expect { }.to

* 22 conversions
    from: obj.should_not_receive(:message)
      to: expect(obj).not_to receive(:message)

* 4 conversions
    from: obj.should_not
      to: expect(obj).not_to

* 2 conversions
    from: == expected
      to: eq(expected)

* 1 conversion
    from: expect(collection).to have_at_least(n).items
      to: expect(collection.size).to be >= n

* 1 conversion
    from: obj.unstub(:message)
      to: allow(obj).to receive(:message).and_call_original

For more details: https://github.com/yujinakayama/transpec#supported-conversions
2016-06-05 19:52:16 -04:00

79 lines
2.6 KiB
Ruby

require_relative '_lib'
describe RestClient do
describe "API" do
it "GET" do
expect(RestClient::Request).to receive(:execute).with(:method => :get, :url => 'http://some/resource', :headers => {})
RestClient.get('http://some/resource')
end
it "POST" do
expect(RestClient::Request).to receive(:execute).with(:method => :post, :url => 'http://some/resource', :payload => 'payload', :headers => {})
RestClient.post('http://some/resource', 'payload')
end
it "PUT" do
expect(RestClient::Request).to receive(:execute).with(:method => :put, :url => 'http://some/resource', :payload => 'payload', :headers => {})
RestClient.put('http://some/resource', 'payload')
end
it "PATCH" do
expect(RestClient::Request).to receive(:execute).with(:method => :patch, :url => 'http://some/resource', :payload => 'payload', :headers => {})
RestClient.patch('http://some/resource', 'payload')
end
it "DELETE" do
expect(RestClient::Request).to receive(:execute).with(:method => :delete, :url => 'http://some/resource', :headers => {})
RestClient.delete('http://some/resource')
end
it "HEAD" do
expect(RestClient::Request).to receive(:execute).with(:method => :head, :url => 'http://some/resource', :headers => {})
RestClient.head('http://some/resource')
end
it "OPTIONS" do
expect(RestClient::Request).to receive(:execute).with(:method => :options, :url => 'http://some/resource', :headers => {})
RestClient.options('http://some/resource')
end
end
describe "logging" do
after do
RestClient.log = nil
end
it "uses << if the log is not a string" do
log = RestClient.log = []
expect(log).to receive(:<<).with('xyz')
RestClient.log << 'xyz'
end
it "displays the log to stdout" do
RestClient.log = 'stdout'
expect(STDOUT).to receive(:puts).with('xyz')
RestClient.log << 'xyz'
end
it "displays the log to stderr" do
RestClient.log = 'stderr'
expect(STDERR).to receive(:puts).with('xyz')
RestClient.log << 'xyz'
end
it "append the log to the requested filename" do
RestClient.log = '/tmp/restclient.log'
f = double('file handle')
expect(File).to receive(:open).with('/tmp/restclient.log', 'a').and_yield(f)
expect(f).to receive(:puts).with('xyz')
RestClient.log << 'xyz'
end
end
describe 'version' do
it 'has a version ~> 2.0.0.alpha' do
ver = Gem::Version.new(RestClient.version)
expect(Gem::Requirement.new('~> 2.0.0.alpha')).to be_satisfied_by(ver)
end
end
end