1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
|
require 'spec_helper'
require 'puppet/settings'
require 'puppet/settings/http_extra_headers_setting'
describe Puppet::Settings::HttpExtraHeadersSetting do
subject { described_class.new(:settings => double('settings'), :desc => "test") }
it "is of type :http_extra_headers" do
expect(subject.type).to eq :http_extra_headers
end
describe "munging the value" do
let(:final_value) { [['header1', 'foo'], ['header2', 'bar']] }
describe "when given a string" do
it "splits multiple values into an array" do
expect(subject.munge("header1:foo,header2:bar")).to match_array(final_value)
end
it "strips whitespace between elements" do
expect(subject.munge("header1:foo , header2:bar")).to match_array(final_value)
end
it "creates an array when one item is given" do
expect(subject.munge("header1:foo")).to match_array([['header1', 'foo']])
end
end
describe "when given an array of strings" do
it "returns an array of arrays" do
expect(subject.munge(['header1:foo', 'header2:bar'])).to match_array(final_value)
end
end
describe "when given an array of arrays" do
it "returns an array of arrays" do
expect(subject.munge([['header1', 'foo'], ['header2', 'bar']])).to match_array(final_value)
end
end
describe "when given a hash" do
it "returns the hash" do
expect(subject.munge({'header1' => 'foo', 'header2' => 'bar'})).to match_array(final_value)
end
end
describe 'raises an error when' do
it 'is given an unexpected object type' do
expect {
subject.munge(65)
}.to raise_error(ArgumentError, /^Expected an Array, String, or Hash, got a Integer/)
end
it 'is given an array of unexpected object types' do
expect {
subject.munge([65, 82])
}.to raise_error(ArgumentError, /^Expected an Array or String, got a Integer/)
end
end
end
end
|