Skip to content

Commit f2550da

Browse files
committed
Syntax fixes for ruby 1.8
1 parent a8733f3 commit f2550da

File tree

8 files changed

+49
-20
lines changed

8 files changed

+49
-20
lines changed

lib/puppet/parser/functions/member.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ module Puppet::Parser::Functions
4444
end
4545

4646
if arguments[1].is_a? String or arguments[1].is_a? Fixnum
47-
item = Array(arguments[1])
47+
item = [arguments[1]]
4848
else
4949
item = arguments[1]
5050
end

spec/functions/deep_merge_spec.rb

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,30 +14,30 @@
1414

1515
describe 'when arguments have key collisions' do
1616
it 'should prefer values from the last hash' do
17-
is_expected.to run
17+
is_expected.to run \
1818
.with_params(
1919
{'key1' => 'value1', 'key2' => 'value2' },
20-
{'key2' => 'replacement_value', 'key3' => 'value3'})
20+
{'key2' => 'replacement_value', 'key3' => 'value3'}) \
2121
.and_return(
2222
{'key1' => 'value1', 'key2' => 'replacement_value', 'key3' => 'value3'})
2323
end
24-
it { is_expected.to run
25-
.with_params({'key1' => 'value1'}, {'key1' => 'value2'}, {'key1' => 'value3'})
24+
it { is_expected.to run \
25+
.with_params({'key1' => 'value1'}, {'key1' => 'value2'}, {'key1' => 'value3'}) \
2626
.and_return({'key1' => 'value3' })
2727
}
2828
end
2929

3030
describe 'when arguments have subhashes' do
31-
it { is_expected.to run
32-
.with_params({'key1' => 'value1'}, {'key2' => 'value2', 'key3' => {'subkey1' => 'value4'}})
31+
it { is_expected.to run \
32+
.with_params({'key1' => 'value1'}, {'key2' => 'value2', 'key3' => {'subkey1' => 'value4'}}) \
3333
.and_return( {'key1' => 'value1', 'key2' => 'value2', 'key3' => {'subkey1' => 'value4'}})
3434
}
35-
it { is_expected.to run
36-
.with_params({'key1' => {'subkey1' => 'value1'}}, {'key1' => {'subkey2' => 'value2'}})
35+
it { is_expected.to run \
36+
.with_params({'key1' => {'subkey1' => 'value1'}}, {'key1' => {'subkey2' => 'value2'}}) \
3737
.and_return( {'key1' => {'subkey1' => 'value1', 'subkey2' => 'value2'}})
3838
}
39-
it { is_expected.to run
40-
.with_params({'key1' => {'subkey1' => {'subsubkey1' => 'value1'}}}, {'key1' => {'subkey1' => {'subsubkey1' => 'value2'}}})
39+
it { is_expected.to run \
40+
.with_params({'key1' => {'subkey1' => {'subsubkey1' => 'value1'}}}, {'key1' => {'subkey1' => {'subsubkey1' => 'value2'}}}) \
4141
.and_return( {'key1' => {'subkey1' => {'subsubkey1' => 'value2'}}})
4242
}
4343
end

spec/functions/delete_spec.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,12 @@
3636
it { is_expected.to run.with_params({}, '').and_return({}) }
3737
it { is_expected.to run.with_params({}, 'key').and_return({}) }
3838
it { is_expected.to run.with_params({'key' => 'value'}, 'key').and_return({}) }
39-
it { is_expected.to run
40-
.with_params({'key1' => 'value1', 'key2' => 'value2', 'key3' => 'value3'}, 'key2')
39+
it { is_expected.to run \
40+
.with_params({'key1' => 'value1', 'key2' => 'value2', 'key3' => 'value3'}, 'key2') \
4141
.and_return( {'key1' => 'value1', 'key3' => 'value3'})
4242
}
43-
it { is_expected.to run
44-
.with_params({'key1' => 'value1', 'key2' => 'value2', 'key3' => 'value3'}, ['key1', 'key2'])
43+
it { is_expected.to run \
44+
.with_params({'key1' => 'value1', 'key2' => 'value2', 'key3' => 'value3'}, ['key1', 'key2']) \
4545
.and_return( {'key3' => 'value3'})
4646
}
4747
end

spec/functions/delete_undef_values_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@
3737
pending("review behaviour when being passed undef as #{undef_value.inspect}") if undef_value == nil
3838
end
3939
it { is_expected.to run.with_params({'key' => undef_value}).and_return({}) }
40-
it { is_expected.to run
41-
.with_params({'key1' => 'value1', 'undef_key' => undef_value, 'key2' => 'value2'})
40+
it { is_expected.to run \
41+
.with_params({'key1' => 'value1', 'undef_key' => undef_value, 'key2' => 'value2'}) \
4242
.and_return({'key1' => 'value1', 'key2' => 'value2'})
4343
}
4444
end

spec/functions/parseyaml_spec.rb

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@
44
it { is_expected.not_to eq(nil) }
55
it { is_expected.to run.with_params().and_raise_error(Puppet::ParseError, /wrong number of arguments/i) }
66
it { is_expected.to run.with_params('', '').and_raise_error(Puppet::ParseError, /wrong number of arguments/i) }
7-
it { is_expected.to run.with_params('["one"').and_raise_error(Psych::SyntaxError) }
87
it { is_expected.to run.with_params('["one", "two", "three"]').and_return(['one', 'two', 'three']) }
8+
context 'when running on modern rubies', :unless => RUBY_VERSION == '1.8.7' do
9+
it { is_expected.to run.with_params('["one"').and_raise_error(Psych::SyntaxError) }
10+
end
11+
context 'when running on ruby 1.8.7, which does not have Psych', :if => RUBY_VERSION == '1.8.7' do
12+
it { is_expected.to run.with_params('["one"').and_raise_error(ArgumentError) }
13+
end
914
end

spec/functions/time_spec.rb

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,13 @@
1616
it { is_expected.to run.with_params({}).and_return(1160727311) }
1717
it { is_expected.to run.with_params('foo').and_return(1160727311) }
1818
it { is_expected.to run.with_params('UTC').and_return(1160727311) }
19-
it { is_expected.to run.with_params('America/Los_Angeles').and_return(1160727311) }
19+
20+
context 'when running on modern rubies', :unless => RUBY_VERSION == '1.8.7' do
21+
it { is_expected.to run.with_params('America/Los_Angeles').and_return(1160727311) }
22+
end
23+
24+
context 'when running on ruby 1.8.7, which garbles the TZ', :if => RUBY_VERSION == '1.8.7' do
25+
it { is_expected.to run.with_params('America/Los_Angeles').and_return(1160702111) }
26+
end
2027
end
2128
end

spec/functions/validate_integer_spec.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,15 @@
1313
it { is_expected.to run.with_params([0, 1, 2, invalid, 3, 4], 10, -10).and_raise_error(Puppet::ParseError, /to be an Integer/) }
1414
end
1515

16+
context 'when running on modern rubies', :unless => RUBY_VERSION == '1.8.7' do
17+
it { is_expected.to run.with_params([0, 1, 2, {1=>2}, 3, 4], 10, -10).and_raise_error(Puppet::ParseError, /to be an Integer/) }
18+
end
19+
20+
context 'when running on ruby, which munges hashes weirdly', :if => RUBY_VERSION == '1.8.7' do
21+
it { is_expected.to run.with_params([0, 1, 2, {1=>2}, 3, 4], 10, -10).and_raise_error(Puppet::ParseError) }
22+
it { is_expected.to run.with_params([0, 1, 2, {0=>2}, 3, 4], 10, -10).and_raise_error(Puppet::ParseError) }
23+
end
24+
1625
it { is_expected.to run.with_params(1, '').and_raise_error(Puppet::ParseError, /to be unset or an Integer/) }
1726
it { is_expected.to run.with_params(1, 2, '').and_raise_error(Puppet::ParseError, /to be unset or an Integer/) }
1827
it { is_expected.to run.with_params(1, 2, 3).and_raise_error(Puppet::ParseError, /second argument to be larger than third argument/) }

spec/functions/validate_numeric_spec.rb

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,15 @@
1010
it { is_expected.to run.with_params(invalid).and_raise_error(Puppet::ParseError, /to be a Numeric/) }
1111
it { is_expected.to run.with_params(invalid, 10.0).and_raise_error(Puppet::ParseError, /to be a Numeric/) }
1212
it { is_expected.to run.with_params(invalid, 10.0, -10.0).and_raise_error(Puppet::ParseError, /to be a Numeric/) }
13-
it { is_expected.to run.with_params([0, 1, 2, invalid, 3, 4], 10.0, -10.0).and_raise_error(Puppet::ParseError, /to be a Numeric/) }
13+
end
14+
15+
context 'when running on modern rubies', :unless => RUBY_VERSION == '1.8.7' do
16+
it { is_expected.to run.with_params([0, 1, 2, {1=>2}, 3, 4], 10, -10).and_raise_error(Puppet::ParseError, /to be a Numeric/) }
17+
end
18+
19+
context 'when running on ruby, which munges hashes weirdly', :if => RUBY_VERSION == '1.8.7' do
20+
it { is_expected.to run.with_params([0, 1, 2, {1=>2}, 3, 4], 10, -10).and_raise_error(Puppet::ParseError) }
21+
it { is_expected.to run.with_params([0, 1, 2, {0=>2}, 3, 4], 10, -10).and_raise_error(Puppet::ParseError) }
1422
end
1523

1624
it { is_expected.to run.with_params(1, '').and_raise_error(Puppet::ParseError, /to be unset or a Numeric/) }

0 commit comments

Comments
 (0)