source: other-projects/hathitrust/vagrant-hadoop-cluster/trunk/modules/stdlib/spec/functions/values_at_spec.rb@ 30903

Last change on this file since 30903 was 30903, checked in by davidb, 7 years ago

Vagrant provisioning files for a 4-node Hadoop cluster. See README.txt for more details

  • Property svn:executable set to *
File size: 3.1 KB
Line 
1require 'spec_helper'
2
3describe 'values_at' do
4 describe 'signature validation' do
5 it { is_expected.not_to eq(nil) }
6 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([]).and_raise_error(Puppet::ParseError, /wrong number of arguments/i) }
8 it {
9 pending("Current implementation ignores parameters after the first two.")
10 is_expected.to run.with_params([], 0, 1).and_raise_error(Puppet::ParseError, /wrong number of arguments/i)
11 }
12 it { is_expected.to run.with_params('', 1).and_raise_error(Puppet::ParseError, /Requires array/i) }
13 it { is_expected.to run.with_params({}, 1).and_raise_error(Puppet::ParseError, /Requires array/i) }
14 it { is_expected.to run.with_params(true, 1).and_raise_error(Puppet::ParseError, /Requires array/i) }
15 it { is_expected.to run.with_params(1, 1).and_raise_error(Puppet::ParseError, /Requires array/i) }
16 it { is_expected.to run.with_params([0,1,2], 'two').and_raise_error(Puppet::ParseError, /Unknown format of given index/) }
17 it { is_expected.to run.with_params([0,1,2], []).and_raise_error(Puppet::ParseError, /provide at least one positive index/) }
18 it { is_expected.to run.with_params([0,1,2], '-1-1').and_raise_error(Puppet::ParseError, /Unknown format of given index/) }
19 it { is_expected.to run.with_params([0,1,2], '2-1').and_raise_error(Puppet::ParseError, /Stop index in given indices range is smaller than the start index/) }
20 end
21
22 context 'when requesting a single item' do
23 it { is_expected.to run.with_params([0, 1, 2], -1).and_raise_error(Puppet::ParseError, /Unknown format of given index/) }
24 it { is_expected.to run.with_params([0, 1, 2], 0).and_return([0]) }
25 it { is_expected.to run.with_params([0, 1, 2], 1).and_return([1]) }
26 it { is_expected.to run.with_params([0, 1, 2], [1]).and_return([1]) }
27 it { is_expected.to run.with_params([0, 1, 2], '1').and_return([1]) }
28 it { is_expected.to run.with_params([0, 1, 2], '1-1').and_return([1]) }
29 it { is_expected.to run.with_params([0, 1, 2], 2).and_return([2]) }
30 it { is_expected.to run.with_params([0, 1, 2], 3).and_raise_error(Puppet::ParseError, /index exceeds array size/) }
31 end
32
33 context 'when requesting multiple items' do
34 it { is_expected.to run.with_params([0, 1, 2], [1, -1]).and_raise_error(Puppet::ParseError, /Unknown format of given index/) }
35 it { is_expected.to run.with_params([0, 1, 2], [0, 2]).and_return([0, 2]) }
36 it { is_expected.to run.with_params([0, 1, 2], ['0-2', 1, 2]).and_return([0, 1, 2, 1, 2]) }
37 it { is_expected.to run.with_params([0, 1, 2], [3, 2]).and_raise_error(Puppet::ParseError, /index exceeds array size/) }
38
39 describe 'different range syntaxes' do
40 it { is_expected.to run.with_params([0, 1, 2], '0-2').and_return([0, 1, 2]) }
41 it { is_expected.to run.with_params([0, 1, 2], '0..2').and_return([0, 1, 2]) }
42 it { is_expected.to run.with_params([0, 1, 2], '0...2').and_return([0, 1]) }
43 it {
44 pending('fix this bounds check')
45 is_expected.to run.with_params([0, 1, 2], '0...3').and_return([0, 1, 2])
46 }
47 end
48 end
49end
Note: See TracBrowser for help on using the repository browser.