1 #! /usr/bin/env ruby -S rspec
2 require 'spec_helper_acceptance'
4 describe 'values_at function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do
6 it 'returns a specific value' do
8 $one = ['a','b','c','d','e']
10 $output = values_at($one,$two)
11 notice(inline_template('<%= @output.inspect %>'))
14 expect(apply_manifest(pp, :catch_failures => true).stdout).to match(/\["b"\]/)
16 it 'returns a specific negative index value' do
17 pending("negative numbers don't work")
19 $one = ['a','b','c','d','e']
21 $output = values_at($one,$two)
22 notice(inline_template('<%= @output.inspect %>'))
25 expect(apply_manifest(pp, :catch_failures => true).stdout).to match(/\["e"\]/)
27 it 'returns a range of values' do
29 $one = ['a','b','c','d','e']
31 $output = values_at($one,$two)
32 notice(inline_template('<%= @output.inspect %>'))
35 expect(apply_manifest(pp, :catch_failures => true).stdout).to match(/\["b", "c", "d"\]/)
37 it 'returns a negative specific value and range of values' do
39 $one = ['a','b','c','d','e']
41 $output = values_at($one,$two)
42 notice(inline_template('<%= @output.inspect %>'))
45 expect(apply_manifest(pp, :catch_failures => true).stdout).to match(/\["b", "c", "d", "a"\]/)
49 it 'handles improper number of arguments' do
51 $one = ['a','b','c','d','e']
52 $output = values_at($one)
53 notice(inline_template('<%= @output.inspect %>'))
56 expect(apply_manifest(pp, :expect_failures => true).stderr).to match(/Wrong number of arguments/)
58 it 'handles non-indicies arguments' do
60 $one = ['a','b','c','d','e']
62 $output = values_at($one,$two)
63 notice(inline_template('<%= @output.inspect %>'))
66 expect(apply_manifest(pp, :expect_failures => true).stderr).to match(/at least one positive index/)
69 it 'detects index ranges smaller than the start range'
70 it 'handles index ranges larger than array'
71 it 'handles non-integer indicies'