2016-01-26 23:22:09 -05:00
|
|
|
require_relative '_lib'
|
|
|
|
|
|
|
|
describe RestClient::ParamsArray do
|
|
|
|
|
|
|
|
describe '.new' do
|
|
|
|
it 'accepts various types of containers' do
|
|
|
|
as_array = [[:foo, 123], [:foo, 456], [:bar, 789], [:empty, nil]]
|
|
|
|
[
|
|
|
|
[[:foo, 123], [:foo, 456], [:bar, 789], [:empty, nil]],
|
|
|
|
[{foo: 123}, {foo: 456}, {bar: 789}, {empty: nil}],
|
|
|
|
[{foo: 123}, {foo: 456}, {bar: 789}, {empty: nil}],
|
|
|
|
[{foo: 123}, [:foo, 456], {bar: 789}, {empty: nil}],
|
|
|
|
[{foo: 123}, [:foo, 456], {bar: 789}, [:empty]],
|
|
|
|
].each do |input|
|
2016-06-05 19:52:16 -04:00
|
|
|
expect(RestClient::ParamsArray.new(input).to_a).to eq as_array
|
2016-01-26 23:22:09 -05:00
|
|
|
end
|
|
|
|
|
2016-06-05 19:52:16 -04:00
|
|
|
expect(RestClient::ParamsArray.new([]).to_a).to eq []
|
|
|
|
expect(RestClient::ParamsArray.new([]).empty?).to eq true
|
2016-01-26 23:22:09 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'rejects various invalid input' do
|
|
|
|
expect {
|
|
|
|
RestClient::ParamsArray.new([[]])
|
|
|
|
}.to raise_error(IndexError)
|
|
|
|
|
|
|
|
expect {
|
|
|
|
RestClient::ParamsArray.new([[1,2,3]])
|
|
|
|
}.to raise_error(ArgumentError)
|
|
|
|
|
|
|
|
expect {
|
|
|
|
RestClient::ParamsArray.new([1,2,3])
|
|
|
|
}.to raise_error(NoMethodError)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|