summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
Diffstat (limited to 'spec')
-rwxr-xr-xspec/acceptance/abs_spec.rb30
-rwxr-xr-xspec/acceptance/any2array_spec.rb49
-rwxr-xr-xspec/acceptance/base64_spec.rb18
-rwxr-xr-xspec/acceptance/bool2num_spec.rb34
-rwxr-xr-xspec/acceptance/build_csv.rb83
-rwxr-xr-xspec/acceptance/capitalize_spec.rb33
-rwxr-xr-xspec/acceptance/chomp_spec.rb21
-rwxr-xr-xspec/acceptance/chop_spec.rb45
-rwxr-xr-xspec/acceptance/concat_spec.rb40
-rwxr-xr-xspec/acceptance/count_spec.rb30
-rwxr-xr-xspec/acceptance/deep_merge_spec.rb20
-rwxr-xr-xspec/acceptance/defined_with_params_spec.rb22
-rwxr-xr-xspec/acceptance/delete_at_spec.rb19
-rwxr-xr-xspec/acceptance/delete_spec.rb19
-rwxr-xr-xspec/acceptance/delete_undef_values_spec.rb19
-rwxr-xr-xspec/acceptance/delete_values_spec.rb25
-rwxr-xr-xspec/acceptance/difference_spec.rb26
-rwxr-xr-xspec/acceptance/dirname_spec.rb42
-rwxr-xr-xspec/acceptance/downcase_spec.rb39
-rwxr-xr-xspec/acceptance/empty_spec.rb39
-rwxr-xr-xspec/acceptance/ensure_packages_spec.rb22
-rwxr-xr-xspec/acceptance/ensure_resource_spec.rb22
-rwxr-xr-xspec/acceptance/flatten_spec.rb39
-rwxr-xr-xspec/acceptance/floor_spec.rb39
-rwxr-xr-xspec/acceptance/fqdn_rotate_spec.rb47
-rwxr-xr-xspec/acceptance/get_module_path_spec.rb27
-rwxr-xr-xspec/acceptance/getparam_spec.rb24
-rwxr-xr-xspec/acceptance/getvar_spec.rb26
-rwxr-xr-xspec/acceptance/grep_spec.rb26
-rwxr-xr-xspec/acceptance/has_interface_with_spec.rb54
-rwxr-xr-xspec/acceptance/has_ip_address_spec.rb33
-rwxr-xr-xspec/acceptance/has_ip_network_spec.rb33
-rwxr-xr-xspec/acceptance/has_key_spec.rb41
-rwxr-xr-xspec/acceptance/hash_spec.rb26
-rwxr-xr-xspec/acceptance/intersection_spec.rb27
-rwxr-xr-xspec/acceptance/is_array_spec.rb67
-rwxr-xr-xspec/acceptance/is_bool_spec.rb81
-rwxr-xr-xspec/acceptance/is_domain_name_spec.rb83
-rwxr-xr-xspec/acceptance/is_float_spec.rb86
-rwxr-xr-xspec/acceptance/is_function_available_spec.rb58
-rwxr-xr-xspec/acceptance/is_hash_spec.rb63
-rwxr-xr-xspec/acceptance/is_integer_spec.rb95
-rwxr-xr-xspec/acceptance/is_ip_address_spec.rb80
-rwxr-xr-xspec/acceptance/is_mac_address_spec.rb38
-rwxr-xr-xspec/acceptance/is_numeric_spec.rb95
-rwxr-xr-xspec/acceptance/is_string_spec.rb102
-rwxr-xr-xspec/acceptance/join_keys_to_values_spec.rb24
-rwxr-xr-xspec/acceptance/join_spec.rb26
-rwxr-xr-xspec/acceptance/keys_spec.rb23
-rw-r--r--spec/acceptance/loadyaml_spec.rb33
-rwxr-xr-xspec/acceptance/lstrip_spec.rb34
-rwxr-xr-xspec/acceptance/max_spec.rb20
-rwxr-xr-xspec/acceptance/member_spec.rb54
-rwxr-xr-xspec/acceptance/merge_spec.rb23
-rwxr-xr-xspec/acceptance/min_spec.rb20
-rw-r--r--spec/acceptance/nodesets/centos-59-x64.yml10
-rw-r--r--spec/acceptance/nodesets/centos-6-vcloud.yml15
-rw-r--r--spec/acceptance/nodesets/centos-64-x64-pe.yml12
-rw-r--r--spec/acceptance/nodesets/centos-64-x64.yml10
-rw-r--r--spec/acceptance/nodesets/centos-65-x64.yml10
-rw-r--r--spec/acceptance/nodesets/default.yml10
-rw-r--r--spec/acceptance/nodesets/fedora-18-x64.yml10
-rw-r--r--spec/acceptance/nodesets/sles-11-x64.yml10
-rw-r--r--spec/acceptance/nodesets/ubuntu-server-10044-x64.yml10
-rw-r--r--spec/acceptance/nodesets/ubuntu-server-12042-x64.yml10
-rw-r--r--spec/acceptance/nodesets/ubuntu-server-1404-x64.yml11
-rw-r--r--spec/acceptance/nodesets/windows-2003-i386.yml26
-rw-r--r--spec/acceptance/nodesets/windows-2003-x86_64.yml26
-rw-r--r--spec/acceptance/nodesets/windows-2008-x86_64.yml26
-rw-r--r--spec/acceptance/nodesets/windows-2008r2-x86_64.yml26
-rw-r--r--spec/acceptance/nodesets/windows-2012-x86_64.yml26
-rw-r--r--spec/acceptance/nodesets/windows-2012r2-x86_64.yml26
-rwxr-xr-xspec/acceptance/num2bool_spec.rb76
-rwxr-xr-xspec/acceptance/parsejson_spec.rb34
-rwxr-xr-xspec/acceptance/parseyaml_spec.rb35
-rwxr-xr-xspec/acceptance/pick_default_spec.rb54
-rwxr-xr-xspec/acceptance/pick_spec.rb44
-rwxr-xr-xspec/acceptance/prefix_spec.rb42
-rwxr-xr-xspec/acceptance/range_spec.rb36
-rwxr-xr-xspec/acceptance/reject_spec.rb42
-rwxr-xr-xspec/acceptance/reverse_spec.rb23
-rwxr-xr-xspec/acceptance/rstrip_spec.rb34
-rwxr-xr-xspec/acceptance/shuffle_spec.rb34
-rwxr-xr-xspec/acceptance/size_spec.rb55
-rwxr-xr-xspec/acceptance/sort_spec.rb34
-rwxr-xr-xspec/acceptance/squeeze_spec.rb47
-rwxr-xr-xspec/acceptance/str2bool_spec.rb31
-rwxr-xr-xspec/acceptance/str2saltedsha512_spec.rb22
-rwxr-xr-xspec/acceptance/strftime_spec.rb22
-rwxr-xr-xspec/acceptance/strip_spec.rb34
-rwxr-xr-xspec/acceptance/suffix_spec.rb42
-rwxr-xr-xspec/acceptance/swapcase_spec.rb22
-rwxr-xr-xspec/acceptance/time_spec.rb36
-rwxr-xr-xspec/acceptance/to_bytes_spec.rb27
-rwxr-xr-xspec/acceptance/type_spec.rb37
-rwxr-xr-xspec/acceptance/union_spec.rb24
-rwxr-xr-xspec/acceptance/unique_spec.rb33
-rwxr-xr-xspec/acceptance/unsupported_spec.rb11
-rwxr-xr-xspec/acceptance/upcase_spec.rb33
-rwxr-xr-xspec/acceptance/uriescape_spec.rb23
-rwxr-xr-xspec/acceptance/validate_absolute_path_spec.rb31
-rwxr-xr-xspec/acceptance/validate_array_spec.rb37
-rwxr-xr-xspec/acceptance/validate_augeas_spec.rb63
-rwxr-xr-xspec/acceptance/validate_bool_spec.rb37
-rwxr-xr-xspec/acceptance/validate_cmd_spec.rb52
-rwxr-xr-xspec/acceptance/validate_hash_spec.rb37
-rwxr-xr-xspec/acceptance/validate_ipv4_address_spec.rb31
-rwxr-xr-xspec/acceptance/validate_ipv6_address_spec.rb31
-rwxr-xr-xspec/acceptance/validate_re_spec.rb47
-rwxr-xr-xspec/acceptance/validate_slength_spec.rb72
-rwxr-xr-xspec/acceptance/validate_string_spec.rb36
-rwxr-xr-xspec/acceptance/values_at_spec.rb73
-rwxr-xr-xspec/acceptance/values_spec.rb35
-rwxr-xr-xspec/acceptance/zip_spec.rb86
-rwxr-xr-x[-rw-r--r--]spec/classes/anchor_spec.rb40
-rw-r--r--spec/fixtures/dscacheutil/root8
-rwxr-xr-xspec/functions/abs_spec.rb (renamed from spec/unit/puppet/parser/functions/abs_spec.rb)8
-rwxr-xr-x[-rw-r--r--]spec/functions/any2array_spec.rb (renamed from spec/unit/puppet/parser/functions/any2array_spec.rb)20
-rwxr-xr-xspec/functions/base64_spec.rb (renamed from spec/unit/puppet/parser/functions/base64_spec.rb)6
-rwxr-xr-xspec/functions/bool2num_spec.rb38
-rwxr-xr-xspec/functions/capitalize_spec.rb28
-rwxr-xr-xspec/functions/chomp_spec.rb (renamed from spec/unit/puppet/parser/functions/chomp_spec.rb)13
-rwxr-xr-xspec/functions/chop_spec.rb28
-rwxr-xr-xspec/functions/concat_spec.rb50
-rwxr-xr-x[-rw-r--r--]spec/functions/count_spec.rb (renamed from spec/unit/puppet/parser/functions/count_spec.rb)10
-rwxr-xr-xspec/functions/deep_merge_spec.rb105
-rwxr-xr-x[-rw-r--r--]spec/functions/defined_with_params_spec.rb18
-rwxr-xr-xspec/functions/delete_at_spec.rb25
-rwxr-xr-xspec/functions/delete_spec.rb61
-rwxr-xr-xspec/functions/delete_undef_values_spec.rb41
-rwxr-xr-xspec/functions/delete_values_spec.rb36
-rwxr-xr-x[-rw-r--r--]spec/functions/difference_spec.rb (renamed from spec/unit/puppet/parser/functions/difference_spec.rb)6
-rwxr-xr-xspec/functions/dirname_spec.rb (renamed from spec/unit/puppet/parser/functions/dirname_spec.rb)8
-rwxr-xr-xspec/functions/downcase_spec.rb (renamed from spec/unit/puppet/parser/functions/downcase_spec.rb)17
-rwxr-xr-xspec/functions/empty_spec.rb (renamed from spec/unit/puppet/parser/functions/empty_spec.rb)17
-rwxr-xr-x[-rw-r--r--]spec/functions/ensure_packages_spec.rb73
-rwxr-xr-x[-rw-r--r--]spec/functions/ensure_resource_spec.rb123
-rwxr-xr-xspec/functions/flatten_spec.rb (renamed from spec/unit/puppet/parser/functions/flatten_spec.rb)10
-rwxr-xr-x[-rw-r--r--]spec/functions/floor_spec.rb (renamed from spec/unit/puppet/parser/functions/floor_spec.rb)14
-rwxr-xr-x[-rw-r--r--]spec/functions/fqdn_rotate_spec.rb (renamed from spec/unit/puppet/parser/functions/fqdn_rotate_spec.rb)20
-rwxr-xr-x[-rw-r--r--]spec/functions/get_module_path_spec.rb (renamed from spec/unit/puppet/parser/functions/get_module_path_spec.rb)8
-rwxr-xr-x[-rw-r--r--]spec/functions/getparam_spec.rb74
-rwxr-xr-x[-rw-r--r--]spec/functions/getvar_spec.rb (renamed from spec/unit/puppet/parser/functions/getvar_spec.rb)6
-rwxr-xr-xspec/functions/grep_spec.rb (renamed from spec/unit/puppet/parser/functions/grep_spec.rb)6
-rwxr-xr-xspec/functions/has_interface_with_spec.rb (renamed from spec/unit/puppet/parser/functions/has_interface_with_spec.rb)20
-rwxr-xr-xspec/functions/has_ip_address_spec.rb (renamed from spec/unit/puppet/parser/functions/has_ip_address_spec.rb)8
-rwxr-xr-xspec/functions/has_ip_network_spec.rb (renamed from spec/unit/puppet/parser/functions/has_ip_network_spec.rb)6
-rwxr-xr-x[-rw-r--r--]spec/functions/has_key_spec.rb (renamed from spec/unit/puppet/parser/functions/has_key_spec.rb)10
-rwxr-xr-x[-rw-r--r--]spec/functions/hash_spec.rb (renamed from spec/unit/puppet/parser/functions/hash_spec.rb)6
-rwxr-xr-x[-rw-r--r--]spec/functions/intersection_spec.rb (renamed from spec/unit/puppet/parser/functions/intersection_spec.rb)6
-rwxr-xr-x[-rw-r--r--]spec/functions/is_array_spec.rb (renamed from spec/unit/puppet/parser/functions/is_array_spec.rb)10
-rwxr-xr-xspec/functions/is_bool_spec.rb44
-rwxr-xr-x[-rw-r--r--]spec/functions/is_domain_name_spec.rb (renamed from spec/unit/puppet/parser/functions/is_domain_name_spec.rb)24
-rwxr-xr-x[-rw-r--r--]spec/functions/is_float_spec.rb (renamed from spec/unit/puppet/parser/functions/is_float_spec.rb)12
-rwxr-xr-x[-rw-r--r--]spec/functions/is_function_available.rb (renamed from spec/unit/puppet/parser/functions/is_function_available.rb)10
-rwxr-xr-x[-rw-r--r--]spec/functions/is_hash_spec.rb (renamed from spec/unit/puppet/parser/functions/is_hash_spec.rb)10
-rwxr-xr-xspec/functions/is_integer_spec.rb69
-rwxr-xr-x[-rw-r--r--]spec/functions/is_ip_address_spec.rb (renamed from spec/unit/puppet/parser/functions/is_ip_address_spec.rb)14
-rwxr-xr-x[-rw-r--r--]spec/functions/is_mac_address_spec.rb (renamed from spec/unit/puppet/parser/functions/is_mac_address_spec.rb)10
-rwxr-xr-xspec/functions/is_numeric_spec.rb119
-rwxr-xr-x[-rw-r--r--]spec/functions/is_string_spec.rb (renamed from spec/unit/puppet/parser/functions/is_string_spec.rb)12
-rwxr-xr-x[-rw-r--r--]spec/functions/join_keys_to_values_spec.rb (renamed from spec/unit/puppet/parser/functions/join_keys_to_values_spec.rb)16
-rwxr-xr-x[-rw-r--r--]spec/functions/join_spec.rb (renamed from spec/unit/puppet/parser/functions/join_spec.rb)6
-rwxr-xr-x[-rw-r--r--]spec/functions/keys_spec.rb (renamed from spec/unit/puppet/parser/functions/keys_spec.rb)6
-rwxr-xr-xspec/functions/loadyaml_spec.rb25
-rwxr-xr-xspec/functions/lstrip_spec.rb28
-rwxr-xr-xspec/functions/max_spec.rb (renamed from spec/unit/puppet/parser/functions/max_spec.rb)10
-rwxr-xr-xspec/functions/member_spec.rb34
-rwxr-xr-x[-rw-r--r--]spec/functions/merge_spec.rb (renamed from spec/unit/puppet/parser/functions/merge_spec.rb)16
-rwxr-xr-xspec/functions/min_spec.rb (renamed from spec/unit/puppet/parser/functions/min_spec.rb)10
-rwxr-xr-x[-rw-r--r--]spec/functions/num2bool_spec.rb (renamed from spec/unit/puppet/parser/functions/num2bool_spec.rb)26
-rwxr-xr-x[-rw-r--r--]spec/functions/parsejson_spec.rb (renamed from spec/unit/puppet/parser/functions/parsejson_spec.rb)6
-rwxr-xr-x[-rw-r--r--]spec/functions/parseyaml_spec.rb (renamed from spec/unit/puppet/parser/functions/parseyaml_spec.rb)6
-rwxr-xr-xspec/functions/pick_default_spec.rb58
-rwxr-xr-xspec/functions/pick_spec.rb34
-rwxr-xr-xspec/functions/prefix_spec.rb28
-rwxr-xr-xspec/functions/private_spec.rb55
-rwxr-xr-x[-rw-r--r--]spec/functions/range_spec.rb (renamed from spec/unit/puppet/parser/functions/range_spec.rb)38
-rwxr-xr-xspec/functions/reject_spec.rb (renamed from spec/unit/puppet/parser/functions/reject_spec.rb)6
-rwxr-xr-xspec/functions/reverse_spec.rb28
-rwxr-xr-x[-rw-r--r--]spec/functions/rstrip_spec.rb (renamed from spec/unit/puppet/parser/functions/rstrip_spec.rb)17
-rwxr-xr-x[-rw-r--r--]spec/functions/shuffle_spec.rb (renamed from spec/unit/puppet/parser/functions/shuffle_spec.rb)17
-rwxr-xr-x[-rw-r--r--]spec/functions/size_spec.rb (renamed from spec/unit/puppet/parser/functions/size_spec.rb)8
-rwxr-xr-x[-rw-r--r--]spec/functions/sort_spec.rb (renamed from spec/unit/puppet/parser/functions/sort_spec.rb)8
-rwxr-xr-x[-rw-r--r--]spec/functions/squeeze_spec.rb (renamed from spec/unit/puppet/parser/functions/squeeze_spec.rb)8
-rwxr-xr-x[-rw-r--r--]spec/functions/str2bool_spec.rb (renamed from spec/unit/puppet/parser/functions/str2bool_spec.rb)14
-rwxr-xr-x[-rw-r--r--]spec/functions/str2saltedsha512_spec.rb (renamed from spec/unit/puppet/parser/functions/str2saltedsha512_spec.rb)6
-rwxr-xr-x[-rw-r--r--]spec/functions/strftime_spec.rb (renamed from spec/unit/puppet/parser/functions/strftime_spec.rb)10
-rwxr-xr-xspec/functions/strip_spec.rb27
-rwxr-xr-xspec/functions/suffix_spec.rb27
-rwxr-xr-xspec/functions/swapcase_spec.rb28
-rwxr-xr-x[-rw-r--r--]spec/functions/time_spec.rb (renamed from spec/unit/puppet/parser/functions/time_spec.rb)10
-rwxr-xr-xspec/functions/to_bytes_spec.rb83
-rw-r--r--spec/functions/type3x_spec.rb43
-rwxr-xr-x[-rw-r--r--]spec/functions/type_spec.rb (renamed from spec/unit/puppet/parser/functions/type_spec.rb)19
-rwxr-xr-x[-rw-r--r--]spec/functions/union_spec.rb (renamed from spec/unit/puppet/parser/functions/union_spec.rb)6
-rwxr-xr-x[-rw-r--r--]spec/functions/unique_spec.rb (renamed from spec/unit/puppet/parser/functions/unique_spec.rb)17
-rwxr-xr-x[-rw-r--r--]spec/functions/upcase_spec.rb (renamed from spec/unit/puppet/parser/functions/upcase_spec.rb)15
-rwxr-xr-x[-rw-r--r--]spec/functions/uriescape_spec.rb (renamed from spec/unit/puppet/parser/functions/uriescape_spec.rb)17
-rwxr-xr-x[-rw-r--r--]spec/functions/validate_absolute_path_spec.rb (renamed from spec/unit/puppet/parser/functions/validate_absolute_path_spec.rb)43
-rwxr-xr-x[-rw-r--r--]spec/functions/validate_array_spec.rb (renamed from spec/unit/puppet/parser/functions/validate_array_spec.rb)0
-rwxr-xr-x[-rw-r--r--]spec/functions/validate_augeas_spec.rb (renamed from spec/unit/puppet/parser/functions/validate_augeas_spec.rb)1
-rwxr-xr-x[-rw-r--r--]spec/functions/validate_bool_spec.rb (renamed from spec/unit/puppet/parser/functions/validate_bool_spec.rb)2
-rwxr-xr-xspec/functions/validate_cmd_spec.rb85
-rwxr-xr-x[-rw-r--r--]spec/functions/validate_hash_spec.rb (renamed from spec/unit/puppet/parser/functions/validate_hash_spec.rb)0
-rwxr-xr-x[-rw-r--r--]spec/functions/validate_ipv4_address_spec.rb (renamed from spec/unit/puppet/parser/functions/validate_ipv4_address_spec.rb)2
-rwxr-xr-x[-rw-r--r--]spec/functions/validate_ipv6_address_spec.rb (renamed from spec/unit/puppet/parser/functions/validate_ipv6_address_spec.rb)2
-rwxr-xr-x[-rw-r--r--]spec/functions/validate_re_spec.rb (renamed from spec/unit/puppet/parser/functions/validate_re_spec.rb)1
-rwxr-xr-xspec/functions/validate_slength_spec.rb (renamed from spec/unit/puppet/parser/functions/validate_slength_spec.rb)2
-rwxr-xr-x[-rw-r--r--]spec/functions/validate_string_spec.rb (renamed from spec/unit/puppet/parser/functions/validate_string_spec.rb)0
-rwxr-xr-x[-rw-r--r--]spec/functions/values_at_spec.rb (renamed from spec/unit/puppet/parser/functions/values_at_spec.rb)14
-rwxr-xr-x[-rw-r--r--]spec/functions/values_spec.rb (renamed from spec/unit/puppet/parser/functions/values_spec.rb)12
-rwxr-xr-xspec/functions/zip_spec.rb31
-rwxr-xr-xspec/lib/puppet_spec/compiler.rb47
-rwxr-xr-xspec/lib/puppet_spec/database.rb30
-rwxr-xr-xspec/lib/puppet_spec/files.rb61
-rwxr-xr-xspec/lib/puppet_spec/fixtures.rb29
-rwxr-xr-xspec/lib/puppet_spec/matchers.rb121
-rwxr-xr-xspec/lib/puppet_spec/modules.rb27
-rwxr-xr-xspec/lib/puppet_spec/pops.rb17
-rwxr-xr-xspec/lib/puppet_spec/scope.rb15
-rwxr-xr-xspec/lib/puppet_spec/settings.rb16
-rwxr-xr-xspec/lib/puppet_spec/verbose.rb10
-rwxr-xr-xspec/monkey_patches/alias_should_to_must.rb1
-rwxr-xr-xspec/monkey_patches/publicize_methods.rb1
-rwxr-xr-x[-rw-r--r--]spec/spec_helper.rb26
-rwxr-xr-xspec/spec_helper_acceptance.rb50
-rwxr-xr-xspec/unit/facter/facter_dot_d_spec.rb32
-rw-r--r--spec/unit/facter/pe_required_facts_spec.rb69
-rwxr-xr-x[-rw-r--r--]spec/unit/facter/pe_version_spec.rb20
-rwxr-xr-x[-rw-r--r--]spec/unit/facter/root_home_spec.rb36
-rwxr-xr-x[-rw-r--r--]spec/unit/facter/util/puppet_settings_spec.rb7
-rw-r--r--spec/unit/puppet/functions/type_of_spec.rb33
-rwxr-xr-xspec/unit/puppet/parser/functions/basename_spec.rb46
-rwxr-xr-xspec/unit/puppet/parser/functions/bool2num_spec.rb24
-rwxr-xr-xspec/unit/puppet/parser/functions/bool2str_spec.rb46
-rwxr-xr-xspec/unit/puppet/parser/functions/camelcase_spec.rb24
-rwxr-xr-xspec/unit/puppet/parser/functions/capitalize_spec.rb19
-rwxr-xr-xspec/unit/puppet/parser/functions/chop_spec.rb19
-rw-r--r--spec/unit/puppet/parser/functions/concat_spec.rb15
-rwxr-xr-xspec/unit/puppet/parser/functions/delete_at_spec.rb19
-rwxr-xr-xspec/unit/puppet/parser/functions/delete_spec.rb38
-rw-r--r--spec/unit/puppet/parser/functions/delete_undef_values_spec.rb29
-rw-r--r--spec/unit/puppet/parser/functions/delete_values_spec.rb30
-rw-r--r--spec/unit/puppet/parser/functions/is_integer_spec.rb34
-rw-r--r--spec/unit/puppet/parser/functions/is_numeric_spec.rb39
-rw-r--r--spec/unit/puppet/parser/functions/lstrip_spec.rb19
-rw-r--r--spec/unit/puppet/parser/functions/member_spec.rb24
-rw-r--r--spec/unit/puppet/parser/functions/pick_spec.rb34
-rw-r--r--spec/unit/puppet/parser/functions/prefix_spec.rb19
-rw-r--r--spec/unit/puppet/parser/functions/reverse_spec.rb19
-rw-r--r--spec/unit/puppet/parser/functions/strip_spec.rb18
-rw-r--r--spec/unit/puppet/parser/functions/suffix_spec.rb19
-rw-r--r--spec/unit/puppet/parser/functions/swapcase_spec.rb19
-rwxr-xr-xspec/unit/puppet/parser/functions/to_bytes_spec.rb58
-rw-r--r--spec/unit/puppet/parser/functions/validate_cmd_spec.rb81
-rw-r--r--spec/unit/puppet/parser/functions/zip_spec.rb15
-rwxr-xr-x[-rw-r--r--]spec/unit/puppet/provider/file_line/ruby_spec.rb203
-rwxr-xr-x[-rw-r--r--]spec/unit/puppet/type/anchor_spec.rb4
-rwxr-xr-x[-rw-r--r--]spec/unit/puppet/type/file_line_spec.rb21
-rw-r--r--spec/watchr.rb86
261 files changed, 6897 insertions, 1263 deletions
diff --git a/spec/acceptance/abs_spec.rb b/spec/acceptance/abs_spec.rb
new file mode 100755
index 0000000..6e41e2f
--- /dev/null
+++ b/spec/acceptance/abs_spec.rb
@@ -0,0 +1,30 @@
+#! /usr/bin/env ruby -S rspec
+require 'spec_helper_acceptance'
+
+describe 'abs function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do
+ describe 'success' do
+ it 'should accept a string' do
+ pp = <<-EOS
+ $input = '-34.56'
+ $output = abs($input)
+ notify { "$output": }
+ EOS
+
+ apply_manifest(pp, :catch_failures => true) do |r|
+ expect(r.stdout).to match(/Notice: 34.56/)
+ end
+ end
+
+ it 'should accept a float' do
+ pp = <<-EOS
+ $input = -34.56
+ $output = abs($input)
+ notify { "$output": }
+ EOS
+
+ apply_manifest(pp, :catch_failures => true) do |r|
+ expect(r.stdout).to match(/Notice: 34.56/)
+ end
+ end
+ end
+end
diff --git a/spec/acceptance/any2array_spec.rb b/spec/acceptance/any2array_spec.rb
new file mode 100755
index 0000000..18ea4cd
--- /dev/null
+++ b/spec/acceptance/any2array_spec.rb
@@ -0,0 +1,49 @@
+#! /usr/bin/env ruby -S rspec
+require 'spec_helper_acceptance'
+
+describe 'any2array function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do
+ describe 'success' do
+ it 'should create an empty array' do
+ pp = <<-EOS
+ $input = ''
+ $output = any2array($input)
+ validate_array($output)
+ notify { "Output: ${output}": }
+ EOS
+
+ apply_manifest(pp, :catch_failures => true) do |r|
+ expect(r.stdout).to match(/Notice: Output: /)
+ end
+ end
+
+ it 'should leave arrays modified' do
+ pp = <<-EOS
+ $input = ['test', 'array']
+ $output = any2array($input)
+ validate_array($output)
+ notify { "Output: ${output}": }
+ EOS
+
+ apply_manifest(pp, :catch_failures => true) do |r|
+ expect(r.stdout).to match(/Notice: Output: (\[|)test(,\s|)array(\]|)/)
+ end
+ end
+
+ it 'should turn a hash into an array' do
+ pp = <<-EOS
+ $input = {'test' => 'array'}
+ $output = any2array($input)
+
+ validate_array($output)
+ # Check each element of the array is a plain string.
+ validate_string($output[0])
+ validate_string($output[1])
+ notify { "Output: ${output}": }
+ EOS
+
+ apply_manifest(pp, :catch_failures => true) do |r|
+ expect(r.stdout).to match(/Notice: Output: (\[|)test(,\s|)array(\]|)/)
+ end
+ end
+ end
+end
diff --git a/spec/acceptance/base64_spec.rb b/spec/acceptance/base64_spec.rb
new file mode 100755
index 0000000..97e1738
--- /dev/null
+++ b/spec/acceptance/base64_spec.rb
@@ -0,0 +1,18 @@
+#! /usr/bin/env ruby -S rspec
+require 'spec_helper_acceptance'
+
+describe 'base64 function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do
+ describe 'success' do
+ it 'should encode then decode a string' do
+ pp = <<-EOS
+ $encodestring = base64('encode', 'thestring')
+ $decodestring = base64('decode', $encodestring)
+ notify { $decodestring: }
+ EOS
+
+ apply_manifest(pp, :catch_failures => true) do |r|
+ expect(r.stdout).to match(/thestring/)
+ end
+ end
+ end
+end
diff --git a/spec/acceptance/bool2num_spec.rb b/spec/acceptance/bool2num_spec.rb
new file mode 100755
index 0000000..52ff75b
--- /dev/null
+++ b/spec/acceptance/bool2num_spec.rb
@@ -0,0 +1,34 @@
+#! /usr/bin/env ruby -S rspec
+require 'spec_helper_acceptance'
+
+describe 'bool2num function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do
+ describe 'success' do
+ ['false', 'f', '0', 'n', 'no'].each do |bool|
+ it "should convert a given boolean, #{bool}, to 0" do
+ pp = <<-EOS
+ $input = "#{bool}"
+ $output = bool2num($input)
+ notify { "$output": }
+ EOS
+
+ apply_manifest(pp, :catch_failures => true) do |r|
+ expect(r.stdout).to match(/Notice: 0/)
+ end
+ end
+ end
+
+ ['true', 't', '1', 'y', 'yes'].each do |bool|
+ it "should convert a given boolean, #{bool}, to 1" do
+ pp = <<-EOS
+ $input = "#{bool}"
+ $output = bool2num($input)
+ notify { "$output": }
+ EOS
+
+ apply_manifest(pp, :catch_failures => true) do |r|
+ expect(r.stdout).to match(/Notice: 1/)
+ end
+ end
+ end
+ end
+end
diff --git a/spec/acceptance/build_csv.rb b/spec/acceptance/build_csv.rb
new file mode 100755
index 0000000..62ecbf1
--- /dev/null
+++ b/spec/acceptance/build_csv.rb
@@ -0,0 +1,83 @@
+#!/usr/bin/env ruby
+# vim: set sw=2 sts=2 et tw=80 :
+require 'rspec'
+
+#XXX Super ugly hack to keep from starting beaker nodes
+module Kernel
+ # make an alias of the original require
+ alias_method :original_require, :require
+ # rewrite require
+ def require name
+ original_require name if name != 'spec_helper_acceptance'
+ end
+end
+UNSUPPORTED_PLATFORMS = []
+def fact(*args) [] end
+#XXX End hax
+
+# Get a list of functions for test coverage
+function_list = Dir[File.join(File.dirname(__FILE__),"..","..","lib","puppet","parser","functions","*.rb")].collect do |function_rb|
+ File.basename(function_rb,".rb")
+end
+
+## Configure rspec to parse tests
+options = RSpec::Core::ConfigurationOptions.new(['spec/acceptance'])
+configuration = RSpec::configuration
+world = RSpec::world
+options.parse_options
+options.configure(configuration)
+configuration.load_spec_files
+
+## Collect up tests and example groups into a hash
+def get_tests(children)
+ children.inject({}) do |memo,c|
+ memo[c.description] = Hash.new
+ memo[c.description]["groups"] = get_tests(c.children) unless c.children.empty?
+ memo[c.description]["tests"] = c.examples.collect { |e|
+ e.description unless e.pending?
+ }.compact unless c.examples.empty?
+ memo[c.description]["pending_tests"] = c.examples.collect { |e|
+ e.description if e.pending?
+ }.compact unless c.examples.empty?
+ memo
+ end
+end
+
+def count_test_types_in(type,group)
+ return 0 if group.nil?
+ group.inject(0) do |m,(k,v)|
+ m += v.length if k == type
+ m += count_tests_in(v) if v.is_a?(Hash)
+ m
+ end
+end
+def count_tests_in(group)
+ count_test_types_in('tests',group)
+end
+def count_pending_tests_in(group)
+ count_test_types_in('pending_tests',group)
+end
+
+# Convert tests hash to csv format
+def to_csv(function_list,tests)
+ function_list.collect do |function_name|
+ if v = tests["#{function_name} function"]
+ positive_tests = count_tests_in(v["groups"]["success"])
+ negative_tests = count_tests_in(v["groups"]["failure"])
+ pending_tests =
+ count_pending_tests_in(v["groups"]["failure"]) +
+ count_pending_tests_in(v["groups"]["failure"])
+ else
+ positive_tests = 0
+ negative_tests = 0
+ pending_tests = 0
+ end
+ sprintf("%-25s, %-9d, %-9d, %-9d", function_name,positive_tests,negative_tests,pending_tests)
+ end.compact
+end
+
+tests = get_tests(world.example_groups)
+csv = to_csv(function_list,tests)
+percentage_tested = "#{tests.count*100/function_list.count}%"
+printf("%-25s, %-9s, %-9s, %-9s\n","#{percentage_tested} have tests.","Positive","Negative","Pending")
+puts csv
diff --git a/spec/acceptance/capitalize_spec.rb b/spec/acceptance/capitalize_spec.rb
new file mode 100755
index 0000000..e5e7b7b
--- /dev/null
+++ b/spec/acceptance/capitalize_spec.rb
@@ -0,0 +1,33 @@
+#! /usr/bin/env ruby -S rspec
+require 'spec_helper_acceptance'
+
+describe 'capitalize function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do
+ describe 'success' do
+ it 'should capitalize the first letter of a string' do
+ pp = <<-EOS
+ $input = 'this is a string'
+ $output = capitalize($input)
+ notify { $output: }
+ EOS
+
+ apply_manifest(pp, :catch_failures => true) do |r|
+ expect(r.stdout).to match(/Notice: This is a string/)
+ end
+ end
+
+ it 'should capitalize the first letter of an array of strings' do
+ pp = <<-EOS
+ $input = ['this', 'is', 'a', 'string']
+ $output = capitalize($input)
+ notify { $output: }
+ EOS
+
+ apply_manifest(pp, :catch_failures => true) do |r|
+ expect(r.stdout).to match(/Notice: This/)
+ expect(r.stdout).to match(/Notice: Is/)
+ expect(r.stdout).to match(/Notice: A/)
+ expect(r.stdout).to match(/Notice: String/)
+ end
+ end
+ end
+end
diff --git a/spec/acceptance/chomp_spec.rb b/spec/acceptance/chomp_spec.rb
new file mode 100755
index 0000000..f6c1595
--- /dev/null
+++ b/spec/acceptance/chomp_spec.rb
@@ -0,0 +1,21 @@
+#! /usr/bin/env ruby -S rspec
+require 'spec_helper_acceptance'
+
+describe 'chomp function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do
+ describe 'success' do
+ it 'should eat the newline' do
+ pp = <<-EOS
+ $input = "test\n"
+ if size($input) != 5 {
+ fail("Size of ${input} is not 5.")
+ }
+ $output = chomp($input)
+ if size($output) != 4 {
+ fail("Size of ${input} is not 4.")
+ }
+ EOS
+
+ apply_manifest(pp, :catch_failures => true)
+ end
+ end
+end
diff --git a/spec/acceptance/chop_spec.rb b/spec/acceptance/chop_spec.rb
new file mode 100755
index 0000000..a16a710
--- /dev/null
+++ b/spec/acceptance/chop_spec.rb
@@ -0,0 +1,45 @@
+#! /usr/bin/env ruby -S rspec
+require 'spec_helper_acceptance'
+
+describe 'chop function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do
+ describe 'success' do
+ it 'should eat the last character' do
+ pp = <<-EOS
+ $input = "test"
+ if size($input) != 4 {
+ fail("Size of ${input} is not 4.")
+ }
+ $output = chop($input)
+ if size($output) != 3 {
+ fail("Size of ${input} is not 3.")
+ }
+ EOS
+
+ apply_manifest(pp, :catch_failures => true)
+ end
+
+ it 'should eat the last two characters of \r\n' do
+ pp = <<-'EOS'
+ $input = "test\r\n"
+ if size($input) != 6 {
+ fail("Size of ${input} is not 6.")
+ }
+ $output = chop($input)
+ if size($output) != 4 {
+ fail("Size of ${input} is not 4.")
+ }
+ EOS
+
+ apply_manifest(pp, :catch_failures => true)
+ end
+
+ it 'should not fail on empty strings' do
+ pp = <<-EOS
+ $input = ""
+ $output = chop($input)
+ EOS
+
+ apply_manifest(pp, :catch_failures => true)
+ end
+ end
+end
diff --git a/spec/acceptance/concat_spec.rb b/spec/acceptance/concat_spec.rb
new file mode 100755
index 0000000..06b649f
--- /dev/null
+++ b/spec/acceptance/concat_spec.rb
@@ -0,0 +1,40 @@
+#! /usr/bin/env ruby -S rspec
+require 'spec_helper_acceptance'
+
+describe 'concat function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do
+ describe 'success' do
+ it 'should concat one array to another' do
+ pp = <<-EOS
+ $output = concat(['1','2','3'],['4','5','6'])
+ validate_array($output)
+ if size($output) != 6 {
+ fail("${output} should have 6 elements.")
+ }
+ EOS
+
+ apply_manifest(pp, :catch_failures => true)
+ end
+ it 'should concat arrays and primitives to array' do
+ pp = <<-EOS
+ $output = concat(['1','2','3'],'4','5','6',['7','8','9'])
+ validate_array($output)
+ if size($output) != 9 {
+ fail("${output} should have 9 elements.")
+ }
+ EOS
+
+ apply_manifest(pp, :catch_failures => true)
+ end
+ it 'should concat multiple arrays to one' do
+ pp = <<-EOS
+ $output = concat(['1','2','3'],['4','5','6'],['7','8','9'])
+ validate_array($output)
+ if size($output) != 9 {
+ fail("${output} should have 9 elements.")
+ }
+ EOS
+
+ apply_manifest(pp, :catch_failures => true)
+ end
+ end
+end
diff --git a/spec/acceptance/count_spec.rb b/spec/acceptance/count_spec.rb
new file mode 100755
index 0000000..fe7ca9d
--- /dev/null
+++ b/spec/acceptance/count_spec.rb
@@ -0,0 +1,30 @@
+#! /usr/bin/env ruby -S rspec
+require 'spec_helper_acceptance'
+
+describe 'count function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do
+ describe 'success' do
+ it 'should count elements in an array' do
+ pp = <<-EOS
+ $input = [1,2,3,4]
+ $output = count($input)
+ notify { "$output": }
+ EOS
+
+ apply_manifest(pp, :catch_failures => true) do |r|
+ expect(r.stdout).to match(/Notice: 4/)
+ end
+ end
+
+ it 'should count elements in an array that match a second argument' do
+ pp = <<-EOS
+ $input = [1,1,1,2]
+ $output = count($input, 1)
+ notify { "$output": }
+ EOS
+
+ apply_manifest(pp, :catch_failures => true) do |r|
+ expect(r.stdout).to match(/Notice: 3/)
+ end
+ end
+ end
+end
diff --git a/spec/acceptance/deep_merge_spec.rb b/spec/acceptance/deep_merge_spec.rb
new file mode 100755
index 0000000..c0f9b12
--- /dev/null
+++ b/spec/acceptance/deep_merge_spec.rb
@@ -0,0 +1,20 @@
+#! /usr/bin/env ruby -S rspec
+require 'spec_helper_acceptance'
+
+describe 'deep_merge function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do
+ describe 'success' do
+ it 'should deep merge two hashes' do
+ pp = <<-EOS
+ $hash1 = {'one' => 1, 'two' => 2, 'three' => { 'four' => 4 } }
+ $hash2 = {'two' => 'dos', 'three' => { 'five' => 5 } }
+ $merged_hash = deep_merge($hash1, $hash2)
+
+ if $merged_hash != { 'one' => 1, 'two' => 'dos', 'three' => { 'four' => 4, 'five' => 5 } } {
+ fail("Hash was incorrectly merged.")
+ }
+ EOS
+
+ apply_manifest(pp, :catch_failures => true)
+ end
+ end
+end
diff --git a/spec/acceptance/defined_with_params_spec.rb b/spec/acceptance/defined_with_params_spec.rb
new file mode 100755
index 0000000..fc54450
--- /dev/null
+++ b/spec/acceptance/defined_with_params_spec.rb
@@ -0,0 +1,22 @@
+#! /usr/bin/env ruby -S rspec
+require 'spec_helper_acceptance'
+
+describe 'defined_with_params function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do
+ describe 'success' do
+ it 'should successfully notify' do
+ pp = <<-EOS
+ user { 'dan':
+ ensure => present,
+ }
+
+ if defined_with_params(User[dan], {'ensure' => 'present' }) {
+ notify { 'User defined with ensure=>present': }
+ }
+ EOS
+
+ apply_manifest(pp, :catch_failures => true) do |r|
+ expect(r.stdout).to match(/Notice: User defined with ensure=>present/)
+ end
+ end
+ end
+end
diff --git a/spec/acceptance/delete_at_spec.rb b/spec/acceptance/delete_at_spec.rb
new file mode 100755
index 0000000..db0c01f
--- /dev/null
+++ b/spec/acceptance/delete_at_spec.rb
@@ -0,0 +1,19 @@
+#! /usr/bin/env ruby -S rspec
+require 'spec_helper_acceptance'
+
+describe 'delete_at function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do
+ describe 'success' do
+ it 'should delete elements of the array' do
+ pp = <<-EOS
+ $output = delete_at(['a','b','c','b'], 1)
+ if $output == ['a','c','b'] {
+ notify { 'output correct': }
+ }
+ EOS
+
+ apply_manifest(pp, :catch_failures => true) do |r|
+ expect(r.stdout).to match(/Notice: output correct/)
+ end
+ end
+ end
+end
diff --git a/spec/acceptance/delete_spec.rb b/spec/acceptance/delete_spec.rb
new file mode 100755
index 0000000..a28604c
--- /dev/null
+++ b/spec/acceptance/delete_spec.rb
@@ -0,0 +1,19 @@
+#! /usr/bin/env ruby -S rspec
+require 'spec_helper_acceptance'
+
+describe 'delete function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do
+ describe 'success' do
+ it 'should delete elements of the array' do
+ pp = <<-EOS
+ $output = delete(['a','b','c','b'], 'b')
+ if $output == ['a','c'] {
+ notify { 'output correct': }
+ }
+ EOS
+
+ apply_manifest(pp, :catch_failures => true) do |r|
+ expect(r.stdout).to match(/Notice: output correct/)
+ end
+ end
+ end
+end
diff --git a/spec/acceptance/delete_undef_values_spec.rb b/spec/acceptance/delete_undef_values_spec.rb
new file mode 100755
index 0000000..b7eda19
--- /dev/null
+++ b/spec/acceptance/delete_undef_values_spec.rb
@@ -0,0 +1,19 @@
+#! /usr/bin/env ruby -S rspec
+require 'spec_helper_acceptance'
+
+describe 'delete_undef_values function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do
+ describe 'success' do
+ it 'should delete elements of the array' do
+ pp = <<-EOS
+ $output = delete_undef_values({a=>'A', b=>'', c=>undef, d => false})
+ if $output == { a => 'A', b => '', d => false } {
+ notify { 'output correct': }
+ }
+ EOS
+
+ apply_manifest(pp, :catch_failures => true) do |r|
+ expect(r.stdout).to match(/Notice: output correct/)
+ end
+ end
+ end
+end
diff --git a/spec/acceptance/delete_values_spec.rb b/spec/acceptance/delete_values_spec.rb
new file mode 100755
index 0000000..6d2369c
--- /dev/null
+++ b/spec/acceptance/delete_values_spec.rb
@@ -0,0 +1,25 @@
+#! /usr/bin/env ruby -S rspec
+require 'spec_helper_acceptance'
+
+describe 'delete_values function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do
+ describe 'success' do
+ it 'should delete elements of the hash' do
+ pp = <<-EOS
+ $a = { 'a' => 'A', 'b' => 'B', 'B' => 'C', 'd' => 'B' }
+ $b = { 'a' => 'A', 'B' => 'C' }
+ $o = delete_values($a, 'B')
+ if $o == $b {
+ notify { 'output correct': }
+ }
+ EOS
+
+ apply_manifest(pp, :catch_failures => true) do |r|
+ expect(r.stdout).to match(/Notice: output correct/)
+ end
+ end
+ end
+ describe 'failure' do
+ it 'handles non-hash arguments'
+ it 'handles improper argument counts'
+ end
+end
diff --git a/spec/acceptance/difference_spec.rb b/spec/acceptance/difference_spec.rb
new file mode 100755
index 0000000..2fae5c4
--- /dev/null
+++ b/spec/acceptance/difference_spec.rb
@@ -0,0 +1,26 @@
+#! /usr/bin/env ruby -S rspec
+require 'spec_helper_acceptance'
+
+describe 'difference function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do
+ describe 'success' do
+ it 'returns non-duplicates in the first array' do
+ pp = <<-EOS
+ $a = ['a','b','c']
+ $b = ['b','c','d']
+ $c = ['a']
+ $o = difference($a, $b)
+ if $o == $c {
+ notify { 'output correct': }
+ }
+ EOS
+
+ apply_manifest(pp, :catch_failures => true) do |r|
+ expect(r.stdout).to match(/Notice: output correct/)
+ end
+ end
+ end
+ describe 'failure' do
+ it 'handles non-array arguments'
+ it 'handles improper argument counts'
+ end
+end
diff --git a/spec/acceptance/dirname_spec.rb b/spec/acceptance/dirname_spec.rb
new file mode 100755
index 0000000..97913dd
--- /dev/null
+++ b/spec/acceptance/dirname_spec.rb
@@ -0,0 +1,42 @@
+#! /usr/bin/env ruby -S rspec
+require 'spec_helper_acceptance'
+
+describe 'dirname function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do
+ describe 'success' do
+ context 'absolute path' do
+ it 'returns the dirname' do
+ pp = <<-EOS
+ $a = '/path/to/a/file.txt'
+ $b = '/path/to/a'
+ $o = dirname($a)
+ if $o == $b {
+ notify { 'output correct': }
+ }
+ EOS
+
+ apply_manifest(pp, :catch_failures => true) do |r|
+ expect(r.stdout).to match(/Notice: output correct/)
+ end
+ end
+ end
+ context 'relative path' do
+ it 'returns the dirname' do
+ pp = <<-EOS
+ $a = 'path/to/a/file.txt'
+ $b = 'path/to/a'
+ $o = dirname($a)
+ if $o == $b {
+ notify { 'output correct': }
+ }
+ EOS
+
+ apply_manifest(pp, :catch_failures => true) do |r|
+ expect(r.stdout).to match(/Notice: output correct/)
+ end
+ end
+ end
+ end
+ describe 'failure' do
+ it 'handles improper argument counts'
+ end
+end
diff --git a/spec/acceptance/downcase_spec.rb b/spec/acceptance/downcase_spec.rb
new file mode 100755
index 0000000..bc4e706
--- /dev/null
+++ b/spec/acceptance/downcase_spec.rb
@@ -0,0 +1,39 @@
+#! /usr/bin/env ruby -S rspec
+require 'spec_helper_acceptance'
+
+describe 'downcase function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do
+ describe 'success' do
+ it 'returns the downcase' do
+ pp = <<-EOS
+ $a = 'AOEU'
+ $b = 'aoeu'
+ $o = downcase($a)
+ if $o == $b {
+ notify { 'output correct': }
+ }
+ EOS
+
+ apply_manifest(pp, :catch_failures => true) do |r|
+ expect(r.stdout).to match(/Notice: output correct/)
+ end
+ end
+ it 'doesn\'t affect lowercase words' do
+ pp = <<-EOS
+ $a = 'aoeu aoeu'
+ $b = 'aoeu aoeu'
+ $o = downcase($a)
+ if $o == $b {
+ notify { 'output correct': }
+ }
+ EOS
+
+ apply_manifest(pp, :catch_failures => true) do |r|
+ expect(r.stdout).to match(/Notice: output correct/)
+ end
+ end
+ end
+ describe 'failure' do
+ it 'handles improper argument counts'
+ it 'handles non-strings'
+ end
+end
diff --git a/spec/acceptance/empty_spec.rb b/spec/acceptance/empty_spec.rb
new file mode 100755
index 0000000..8b46aac
--- /dev/null
+++ b/spec/acceptance/empty_spec.rb
@@ -0,0 +1,39 @@
+#! /usr/bin/env ruby -S rspec
+require 'spec_helper_acceptance'
+
+describe 'empty function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do
+ describe 'success' do
+ it 'recognizes empty strings' do
+ pp = <<-EOS
+ $a = ''
+ $b = true
+ $o = empty($a)
+ if $o == $b {
+ notify { 'output correct': }
+ }
+ EOS
+
+ apply_manifest(pp, :catch_failures => true) do |r|
+ expect(r.stdout).to match(/Notice: output correct/)
+ end
+ end
+ it 'recognizes non-empty strings' do
+ pp = <<-EOS
+ $a = 'aoeu'
+ $b = false
+ $o = empty($a)
+ if $o == $b {
+ notify { 'output correct': }
+ }
+ EOS
+
+ apply_manifest(pp, :catch_failures => true) do |r|
+ expect(r.stdout).to match(/Notice: output correct/)
+ end
+ end
+ end
+ describe 'failure' do
+ it 'handles improper argument counts'
+ it 'handles non-strings'
+ end
+end
diff --git a/spec/acceptance/ensure_packages_spec.rb b/spec/acceptance/ensure_packages_spec.rb
new file mode 100755
index 0000000..aedcfb5
--- /dev/null
+++ b/spec/acceptance/ensure_packages_spec.rb
@@ -0,0 +1,22 @@
+#! /usr/bin/env ruby -S rspec
+require 'spec_helper_acceptance'
+
+describe 'ensure_packages function', :unless => fact('osfamily') =~ /windows/i do
+ describe 'success' do
+ it 'ensure_packages a package' do
+ apply_manifest('package { "rake": ensure => absent, provider => "gem", }')
+ pp = <<-EOS
+ $a = "rake"
+ ensure_packages($a,{'provider' => 'gem'})
+ EOS
+
+ apply_manifest(pp, :expect_changes => true)
+ end
+ it 'ensures a package already declared'
+ it 'takes defaults arguments'
+ end
+ describe 'failure' do
+ it 'handles no arguments'
+ it 'handles non strings'
+ end
+end
diff --git a/spec/acceptance/ensure_resource_spec.rb b/spec/acceptance/ensure_resource_spec.rb
new file mode 100755
index 0000000..1cee53d
--- /dev/null
+++ b/spec/acceptance/ensure_resource_spec.rb
@@ -0,0 +1,22 @@
+#! /usr/bin/env ruby -S rspec
+require 'spec_helper_acceptance'
+
+describe 'ensure_resource function', :unless => fact('osfamily') =~ /windows/i do
+ describe 'success' do
+ it 'ensure_resource a package' do
+ apply_manifest('package { "rake": ensure => absent, provider => "gem", }')
+ pp = <<-EOS
+ $a = "rake"
+ ensure_resource('package', $a, {'provider' => 'gem'})
+ EOS
+
+ apply_manifest(pp, :expect_changes => true)
+ end
+ it 'ensures a resource already declared'
+ it 'takes defaults arguments'
+ end
+ describe 'failure' do
+ it 'handles no arguments'
+ it 'handles non strings'
+ end
+end
diff --git a/spec/acceptance/flatten_spec.rb b/spec/acceptance/flatten_spec.rb
new file mode 100755
index 0000000..c4d66e0
--- /dev/null
+++ b/spec/acceptance/flatten_spec.rb
@@ -0,0 +1,39 @@
+#! /usr/bin/env ruby -S rspec
+require 'spec_helper_acceptance'
+
+describe 'flatten function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do
+ describe 'success' do
+ it 'flattens arrays' do
+ pp = <<-EOS
+ $a = ["a","b",["c",["d","e"],"f","g"]]
+ $b = ["a","b","c","d","e","f","g"]
+ $o = flatten($a)
+ if $o == $b {
+ notify { 'output correct': }
+ }
+ EOS
+
+ apply_manifest(pp, :catch_failures => true) do |r|
+ expect(r.stdout).to match(/Notice: output correct/)
+ end
+ end
+ it 'does not affect flat arrays' do
+ pp = <<-EOS
+ $a = ["a","b","c","d","e","f","g"]
+ $b = ["a","b","c","d","e","f","g"]
+ $o = flatten($a)
+ if $o == $b {
+ notify { 'output correct': }
+ }
+ EOS
+
+ apply_manifest(pp, :catch_failures => true) do |r|
+ expect(r.stdout).to match(/Notice: output correct/)
+ end
+ end
+ end
+ describe 'failure' do
+ it 'handles improper argument counts'
+ it 'handles non-strings'
+ end
+end
diff --git a/spec/acceptance/floor_spec.rb b/spec/acceptance/floor_spec.rb
new file mode 100755
index 0000000..0dcdad9
--- /dev/null
+++ b/spec/acceptance/floor_spec.rb
@@ -0,0 +1,39 @@
+#! /usr/bin/env ruby -S rspec
+require 'spec_helper_acceptance'
+
+describe 'floor function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do
+ describe 'success' do
+ it 'floors floats' do
+ pp = <<-EOS
+ $a = 12.8
+ $b = 12
+ $o = floor($a)
+ if $o == $b {
+ notify { 'output correct': }
+ }
+ EOS
+
+ apply_manifest(pp, :catch_failures => true) do |r|
+ expect(r.stdout).to match(/Notice: output correct/)
+ end
+ end
+ it 'floors integers' do
+ pp = <<-EOS
+ $a = 7
+ $b = 7
+ $o = floor($a)
+ if $o == $b {
+ notify { 'output correct': }
+ }
+ EOS
+
+ apply_manifest(pp, :catch_failures => true) do |r|
+ expect(r.stdout).to match(/Notice: output correct/)
+ end
+ end
+ end
+ describe 'failure' do
+ it 'handles improper argument counts'
+ it 'handles non-numbers'
+ end
+end
diff --git a/spec/acceptance/fqdn_rotate_spec.rb b/spec/acceptance/fqdn_rotate_spec.rb
new file mode 100755
index 0000000..753068b
--- /dev/null
+++ b/spec/acceptance/fqdn_rotate_spec.rb
@@ -0,0 +1,47 @@
+#! /usr/bin/env ruby -S rspec
+require 'spec_helper_acceptance'
+
+describe 'fqdn_rotate function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do
+ describe 'success' do
+ let(:facts_d) do
+ if fact('is_pe', '--puppet') == "true"
+ if fact('osfamily') =~ /windows/i
+ if fact('kernelmajversion').to_f < 6.0
+ 'C:/Documents and Settings/All Users/Application Data/PuppetLabs/facter/facts.d'
+ else
+ 'C:/ProgramData/PuppetLabs/facter/facts.d'
+ end
+ else
+ '/etc/puppetlabs/facter/facts.d'
+ end
+ else
+ '/etc/facter/facts.d'
+ end
+ end
+ after :each do
+ shell("if [ -f '#{facts_d}/fqdn.txt' ] ; then rm '#{facts_d}/fqdn.txt' ; fi")
+ end
+ before :each do
+ #No need to create on windows, PE creates by default
+ if fact('osfamily') !~ /windows/i
+ shell("mkdir -p '#{facts_d}'")
+ end
+ end
+ it 'fqdn_rotates floats' do
+ shell("echo fqdn=fakehost.localdomain > '#{facts_d}/fqdn.txt'")
+ pp = <<-EOS
+ $a = ['a','b','c','d']
+ $o = fqdn_rotate($a)
+ notice(inline_template('fqdn_rotate is <%= @o.inspect %>'))
+ EOS
+
+ apply_manifest(pp, :catch_failures => true) do |r|
+ expect(r.stdout).to match(/fqdn_rotate is \["c", "d", "a", "b"\]/)
+ end
+ end
+ end
+ describe 'failure' do
+ it 'handles improper argument counts'
+ it 'handles non-numbers'
+ end
+end
diff --git a/spec/acceptance/get_module_path_spec.rb b/spec/acceptance/get_module_path_spec.rb
new file mode 100755
index 0000000..6ac690c
--- /dev/null
+++ b/spec/acceptance/get_module_path_spec.rb
@@ -0,0 +1,27 @@
+#! /usr/bin/env ruby -S rspec
+require 'spec_helper_acceptance'
+
+describe 'get_module_path function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do
+ describe 'success' do
+ it 'get_module_paths dne' do
+ pp = <<-EOS
+ $a = $::is_pe ? {
+ 'true' => '/etc/puppetlabs/puppet/modules/dne',
+ 'false' => '/etc/puppet/modules/dne',
+ }
+ $o = get_module_path('dne')
+ if $o == $a {
+ notify { 'output correct': }
+ } else {
+ notify { "failed; module path is '$o'": }
+ }
+ EOS
+
+ apply_manifest(pp, :expect_failures => true)
+ end
+ end
+ describe 'failure' do
+ it 'handles improper argument counts'
+ it 'handles non-numbers'
+ end
+end
diff --git a/spec/acceptance/getparam_spec.rb b/spec/acceptance/getparam_spec.rb
new file mode 100755
index 0000000..b1a677e
--- /dev/null
+++ b/spec/acceptance/getparam_spec.rb
@@ -0,0 +1,24 @@
+#! /usr/bin/env ruby -S rspec
+require 'spec_helper_acceptance'
+
+describe 'getparam function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do
+ describe 'success' do
+ it 'getparam a notify' do
+ pp = <<-EOS
+ notify { 'rspec':
+ message => 'custom rspec message',
+ }
+ $o = getparam(Notify['rspec'], 'message')
+ notice(inline_template('getparam is <%= @o.inspect %>'))
+ EOS
+
+ apply_manifest(pp, :catch_failures => true) do |r|
+ expect(r.stdout).to match(/getparam is "custom rspec message"/)
+ end
+ end
+ end
+ describe 'failure' do
+ it 'handles no arguments'
+ it 'handles non strings'
+ end
+end
diff --git a/spec/acceptance/getvar_spec.rb b/spec/acceptance/getvar_spec.rb
new file mode 100755
index 0000000..333c467
--- /dev/null
+++ b/spec/acceptance/getvar_spec.rb
@@ -0,0 +1,26 @@
+#! /usr/bin/env ruby -S rspec
+require 'spec_helper_acceptance'
+
+describe 'getvar function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do
+ describe 'success' do
+ it 'getvars from classes' do
+ pp = <<-EOS
+ class a::data { $foo = 'aoeu' }
+ include a::data
+ $b = 'aoeu'
+ $o = getvar("a::data::foo")
+ if $o == $b {
+ notify { 'output correct': }
+ }
+ EOS
+
+ apply_manifest(pp, :catch_failures => true) do |r|
+ expect(r.stdout).to match(/Notice: output correct/)
+ end
+ end
+ end
+ describe 'failure' do
+ it 'handles improper argument counts'
+ it 'handles non-numbers'
+ end
+end
diff --git a/spec/acceptance/grep_spec.rb b/spec/acceptance/grep_spec.rb
new file mode 100755
index 0000000..b39d48e
--- /dev/null
+++ b/spec/acceptance/grep_spec.rb
@@ -0,0 +1,26 @@
+#! /usr/bin/env ruby -S rspec
+require 'spec_helper_acceptance'
+
+describe 'grep function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do
+ describe 'success' do
+ it 'greps arrays' do
+ pp = <<-EOS
+ $a = ['aaabbb','bbbccc','dddeee']
+ $b = 'bbb'
+ $c = ['aaabbb','bbbccc']
+ $o = grep($a,$b)
+ if $o == $c {
+ notify { 'output correct': }
+ }
+ EOS
+
+ apply_manifest(pp, :catch_failures => true) do |r|
+ expect(r.stdout).to match(/Notice: output correct/)
+ end
+ end
+ end
+ describe 'failure' do
+ it 'handles improper argument counts'
+ it 'handles non-arrays'
+ end
+end
diff --git a/spec/acceptance/has_interface_with_spec.rb b/spec/acceptance/has_interface_with_spec.rb
new file mode 100755
index 0000000..9590193
--- /dev/null
+++ b/spec/acceptance/has_interface_with_spec.rb
@@ -0,0 +1,54 @@
+#! /usr/bin/env ruby -S rspec
+require 'spec_helper_acceptance'
+
+describe 'has_interface_with function', :unless => ((UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem'))) or (fact('osfamily') == 'windows') or (fact('osfamily') == 'AIX')) do
+ describe 'success' do
+ it 'has_interface_with existing ipaddress' do
+ pp = <<-EOS
+ $a = $::ipaddress
+ $o = has_interface_with('ipaddress', $a)
+ notice(inline_template('has_interface_with is <%= @o.inspect %>'))
+ EOS
+
+ apply_manifest(pp, :catch_failures => true) do |r|
+ expect(r.stdout).to match(/has_interface_with is true/)
+ end
+ end
+ it 'has_interface_with absent ipaddress' do
+ pp = <<-EOS
+ $a = '128.0.0.1'
+ $o = has_interface_with('ipaddress', $a)
+ notice(inline_template('has_interface_with is <%= @o.inspect %>'))
+ EOS
+
+ apply_manifest(pp, :catch_failures => true) do |r|
+ expect(r.stdout).to match(/has_interface_with is false/)
+ end
+ end
+ it 'has_interface_with existing interface' do
+ pp = <<-EOS
+ if $osfamily == 'Solaris' or $osfamily == 'Darwin' {
+ $a = 'lo0'
+ }elsif $osfamily == 'windows' {
+ $a = $::kernelmajversion ? {
+ /6\.(2|3|4)/ => 'Ethernet0',
+ /6\.(0|1)/ => 'Local_Area_Connection',
+ /5\.(1|2)/ => undef, #Broken current in facter
+ }
+ }else {
+ $a = 'lo'
+ }
+ $o = has_interface_with($a)
+ notice(inline_template('has_interface_with is <%= @o.inspect %>'))
+ EOS
+
+ apply_manifest(pp, :catch_failures => true) do |r|
+ expect(r.stdout).to match(/has_interface_with is true/)
+ end
+ end
+ end
+ describe 'failure' do
+ it 'handles no arguments'
+ it 'handles non strings'
+ end
+end
diff --git a/spec/acceptance/has_ip_address_spec.rb b/spec/acceptance/has_ip_address_spec.rb
new file mode 100755
index 0000000..149a10d
--- /dev/null
+++ b/spec/acceptance/has_ip_address_spec.rb
@@ -0,0 +1,33 @@
+#! /usr/bin/env ruby -S rspec
+require 'spec_helper_acceptance'
+
+describe 'has_ip_address function', :unless => ((UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem'))) or (fact('osfamily') == 'windows') or (fact('osfamily') == 'AIX')) do
+ describe 'success' do
+ it 'has_ip_address existing ipaddress' do
+ pp = <<-EOS
+ $a = '127.0.0.1'
+ $o = has_ip_address($a)
+ notice(inline_template('has_ip_address is <%= @o.inspect %>'))
+ EOS
+
+ apply_manifest(pp, :catch_failures => true) do |r|
+ expect(r.stdout).to match(/has_ip_address is true/)
+ end
+ end
+ it 'has_ip_address absent ipaddress' do
+ pp = <<-EOS
+ $a = '128.0.0.1'
+ $o = has_ip_address($a)
+ notice(inline_template('has_ip_address is <%= @o.inspect %>'))
+ EOS
+
+ apply_manifest(pp, :catch_failures => true) do |r|
+ expect(r.stdout).to match(/has_ip_address is false/)
+ end
+ end
+ end
+ describe 'failure' do
+ it 'handles no arguments'
+ it 'handles non strings'
+ end
+end
diff --git a/spec/acceptance/has_ip_network_spec.rb b/spec/acceptance/has_ip_network_spec.rb
new file mode 100755
index 0000000..7d2f34e
--- /dev/null
+++ b/spec/acceptance/has_ip_network_spec.rb
@@ -0,0 +1,33 @@
+#! /usr/bin/env ruby -S rspec
+require 'spec_helper_acceptance'
+
+describe 'has_ip_network function', :unless => ((UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem'))) or (fact('osfamily') == 'windows') or (fact('osfamily') == 'AIX')) do
+ describe 'success' do
+ it 'has_ip_network existing ipaddress' do
+ pp = <<-EOS
+ $a = '127.0.0.0'
+ $o = has_ip_network($a)
+ notice(inline_template('has_ip_network is <%= @o.inspect %>'))
+ EOS
+
+ apply_manifest(pp, :catch_failures => true) do |r|
+ expect(r.stdout).to match(/has_ip_network is true/)
+ end
+ end
+ it 'has_ip_network absent ipaddress' do
+ pp = <<-EOS
+ $a = '128.0.0.0'
+ $o = has_ip_network($a)
+ notice(inline_template('has_ip_network is <%= @o.inspect %>'))
+ EOS
+
+ apply_manifest(pp, :catch_failures => true) do |r|
+ expect(r.stdout).to match(/has_ip_network is false/)
+ end
+ end
+ end
+ describe 'failure' do
+ it 'handles no arguments'
+ it 'handles non strings'
+ end
+end
diff --git a/spec/acceptance/has_key_spec.rb b/spec/acceptance/has_key_spec.rb
new file mode 100755
index 0000000..c8557cb
--- /dev/null
+++ b/spec/acceptance/has_key_spec.rb
@@ -0,0 +1,41 @@
+#! /usr/bin/env ruby -S rspec
+require 'spec_helper_acceptance'
+
+describe 'has_key function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do
+ describe 'success' do
+ it 'has_keys in hashes' do
+ pp = <<-EOS
+ $a = { 'aaa' => 'bbb','bbb' => 'ccc','ddd' => 'eee' }
+ $b = 'bbb'
+ $c = true
+ $o = has_key($a,$b)
+ if $o == $c {
+ notify { 'output correct': }
+ }
+ EOS
+
+ apply_manifest(pp, :catch_failures => true) do |r|
+ expect(r.stdout).to match(/Notice: output correct/)
+ end
+ end
+ it 'has_keys not in hashes' do
+ pp = <<-EOS
+ $a = { 'aaa' => 'bbb','bbb' => 'ccc','ddd' => 'eee' }
+ $b = 'ccc'
+ $c = false
+ $o = has_key($a,$b)
+ if $o == $c {
+ notify { 'output correct': }
+ }
+ EOS
+
+ apply_manifest(pp, :catch_failures => true) do |r|
+ expect(r.stdout).to match(/Notice: output correct/)
+ end
+ end
+ end
+ describe 'failure' do
+ it 'handles improper argument counts'
+ it 'handles non-hashes'
+ end
+end
diff --git a/spec/acceptance/hash_spec.rb b/spec/acceptance/hash_spec.rb
new file mode 100755
index 0000000..ed53834
--- /dev/null
+++ b/spec/acceptance/hash_spec.rb
@@ -0,0 +1,26 @@
+#! /usr/bin/env ruby -S rspec
+require 'spec_helper_acceptance'
+
+describe 'hash function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do
+ describe 'success' do
+ it 'hashs arrays' do
+ pp = <<-EOS
+ $a = ['aaa','bbb','bbb','ccc','ddd','eee']
+ $b = { 'aaa' => 'bbb', 'bbb' => 'ccc', 'ddd' => 'eee' }
+ $o = hash($a)
+ if $o == $b {
+ notify { 'output correct': }
+ }
+ EOS
+
+ apply_manifest(pp, :catch_failures => true) do |r|
+ expect(r.stdout).to match(/Notice: output correct/)
+ end
+ end
+ it 'handles odd-length arrays'
+ end
+ describe 'failure' do
+ it 'handles improper argument counts'
+ it 'handles non-arrays'
+ end
+end
diff --git a/spec/acceptance/intersection_spec.rb b/spec/acceptance/intersection_spec.rb
new file mode 100755
index 0000000..66b8652
--- /dev/null
+++ b/spec/acceptance/intersection_spec.rb
@@ -0,0 +1,27 @@
+#! /usr/bin/env ruby -S rspec
+require 'spec_helper_acceptance'
+
+describe 'intersection function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do
+ describe 'success' do
+ it 'intersections arrays' do
+ pp = <<-EOS
+ $a = ['aaa','bbb','ccc']
+ $b = ['bbb','ccc','ddd','eee']
+ $c = ['bbb','ccc']
+ $o = intersection($a,$b)
+ if $o == $c {
+ notify { 'output correct': }
+ }
+ EOS
+
+ apply_manifest(pp, :catch_failures => true) do |r|
+ expect(r.stdout).to match(/Notice: output correct/)
+ end
+ end
+ it 'intersections empty arrays'
+ end
+ describe 'failure' do
+ it 'handles improper argument counts'
+ it 'handles non-arrays'
+ end
+end
diff --git a/spec/acceptance/is_array_spec.rb b/spec/acceptance/is_array_spec.rb
new file mode 100755
index 0000000..9c6bad7
--- /dev/null
+++ b/spec/acceptance/is_array_spec.rb
@@ -0,0 +1,67 @@
+#! /usr/bin/env ruby -S rspec
+require 'spec_helper_acceptance'
+
+describe 'is_array function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do
+ describe 'success' do
+ it 'is_arrays arrays' do
+ pp = <<-EOS
+ $a = ['aaa','bbb','ccc']
+ $b = true
+ $o = is_array($a)
+ if $o == $b {
+ notify { 'output correct': }
+ }
+ EOS
+
+ apply_manifest(pp, :catch_failures => true) do |r|
+ expect(r.stdout).to match(/Notice: output correct/)
+ end
+ end
+ it 'is_arrays empty arrays' do
+ pp = <<-EOS
+ $a = []
+ $b = true
+ $o = is_array($a)
+ if $o == $b {
+ notify { 'output correct': }
+ }
+ EOS
+
+ apply_manifest(pp, :catch_failures => true) do |r|
+ expect(r.stdout).to match(/Notice: output correct/)
+ end
+ end
+ it 'is_arrays strings' do
+ pp = <<-EOS
+ $a = "aoeu"
+ $b = false
+ $o = is_array($a)
+ if $o == $b {
+ notify { 'output correct': }
+ }
+ EOS
+
+ apply_manifest(pp, :catch_failures => true) do |r|
+ expect(r.stdout).to match(/Notice: output correct/)
+ end
+ end
+ it 'is_arrays hashes' do
+ pp = <<-EOS
+ $a = {'aaa'=>'bbb'}
+ $b = false
+ $o = is_array($a)
+ if $o == $b {
+ notify { 'output correct': }
+ }
+ EOS
+
+ apply_manifest(pp, :catch_failures => true) do |r|
+ expect(r.stdout).to match(/Notice: output correct/)
+ end
+ end
+ end
+ describe 'failure' do
+ it 'handles improper argument counts'
+ it 'handles non-arrays'
+ end
+end
diff --git a/spec/acceptance/is_bool_spec.rb b/spec/acceptance/is_bool_spec.rb
new file mode 100755
index 0000000..60079f9
--- /dev/null
+++ b/spec/acceptance/is_bool_spec.rb
@@ -0,0 +1,81 @@
+#! /usr/bin/env ruby -S rspec
+require 'spec_helper_acceptance'
+
+describe 'is_bool function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do
+ describe 'success' do
+ it 'is_bools arrays' do
+ pp = <<-EOS
+ $a = ['aaa','bbb','ccc']
+ $b = false
+ $o = is_bool($a)
+ if $o == $b {
+ notify { 'output correct': }
+ }
+ EOS
+
+ apply_manifest(pp, :catch_failures => true) do |r|
+ expect(r.stdout).to match(/Notice: output correct/)
+ end
+ end
+ it 'is_bools true' do
+ pp = <<-EOS
+ $a = true
+ $b = true
+ $o = is_bool($a)
+ if $o == $b {
+ notify { 'output correct': }
+ }
+ EOS
+
+ apply_manifest(pp, :catch_failures => true) do |r|
+ expect(r.stdout).to match(/Notice: output correct/)
+ end
+ end
+ it 'is_bools false' do
+ pp = <<-EOS
+ $a = false
+ $b = true
+ $o = is_bool($a)
+ if $o == $b {
+ notify { 'output correct': }
+ }
+ EOS
+
+ apply_manifest(pp, :catch_failures => true) do |r|
+ expect(r.stdout).to match(/Notice: output correct/)
+ end
+ end
+ it 'is_bools strings' do
+ pp = <<-EOS
+ $a = "true"
+ $b = false
+ $o = is_bool($a)
+ if $o == $b {
+ notify { 'output correct': }
+ }
+ EOS
+
+ apply_manifest(pp, :catch_failures => true) do |r|
+ expect(r.stdout).to match(/Notice: output correct/)
+ end
+ end
+ it 'is_bools hashes' do
+ pp = <<-EOS
+ $a = {'aaa'=>'bbb'}
+ $b = false
+ $o = is_bool($a)
+ if $o == $b {
+ notify { 'output correct': }
+ }
+ EOS
+
+ apply_manifest(pp, :catch_failures => true) do |r|
+ expect(r.stdout).to match(/Notice: output correct/)
+ end
+ end
+ end
+ describe 'failure' do
+ it 'handles improper argument counts'
+ it 'handles non-arrays'
+ end
+end
diff --git a/spec/acceptance/is_domain_name_spec.rb b/spec/acceptance/is_domain_name_spec.rb
new file mode 100755
index 0000000..e0f03fa
--- /dev/null
+++ b/spec/acceptance/is_domain_name_spec.rb
@@ -0,0 +1,83 @@
+#! /usr/bin/env ruby -S rspec
+require 'spec_helper_acceptance'
+
+describe 'is_domain_name function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do
+ describe 'success' do
+ it 'is_domain_names arrays' do
+ pp = <<-EOS
+ $a = ['aaa.com','bbb','ccc']
+ $o = is_domain_name($a)
+ notice(inline_template('is_domain_name is <%= @o.inspect %>'))
+ EOS
+
+ apply_manifest(pp, :catch_failures => true) do |r|
+ expect(r.stdout).to match(/is_domain_name is false/)
+ end
+ end
+ it 'is_domain_names true' do
+ pp = <<-EOS
+ $a = true
+ $o = is_domain_name($a)
+ notice(inline_template('is_domain_name is <%= @o.inspect %>'))
+ EOS
+
+ apply_manifest(pp, :catch_failures => true) do |r|
+ expect(r.stdout).to match(/is_domain_name is false/)
+ end
+ end
+ it 'is_domain_names false' do
+ pp = <<-EOS
+ $a = false
+ $o = is_domain_name($a)
+ notice(inline_template('is_domain_name is <%= @o.inspect %>'))
+ EOS
+
+ apply_manifest(pp, :catch_failures => true) do |r|
+ expect(r.stdout).to match(/is_domain_name is false/)
+ end
+ end
+ it 'is_domain_names strings with hyphens' do
+ pp = <<-EOS
+ $a = "3foo-bar.2bar-fuzz.com"
+ $b = true
+ $o = is_domain_name($a)
+ if $o == $b {
+ notify { 'output correct': }
+ }
+ EOS
+
+ apply_manifest(pp, :catch_failures => true) do |r|
+ expect(r.stdout).to match(/Notice: output correct/)
+ end
+ end
+ it 'is_domain_names strings beginning with hyphens' do
+ pp = <<-EOS
+ $a = "-bar.2bar-fuzz.com"
+ $b = false
+ $o = is_domain_name($a)
+ if $o == $b {
+ notify { 'output correct': }
+ }
+ EOS
+
+ apply_manifest(pp, :catch_failures => true) do |r|
+ expect(r.stdout).to match(/Notice: output correct/)
+ end
+ end
+ it 'is_domain_names hashes' do
+ pp = <<-EOS
+ $a = {'aaa'=>'www.com'}
+ $o = is_domain_name($a)
+ notice(inline_template('is_domain_name is <%= @o.inspect %>'))
+ EOS
+
+ apply_manifest(pp, :catch_failures => true) do |r|
+ expect(r.stdout).to match(/is_domain_name is false/)
+ end
+ end
+ end
+ describe 'failure' do
+ it 'handles improper argument counts'
+ it 'handles non-arrays'
+ end
+end
diff --git a/spec/acceptance/is_float_spec.rb b/spec/acceptance/is_float_spec.rb
new file mode 100755
index 0000000..338ba58
--- /dev/null
+++ b/spec/acceptance/is_float_spec.rb
@@ -0,0 +1,86 @@
+#! /usr/bin/env ruby -S rspec
+require 'spec_helper_acceptance'
+
+describe 'is_float function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do
+ describe 'success' do
+ it 'is_floats arrays' do
+ pp = <<-EOS
+ $a = ['aaa.com','bbb','ccc']
+ $o = is_float($a)
+ notice(inline_template('is_float is <%= @o.inspect %>'))
+ EOS
+
+ apply_manifest(pp, :catch_failures => true) do |r|
+ expect(r.stdout).to match(/is_float is false/)
+ end
+ end
+ it 'is_floats true' do
+ pp = <<-EOS
+ $a = true
+ $o = is_float($a)
+ notice(inline_template('is_float is <%= @o.inspect %>'))
+ EOS
+
+ apply_manifest(pp, :catch_failures => true) do |r|
+ expect(r.stdout).to match(/is_float is false/)
+ end
+ end
+ it 'is_floats strings' do
+ pp = <<-EOS
+ $a = "3.5"
+ $b = true
+ $o = is_float($a)
+ if $o == $b {
+ notify { 'output correct': }
+ }
+ EOS
+
+ apply_manifest(pp, :catch_failures => true) do |r|
+ expect(r.stdout).to match(/Notice: output correct/)
+ end
+ end
+ it 'is_floats floats' do
+ pp = <<-EOS
+ $a = 3.5
+ $b = true
+ $o = is_float($a)
+ if $o == $b {
+ notify { 'output correct': }
+ }
+ EOS
+
+ apply_manifest(pp, :catch_failures => true) do |r|
+ expect(r.stdout).to match(/Notice: output correct/)
+ end
+ end
+ it 'is_floats integers' do
+ pp = <<-EOS
+ $a = 3
+ $b = false
+ $o = is_float($a)
+ if $o == $b {
+ notify { 'output correct': }
+ }
+ EOS
+
+ apply_manifest(pp, :catch_failures => true) do |r|
+ expect(r.stdout).to match(/Notice: output correct/)
+ end
+ end
+ it 'is_floats hashes' do
+ pp = <<-EOS
+ $a = {'aaa'=>'www.com'}
+ $o = is_float($a)
+ notice(inline_template('is_float is <%= @o.inspect %>'))
+ EOS
+
+ apply_manifest(pp, :catch_failures => true) do |r|
+ expect(r.stdout).to match(/is_float is false/)
+ end
+ end
+ end
+ describe 'failure' do
+ it 'handles improper argument counts'
+ it 'handles non-arrays'
+ end
+end
diff --git a/spec/acceptance/is_function_available_spec.rb b/spec/acceptance/is_function_available_spec.rb
new file mode 100755
index 0000000..2b5dd6d
--- /dev/null
+++ b/spec/acceptance/is_function_available_spec.rb
@@ -0,0 +1,58 @@
+#! /usr/bin/env ruby -S rspec
+require 'spec_helper_acceptance'
+
+describe 'is_function_available function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do
+ describe 'success' do
+ it 'is_function_availables arrays' do
+ pp = <<-EOS
+ $a = ['fail','include','require']
+ $o = is_function_available($a)
+ notice(inline_template('is_function_available is <%= @o.inspect %>'))
+ EOS
+
+ apply_manifest(pp, :catch_failures => true) do |r|
+ expect(r.stdout).to match(/is_function_available is false/)
+ end
+ end
+ it 'is_function_availables true' do
+ pp = <<-EOS
+ $a = true
+ $o = is_function_available($a)
+ notice(inline_template('is_function_available is <%= @o.inspect %>'))
+ EOS
+
+ apply_manifest(pp, :catch_failures => true) do |r|
+ expect(r.stdout).to match(/is_function_available is false/)
+ end
+ end
+ it 'is_function_availables strings' do
+ pp = <<-EOS
+ $a = "fail"
+ $b = true
+ $o = is_function_available($a)
+ if $o == $b {
+ notify { 'output correct': }
+ }
+ EOS
+
+ apply_manifest(pp, :catch_failures => true) do |r|
+ expect(r.stdout).to match(/Notice: output correct/)
+ end
+ end
+ it 'is_function_availables function_availables' do
+ pp = <<-EOS
+ $a = "is_function_available"
+ $o = is_function_available($a)
+ notice(inline_template('is_function_available is <%= @o.inspect %>'))
+ EOS
+
+ apply_manifest(pp, :catch_failures => true) do |r|
+ expect(r.stdout).to match(/is_function_available is true/)
+ end
+ end
+ end
+ describe 'failure' do
+ it 'handles improper argument counts'
+ it 'handles non-arrays'
+ end
+end
diff --git a/spec/acceptance/is_hash_spec.rb b/spec/acceptance/is_hash_spec.rb
new file mode 100755
index 0000000..2ef310a
--- /dev/null
+++ b/spec/acceptance/is_hash_spec.rb
@@ -0,0 +1,63 @@
+#! /usr/bin/env ruby -S rspec
+require 'spec_helper_acceptance'
+
+describe 'is_hash function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do
+ describe 'success' do
+ it 'is_hashs arrays' do
+ pp = <<-EOS
+ $a = ['aaa','bbb','ccc']
+ $o = is_hash($a)
+ notice(inline_template('is_hash is <%= @o.inspect %>'))
+ EOS
+
+ apply_manifest(pp, :catch_failures => true) do |r|
+ expect(r.stdout).to match(/is_hash is false/)
+ end
+ end
+ it 'is_hashs empty hashs' do
+ pp = <<-EOS
+ $a = {}
+ $b = true
+ $o = is_hash($a)
+ if $o == $b {
+ notify { 'output correct': }
+ }
+ EOS
+
+ apply_manifest(pp, :catch_failures => true) do |r|
+ expect(r.stdout).to match(/Notice: output correct/)
+ end
+ end
+ it 'is_hashs strings' do
+ pp = <<-EOS
+ $a = "aoeu"
+ $b = false
+ $o = is_hash($a)
+ if $o == $b {
+ notify { 'output correct': }
+ }
+ EOS
+
+ apply_manifest(pp, :catch_failures => true) do |r|
+ expect(r.stdout).to match(/Notice: output correct/)
+ end
+ end
+ it 'is_hashs hashes' do
+ pp = <<-EOS
+ $a = {'aaa'=>'bbb'}
+ $b = true
+ $o = is_hash($a)
+ if $o == $b {
+ notify { 'output correct': }
+ }
+ EOS
+
+ apply_manifest(pp, :catch_failures => true) do |r|
+ expect(r.stdout).to match(/Notice: output correct/)
+ end
+ end
+ end
+ describe 'failure' do
+ it 'handles improper argument counts'
+ end
+end
diff --git a/spec/acceptance/is_integer_spec.rb b/spec/acceptance/is_integer_spec.rb
new file mode 100755
index 0000000..bf6902b
--- /dev/null
+++ b/spec/acceptance/is_integer_spec.rb
@@ -0,0 +1,95 @@
+#! /usr/bin/env ruby -S rspec
+require 'spec_helper_acceptance'
+
+describe 'is_integer function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do
+ describe 'success' do
+ it 'is_integers arrays' do
+ pp = <<-EOS
+ $a = ['aaa.com','bbb','ccc']
+ $b = false
+ $o = is_integer($a)
+ if $o == $b {
+ notify { 'output correct': }
+ }
+ EOS
+
+ apply_manifest(pp, :catch_failures => true) do |r|
+ expect(r.stdout).to match(/Notice: output correct/)
+ end
+ end
+ it 'is_integers true' do
+ pp = <<-EOS
+ $a = true
+ $b = false
+ $o = is_integer($a)
+ if $o == $b {
+ notify { 'output correct': }
+ }
+ EOS
+
+ apply_manifest(pp, :catch_failures => true) do |r|
+ expect(r.stdout).to match(/Notice: output correct/)
+ end
+ end
+ it 'is_integers strings' do
+ pp = <<-EOS
+ $a = "3"
+ $b = true
+ $o = is_integer($a)
+ if $o == $b {
+ notify { 'output correct': }
+ }
+ EOS
+
+ apply_manifest(pp, :catch_failures => true) do |r|
+ expect(r.stdout).to match(/Notice: output correct/)
+ end
+ end
+ it 'is_integers floats' do
+ pp = <<-EOS
+ $a = 3.5
+ $b = false
+ $o = is_integer($a)
+ if $o == $b {
+ notify { 'output correct': }
+ }
+ EOS
+
+ apply_manifest(pp, :catch_failures => true) do |r|
+ expect(r.stdout).to match(/Notice: output correct/)
+ end
+ end
+ it 'is_integers integers' do
+ pp = <<-EOS
+ $a = 3
+ $b = true
+ $o = is_integer($a)
+ if $o == $b {
+ notify { 'output correct': }
+ }
+ EOS
+
+ apply_manifest(pp, :catch_failures => true) do |r|
+ expect(r.stdout).to match(/Notice: output correct/)
+ end
+ end
+ it 'is_integers hashes' do
+ pp = <<-EOS
+ $a = {'aaa'=>'www.com'}
+ $b = false
+ $o = is_integer($a)
+ if $o == $b {
+ notify { 'output correct': }
+ }
+ EOS
+
+ apply_manifest(pp, :catch_failures => true) do |r|
+ expect(r.stdout).to match(/Notice: output correct/)
+ end
+ end
+ end
+ describe 'failure' do
+ it 'handles improper argument counts'
+ it 'handles non-arrays'
+ end
+end
diff --git a/spec/acceptance/is_ip_address_spec.rb b/spec/acceptance/is_ip_address_spec.rb
new file mode 100755
index 0000000..ed7a854
--- /dev/null
+++ b/spec/acceptance/is_ip_address_spec.rb
@@ -0,0 +1,80 @@
+#! /usr/bin/env ruby -S rspec
+require 'spec_helper_acceptance'
+
+describe 'is_ip_address function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do
+ describe 'success' do
+ it 'is_ip_addresss ipv4' do
+ pp = <<-EOS
+ $a = '1.2.3.4'
+ $b = true
+ $o = is_ip_address($a)
+ if $o == $b {
+ notify { 'output correct': }
+ }
+ EOS
+
+ apply_manifest(pp, :catch_failures => true) do |r|
+ expect(r.stdout).to match(/Notice: output correct/)
+ end
+ end
+ it 'is_ip_addresss ipv6' do
+ pp = <<-EOS
+ $a = "fe80:0000:cd12:d123:e2f8:47ff:fe09:dd74"
+ $b = true
+ $o = is_ip_address($a)
+ if $o == $b {
+ notify { 'output correct': }
+ }
+ EOS
+
+ apply_manifest(pp, :catch_failures => true) do |r|
+ expect(r.stdout).to match(/Notice: output correct/)
+ end
+ end
+ it 'is_ip_addresss ipv6 compressed' do
+ pp = <<-EOS
+ $a = "fe00::1"
+ $b = true
+ $o = is_ip_address($a)
+ if $o == $b {
+ notify { 'output correct': }
+ }
+ EOS
+
+ apply_manifest(pp, :catch_failures => true) do |r|
+ expect(r.stdout).to match(/Notice: output correct/)
+ end
+ end
+ it 'is_ip_addresss strings' do
+ pp = <<-EOS
+ $a = "aoeu"
+ $b = false
+ $o = is_ip_address($a)
+ if $o == $b {
+ notify { 'output correct': }
+ }
+ EOS
+
+ apply_manifest(pp, :catch_failures => true) do |r|
+ expect(r.stdout).to match(/Notice: output correct/)
+ end
+ end
+ it 'is_ip_addresss ipv4 out of range' do
+ pp = <<-EOS
+ $a = '1.2.3.400'
+ $b = false
+ $o = is_ip_address($a)
+ if $o == $b {
+ notify { 'output correct': }
+ }
+ EOS
+
+ apply_manifest(pp, :catch_failures => true) do |r|
+ expect(r.stdout).to match(/Notice: output correct/)
+ end
+ end
+ end
+ describe 'failure' do
+ it 'handles improper argument counts'
+ end
+end
diff --git a/spec/acceptance/is_mac_address_spec.rb b/spec/acceptance/is_mac_address_spec.rb
new file mode 100755
index 0000000..a2c892f
--- /dev/null
+++ b/spec/acceptance/is_mac_address_spec.rb
@@ -0,0 +1,38 @@
+#! /usr/bin/env ruby -S rspec
+require 'spec_helper_acceptance'
+
+describe 'is_mac_address function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do
+ describe 'success' do
+ it 'is_mac_addresss a mac' do
+ pp = <<-EOS
+ $a = '00:a0:1f:12:7f:a0'
+ $b = true
+ $o = is_mac_address($a)
+ if $o == $b {
+ notify { 'output correct': }
+ }
+ EOS
+
+ apply_manifest(pp, :catch_failures => true) do |r|
+ expect(r.stdout).to match(/Notice: output correct/)
+ end
+ end
+ it 'is_mac_addresss a mac out of range' do
+ pp = <<-EOS
+ $a = '00:a0:1f:12:7f:g0'
+ $b = false
+ $o = is_mac_address($a)
+ if $o == $b {
+ notify { 'output correct': }
+ }
+ EOS
+
+ apply_manifest(pp, :catch_failures => true) do |r|
+ expect(r.stdout).to match(/Notice: output correct/)
+ end
+ end
+ end
+ describe 'failure' do
+ it 'handles improper argument counts'
+ end
+end
diff --git a/spec/acceptance/is_numeric_spec.rb b/spec/acceptance/is_numeric_spec.rb
new file mode 100755
index 0000000..21c8988
--- /dev/null
+++ b/spec/acceptance/is_numeric_spec.rb
@@ -0,0 +1,95 @@
+#! /usr/bin/env ruby -S rspec
+require 'spec_helper_acceptance'
+
+describe 'is_numeric function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do
+ describe 'success' do
+ it 'is_numerics arrays' do
+ pp = <<-EOS
+ $a = ['aaa.com','bbb','ccc']
+ $b = false
+ $o = is_numeric($a)
+ if $o == $b {
+ notify { 'output correct': }
+ }
+ EOS
+
+ apply_manifest(pp, :catch_failures => true) do |r|
+ expect(r.stdout).to match(/Notice: output correct/)
+ end
+ end
+ it 'is_numerics true' do
+ pp = <<-EOS
+ $a = true
+ $b = false
+ $o = is_numeric($a)
+ if $o == $b {
+ notify { 'output correct': }
+ }
+ EOS
+
+ apply_manifest(pp, :catch_failures => true) do |r|
+ expect(r.stdout).to match(/Notice: output correct/)
+ end
+ end
+ it 'is_numerics strings' do
+ pp = <<-EOS
+ $a = "3"
+ $b = true
+ $o = is_numeric($a)
+ if $o == $b {
+ notify { 'output correct': }
+ }
+ EOS
+
+ apply_manifest(pp, :catch_failures => true) do |r|
+ expect(r.stdout).to match(/Notice: output correct/)
+ end
+ end
+ it 'is_numerics floats' do
+ pp = <<-EOS
+ $a = 3.5
+ $b = true
+ $o = is_numeric($a)
+ if $o == $b {
+ notify { 'output correct': }
+ }
+ EOS
+
+ apply_manifest(pp, :catch_failures => true) do |r|
+ expect(r.stdout).to match(/Notice: output correct/)
+ end
+ end
+ it 'is_numerics integers' do
+ pp = <<-EOS
+ $a = 3
+ $b = true
+ $o = is_numeric($a)
+ if $o == $b {
+ notify { 'output correct': }
+ }
+ EOS
+
+ apply_manifest(pp, :catch_failures => true) do |r|
+ expect(r.stdout).to match(/Notice: output correct/)
+ end
+ end
+ it 'is_numerics hashes' do
+ pp = <<-EOS
+ $a = {'aaa'=>'www.com'}
+ $b = false
+ $o = is_numeric($a)
+ if $o == $b {
+ notify { 'output correct': }
+ }
+ EOS
+
+ apply_manifest(pp, :catch_failures => true) do |r|
+ expect(r.stdout).to match(/Notice: output correct/)
+ end
+ end
+ end
+ describe 'failure' do
+ it 'handles improper argument counts'
+ it 'handles non-arrays'
+ end
+end
diff --git a/spec/acceptance/is_string_spec.rb b/spec/acceptance/is_string_spec.rb
new file mode 100755
index 0000000..94d8e96
--- /dev/null
+++ b/spec/acceptance/is_string_spec.rb
@@ -0,0 +1,102 @@
+#! /usr/bin/env ruby -S rspec
+require 'spec_helper_acceptance'
+
+describe 'is_string function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do
+ describe 'success' do
+ it 'is_strings arrays' do
+ pp = <<-EOS
+ $a = ['aaa.com','bbb','ccc']
+ $b = false
+ $o = is_string($a)
+ if $o == $b {
+ notify { 'output correct': }
+ }
+ EOS
+
+ apply_manifest(pp, :catch_failures => true) do |r|
+ expect(r.stdout).to match(/Notice: output correct/)
+ end
+ end
+ it 'is_strings true' do
+ pp = <<-EOS
+ $a = true
+ $b = false
+ $o = is_string($a)
+ if $o == $b {
+ notify { 'output correct': }
+ }
+ EOS
+
+ apply_manifest(pp, :catch_failures => true) do |r|
+ expect(r.stdout).to match(/Notice: output correct/)
+ end
+ end
+ it 'is_strings strings' do
+ pp = <<-EOS
+ $a = "aoeu"
+ $o = is_string($a)
+ notice(inline_template('is_string is <%= @o.inspect %>'))
+ EOS
+
+ apply_manifest(pp, :catch_failures => true) do |r|
+ expect(r.stdout).to match(/is_string is true/)
+ end
+ end
+ it 'is_strings number strings' do
+ pp = <<-EOS
+ $a = "3"
+ $o = is_string($a)
+ notice(inline_template('is_string is <%= @o.inspect %>'))
+ EOS
+
+ apply_manifest(pp, :catch_failures => true) do |r|
+ expect(r.stdout).to match(/is_string is false/)
+ end
+ end
+ it 'is_strings floats' do
+ pp = <<-EOS
+ $a = 3.5
+ $b = false
+ $o = is_string($a)
+ if $o == $b {
+ notify { 'output correct': }
+ }
+ EOS
+
+ apply_manifest(pp, :catch_failures => true) do |r|
+ expect(r.stdout).to match(/Notice: output correct/)
+ end
+ end
+ it 'is_strings integers' do
+ pp = <<-EOS
+ $a = 3
+ $b = false
+ $o = is_string($a)
+ if $o == $b {
+ notify { 'output correct': }
+ }
+ EOS
+
+ apply_manifest(pp, :catch_failures => true) do |r|
+ expect(r.stdout).to match(/Notice: output correct/)
+ end
+ end
+ it 'is_strings hashes' do
+ pp = <<-EOS
+ $a = {'aaa'=>'www.com'}
+ $b = false
+ $o = is_string($a)
+ if $o == $b {
+ notify { 'output correct': }
+ }
+ EOS
+
+ apply_manifest(pp, :catch_failures => true) do |r|
+ expect(r.stdout).to match(/Notice: output correct/)
+ end
+ end
+ end
+ describe 'failure' do
+ it 'handles improper argument counts'
+ end
+end
diff --git a/spec/acceptance/join_keys_to_values_spec.rb b/spec/acceptance/join_keys_to_values_spec.rb
new file mode 100755
index 0000000..70493fd
--- /dev/null
+++ b/spec/acceptance/join_keys_to_values_spec.rb
@@ -0,0 +1,24 @@
+#! /usr/bin/env ruby -S rspec
+require 'spec_helper_acceptance'
+
+describe 'join_keys_to_values function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do
+ describe 'success' do
+ it 'join_keys_to_valuess hashes' do
+ pp = <<-EOS
+ $a = {'aaa'=>'bbb','ccc'=>'ddd'}
+ $b = ':'
+ $o = join_keys_to_values($a,$b)
+ notice(inline_template('join_keys_to_values is <%= @o.sort.inspect %>'))
+ EOS
+
+ apply_manifest(pp, :catch_failures => true) do |r|
+ expect(r.stdout).to match(/join_keys_to_values is \["aaa:bbb", "ccc:ddd"\]/)
+ end
+ end
+ it 'handles non hashes'
+ it 'handles empty hashes'
+ end
+ describe 'failure' do
+ it 'handles improper argument counts'
+ end
+end
diff --git a/spec/acceptance/join_spec.rb b/spec/acceptance/join_spec.rb
new file mode 100755
index 0000000..5397ce2
--- /dev/null
+++ b/spec/acceptance/join_spec.rb
@@ -0,0 +1,26 @@
+#! /usr/bin/env ruby -S rspec
+require 'spec_helper_acceptance'
+
+describe 'join function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do
+ describe 'success' do
+ it 'joins arrays' do
+ pp = <<-EOS
+ $a = ['aaa','bbb','ccc']
+ $b = ':'
+ $c = 'aaa:bbb:ccc'
+ $o = join($a,$b)
+ if $o == $c {
+ notify { 'output correct': }
+ }
+ EOS
+
+ apply_manifest(pp, :catch_failures => true) do |r|
+ expect(r.stdout).to match(/Notice: output correct/)
+ end
+ end
+ it 'handles non arrays'
+ end
+ describe 'failure' do
+ it 'handles improper argument counts'
+ end
+end
diff --git a/spec/acceptance/keys_spec.rb b/spec/acceptance/keys_spec.rb
new file mode 100755
index 0000000..176918e
--- /dev/null
+++ b/spec/acceptance/keys_spec.rb
@@ -0,0 +1,23 @@
+#! /usr/bin/env ruby -S rspec
+require 'spec_helper_acceptance'
+
+describe 'keys function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do
+ describe 'success' do
+ it 'keyss hashes' do
+ pp = <<-EOS
+ $a = {'aaa'=>'bbb','ccc'=>'ddd'}
+ $o = keys($a)
+ notice(inline_template('keys is <%= @o.sort.inspect %>'))
+ EOS
+
+ apply_manifest(pp, :catch_failures => true) do |r|
+ expect(r.stdout).to match(/keys is \["aaa", "ccc"\]/)
+ end
+ end
+ it 'handles non hashes'
+ it 'handles empty hashes'
+ end
+ describe 'failure' do
+ it 'handles improper argument counts'
+ end
+end
diff --git a/spec/acceptance/loadyaml_spec.rb b/spec/acceptance/loadyaml_spec.rb
new file mode 100644
index 0000000..1e910a9
--- /dev/null
+++ b/spec/acceptance/loadyaml_spec.rb
@@ -0,0 +1,33 @@
+#! /usr/bin/env ruby -S rspec
+require 'spec_helper_acceptance'
+
+tmpdir = default.tmpdir('stdlib')
+
+describe 'loadyaml function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do
+ describe 'success' do
+ it 'loadyamls array of values' do
+ shell("echo '---
+ aaa: 1
+ bbb: 2
+ ccc: 3
+ ddd: 4' > #{tmpdir}/testyaml.yaml")
+ pp = <<-EOS
+ $o = loadyaml('#{tmpdir}/testyaml.yaml')
+ notice(inline_template('loadyaml[aaa] is <%= @o["aaa"].inspect %>'))
+ notice(inline_template('loadyaml[bbb] is <%= @o["bbb"].inspect %>'))
+ notice(inline_template('loadyaml[ccc] is <%= @o["ccc"].inspect %>'))
+ notice(inline_template('loadyaml[ddd] is <%= @o["ddd"].inspect %>'))
+ EOS
+
+ apply_manifest(pp, :catch_failures => true) do |r|
+ expect(r.stdout).to match(/loadyaml\[aaa\] is 1/)
+ expect(r.stdout).to match(/loadyaml\[bbb\] is 2/)
+ expect(r.stdout).to match(/loadyaml\[ccc\] is 3/)
+ expect(r.stdout).to match(/loadyaml\[ddd\] is 4/)
+ end
+ end
+ end
+ describe 'failure' do
+ it 'fails with no arguments'
+ end
+end
diff --git a/spec/acceptance/lstrip_spec.rb b/spec/acceptance/lstrip_spec.rb
new file mode 100755
index 0000000..3dc952f
--- /dev/null
+++ b/spec/acceptance/lstrip_spec.rb
@@ -0,0 +1,34 @@
+#! /usr/bin/env ruby -S rspec
+require 'spec_helper_acceptance'
+
+describe 'lstrip function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do
+ describe 'success' do
+ it 'lstrips arrays' do
+ pp = <<-EOS
+ $a = [" the "," public "," art","galleries "]
+ # Anagram: Large picture halls, I bet
+ $o = lstrip($a)
+ notice(inline_template('lstrip is <%= @o.inspect %>'))
+ EOS
+
+ apply_manifest(pp, :catch_failures => true) do |r|
+ expect(r.stdout).to match(/lstrip is \["the ", "public ", "art", "galleries "\]/)
+ end
+ end
+ it 'lstrips strings' do
+ pp = <<-EOS
+ $a = " blowzy night-frumps vex'd jack q "
+ $o = lstrip($a)
+ notice(inline_template('lstrip is <%= @o.inspect %>'))
+ EOS
+
+ apply_manifest(pp, :catch_failures => true) do |r|
+ expect(r.stdout).to match(/lstrip is "blowzy night-frumps vex'd jack q "/)
+ end
+ end
+ end
+ describe 'failure' do
+ it 'handles no arguments'
+ it 'handles non strings or arrays'
+ end
+end
diff --git a/spec/acceptance/max_spec.rb b/spec/acceptance/max_spec.rb
new file mode 100755
index 0000000..f04e3d2
--- /dev/null
+++ b/spec/acceptance/max_spec.rb
@@ -0,0 +1,20 @@
+#! /usr/bin/env ruby -S rspec
+require 'spec_helper_acceptance'
+
+describe 'max function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do
+ describe 'success' do
+ it 'maxs arrays' do
+ pp = <<-EOS
+ $o = max("the","public","art","galleries")
+ notice(inline_template('max is <%= @o.inspect %>'))
+ EOS
+
+ apply_manifest(pp, :catch_failures => true) do |r|
+ expect(r.stdout).to match(/max is "the"/)
+ end
+ end
+ end
+ describe 'failure' do
+ it 'handles no arguments'
+ end
+end
diff --git a/spec/acceptance/member_spec.rb b/spec/acceptance/member_spec.rb
new file mode 100755
index 0000000..fe75a07
--- /dev/null
+++ b/spec/acceptance/member_spec.rb
@@ -0,0 +1,54 @@
+#! /usr/bin/env ruby -S rspec
+require 'spec_helper_acceptance'
+
+describe 'member function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do
+ shared_examples 'item found' do
+ it 'should output correctly' do
+ apply_manifest(pp, :catch_failures => true) do |r|
+ expect(r.stdout).to match(/Notice: output correct/)
+ end
+ end
+ end
+ describe 'success' do
+ it 'members arrays' do
+ pp = <<-EOS
+ $a = ['aaa','bbb','ccc']
+ $b = 'ccc'
+ $c = true
+ $o = member($a,$b)
+ if $o == $c {
+ notify { 'output correct': }
+ }
+ EOS
+
+ apply_manifest(pp, :catch_failures => true) do |r|
+ expect(r.stdout).to match(/Notice: output correct/)
+ end
+ end
+ describe 'members array of integers' do
+ it_should_behave_like 'item found' do
+ let(:pp) { <<-EOS
+ if member( [1,2,3,4], 4 ){
+ notify { 'output correct': }
+ }
+ EOS
+ }
+ end
+ end
+ describe 'members of mixed array' do
+ it_should_behave_like 'item found' do
+ let(:pp) { <<-EOS
+ if member( ['a','4',3], 'a' ){
+ notify { 'output correct': }
+}
+ EOS
+ }
+ end
+ end
+ it 'members arrays without members'
+ end
+
+ describe 'failure' do
+ it 'handles improper argument counts'
+ end
+end
diff --git a/spec/acceptance/merge_spec.rb b/spec/acceptance/merge_spec.rb
new file mode 100755
index 0000000..227b994
--- /dev/null
+++ b/spec/acceptance/merge_spec.rb
@@ -0,0 +1,23 @@
+#! /usr/bin/env ruby -S rspec
+require 'spec_helper_acceptance'
+
+describe 'merge function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do
+ describe 'success' do
+ it 'should merge two hashes' do
+ pp = <<-EOS
+ $a = {'one' => 1, 'two' => 2, 'three' => { 'four' => 4 } }
+ $b = {'two' => 'dos', 'three' => { 'five' => 5 } }
+ $o = merge($a, $b)
+ notice(inline_template('merge[one] is <%= @o["one"].inspect %>'))
+ notice(inline_template('merge[two] is <%= @o["two"].inspect %>'))
+ notice(inline_template('merge[three] is <%= @o["three"].inspect %>'))
+ EOS
+
+ apply_manifest(pp, :catch_failures => true) do |r|
+ expect(r.stdout).to match(/merge\[one\] is ("1"|1)/)
+ expect(r.stdout).to match(/merge\[two\] is "dos"/)
+ expect(r.stdout).to match(/merge\[three\] is {"five"=>("5"|5)}/)
+ end
+ end
+ end
+end
diff --git a/spec/acceptance/min_spec.rb b/spec/acceptance/min_spec.rb
new file mode 100755
index 0000000..509092d
--- /dev/null
+++ b/spec/acceptance/min_spec.rb
@@ -0,0 +1,20 @@
+#! /usr/bin/env ruby -S rspec
+require 'spec_helper_acceptance'
+
+describe 'min function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do
+ describe 'success' do
+ it 'mins arrays' do
+ pp = <<-EOS
+ $o = min("the","public","art","galleries")
+ notice(inline_template('min is <%= @o.inspect %>'))
+ EOS
+
+ apply_manifest(pp, :catch_failures => true) do |r|
+ expect(r.stdout).to match(/min is "art"/)
+ end
+ end
+ end
+ describe 'failure' do
+ it 'handles no arguments'
+ end
+end
diff --git a/spec/acceptance/nodesets/centos-59-x64.yml b/spec/acceptance/nodesets/centos-59-x64.yml
new file mode 100644
index 0000000..2ad90b8
--- /dev/null
+++ b/spec/acceptance/nodesets/centos-59-x64.yml
@@ -0,0 +1,10 @@
+HOSTS:
+ centos-59-x64:
+ roles:
+ - master
+ platform: el-5-x86_64
+ box : centos-59-x64-vbox4210-nocm
+ box_url : http://puppet-vagrant-boxes.puppetlabs.com/centos-59-x64-vbox4210-nocm.box
+ hypervisor : vagrant
+CONFIG:
+ type: git
diff --git a/spec/acceptance/nodesets/centos-6-vcloud.yml b/spec/acceptance/nodesets/centos-6-vcloud.yml
new file mode 100644
index 0000000..ca9c1d3
--- /dev/null
+++ b/spec/acceptance/nodesets/centos-6-vcloud.yml
@@ -0,0 +1,15 @@
+HOSTS:
+ 'centos-6-vcloud':
+ roles:
+ - master
+ platform: el-6-x86_64
+ hypervisor: vcloud
+ template: centos-6-x86_64
+CONFIG:
+ type: foss
+ ssh:
+ keys: "~/.ssh/id_rsa-acceptance"
+ datastore: instance0
+ folder: Delivery/Quality Assurance/Enterprise/Dynamic
+ resourcepool: delivery/Quality Assurance/Enterprise/Dynamic
+ pooling_api: http://vcloud.delivery.puppetlabs.net/
diff --git a/spec/acceptance/nodesets/centos-64-x64-pe.yml b/spec/acceptance/nodesets/centos-64-x64-pe.yml
new file mode 100644
index 0000000..7d9242f
--- /dev/null
+++ b/spec/acceptance/nodesets/centos-64-x64-pe.yml
@@ -0,0 +1,12 @@
+HOSTS:
+ centos-64-x64:
+ roles:
+ - master
+ - database
+ - dashboard
+ platform: el-6-x86_64
+ box : centos-64-x64-vbox4210-nocm
+ box_url : http://puppet-vagrant-boxes.puppetlabs.com/centos-64-x64-vbox4210-nocm.box
+ hypervisor : vagrant
+CONFIG:
+ type: pe
diff --git a/spec/acceptance/nodesets/centos-64-x64.yml b/spec/acceptance/nodesets/centos-64-x64.yml
new file mode 100644
index 0000000..05540ed
--- /dev/null
+++ b/spec/acceptance/nodesets/centos-64-x64.yml
@@ -0,0 +1,10 @@
+HOSTS:
+ centos-64-x64:
+ roles:
+ - master
+ platform: el-6-x86_64
+ box : centos-64-x64-vbox4210-nocm
+ box_url : http://puppet-vagrant-boxes.puppetlabs.com/centos-64-x64-vbox4210-nocm.box
+ hypervisor : vagrant
+CONFIG:
+ type: foss
diff --git a/spec/acceptance/nodesets/centos-65-x64.yml b/spec/acceptance/nodesets/centos-65-x64.yml
new file mode 100644
index 0000000..4e2cb80
--- /dev/null
+++ b/spec/acceptance/nodesets/centos-65-x64.yml
@@ -0,0 +1,10 @@
+HOSTS:
+ centos-65-x64:
+ roles:
+ - master
+ platform: el-6-x86_64
+ box : centos-65-x64-vbox436-nocm
+ box_url : http://puppet-vagrant-boxes.puppetlabs.com/centos-65-x64-virtualbox-nocm.box
+ hypervisor : vagrant
+CONFIG:
+ type: foss
diff --git a/spec/acceptance/nodesets/default.yml b/spec/acceptance/nodesets/default.yml
new file mode 100644
index 0000000..4e2cb80
--- /dev/null
+++ b/spec/acceptance/nodesets/default.yml
@@ -0,0 +1,10 @@
+HOSTS:
+ centos-65-x64:
+ roles:
+ - master
+ platform: el-6-x86_64
+ box : centos-65-x64-vbox436-nocm
+ box_url : http://puppet-vagrant-boxes.puppetlabs.com/centos-65-x64-virtualbox-nocm.box
+ hypervisor : vagrant
+CONFIG:
+ type: foss
diff --git a/spec/acceptance/nodesets/fedora-18-x64.yml b/spec/acceptance/nodesets/fedora-18-x64.yml
new file mode 100644
index 0000000..1361649
--- /dev/null
+++ b/spec/acceptance/nodesets/fedora-18-x64.yml
@@ -0,0 +1,10 @@
+HOSTS:
+ fedora-18-x64:
+ roles:
+ - master
+ platform: fedora-18-x86_64
+ box : fedora-18-x64-vbox4210-nocm
+ box_url : http://puppet-vagrant-boxes.puppetlabs.com/fedora-18-x64-vbox4210-nocm.box
+ hypervisor : vagrant
+CONFIG:
+ type: foss
diff --git a/spec/acceptance/nodesets/sles-11-x64.yml b/spec/acceptance/nodesets/sles-11-x64.yml
new file mode 100644
index 0000000..41abe21
--- /dev/null
+++ b/spec/acceptance/nodesets/sles-11-x64.yml
@@ -0,0 +1,10 @@
+HOSTS:
+ sles-11-x64.local:
+ roles:
+ - master
+ platform: sles-11-x64
+ box : sles-11sp1-x64-vbox4210-nocm
+ box_url : http://puppet-vagrant-boxes.puppetlabs.com/sles-11sp1-x64-vbox4210-nocm.box
+ hypervisor : vagrant
+CONFIG:
+ type: foss
diff --git a/spec/acceptance/nodesets/ubuntu-server-10044-x64.yml b/spec/acceptance/nodesets/ubuntu-server-10044-x64.yml
new file mode 100644
index 0000000..5ca1514
--- /dev/null
+++ b/spec/acceptance/nodesets/ubuntu-server-10044-x64.yml
@@ -0,0 +1,10 @@
+HOSTS:
+ ubuntu-server-10044-x64:
+ roles:
+ - master
+ platform: ubuntu-10.04-amd64
+ box : ubuntu-server-10044-x64-vbox4210-nocm
+ box_url : http://puppet-vagrant-boxes.puppetlabs.com/ubuntu-server-10044-x64-vbox4210-nocm.box
+ hypervisor : vagrant
+CONFIG:
+ type: foss
diff --git a/spec/acceptance/nodesets/ubuntu-server-12042-x64.yml b/spec/acceptance/nodesets/ubuntu-server-12042-x64.yml
new file mode 100644
index 0000000..d065b30
--- /dev/null
+++ b/spec/acceptance/nodesets/ubuntu-server-12042-x64.yml
@@ -0,0 +1,10 @@
+HOSTS:
+ ubuntu-server-12042-x64:
+ roles:
+ - master
+ platform: ubuntu-12.04-amd64
+ box : ubuntu-server-12042-x64-vbox4210-nocm
+ box_url : http://puppet-vagrant-boxes.puppetlabs.com/ubuntu-server-12042-x64-vbox4210-nocm.box
+ hypervisor : vagrant
+CONFIG:
+ type: foss
diff --git a/spec/acceptance/nodesets/ubuntu-server-1404-x64.yml b/spec/acceptance/nodesets/ubuntu-server-1404-x64.yml
new file mode 100644
index 0000000..cba1cd0
--- /dev/null
+++ b/spec/acceptance/nodesets/ubuntu-server-1404-x64.yml
@@ -0,0 +1,11 @@
+HOSTS:
+ ubuntu-server-1404-x64:
+ roles:
+ - master
+ platform: ubuntu-14.04-amd64
+ box : puppetlabs/ubuntu-14.04-64-nocm
+ box_url : https://vagrantcloud.com/puppetlabs/ubuntu-14.04-64-nocm
+ hypervisor : vagrant
+CONFIG:
+ log_level : debug
+ type: git
diff --git a/spec/acceptance/nodesets/windows-2003-i386.yml b/spec/acceptance/nodesets/windows-2003-i386.yml
new file mode 100644
index 0000000..47dadbd
--- /dev/null
+++ b/spec/acceptance/nodesets/windows-2003-i386.yml
@@ -0,0 +1,26 @@
+HOSTS:
+ ubuntu1204:
+ roles:
+ - master
+ - database
+ - dashboard
+ platform: ubuntu-12.04-amd64
+ template: ubuntu-1204-x86_64
+ hypervisor: vcloud
+ win2003_i386:
+ roles:
+ - agent
+ - default
+ platform: windows-2003-i386
+ template: win-2003-i386
+ hypervisor: vcloud
+CONFIG:
+ nfs_server: none
+ ssh:
+ keys: "~/.ssh/id_rsa-acceptance"
+ consoleport: 443
+ datastore: instance0
+ folder: Delivery/Quality Assurance/Enterprise/Dynamic
+ resourcepool: delivery/Quality Assurance/Enterprise/Dynamic
+ pooling_api: http://vcloud.delivery.puppetlabs.net/
+ pe_dir: http://neptune.puppetlabs.lan/3.2/ci-ready/
diff --git a/spec/acceptance/nodesets/windows-2003-x86_64.yml b/spec/acceptance/nodesets/windows-2003-x86_64.yml
new file mode 100644
index 0000000..6a884bc
--- /dev/null
+++ b/spec/acceptance/nodesets/windows-2003-x86_64.yml
@@ -0,0 +1,26 @@
+HOSTS:
+ ubuntu1204:
+ roles:
+ - master
+ - database
+ - dashboard
+ platform: ubuntu-12.04-amd64
+ template: ubuntu-1204-x86_64
+ hypervisor: vcloud
+ win2003_x86_64:
+ roles:
+ - agent
+ - default
+ platform: windows-2003-x86_64
+ template: win-2003-x86_64
+ hypervisor: vcloud
+CONFIG:
+ nfs_server: none
+ ssh:
+ keys: "~/.ssh/id_rsa-acceptance"
+ consoleport: 443
+ datastore: instance0
+ folder: Delivery/Quality Assurance/Enterprise/Dynamic
+ resourcepool: delivery/Quality Assurance/Enterprise/Dynamic
+ pooling_api: http://vcloud.delivery.puppetlabs.net/
+ pe_dir: http://neptune.puppetlabs.lan/3.2/ci-ready/
diff --git a/spec/acceptance/nodesets/windows-2008-x86_64.yml b/spec/acceptance/nodesets/windows-2008-x86_64.yml
new file mode 100644
index 0000000..ae3c11d
--- /dev/null
+++ b/spec/acceptance/nodesets/windows-2008-x86_64.yml
@@ -0,0 +1,26 @@
+HOSTS:
+ ubuntu1204:
+ roles:
+ - master
+ - database
+ - dashboard
+ platform: ubuntu-12.04-amd64
+ template: ubuntu-1204-x86_64
+ hypervisor: vcloud
+ win2008_x86_64:
+ roles:
+ - agent
+ - default
+ platform: windows-2008-x86_64
+ template: win-2008-x86_64
+ hypervisor: vcloud
+CONFIG:
+ nfs_server: none
+ ssh:
+ keys: "~/.ssh/id_rsa-acceptance"
+ consoleport: 443
+ datastore: instance0
+ folder: Delivery/Quality Assurance/Enterprise/Dynamic
+ resourcepool: delivery/Quality Assurance/Enterprise/Dynamic
+ pooling_api: http://vcloud.delivery.puppetlabs.net/
+ pe_dir: http://neptune.puppetlabs.lan/3.2/ci-ready/
diff --git a/spec/acceptance/nodesets/windows-2008r2-x86_64.yml b/spec/acceptance/nodesets/windows-2008r2-x86_64.yml
new file mode 100644
index 0000000..63923ac
--- /dev/null
+++ b/spec/acceptance/nodesets/windows-2008r2-x86_64.yml
@@ -0,0 +1,26 @@
+HOSTS:
+ ubuntu1204:
+ roles:
+ - master
+ - database
+ - dashboard
+ platform: ubuntu-12.04-amd64
+ template: ubuntu-1204-x86_64
+ hypervisor: vcloud
+ win2008r2:
+ roles:
+ - agent
+ - default
+ platform: windows-2008r2-x86_64
+ template: win-2008r2-x86_64
+ hypervisor: vcloud
+CONFIG:
+ nfs_server: none
+ ssh:
+ keys: "~/.ssh/id_rsa-acceptance"
+ consoleport: 443
+ datastore: instance0
+ folder: Delivery/Quality Assurance/Enterprise/Dynamic
+ resourcepool: delivery/Quality Assurance/Enterprise/Dynamic
+ pooling_api: http://vcloud.delivery.puppetlabs.net/
+ pe_dir: http://neptune.puppetlabs.lan/3.2/ci-ready/
diff --git a/spec/acceptance/nodesets/windows-2012-x86_64.yml b/spec/acceptance/nodesets/windows-2012-x86_64.yml
new file mode 100644
index 0000000..eaa4eca
--- /dev/null
+++ b/spec/acceptance/nodesets/windows-2012-x86_64.yml
@@ -0,0 +1,26 @@
+HOSTS:
+ ubuntu1204:
+ roles:
+ - master
+ - database
+ - dashboard
+ platform: ubuntu-12.04-amd64
+ template: ubuntu-1204-x86_64
+ hypervisor: vcloud
+ win2012:
+ roles:
+ - agent
+ - default
+ platform: windows-2012-x86_64
+ template: win-2012-x86_64
+ hypervisor: vcloud
+CONFIG:
+ nfs_server: none
+ ssh:
+ keys: "~/.ssh/id_rsa-acceptance"
+ consoleport: 443
+ datastore: instance0
+ folder: Delivery/Quality Assurance/Enterprise/Dynamic
+ resourcepool: delivery/Quality Assurance/Enterprise/Dynamic
+ pooling_api: http://vcloud.delivery.puppetlabs.net/
+ pe_dir: http://neptune.puppetlabs.lan/3.2/ci-ready/
diff --git a/spec/acceptance/nodesets/windows-2012r2-x86_64.yml b/spec/acceptance/nodesets/windows-2012r2-x86_64.yml
new file mode 100644
index 0000000..1f0ea97
--- /dev/null
+++ b/spec/acceptance/nodesets/windows-2012r2-x86_64.yml
@@ -0,0 +1,26 @@
+HOSTS:
+ ubuntu1204:
+ roles:
+ - master
+ - database
+ - dashboard
+ platform: ubuntu-12.04-amd64
+ template: ubuntu-1204-x86_64
+ hypervisor: vcloud
+ win2012r2:
+ roles:
+ - agent
+ - default
+ platform: windows-2012r2-x86_64
+ template: win-2012r2-x86_64
+ hypervisor: vcloud
+CONFIG:
+ nfs_server: none
+ ssh:
+ keys: "~/.ssh/id_rsa-acceptance"
+ consoleport: 443
+ datastore: instance0
+ folder: Delivery/Quality Assurance/Enterprise/Dynamic
+ resourcepool: delivery/Quality Assurance/Enterprise/Dynamic
+ pooling_api: http://vcloud.delivery.puppetlabs.net/
+ pe_dir: http://neptune.puppetlabs.lan/3.2/ci-ready/
diff --git a/spec/acceptance/num2bool_spec.rb b/spec/acceptance/num2bool_spec.rb
new file mode 100755
index 0000000..1d99ba0
--- /dev/null
+++ b/spec/acceptance/num2bool_spec.rb
@@ -0,0 +1,76 @@
+#! /usr/bin/env ruby -S rspec
+require 'spec_helper_acceptance'
+
+describe 'num2bool function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do
+ describe 'success' do
+ it 'bools positive numbers and numeric strings as true' do
+ pp = <<-EOS
+ $a = 1
+ $b = "1"
+ $c = "50"
+ $ao = num2bool($a)
+ $bo = num2bool($b)
+ $co = num2bool($c)
+ notice(inline_template('a is <%= @ao.inspect %>'))
+ notice(inline_template('b is <%= @bo.inspect %>'))
+ notice(inline_template('c is <%= @co.inspect %>'))
+ EOS
+
+ apply_manifest(pp, :catch_failures => true) do |r|
+ expect(r.stdout).to match(/a is true/)
+ expect(r.stdout).to match(/b is true/)
+ expect(r.stdout).to match(/c is true/)
+ end
+ end
+ it 'bools negative numbers as false' do
+ pp = <<-EOS
+ $a = 0
+ $b = -0.1
+ $c = ["-50","1"]
+ $ao = num2bool($a)
+ $bo = num2bool($b)
+ $co = num2bool($c)
+ notice(inline_template('a is <%= @ao.inspect %>'))
+ notice(inline_template('b is <%= @bo.inspect %>'))
+ notice(inline_template('c is <%= @co.inspect %>'))
+ EOS
+
+ apply_manifest(pp, :catch_failures => true) do |r|
+ expect(r.stdout).to match(/a is false/)
+ expect(r.stdout).to match(/b is false/)
+ expect(r.stdout).to match(/c is false/)
+ end
+ end
+ end
+ describe 'failure' do
+ it 'fails on words' do
+ pp = <<-EOS
+ $a = "a"
+ $ao = num2bool($a)
+ notice(inline_template('a is <%= @ao.inspect %>'))
+ EOS
+ expect(apply_manifest(pp, :expect_failures => true).stderr).to match(/not look like a number/)
+ end
+
+ it 'fails on numberwords' do
+ pp = <<-EOS
+ $b = "1b"
+ $bo = num2bool($b)
+ notice(inline_template('b is <%= @bo.inspect %>'))
+ EOS
+ expect(apply_manifest(pp, :expect_failures => true).stderr).to match(/not look like a number/)
+
+ end
+
+ it 'fails on non-numeric/strings' do
+ pending "The function will call .to_s.to_i on anything not a Numeric or
+ String, and results in 0. Is this intended?"
+ pp = <<-EOS
+ $c = {"c" => "-50"}
+ $co = num2bool($c)
+ notice(inline_template('c is <%= @co.inspect %>'))
+ EOS
+ expect(apply_manifest(ppc :expect_failures => true).stderr).to match(/Unable to parse/)
+ end
+ end
+end
diff --git a/spec/acceptance/parsejson_spec.rb b/spec/acceptance/parsejson_spec.rb
new file mode 100755
index 0000000..5097810
--- /dev/null
+++ b/spec/acceptance/parsejson_spec.rb
@@ -0,0 +1,34 @@
+#! /usr/bin/env ruby -S rspec
+require 'spec_helper_acceptance'
+
+describe 'parsejson function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do
+ describe 'success' do
+ it 'parses valid json' do
+ pp = <<-EOS
+ $a = '{"hunter": "washere", "tests": "passing"}'
+ $ao = parsejson($a)
+ $tests = $ao['tests']
+ notice(inline_template('tests are <%= @tests.inspect %>'))
+ EOS
+
+ apply_manifest(pp, :catch_failures => true) do |r|
+ expect(r.stdout).to match(/tests are "passing"/)
+ end
+ end
+ end
+ describe 'failure' do
+ it 'raises error on incorrect json' do
+ pp = <<-EOS
+ $a = '{"hunter": "washere", "tests": "passing",}'
+ $ao = parsejson($a)
+ notice(inline_template('a is <%= @ao.inspect %>'))
+ EOS
+
+ apply_manifest(pp, :expect_failures => true) do |r|
+ expect(r.stderr).to match(/expected next name/)
+ end
+ end
+
+ it 'raises error on incorrect number of arguments'
+ end
+end
diff --git a/spec/acceptance/parseyaml_spec.rb b/spec/acceptance/parseyaml_spec.rb
new file mode 100755
index 0000000..5819837
--- /dev/null
+++ b/spec/acceptance/parseyaml_spec.rb
@@ -0,0 +1,35 @@
+#! /usr/bin/env ruby -S rspec
+require 'spec_helper_acceptance'
+
+describe 'parseyaml function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do
+ describe 'success' do
+ it 'parses valid yaml' do
+ pp = <<-EOS
+ $a = "---\nhunter: washere\ntests: passing\n"
+ $o = parseyaml($a)
+ $tests = $o['tests']
+ notice(inline_template('tests are <%= @tests.inspect %>'))
+ EOS
+
+ apply_manifest(pp, :catch_failures => true) do |r|
+ expect(r.stdout).to match(/tests are "passing"/)
+ end
+ end
+ end
+ describe 'failure' do
+ it 'raises error on incorrect yaml' do
+ pp = <<-EOS
+ $a = "---\nhunter: washere\ntests: passing\n:"
+ $o = parseyaml($a)
+ $tests = $o['tests']
+ notice(inline_template('tests are <%= @tests.inspect %>'))
+ EOS
+
+ apply_manifest(pp, :expect_failures => true) do |r|
+ expect(r.stderr).to match(/(syntax error|did not find expected key)/)
+ end
+ end
+
+ it 'raises error on incorrect number of arguments'
+ end
+end
diff --git a/spec/acceptance/pick_default_spec.rb b/spec/acceptance/pick_default_spec.rb
new file mode 100755
index 0000000..a663f54
--- /dev/null
+++ b/spec/acceptance/pick_default_spec.rb
@@ -0,0 +1,54 @@
+#! /usr/bin/env ruby -S rspec
+require 'spec_helper_acceptance'
+
+describe 'pick_default function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do
+ describe 'success' do
+ it 'pick_defaults a default value' do
+ pp = <<-EOS
+ $a = undef
+ $o = pick_default($a, 'default')
+ notice(inline_template('picked is <%= @o.inspect %>'))
+ EOS
+
+ apply_manifest(pp, :catch_failures => true) do |r|
+ expect(r.stdout).to match(/picked is "default"/)
+ end
+ end
+ it 'pick_defaults with no value' do
+ pp = <<-EOS
+ $a = undef
+ $b = undef
+ $o = pick_default($a,$b)
+ notice(inline_template('picked is <%= @o.inspect %>'))
+ EOS
+
+ apply_manifest(pp, :catch_failures => true) do |r|
+ expect(r.stdout).to match(/picked is ""/)
+ end
+ end
+ it 'pick_defaults the first set value' do
+ pp = <<-EOS
+ $a = "something"
+ $b = "long"
+ $o = pick_default($a, $b, 'default')
+ notice(inline_template('picked is <%= @o.inspect %>'))
+ EOS
+
+ apply_manifest(pp, :catch_failures => true) do |r|
+ expect(r.stdout).to match(/picked is "something"/)
+ end
+ end
+ end
+ describe 'failure' do
+ it 'raises error with no values' do
+ pp = <<-EOS
+ $o = pick_default()
+ notice(inline_template('picked is <%= @o.inspect %>'))
+ EOS
+
+ apply_manifest(pp, :expect_failures => true) do |r|
+ expect(r.stderr).to match(/Must receive at least one argument/)
+ end
+ end
+ end
+end
diff --git a/spec/acceptance/pick_spec.rb b/spec/acceptance/pick_spec.rb
new file mode 100755
index 0000000..46cf63f
--- /dev/null
+++ b/spec/acceptance/pick_spec.rb
@@ -0,0 +1,44 @@
+#! /usr/bin/env ruby -S rspec
+require 'spec_helper_acceptance'
+
+describe 'pick function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do
+ describe 'success' do
+ it 'picks a default value' do
+ pp = <<-EOS
+ $a = undef
+ $o = pick($a, 'default')
+ notice(inline_template('picked is <%= @o.inspect %>'))
+ EOS
+
+ apply_manifest(pp, :catch_failures => true) do |r|
+ expect(r.stdout).to match(/picked is "default"/)
+ end
+ end
+ it 'picks the first set value' do
+ pp = <<-EOS
+ $a = "something"
+ $b = "long"
+ $o = pick($a, $b, 'default')
+ notice(inline_template('picked is <%= @o.inspect %>'))
+ EOS
+
+ apply_manifest(pp, :catch_failures => true) do |r|
+ expect(r.stdout).to match(/picked is "something"/)
+ end
+ end
+ end
+ describe 'failure' do
+ it 'raises error with all undef values' do
+ pp = <<-EOS
+ $a = undef
+ $b = undef
+ $o = pick($a, $b)
+ notice(inline_template('picked is <%= @o.inspect %>'))
+ EOS
+
+ apply_manifest(pp, :expect_failures => true) do |r|
+ expect(r.stderr).to match(/must receive at least one non empty value/)
+ end
+ end
+ end
+end
diff --git a/spec/acceptance/prefix_spec.rb b/spec/acceptance/prefix_spec.rb
new file mode 100755
index 0000000..de55530
--- /dev/null
+++ b/spec/acceptance/prefix_spec.rb
@@ -0,0 +1,42 @@
+#! /usr/bin/env ruby -S rspec
+require 'spec_helper_acceptance'
+
+describe 'prefix function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do
+ describe 'success' do
+ it 'prefixes array of values' do
+ pp = <<-EOS
+ $o = prefix(['a','b','c'],'p')
+ notice(inline_template('prefix is <%= @o.inspect %>'))
+ EOS
+
+ apply_manifest(pp, :catch_failures => true) do |r|
+ expect(r.stdout).to match(/prefix is \["pa", "pb", "pc"\]/)
+ end
+ end
+ it 'prefixs with empty array' do
+ pp = <<-EOS
+ $o = prefix([],'p')
+ notice(inline_template('prefix is <%= @o.inspect %>'))
+ EOS
+
+ apply_manifest(pp, :catch_failures => true) do |r|
+ expect(r.stdout).to match(/prefix is \[\]/)
+ end
+ end
+ it 'prefixs array of values with undef' do
+ pp = <<-EOS
+ $o = prefix(['a','b','c'], undef)
+ notice(inline_template('prefix is <%= @o.inspect %>'))
+ EOS
+
+ apply_manifest(pp, :catch_failures => true) do |r|
+ expect(r.stdout).to match(/prefix is \["a", "b", "c"\]/)
+ end
+ end
+ end
+ describe 'failure' do
+ it 'fails with no arguments'
+ it 'fails when first argument is not array'
+ it 'fails when second argument is not string'
+ end
+end
diff --git a/spec/acceptance/range_spec.rb b/spec/acceptance/range_spec.rb
new file mode 100755
index 0000000..a3ccd33
--- /dev/null
+++ b/spec/acceptance/range_spec.rb
@@ -0,0 +1,36 @@
+#! /usr/bin/env ruby -S rspec
+require 'spec_helper_acceptance'
+
+describe 'range function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do
+ describe 'success' do
+ it 'ranges letters' do
+ pp = <<-EOS
+ $o = range('a','d')
+ notice(inline_template('range is <%= @o.inspect %>'))
+ EOS
+
+ apply_manifest(pp, :catch_failures => true) do |r|
+ expect(r.stdout).to match(/range is \["a", "b", "c", "d"\]/)
+ end
+ end
+ it 'ranges letters with a step' do
+ pp = <<-EOS
+ $o = range('a','d', '2')
+ notice(inline_template('range is <%= @o.inspect %>'))
+ EOS
+
+ apply_manifest(pp, :catch_failures => true) do |r|
+ expect(r.stdout).to match(/range is \["a", "c"\]/)
+ end
+ end
+ it 'ranges letters with a negative step'
+ it 'ranges numbers'
+ it 'ranges numbers with a step'
+ it 'ranges numbers with a negative step'
+ it 'ranges numeric strings'
+ it 'ranges zero padded numbers'
+ end
+ describe 'failure' do
+ it 'fails with no arguments'
+ end
+end
diff --git a/spec/acceptance/reject_spec.rb b/spec/acceptance/reject_spec.rb
new file mode 100755
index 0000000..7f16a00
--- /dev/null
+++ b/spec/acceptance/reject_spec.rb
@@ -0,0 +1,42 @@
+#! /usr/bin/env ruby -S rspec
+require 'spec_helper_acceptance'
+
+describe 'reject function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do
+ describe 'success' do
+ it 'rejects array of values' do
+ pp = <<-EOS
+ $o = reject(['aaa','bbb','ccc','aaaddd'], 'aaa')
+ notice(inline_template('reject is <%= @o.inspect %>'))
+ EOS
+
+ apply_manifest(pp, :catch_failures => true) do |r|
+ expect(r.stdout).to match(/reject is \["bbb", "ccc"\]/)
+ end
+ end
+ it 'rejects with empty array' do
+ pp = <<-EOS
+ $o = reject([],'aaa')
+ notice(inline_template('reject is <%= @o.inspect %>'))
+ EOS
+
+ apply_manifest(pp, :catch_failures => true) do |r|
+ expect(r.stdout).to match(/reject is \[\]/)
+ end
+ end
+ it 'rejects array of values with undef' do
+ pp = <<-EOS
+ $o = reject(['aaa','bbb','ccc','aaaddd'], undef)
+ notice(inline_template('reject is <%= @o.inspect %>'))
+ EOS
+
+ apply_manifest(pp, :catch_failures => true) do |r|
+ expect(r.stdout).to match(/reject is \[\]/)
+ end
+ end
+ end
+ describe 'failure' do
+ it 'fails with no arguments'
+ it 'fails when first argument is not array'
+ it 'fails when second argument is not string'
+ end
+end
diff --git a/spec/acceptance/reverse_spec.rb b/spec/acceptance/reverse_spec.rb
new file mode 100755
index 0000000..c3f0156
--- /dev/null
+++ b/spec/acceptance/reverse_spec.rb
@@ -0,0 +1,23 @@
+#! /usr/bin/env ruby -S rspec
+require 'spec_helper_acceptance'
+
+describe 'reverse function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do
+ describe 'success' do
+ it 'reverses strings' do
+ pp = <<-EOS
+ $a = "the public art galleries"
+ # Anagram: Large picture halls, I bet
+ $o = reverse($a)
+ notice(inline_template('reverse is <%= @o.inspect %>'))
+ EOS
+
+ apply_manifest(pp, :catch_failures => true) do |r|
+ expect(r.stdout).to match(/reverse is "seirellag tra cilbup eht"/)
+ end
+ end
+ end
+ describe 'failure' do
+ it 'handles no arguments'
+ it 'handles non strings or arrays'
+ end
+end
diff --git a/spec/acceptance/rstrip_spec.rb b/spec/acceptance/rstrip_spec.rb
new file mode 100755
index 0000000..b57a8b0
--- /dev/null
+++ b/spec/acceptance/rstrip_spec.rb
@@ -0,0 +1,34 @@
+#! /usr/bin/env ruby -S rspec
+require 'spec_helper_acceptance'
+
+describe 'rstrip function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do
+ describe 'success' do
+ it 'rstrips arrays' do
+ pp = <<-EOS
+ $a = [" the "," public "," art","galleries "]
+ # Anagram: Large picture halls, I bet
+ $o = rstrip($a)
+ notice(inline_template('rstrip is <%= @o.inspect %>'))
+ EOS
+
+ apply_manifest(pp, :catch_failures => true) do |r|
+ expect(r.stdout).to match(/rstrip is \[" the", " public", " art", "galleries"\]/)
+ end
+ end
+ it 'rstrips strings' do
+ pp = <<-EOS
+ $a = " blowzy night-frumps vex'd jack q "
+ $o = rstrip($a)
+ notice(inline_template('rstrip is <%= @o.inspect %>'))
+ EOS
+
+ apply_manifest(pp, :catch_failures => true) do |r|
+ expect(r.stdout).to match(/rstrip is " blowzy night-frumps vex'd jack q"/)
+ end
+ end
+ end
+ describe 'failure' do
+ it 'handles no arguments'
+ it 'handles non strings or arrays'
+ end
+end
diff --git a/spec/acceptance/shuffle_spec.rb b/spec/acceptance/shuffle_spec.rb
new file mode 100755
index 0000000..b840d1f
--- /dev/null
+++ b/spec/acceptance/shuffle_spec.rb
@@ -0,0 +1,34 @@
+#! /usr/bin/env ruby -S rspec
+require 'spec_helper_acceptance'
+
+describe 'shuffle function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do
+ describe 'success' do
+ it 'shuffles arrays' do
+ pp = <<-EOS
+ $a = ["1", "2", "3", "4", "5", "6", "7", "8", "the","public","art","galleries"]
+ # Anagram: Large picture halls, I bet
+ $o = shuffle($a)
+ notice(inline_template('shuffle is <%= @o.inspect %>'))
+ EOS
+
+ apply_manifest(pp, :catch_failures => true) do |r|
+ expect(r.stdout).to_not match(/shuffle is \["1", "2", "3", "4", "5", "6", "7", "8", "the", "public", "art", "galleries"\]/)
+ end
+ end
+ it 'shuffles strings' do
+ pp = <<-EOS
+ $a = "blowzy night-frumps vex'd jack q"
+ $o = shuffle($a)
+ notice(inline_template('shuffle is <%= @o.inspect %>'))
+ EOS
+
+ apply_manifest(pp, :catch_failures => true) do |r|
+ expect(r.stdout).to_not match(/shuffle is "blowzy night-frumps vex'd jack q"/)
+ end
+ end
+ end
+ describe 'failure' do
+ it 'handles no arguments'
+ it 'handles non strings or arrays'
+ end
+end
diff --git a/spec/acceptance/size_spec.rb b/spec/acceptance/size_spec.rb
new file mode 100755
index 0000000..a52b778
--- /dev/null
+++ b/spec/acceptance/size_spec.rb
@@ -0,0 +1,55 @@
+#! /usr/bin/env ruby -S rspec
+require 'spec_helper_acceptance'
+
+describe 'size function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do
+ describe 'success' do
+ it 'single string size' do
+ pp = <<-EOS
+ $a = 'discombobulate'
+ $o = size($a)
+ notice(inline_template('size is <%= @o.inspect %>'))
+ EOS
+
+ apply_manifest(pp, :catch_failures => true) do |r|
+ expect(r.stdout).to match(/size is 14/)
+ end
+ end
+ it 'with empty string' do
+ pp = <<-EOS
+ $a = ''
+ $o = size($a)
+ notice(inline_template('size is <%= @o.inspect %>'))
+ EOS
+
+ apply_manifest(pp, :catch_failures => true) do |r|
+ expect(r.stdout).to match(/size is 0/)
+ end
+ end
+ it 'with undef' do
+ pp = <<-EOS
+ $a = undef
+ $o = size($a)
+ notice(inline_template('size is <%= @o.inspect %>'))
+ EOS
+
+ apply_manifest(pp, :catch_failures => true) do |r|
+ expect(r.stdout).to match(/size is 0/)
+ end
+ end
+ it 'strings in array' do
+ pp = <<-EOS
+ $a = ['discombobulate', 'moo']
+ $o = size($a)
+ notice(inline_template('size is <%= @o.inspect %>'))
+ EOS
+
+ apply_manifest(pp, :catch_failures => true) do |r|
+ expect(r.stdout).to match(/size is 2/)
+ end
+ end
+ end
+ describe 'failure' do
+ it 'handles no arguments'
+ it 'handles non strings or arrays'
+ end
+end
diff --git a/spec/acceptance/sort_spec.rb b/spec/acceptance/sort_spec.rb
new file mode 100755
index 0000000..c85bfab
--- /dev/null
+++ b/spec/acceptance/sort_spec.rb
@@ -0,0 +1,34 @@
+#! /usr/bin/env ruby -S rspec
+require 'spec_helper_acceptance'
+
+describe 'sort function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do
+ describe 'success' do
+ it 'sorts arrays' do
+ pp = <<-EOS
+ $a = ["the","public","art","galleries"]
+ # Anagram: Large picture halls, I bet
+ $o = sort($a)
+ notice(inline_template('sort is <%= @o.inspect %>'))
+ EOS
+
+ apply_manifest(pp, :catch_failures => true) do |r|
+ expect(r.stdout).to match(/sort is \["art", "galleries", "public", "the"\]/)
+ end
+ end
+ it 'sorts strings' do
+ pp = <<-EOS
+ $a = "blowzy night-frumps vex'd jack q"
+ $o = sort($a)
+ notice(inline_template('sort is <%= @o.inspect %>'))
+ EOS
+
+ apply_manifest(pp, :catch_failures => true) do |r|
+ expect(r.stdout).to match(/sort is " '-abcdefghijklmnopqrstuvwxyz"/)
+ end
+ end
+ end
+ describe 'failure' do
+ it 'handles no arguments'
+ it 'handles non strings or arrays'
+ end
+end
diff --git a/spec/acceptance/squeeze_spec.rb b/spec/acceptance/squeeze_spec.rb
new file mode 100755
index 0000000..400a458
--- /dev/null
+++ b/spec/acceptance/squeeze_spec.rb
@@ -0,0 +1,47 @@
+#! /usr/bin/env ruby -S rspec
+require 'spec_helper_acceptance'
+
+describe 'squeeze function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do
+ describe 'success' do
+ it 'squeezes arrays' do
+ pp = <<-EOS
+ # Real words!
+ $a = ["wallless", "laparohysterosalpingooophorectomy", "brrr", "goddessship"]
+ $o = squeeze($a)
+ notice(inline_template('squeeze is <%= @o.inspect %>'))
+ EOS
+
+ apply_manifest(pp, :catch_failures => true) do |r|
+ expect(r.stdout).to match(/squeeze is \["wales", "laparohysterosalpingophorectomy", "br", "godeship"\]/)
+ end
+ end
+ it 'squeezez arrays with an argument'
+ it 'squeezes strings' do
+ pp = <<-EOS
+ $a = "wallless laparohysterosalpingooophorectomy brrr goddessship"
+ $o = squeeze($a)
+ notice(inline_template('squeeze is <%= @o.inspect %>'))
+ EOS
+
+ apply_manifest(pp, :catch_failures => true) do |r|
+ expect(r.stdout).to match(/squeeze is "wales laparohysterosalpingophorectomy br godeship"/)
+ end
+ end
+
+ it 'squeezes strings with an argument' do
+ pp = <<-EOS
+ $a = "countessship duchessship governessship hostessship"
+ $o = squeeze($a, 's')
+ notice(inline_template('squeeze is <%= @o.inspect %>'))
+ EOS
+
+ apply_manifest(pp, :catch_failures => true) do |r|
+ expect(r.stdout).to match(/squeeze is "counteship ducheship governeship hosteship"/)
+ end
+ end
+ end
+ describe 'failure' do
+ it 'handles no arguments'
+ it 'handles non strings or arrays'
+ end
+end
diff --git a/spec/acceptance/str2bool_spec.rb b/spec/acceptance/str2bool_spec.rb
new file mode 100755
index 0000000..cf549da
--- /dev/null
+++ b/spec/acceptance/str2bool_spec.rb
@@ -0,0 +1,31 @@
+#! /usr/bin/env ruby -S rspec
+require 'spec_helper_acceptance'
+
+describe 'str2bool function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do
+ describe 'success' do
+ it 'works with "y"' do
+ pp = <<-EOS
+ $o = str2bool('y')
+ notice(inline_template('str2bool is <%= @o.inspect %>'))
+ EOS
+
+ apply_manifest(pp, :catch_failures => true) do |r|
+ expect(r.stdout).to match(/str2bool is true/)
+ end
+ end
+ it 'works with "Y"'
+ it 'works with "yes"'
+ it 'works with "1"'
+ it 'works with "true"'
+ it 'works with "n"'
+ it 'works with "N"'
+ it 'works with "no"'
+ it 'works with "0"'
+ it 'works with "false"'
+ it 'works with undef'
+ end
+ describe 'failure' do
+ it 'handles no arguments'
+ it 'handles non arrays or strings'
+ end
+end
diff --git a/spec/acceptance/str2saltedsha512_spec.rb b/spec/acceptance/str2saltedsha512_spec.rb
new file mode 100755
index 0000000..993e63b
--- /dev/null
+++ b/spec/acceptance/str2saltedsha512_spec.rb
@@ -0,0 +1,22 @@
+#! /usr/bin/env ruby -S rspec
+require 'spec_helper_acceptance'
+
+describe 'str2saltedsha512 function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do
+ describe 'success' do
+ it 'works with "y"' do
+ pp = <<-EOS
+ $o = str2saltedsha512('password')
+ notice(inline_template('str2saltedsha512 is <%= @o.inspect %>'))
+ EOS
+
+ apply_manifest(pp, :catch_failures => true) do |r|
+ expect(r.stdout).to match(/str2saltedsha512 is "[a-f0-9]{136}"/)
+ end
+ end
+ end
+ describe 'failure' do
+ it 'handles no arguments'
+ it 'handles more than one argument'
+ it 'handles non strings'
+ end
+end
diff --git a/spec/acceptance/strftime_spec.rb b/spec/acceptance/strftime_spec.rb
new file mode 100755
index 0000000..53b7f90
--- /dev/null
+++ b/spec/acceptance/strftime_spec.rb
@@ -0,0 +1,22 @@
+#! /usr/bin/env ruby -S rspec
+require 'spec_helper_acceptance'
+
+describe 'strftime function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do
+ describe 'success' do
+ it 'gives the Century' do
+ pp = <<-EOS
+ $o = strftime('%C')
+ notice(inline_template('strftime is <%= @o.inspect %>'))
+ EOS
+
+ apply_manifest(pp, :catch_failures => true) do |r|
+ expect(r.stdout).to match(/strftime is "20"/)
+ end
+ end
+ it 'takes a timezone argument'
+ end
+ describe 'failure' do
+ it 'handles no arguments'
+ it 'handles invalid format strings'
+ end
+end
diff --git a/spec/acceptance/strip_spec.rb b/spec/acceptance/strip_spec.rb
new file mode 100755
index 0000000..906fd7a
--- /dev/null
+++ b/spec/acceptance/strip_spec.rb
@@ -0,0 +1,34 @@
+#! /usr/bin/env ruby -S rspec
+require 'spec_helper_acceptance'
+
+describe 'strip function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do
+ describe 'success' do
+ it 'strips arrays' do
+ pp = <<-EOS
+ $a = [" the "," public "," art","galleries "]
+ # Anagram: Large picture halls, I bet
+ $o = strip($a)
+ notice(inline_template('strip is <%= @o.inspect %>'))
+ EOS
+
+ apply_manifest(pp, :catch_failures => true) do |r|
+ expect(r.stdout).to match(/strip is \["the", "public", "art", "galleries"\]/)
+ end
+ end
+ it 'strips strings' do
+ pp = <<-EOS
+ $a = " blowzy night-frumps vex'd jack q "
+ $o = strip($a)
+ notice(inline_template('strip is <%= @o.inspect %>'))
+ EOS
+
+ apply_manifest(pp, :catch_failures => true) do |r|
+ expect(r.stdout).to match(/strip is "blowzy night-frumps vex'd jack q"/)
+ end
+ end
+ end
+ describe 'failure' do
+ it 'handles no arguments'
+ it 'handles non strings or arrays'
+ end
+end
diff --git a/spec/acceptance/suffix_spec.rb b/spec/acceptance/suffix_spec.rb
new file mode 100755
index 0000000..630f866
--- /dev/null
+++ b/spec/acceptance/suffix_spec.rb
@@ -0,0 +1,42 @@
+#! /usr/bin/env ruby -S rspec
+require 'spec_helper_acceptance'
+
+describe 'suffix function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do
+ describe 'success' do
+ it 'suffixes array of values' do
+ pp = <<-EOS
+ $o = suffix(['a','b','c'],'p')
+ notice(inline_template('suffix is <%= @o.inspect %>'))
+ EOS
+
+ apply_manifest(pp, :catch_failures => true) do |r|
+ expect(r.stdout).to match(/suffix is \["ap", "bp", "cp"\]/)
+ end
+ end
+ it 'suffixs with empty array' do
+ pp = <<-EOS
+ $o = suffix([],'p')
+ notice(inline_template('suffix is <%= @o.inspect %>'))
+ EOS
+
+ apply_manifest(pp, :catch_failures => true) do |r|
+ expect(r.stdout).to match(/suffix is \[\]/)
+ end
+ end
+ it 'suffixs array of values with undef' do
+ pp = <<-EOS
+ $o = suffix(['a','b','c'], undef)
+ notice(inline_template('suffix is <%= @o.inspect %>'))
+ EOS
+
+ apply_manifest(pp, :catch_failures => true) do |r|
+ expect(r.stdout).to match(/suffix is \["a", "b", "c"\]/)
+ end
+ end
+ end
+ describe 'failure' do
+ it 'fails with no arguments'
+ it 'fails when first argument is not array'
+ it 'fails when second argument is not string'
+ end
+end
diff --git a/spec/acceptance/swapcase_spec.rb b/spec/acceptance/swapcase_spec.rb
new file mode 100755
index 0000000..b7894fb
--- /dev/null
+++ b/spec/acceptance/swapcase_spec.rb
@@ -0,0 +1,22 @@
+#! /usr/bin/env ruby -S rspec
+require 'spec_helper_acceptance'
+
+describe 'swapcase function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do
+ describe 'success' do
+ it 'works with strings' do
+ pp = <<-EOS
+ $o = swapcase('aBcD')
+ notice(inline_template('swapcase is <%= @o.inspect %>'))
+ EOS
+
+ apply_manifest(pp, :catch_failures => true) do |r|
+ expect(r.stdout).to match(/swapcase is "AbCd"/)
+ end
+ end
+ it 'works with arrays'
+ end
+ describe 'failure' do
+ it 'handles no arguments'
+ it 'handles non arrays or strings'
+ end
+end
diff --git a/spec/acceptance/time_spec.rb b/spec/acceptance/time_spec.rb
new file mode 100755
index 0000000..cdb2960
--- /dev/null
+++ b/spec/acceptance/time_spec.rb
@@ -0,0 +1,36 @@
+#! /usr/bin/env ruby -S rspec
+require 'spec_helper_acceptance'
+
+describe 'time function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do
+ describe 'success' do
+ it 'gives the time' do
+ pp = <<-EOS
+ $o = time()
+ notice(inline_template('time is <%= @o.inspect %>'))
+ EOS
+
+ apply_manifest(pp, :catch_failures => true) do |r|
+ m = r.stdout.match(/time is (\d+)\D/)
+
+ # When I wrote this test
+ expect(Integer(m[1])).to be > 1398894170
+ end
+ end
+ it 'takes a timezone argument' do
+ pp = <<-EOS
+ $o = time('UTC')
+ notice(inline_template('time is <%= @o.inspect %>'))
+ EOS
+
+ apply_manifest(pp, :catch_failures => true) do |r|
+ m = r.stdout.match(/time is (\d+)\D/)
+
+ expect(Integer(m[1])).to be > 1398894170
+ end
+ end
+ end
+ describe 'failure' do
+ it 'handles more arguments'
+ it 'handles invalid timezones'
+ end
+end
diff --git a/spec/acceptance/to_bytes_spec.rb b/spec/acceptance/to_bytes_spec.rb
new file mode 100755
index 0000000..2b4c61f
--- /dev/null
+++ b/spec/acceptance/to_bytes_spec.rb
@@ -0,0 +1,27 @@
+#! /usr/bin/env ruby -S rspec
+require 'spec_helper_acceptance'
+
+describe 'to_bytes function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do
+ describe 'success' do
+ it 'converts kB to B' do
+ pp = <<-EOS
+ $o = to_bytes('4 kB')
+ notice(inline_template('to_bytes is <%= @o.inspect %>'))
+ EOS
+
+ apply_manifest(pp, :catch_failures => true) do |r|
+ m = r.stdout.match(/to_bytes is (\d+)\D/)
+ expect(m[1]).to eq("4096")
+ end
+ end
+ it 'works without the B in unit'
+ it 'works without a space before unit'
+ it 'works without a unit'
+ it 'converts fractions'
+ end
+ describe 'failure' do
+ it 'handles no arguments'
+ it 'handles non integer arguments'
+ it 'handles unknown units like uB'
+ end
+end
diff --git a/spec/acceptance/type_spec.rb b/spec/acceptance/type_spec.rb
new file mode 100755
index 0000000..67e3248
--- /dev/null
+++ b/spec/acceptance/type_spec.rb
@@ -0,0 +1,37 @@
+#! /usr/bin/env ruby -S rspec
+require 'spec_helper_acceptance'
+
+describe 'type function', :unless => (UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) || is_future_parser_enabled?) do
+ describe 'success' do
+ it 'types arrays' do
+ pp = <<-EOS
+ $a = ["the","public","art","galleries"]
+ # Anagram: Large picture halls, I bet
+ $o = type($a)
+ notice(inline_template('type is <%= @o.inspect %>'))
+ EOS
+
+ apply_manifest(pp, :catch_failures => true) do |r|
+ expect(r.stdout).to match(/type is "array"/)
+ end
+ end
+ it 'types strings' do
+ pp = <<-EOS
+ $a = "blowzy night-frumps vex'd jack q"
+ $o = type($a)
+ notice(inline_template('type is <%= @o.inspect %>'))
+ EOS
+
+ apply_manifest(pp, :catch_failures => true) do |r|
+ expect(r.stdout).to match(/type is "string"/)
+ end
+ end
+ it 'types hashes'
+ it 'types integers'
+ it 'types floats'
+ it 'types booleans'
+ end
+ describe 'failure' do
+ it 'handles no arguments'
+ end
+end
diff --git a/spec/acceptance/union_spec.rb b/spec/acceptance/union_spec.rb
new file mode 100755
index 0000000..6db8d0c
--- /dev/null
+++ b/spec/acceptance/union_spec.rb
@@ -0,0 +1,24 @@
+#! /usr/bin/env ruby -S rspec
+require 'spec_helper_acceptance'
+
+describe 'union function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do
+ describe 'success' do
+ it 'unions arrays' do
+ pp = <<-EOS
+ $a = ["the","public"]
+ $b = ["art","galleries"]
+ # Anagram: Large picture halls, I bet
+ $o = union($a,$b)
+ notice(inline_template('union is <%= @o.inspect %>'))
+ EOS
+
+ apply_manifest(pp, :catch_failures => true) do |r|
+ expect(r.stdout).to match(/union is \["the", "public", "art", "galleries"\]/)
+ end
+ end
+ end
+ describe 'failure' do
+ it 'handles no arguments'
+ it 'handles non arrays'
+ end
+end
diff --git a/spec/acceptance/unique_spec.rb b/spec/acceptance/unique_spec.rb
new file mode 100755
index 0000000..bfadad1
--- /dev/null
+++ b/spec/acceptance/unique_spec.rb
@@ -0,0 +1,33 @@
+#! /usr/bin/env ruby -S rspec
+require 'spec_helper_acceptance'
+
+describe 'unique function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do
+ describe 'success' do
+ it 'uniques arrays' do
+ pp = <<-EOS
+ $a = ["wallless", "wallless", "brrr", "goddessship"]
+ $o = unique($a)
+ notice(inline_template('unique is <%= @o.inspect %>'))
+ EOS
+
+ apply_manifest(pp, :catch_failures => true) do |r|
+ expect(r.stdout).to match(/unique is \["wallless", "brrr", "goddessship"\]/)
+ end
+ end
+ it 'uniques strings' do
+ pp = <<-EOS
+ $a = "wallless laparohysterosalpingooophorectomy brrr goddessship"
+ $o = unique($a)
+ notice(inline_template('unique is <%= @o.inspect %>'))
+ EOS
+
+ apply_manifest(pp, :catch_failures => true) do |r|
+ expect(r.stdout).to match(/unique is "wales prohytingcmbd"/)
+ end
+ end
+ end
+ describe 'failure' do
+ it 'handles no arguments'
+ it 'handles non strings or arrays'
+ end
+end
diff --git a/spec/acceptance/unsupported_spec.rb b/spec/acceptance/unsupported_spec.rb
new file mode 100755
index 0000000..1c559f6
--- /dev/null
+++ b/spec/acceptance/unsupported_spec.rb
@@ -0,0 +1,11 @@
+#! /usr/bin/env ruby -S rspec
+require 'spec_helper_acceptance'
+
+describe 'unsupported distributions and OSes', :if => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do
+ it 'should fail' do
+ pp = <<-EOS
+ class { 'mysql::server': }
+ EOS
+ expect(apply_manifest(pp, :expect_failures => true).stderr).to match(/unsupported osfamily/i)
+ end
+end
diff --git a/spec/acceptance/upcase_spec.rb b/spec/acceptance/upcase_spec.rb
new file mode 100755
index 0000000..3d2906d
--- /dev/null
+++ b/spec/acceptance/upcase_spec.rb
@@ -0,0 +1,33 @@
+#! /usr/bin/env ruby -S rspec
+require 'spec_helper_acceptance'
+
+describe 'upcase function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do
+ describe 'success' do
+ it 'upcases arrays' do
+ pp = <<-EOS
+ $a = ["wallless", "laparohysterosalpingooophorectomy", "brrr", "goddessship"]
+ $o = upcase($a)
+ notice(inline_template('upcase is <%= @o.inspect %>'))
+ EOS
+
+ apply_manifest(pp, :catch_failures => true) do |r|
+ expect(r.stdout).to match(/upcase is \["WALLLESS", "LAPAROHYSTEROSALPINGOOOPHORECTOMY", "BRRR", "GODDESSSHIP"\]/)
+ end
+ end
+ it 'upcases strings' do
+ pp = <<-EOS
+ $a = "wallless laparohysterosalpingooophorectomy brrr goddessship"
+ $o = upcase($a)
+ notice(inline_template('upcase is <%= @o.inspect %>'))
+ EOS
+
+ apply_manifest(pp, :catch_failures => true) do |r|
+ expect(r.stdout).to match(/upcase is "WALLLESS LAPAROHYSTEROSALPINGOOOPHORECTOMY BRRR GODDESSSHIP"/)
+ end
+ end
+ end
+ describe 'failure' do
+ it 'handles no arguments'
+ it 'handles non strings or arrays'
+ end
+end
diff --git a/spec/acceptance/uriescape_spec.rb b/spec/acceptance/uriescape_spec.rb
new file mode 100755
index 0000000..7e30205
--- /dev/null
+++ b/spec/acceptance/uriescape_spec.rb
@@ -0,0 +1,23 @@
+#! /usr/bin/env ruby -S rspec
+require 'spec_helper_acceptance'
+
+describe 'uriescape function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do
+ describe 'success' do
+ it 'uriescape strings' do
+ pp = <<-EOS
+ $a = ":/?#[]@!$&'()*+,;= \\\"{}"
+ $o = uriescape($a)
+ notice(inline_template('uriescape is <%= @o.inspect %>'))
+ EOS
+
+ apply_manifest(pp, :catch_failures => true) do |r|
+ expect(r.stdout).to match(/uriescape is ":\/\?%23\[\]@!\$&'\(\)\*\+,;=%20%22%7B%7D"/)
+ end
+ end
+ it 'does nothing if a string is already safe'
+ end
+ describe 'failure' do
+ it 'handles no arguments'
+ it 'handles non strings or arrays'
+ end
+end
diff --git a/spec/acceptance/validate_absolute_path_spec.rb b/spec/acceptance/validate_absolute_path_spec.rb
new file mode 100755
index 0000000..7082e84
--- /dev/null
+++ b/spec/acceptance/validate_absolute_path_spec.rb
@@ -0,0 +1,31 @@
+#! /usr/bin/env ruby -S rspec
+require 'spec_helper_acceptance'
+
+describe 'validate_absolute_path function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do
+ describe 'success' do
+ %w{
+ C:/
+ C:\\\\
+ C:\\\\WINDOWS\\\\System32
+ C:/windows/system32
+ X:/foo/bar
+ X:\\\\foo\\\\bar
+ /var/tmp
+ /var/lib/puppet
+ /var/opt/../lib/puppet
+ }.each do |path|
+ it "validates a single argument #{path}" do
+ pp = <<-EOS
+ $one = '#{path}'
+ validate_absolute_path($one)
+ EOS
+
+ apply_manifest(pp, :catch_failures => true)
+ end
+ end
+ end
+ describe 'failure' do
+ it 'handles improper number of arguments'
+ it 'handles relative paths'
+ end
+end
diff --git a/spec/acceptance/validate_array_spec.rb b/spec/acceptance/validate_array_spec.rb
new file mode 100755
index 0000000..b53e98c
--- /dev/null
+++ b/spec/acceptance/validate_array_spec.rb
@@ -0,0 +1,37 @@
+#! /usr/bin/env ruby -S rspec
+require 'spec_helper_acceptance'
+
+describe 'validate_array function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do
+ describe 'success' do
+ it 'validates a single argument' do
+ pp = <<-EOS
+ $one = ['a', 'b']
+ validate_array($one)
+ EOS
+
+ apply_manifest(pp, :catch_failures => true)
+ end
+ it 'validates an multiple arguments' do
+ pp = <<-EOS
+ $one = ['a', 'b']
+ $two = [['c'], 'd']
+ validate_array($one,$two)
+ EOS
+
+ apply_manifest(pp, :catch_failures => true)
+ end
+ it 'validates a non-array' do
+ {
+ %{validate_array({'a' => 'hash' })} => "Hash",
+ %{validate_array('string')} => "String",
+ %{validate_array(false)} => "FalseClass",
+ %{validate_array(undef)} => "String"
+ }.each do |pp,type|
+ expect(apply_manifest(pp, :expect_failures => true).stderr).to match(/a #{type}/)
+ end
+ end
+ end
+ describe 'failure' do
+ it 'handles improper number of arguments'
+ end
+end
diff --git a/spec/acceptance/validate_augeas_spec.rb b/spec/acceptance/validate_augeas_spec.rb
new file mode 100755
index 0000000..71a4c84
--- /dev/null
+++ b/spec/acceptance/validate_augeas_spec.rb
@@ -0,0 +1,63 @@
+#! /usr/bin/env ruby -S rspec
+require 'spec_helper_acceptance'
+
+describe 'validate_augeas function', :unless => ((UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem'))) or (fact('osfamily') == 'windows')) do
+ describe 'prep' do
+ it 'installs augeas for tests'
+ end
+ describe 'success' do
+ context 'valid inputs with no 3rd argument' do
+ {
+ 'root:x:0:0:root:/root:/bin/bash\n' => 'Passwd.lns',
+ 'proc /proc proc nodev,noexec,nosuid 0 0\n' => 'Fstab.lns'
+ }.each do |line,lens|
+ it "validates a single argument for #{lens}" do
+ pp = <<-EOS
+ $line = "#{line}"
+ $lens = "#{lens}"
+ validate_augeas($line, $lens)
+ EOS
+
+ apply_manifest(pp, :catch_failures => true)
+ end
+ end
+ end
+ context 'valid inputs with 3rd and 4th arguments' do
+ it "validates a restricted value" do
+ line = 'root:x:0:0:root:/root:/bin/barsh\n'
+ lens = 'Passwd.lns'
+ restriction = '$file/*[shell="/bin/barsh"]'
+ pp = <<-EOS
+ $line = "#{line}"
+ $lens = "#{lens}"
+ $restriction = ['#{restriction}']
+ validate_augeas($line, $lens, $restriction, "my custom failure message")
+ EOS
+
+ expect(apply_manifest(pp, :expect_failures => true).stderr).to match(/my custom failure message/)
+ end
+ end
+ context 'invalid inputs' do
+ {
+ 'root:x:0:0:root' => 'Passwd.lns',
+ '127.0.1.1' => 'Hosts.lns'
+ }.each do |line,lens|
+ it "validates a single argument for #{lens}" do
+ pp = <<-EOS
+ $line = "#{line}"
+ $lens = "#{lens}"
+ validate_augeas($line, $lens)
+ EOS
+
+ apply_manifest(pp, :expect_failures => true)
+ end
+ end
+ end
+ context 'garbage inputs' do
+ it 'raises an error on invalid inputs'
+ end
+ end
+ describe 'failure' do
+ it 'handles improper number of arguments'
+ end
+end
diff --git a/spec/acceptance/validate_bool_spec.rb b/spec/acceptance/validate_bool_spec.rb
new file mode 100755
index 0000000..c837f08
--- /dev/null
+++ b/spec/acceptance/validate_bool_spec.rb
@@ -0,0 +1,37 @@
+#! /usr/bin/env ruby -S rspec
+require 'spec_helper_acceptance'
+
+describe 'validate_bool function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do
+ describe 'success' do
+ it 'validates a single argument' do
+ pp = <<-EOS
+ $one = true
+ validate_bool($one)
+ EOS
+
+ apply_manifest(pp, :catch_failures => true)
+ end
+ it 'validates an multiple arguments' do
+ pp = <<-EOS
+ $one = true
+ $two = false
+ validate_bool($one,$two)
+ EOS
+
+ apply_manifest(pp, :catch_failures => true)
+ end
+ it 'validates a non-bool' do
+ {
+ %{validate_bool('true')} => "String",
+ %{validate_bool('false')} => "String",
+ %{validate_bool([true])} => "Array",
+ %{validate_bool(undef)} => "String",
+ }.each do |pp,type|
+ expect(apply_manifest(pp, :expect_failures => true).stderr).to match(/a #{type}/)
+ end
+ end
+ end
+ describe 'failure' do
+ it 'handles improper number of arguments'
+ end
+end
diff --git a/spec/acceptance/validate_cmd_spec.rb b/spec/acceptance/validate_cmd_spec.rb
new file mode 100755
index 0000000..5ac66fd
--- /dev/null
+++ b/spec/acceptance/validate_cmd_spec.rb
@@ -0,0 +1,52 @@
+#! /usr/bin/env ruby -S rspec
+require 'spec_helper_acceptance'
+
+describe 'validate_cmd function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do
+ describe 'success' do
+ it 'validates a true command' do
+ pp = <<-EOS
+ $one = 'foo'
+ if $::osfamily == 'windows' {
+ $two = 'echo' #shell built-in
+ } else {
+ $two = '/bin/echo'
+ }
+ validate_cmd($one,$two)
+ EOS
+
+ apply_manifest(pp, :catch_failures => true)
+ end
+ it 'validates a fail command' do
+ pp = <<-EOS
+ $one = 'foo'
+ if $::osfamily == 'windows' {
+ $two = 'C:/aoeu'
+ } else {
+ $two = '/bin/aoeu'
+ }
+ validate_cmd($one,$two)
+ EOS
+
+ apply_manifest(pp, :expect_failures => true)
+ end
+ it 'validates a fail command with a custom error message' do
+ pp = <<-EOS
+ $one = 'foo'
+ if $::osfamily == 'windows' {
+ $two = 'C:/aoeu'
+ } else {
+ $two = '/bin/aoeu'
+ }
+ validate_cmd($one,$two,"aoeu is dvorak")
+ EOS
+
+ apply_manifest(pp, :expect_failures => true) do |output|
+ expect(output.stderr).to match(/aoeu is dvorak/)
+ end
+ end
+ end
+ describe 'failure' do
+ it 'handles improper number of arguments'
+ it 'handles improper argument types'
+ end
+end
diff --git a/spec/acceptance/validate_hash_spec.rb b/spec/acceptance/validate_hash_spec.rb
new file mode 100755
index 0000000..52fb615
--- /dev/null
+++ b/spec/acceptance/validate_hash_spec.rb
@@ -0,0 +1,37 @@
+#! /usr/bin/env ruby -S rspec
+require 'spec_helper_acceptance'
+
+describe 'validate_hash function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do
+ describe 'success' do
+ it 'validates a single argument' do
+ pp = <<-EOS
+ $one = { 'a' => 1 }
+ validate_hash($one)
+ EOS
+
+ apply_manifest(pp, :catch_failures => true)
+ end
+ it 'validates an multiple arguments' do
+ pp = <<-EOS
+ $one = { 'a' => 1 }
+ $two = { 'b' => 2 }
+ validate_hash($one,$two)
+ EOS
+
+ apply_manifest(pp, :catch_failures => true)
+ end
+ it 'validates a non-hash' do
+ {
+ %{validate_hash('{ "not" => "hash" }')} => "String",
+ %{validate_hash('string')} => "String",
+ %{validate_hash(["array"])} => "Array",
+ %{validate_hash(undef)} => "String",
+ }.each do |pp,type|
+ expect(apply_manifest(pp, :expect_failures => true).stderr).to match(/a #{type}/)
+ end
+ end
+ end
+ describe 'failure' do
+ it 'handles improper number of arguments'
+ end
+end
diff --git a/spec/acceptance/validate_ipv4_address_spec.rb b/spec/acceptance/validate_ipv4_address_spec.rb
new file mode 100755
index 0000000..64841c3
--- /dev/null
+++ b/spec/acceptance/validate_ipv4_address_spec.rb
@@ -0,0 +1,31 @@
+#! /usr/bin/env ruby -S rspec
+require 'spec_helper_acceptance'
+
+describe 'validate_ipv4_address function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do
+ describe 'success' do
+ it 'validates a single argument' do
+ pp = <<-EOS
+ $one = '1.2.3.4'
+ validate_ipv4_address($one)
+ EOS
+
+ apply_manifest(pp, :catch_failures => true)
+ end
+ it 'validates an multiple arguments' do
+ pp = <<-EOS
+ $one = '1.2.3.4'
+ $two = '5.6.7.8'
+ validate_ipv4_address($one,$two)
+ EOS
+
+ apply_manifest(pp, :catch_failures => true)
+ end
+ end
+ describe 'failure' do
+ it 'handles improper number of arguments'
+ it 'handles ipv6 addresses'
+ it 'handles non-ipv4 strings'
+ it 'handles numbers'
+ it 'handles no arguments'
+ end
+end
diff --git a/spec/acceptance/validate_ipv6_address_spec.rb b/spec/acceptance/validate_ipv6_address_spec.rb
new file mode 100755
index 0000000..6426d1a
--- /dev/null
+++ b/spec/acceptance/validate_ipv6_address_spec.rb
@@ -0,0 +1,31 @@
+#! /usr/bin/env ruby -S rspec
+require 'spec_helper_acceptance'
+
+describe 'validate_ipv6_address function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do
+ describe 'success' do
+ it 'validates a single argument' do
+ pp = <<-EOS
+ $one = '3ffe:0505:0002::'
+ validate_ipv6_address($one)
+ EOS
+
+ apply_manifest(pp, :catch_failures => true)
+ end
+ it 'validates an multiple arguments' do
+ pp = <<-EOS
+ $one = '3ffe:0505:0002::'
+ $two = '3ffe:0505:0001::'
+ validate_ipv6_address($one,$two)
+ EOS
+
+ apply_manifest(pp, :catch_failures => true)
+ end
+ end
+ describe 'failure' do
+ it 'handles improper number of arguments'
+ it 'handles ipv6 addresses'
+ it 'handles non-ipv6 strings'
+ it 'handles numbers'
+ it 'handles no arguments'
+ end
+end
diff --git a/spec/acceptance/validate_re_spec.rb b/spec/acceptance/validate_re_spec.rb
new file mode 100755
index 0000000..22f6d47
--- /dev/null
+++ b/spec/acceptance/validate_re_spec.rb
@@ -0,0 +1,47 @@
+#! /usr/bin/env ruby -S rspec
+require 'spec_helper_acceptance'
+
+describe 'validate_re function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do
+ describe 'success' do
+ it 'validates a string' do
+ pp = <<-EOS
+ $one = 'one'
+ $two = '^one$'
+ validate_re($one,$two)
+ EOS
+
+ apply_manifest(pp, :catch_failures => true)
+ end
+ it 'validates an array' do
+ pp = <<-EOS
+ $one = 'one'
+ $two = ['^one$', '^two']
+ validate_re($one,$two)
+ EOS
+
+ apply_manifest(pp, :catch_failures => true)
+ end
+ it 'validates a failed array' do
+ pp = <<-EOS
+ $one = 'one'
+ $two = ['^two$', '^three']
+ validate_re($one,$two)
+ EOS
+
+ apply_manifest(pp, :expect_failures => true)
+ end
+ it 'validates a failed array with a custom error message' do
+ pp = <<-EOS
+ $one = '3.4.3'
+ $two = '^2.7'
+ validate_re($one,$two,"The $puppetversion fact does not match 2.7")
+ EOS
+
+ expect(apply_manifest(pp, :expect_failures => true).stderr).to match(/does not match/)
+ end
+ end
+ describe 'failure' do
+ it 'handles improper number of arguments'
+ it 'handles improper argument types'
+ end
+end
diff --git a/spec/acceptance/validate_slength_spec.rb b/spec/acceptance/validate_slength_spec.rb
new file mode 100755
index 0000000..1ab2bb9
--- /dev/null
+++ b/spec/acceptance/validate_slength_spec.rb
@@ -0,0 +1,72 @@
+#! /usr/bin/env ruby -S rspec
+require 'spec_helper_acceptance'
+
+describe 'validate_slength function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do
+ describe 'success' do
+ it 'validates a single string max' do
+ pp = <<-EOS
+ $one = 'discombobulate'
+ $two = 17
+ validate_slength($one,$two)
+ EOS
+
+ apply_manifest(pp, :catch_failures => true)
+ end
+ it 'validates multiple string maxes' do
+ pp = <<-EOS
+ $one = ['discombobulate', 'moo']
+ $two = 17
+ validate_slength($one,$two)
+ EOS
+
+ apply_manifest(pp, :catch_failures => true)
+ end
+ it 'validates min/max of strings in array' do
+ pp = <<-EOS
+ $one = ['discombobulate', 'moo']
+ $two = 17
+ $three = 3
+ validate_slength($one,$two,$three)
+ EOS
+
+ apply_manifest(pp, :catch_failures => true)
+ end
+ it 'validates a single string max of incorrect length' do
+ pp = <<-EOS
+ $one = 'discombobulate'
+ $two = 1
+ validate_slength($one,$two)
+ EOS
+
+ apply_manifest(pp, :expect_failures => true)
+ end
+ it 'validates multiple string maxes of incorrect length' do
+ pp = <<-EOS
+ $one = ['discombobulate', 'moo']
+ $two = 3
+ validate_slength($one,$two)
+ EOS
+
+ apply_manifest(pp, :expect_failures => true)
+ end
+ it 'validates multiple strings min/maxes of incorrect length' do
+ pp = <<-EOS
+ $one = ['discombobulate', 'moo']
+ $two = 17
+ $three = 10
+ validate_slength($one,$two,$three)
+ EOS
+
+ apply_manifest(pp, :expect_failures => true)
+ end
+ end
+ describe 'failure' do
+ it 'handles improper number of arguments'
+ it 'handles improper first argument type'
+ it 'handles non-strings in array of first argument'
+ it 'handles improper second argument type'
+ it 'handles improper third argument type'
+ it 'handles negative ranges'
+ it 'handles improper ranges'
+ end
+end
diff --git a/spec/acceptance/validate_string_spec.rb b/spec/acceptance/validate_string_spec.rb
new file mode 100755
index 0000000..8956f48
--- /dev/null
+++ b/spec/acceptance/validate_string_spec.rb
@@ -0,0 +1,36 @@
+#! /usr/bin/env ruby -S rspec
+require 'spec_helper_acceptance'
+
+describe 'validate_string function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do
+ describe 'success' do
+ it 'validates a single argument' do
+ pp = <<-EOS
+ $one = 'string'
+ validate_string($one)
+ EOS
+
+ apply_manifest(pp, :catch_failures => true)
+ end
+ it 'validates an multiple arguments' do
+ pp = <<-EOS
+ $one = 'string'
+ $two = 'also string'
+ validate_string($one,$two)
+ EOS
+
+ apply_manifest(pp, :catch_failures => true)
+ end
+ it 'validates a non-string' do
+ {
+ %{validate_string({ 'a' => 'hash' })} => "Hash",
+ %{validate_string(['array'])} => "Array",
+ %{validate_string(false)} => "FalseClass",
+ }.each do |pp,type|
+ expect(apply_manifest(pp, :expect_failures => true).stderr).to match(/a #{type}/)
+ end
+ end
+ end
+ describe 'failure' do
+ it 'handles improper number of arguments'
+ end
+end
diff --git a/spec/acceptance/values_at_spec.rb b/spec/acceptance/values_at_spec.rb
new file mode 100755
index 0000000..da63cf3
--- /dev/null
+++ b/spec/acceptance/values_at_spec.rb
@@ -0,0 +1,73 @@
+#! /usr/bin/env ruby -S rspec
+require 'spec_helper_acceptance'
+
+describe 'values_at function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do
+ describe 'success' do
+ it 'returns a specific value' do
+ pp = <<-EOS
+ $one = ['a','b','c','d','e']
+ $two = 1
+ $output = values_at($one,$two)
+ notice(inline_template('<%= @output.inspect %>'))
+ EOS
+
+ expect(apply_manifest(pp, :catch_failures => true).stdout).to match(/\["b"\]/)
+ end
+ it 'returns a specific negative index value' do
+ pending("negative numbers don't work")
+ pp = <<-EOS
+ $one = ['a','b','c','d','e']
+ $two = -1
+ $output = values_at($one,$two)
+ notice(inline_template('<%= @output.inspect %>'))
+ EOS
+
+ expect(apply_manifest(pp, :catch_failures => true).stdout).to match(/\["e"\]/)
+ end
+ it 'returns a range of values' do
+ pp = <<-EOS
+ $one = ['a','b','c','d','e']
+ $two = "1-3"
+ $output = values_at($one,$two)
+ notice(inline_template('<%= @output.inspect %>'))
+ EOS
+
+ expect(apply_manifest(pp, :catch_failures => true).stdout).to match(/\["b", "c", "d"\]/)
+ end
+ it 'returns a negative specific value and range of values' do
+ pp = <<-EOS
+ $one = ['a','b','c','d','e']
+ $two = ["1-3",0]
+ $output = values_at($one,$two)
+ notice(inline_template('<%= @output.inspect %>'))
+ EOS
+
+ expect(apply_manifest(pp, :catch_failures => true).stdout).to match(/\["b", "c", "d", "a"\]/)
+ end
+ end
+ describe 'failure' do
+ it 'handles improper number of arguments' do
+ pp = <<-EOS
+ $one = ['a','b','c','d','e']
+ $output = values_at($one)
+ notice(inline_template('<%= @output.inspect %>'))
+ EOS
+
+ expect(apply_manifest(pp, :expect_failures => true).stderr).to match(/Wrong number of arguments/)
+ end
+ it 'handles non-indicies arguments' do
+ pp = <<-EOS
+ $one = ['a','b','c','d','e']
+ $two = []
+ $output = values_at($one,$two)
+ notice(inline_template('<%= @output.inspect %>'))
+ EOS
+
+ expect(apply_manifest(pp, :expect_failures => true).stderr).to match(/at least one positive index/)
+ end
+
+ it 'detects index ranges smaller than the start range'
+ it 'handles index ranges larger than array'
+ it 'handles non-integer indicies'
+ end
+end
diff --git a/spec/acceptance/values_spec.rb b/spec/acceptance/values_spec.rb
new file mode 100755
index 0000000..a2eff32
--- /dev/null
+++ b/spec/acceptance/values_spec.rb
@@ -0,0 +1,35 @@
+#! /usr/bin/env ruby -S rspec
+require 'spec_helper_acceptance'
+
+describe 'values function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do
+ describe 'success' do
+ it 'returns an array of values' do
+ pp = <<-EOS
+ $arg = {
+ 'a' => 1,
+ 'b' => 2,
+ 'c' => 3,
+ }
+ $output = values($arg)
+ notice(inline_template('<%= @output.sort.inspect %>'))
+ EOS
+ if is_future_parser_enabled?
+ expect(apply_manifest(pp, :catch_failures => true).stdout).to match(/\[1, 2, 3\]/)
+ else
+ expect(apply_manifest(pp, :catch_failures => true).stdout).to match(/\["1", "2", "3"\]/)
+ end
+
+ end
+ end
+ describe 'failure' do
+ it 'handles non-hash arguments' do
+ pp = <<-EOS
+ $arg = "foo"
+ $output = values($arg)
+ notice(inline_template('<%= @output.inspect %>'))
+ EOS
+
+ expect(apply_manifest(pp, :expect_failures => true).stderr).to match(/Requires hash/)
+ end
+ end
+end
diff --git a/spec/acceptance/zip_spec.rb b/spec/acceptance/zip_spec.rb
new file mode 100755
index 0000000..139079e
--- /dev/null
+++ b/spec/acceptance/zip_spec.rb
@@ -0,0 +1,86 @@
+#! /usr/bin/env ruby -S rspec
+require 'spec_helper_acceptance'
+require 'puppet'
+
+describe 'zip function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do
+ describe 'success' do
+ it 'zips two arrays of numbers together' do
+ pp = <<-EOS
+ $one = [1,2,3,4]
+ $two = [5,6,7,8]
+ $output = zip($one,$two)
+ notice(inline_template('<%= @output.inspect %>'))
+ EOS
+ if is_future_parser_enabled?
+ expect(apply_manifest(pp, :catch_failures => true).stdout).to match(/\[\[1, 5\], \[2, 6\], \[3, 7\], \[4, 8\]\]/)
+ else
+ expect(apply_manifest(pp, :catch_failures => true).stdout).to match(/\[\["1", "5"\], \["2", "6"\], \["3", "7"\], \["4", "8"\]\]/)
+ end
+ end
+ it 'zips two arrays of numbers & bools together' do
+ pp = <<-EOS
+ $one = [1,2,"three",4]
+ $two = [true,true,false,false]
+ $output = zip($one,$two)
+ notice(inline_template('<%= @output.inspect %>'))
+ EOS
+ if is_future_parser_enabled?
+ expect(apply_manifest(pp, :catch_failures => true).stdout).to match(/\[\[1, true\], \[2, true\], \["three", false\], \[4, false\]\]/)
+ else
+ expect(apply_manifest(pp, :catch_failures => true).stdout).to match(/\[\["1", true\], \["2", true\], \["three", false\], \["4", false\]\]/)
+ end
+ end
+ it 'zips two arrays of numbers together and flattens them' do
+ # XXX This only tests the argument `true`, even though the following are valid:
+ # 1 t y true yes
+ # 0 f n false no
+ # undef undefined
+ pp = <<-EOS
+ $one = [1,2,3,4]
+ $two = [5,6,7,8]
+ $output = zip($one,$two,true)
+ notice(inline_template('<%= @output.inspect %>'))
+ EOS
+ if is_future_parser_enabled?
+ expect(apply_manifest(pp, :catch_failures => true).stdout).to match(/\[1, 5, 2, 6, 3, 7, 4, 8\]/)
+ else
+ expect(apply_manifest(pp, :catch_failures => true).stdout).to match(/\["1", "5", "2", "6", "3", "7", "4", "8"\]/)
+ end
+ end
+ it 'handles unmatched length' do
+ # XXX Is this expected behavior?
+ pp = <<-EOS
+ $one = [1,2]
+ $two = [5,6,7,8]
+ $output = zip($one,$two)
+ notice(inline_template('<%= @output.inspect %>'))
+ EOS
+ if is_future_parser_enabled?
+ expect(apply_manifest(pp, :catch_failures => true).stdout).to match(/\[\[1, 5\], \[2, 6\]\]/)
+ else
+ expect(apply_manifest(pp, :catch_failures => true).stdout).to match(/\[\["1", "5"\], \["2", "6"\]\]/)
+ end
+ end
+ end
+ describe 'failure' do
+ it 'handles improper number of arguments' do
+ pp = <<-EOS
+ $one = [1,2]
+ $output = zip($one)
+ notice(inline_template('<%= @output.inspect %>'))
+ EOS
+
+ expect(apply_manifest(pp, :expect_failures => true).stderr).to match(/Wrong number of arguments/)
+ end
+ it 'handles improper argument types' do
+ pp = <<-EOS
+ $one = "a string"
+ $two = [5,6,7,8]
+ $output = zip($one,$two)
+ notice(inline_template('<%= @output.inspect %>'))
+ EOS
+
+ expect(apply_manifest(pp, :expect_failures => true).stderr).to match(/Requires array/)
+ end
+ end
+end
diff --git a/spec/classes/anchor_spec.rb b/spec/classes/anchor_spec.rb
index 2dd17de..2d4455e 100644..100755
--- a/spec/classes/anchor_spec.rb
+++ b/spec/classes/anchor_spec.rb
@@ -1,31 +1,29 @@
-require 'puppet'
-require 'rspec-puppet'
+#! /usr/bin/env ruby -S rspec
+require 'spec_helper'
+require 'puppet_spec/compiler'
describe "anchorrefresh" do
- let(:node) { 'testhost.example.com' }
- let :pre_condition do
- <<-ANCHORCLASS
-class anchored {
- anchor { 'anchored::begin': }
- ~> anchor { 'anchored::end': }
-}
+ include PuppetSpec::Compiler
-class anchorrefresh {
- notify { 'first': }
- ~> class { 'anchored': }
- ~> anchor { 'final': }
-}
- ANCHORCLASS
- end
+ let :transaction do
+ apply_compiled_manifest(<<-ANCHORCLASS)
+ class anchored {
+ anchor { 'anchored::begin': }
+ ~> anchor { 'anchored::end': }
+ }
- def apply_catalog_and_return_exec_rsrc
- catalog = subject.to_ral
- transaction = catalog.apply
- transaction.resource_status("Anchor[final]")
+ class anchorrefresh {
+ notify { 'first': }
+ ~> class { 'anchored': }
+ ~> anchor { 'final': }
+ }
+
+ include anchorrefresh
+ ANCHORCLASS
end
it 'propagates events through the anchored class' do
- resource = apply_catalog_and_return_exec_rsrc
+ resource = transaction.resource_status('Anchor[final]')
expect(resource.restarted).to eq(true)
end
diff --git a/spec/fixtures/dscacheutil/root b/spec/fixtures/dscacheutil/root
new file mode 100644
index 0000000..1e34519
--- /dev/null
+++ b/spec/fixtures/dscacheutil/root
@@ -0,0 +1,8 @@
+name: root
+password: *
+uid: 0
+gid: 0
+dir: /var/root
+shell: /bin/bash
+gecos: rawr Root
+
diff --git a/spec/unit/puppet/parser/functions/abs_spec.rb b/spec/functions/abs_spec.rb
index c0b4297..3c25ce2 100755
--- a/spec/unit/puppet/parser/functions/abs_spec.rb
+++ b/spec/functions/abs_spec.rb
@@ -6,20 +6,20 @@ describe "the abs function" do
let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
it "should exist" do
- Puppet::Parser::Functions.function("abs").should == "function_abs"
+ expect(Puppet::Parser::Functions.function("abs")).to eq("function_abs")
end
it "should raise a ParseError if there is less than 1 arguments" do
- lambda { scope.function_abs([]) }.should( raise_error(Puppet::ParseError))
+ expect { scope.function_abs([]) }.to( raise_error(Puppet::ParseError))
end
it "should convert a negative number into a positive" do
result = scope.function_abs(["-34"])
- result.should(eq(34))
+ expect(result).to(eq(34))
end
it "should do nothing with a positive number" do
result = scope.function_abs(["5678"])
- result.should(eq(5678))
+ expect(result).to(eq(5678))
end
end
diff --git a/spec/unit/puppet/parser/functions/any2array_spec.rb b/spec/functions/any2array_spec.rb
index b266e84..87cd04b 100644..100755
--- a/spec/unit/puppet/parser/functions/any2array_spec.rb
+++ b/spec/functions/any2array_spec.rb
@@ -5,51 +5,51 @@ describe "the any2array function" do
let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
it "should exist" do
- Puppet::Parser::Functions.function("any2array").should == "function_any2array"
+ expect(Puppet::Parser::Functions.function("any2array")).to eq("function_any2array")
end
it "should return an empty array if there is less than 1 argument" do
result = scope.function_any2array([])
- result.should(eq([]))
+ expect(result).to(eq([]))
end
it "should convert boolean true to [ true ] " do
result = scope.function_any2array([true])
- result.should(eq([true]))
+ expect(result).to(eq([true]))
end
it "should convert one object to [object]" do
result = scope.function_any2array(['one'])
- result.should(eq(['one']))
+ expect(result).to(eq(['one']))
end
it "should convert multiple objects to [objects]" do
result = scope.function_any2array(['one', 'two'])
- result.should(eq(['one', 'two']))
+ expect(result).to(eq(['one', 'two']))
end
it "should return empty array it was called with" do
result = scope.function_any2array([[]])
- result.should(eq([]))
+ expect(result).to(eq([]))
end
it "should return one-member array it was called with" do
result = scope.function_any2array([['string']])
- result.should(eq(['string']))
+ expect(result).to(eq(['string']))
end
it "should return multi-member array it was called with" do
result = scope.function_any2array([['one', 'two']])
- result.should(eq(['one', 'two']))
+ expect(result).to(eq(['one', 'two']))
end
it "should return members of a hash it was called with" do
result = scope.function_any2array([{ 'key' => 'value' }])
- result.should(eq(['key', 'value']))
+ expect(result).to(eq(['key', 'value']))
end
it "should return an empty array if it was called with an empty hash" do
result = scope.function_any2array([{ }])
- result.should(eq([]))
+ expect(result).to(eq([]))
end
end
diff --git a/spec/unit/puppet/parser/functions/base64_spec.rb b/spec/functions/base64_spec.rb
index 5faa5e6..e93fafc 100755
--- a/spec/unit/puppet/parser/functions/base64_spec.rb
+++ b/spec/functions/base64_spec.rb
@@ -6,7 +6,7 @@ describe "the base64 function" do
let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
it "should exist" do
- Puppet::Parser::Functions.function("base64").should == "function_base64"
+ expect(Puppet::Parser::Functions.function("base64")).to eq("function_base64")
end
it "should raise a ParseError if there are other than 2 arguments" do
@@ -25,10 +25,10 @@ describe "the base64 function" do
it "should encode a encoded string" do
result = scope.function_base64(["encode",'thestring'])
- result.should =~ /\AdGhlc3RyaW5n\n\Z/
+ expect(result).to match(/\AdGhlc3RyaW5n\n\Z/)
end
it "should decode a base64 encoded string" do
result = scope.function_base64(["decode",'dGhlc3RyaW5n'])
- result.should == 'thestring'
+ expect(result).to eq('thestring')
end
end
diff --git a/spec/functions/bool2num_spec.rb b/spec/functions/bool2num_spec.rb
new file mode 100755
index 0000000..3904d7e
--- /dev/null
+++ b/spec/functions/bool2num_spec.rb
@@ -0,0 +1,38 @@
+#! /usr/bin/env ruby -S rspec
+require 'spec_helper'
+
+describe "the bool2num function" do
+ let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
+
+ it "should exist" do
+ expect(Puppet::Parser::Functions.function("bool2num")).to eq("function_bool2num")
+ end
+
+ it "should raise a ParseError if there is less than 1 arguments" do
+ expect { scope.function_bool2num([]) }.to( raise_error(Puppet::ParseError))
+ end
+
+ it "should convert true to 1" do
+ result = scope.function_bool2num([true])
+ expect(result).to(eq(1))
+ end
+
+ it "should convert 'true' to 1" do
+ result = scope.function_bool2num(['true'])
+ result.should(eq(1))
+ end
+
+ it "should convert 'false' to 0" do
+ result = scope.function_bool2num(['false'])
+ expect(result).to(eq(0))
+ end
+
+ it "should accept objects which extend String" do
+ class AlsoString < String
+ end
+
+ value = AlsoString.new('true')
+ result = scope.function_bool2num([value])
+ result.should(eq(1))
+ end
+end
diff --git a/spec/functions/capitalize_spec.rb b/spec/functions/capitalize_spec.rb
new file mode 100755
index 0000000..fd0e92b
--- /dev/null
+++ b/spec/functions/capitalize_spec.rb
@@ -0,0 +1,28 @@
+#! /usr/bin/env ruby -S rspec
+require 'spec_helper'
+
+describe "the capitalize function" do
+ let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
+
+ it "should exist" do
+ expect(Puppet::Parser::Functions.function("capitalize")).to eq("function_capitalize")
+ end
+
+ it "should raise a ParseError if there is less than 1 arguments" do
+ expect { scope.function_capitalize([]) }.to( raise_error(Puppet::ParseError))
+ end
+
+ it "should capitalize the beginning of a string" do
+ result = scope.function_capitalize(["abc"])
+ expect(result).to(eq("Abc"))
+ end
+
+ it "should accept objects which extend String" do
+ class AlsoString < String
+ end
+
+ value = AlsoString.new('abc')
+ result = scope.function_capitalize([value])
+ result.should(eq('Abc'))
+ end
+end
diff --git a/spec/unit/puppet/parser/functions/chomp_spec.rb b/spec/functions/chomp_spec.rb
index e425365..b1e1e60 100755
--- a/spec/unit/puppet/parser/functions/chomp_spec.rb
+++ b/spec/functions/chomp_spec.rb
@@ -5,15 +5,24 @@ describe "the chomp function" do
let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
it "should exist" do
- Puppet::Parser::Functions.function("chomp").should == "function_chomp"
+ expect(Puppet::Parser::Functions.function("chomp")).to eq("function_chomp")
end
it "should raise a ParseError if there is less than 1 arguments" do
- lambda { scope.function_chomp([]) }.should( raise_error(Puppet::ParseError))
+ expect { scope.function_chomp([]) }.to( raise_error(Puppet::ParseError))
end
it "should chomp the end of a string" do
result = scope.function_chomp(["abc\n"])
+ expect(result).to(eq("abc"))
+ end
+
+ it "should accept objects which extend String" do
+ class AlsoString < String
+ end
+
+ value = AlsoString.new("abc\n")
+ result = scope.function_chomp([value])
result.should(eq("abc"))
end
end
diff --git a/spec/functions/chop_spec.rb b/spec/functions/chop_spec.rb
new file mode 100755
index 0000000..c8a1951
--- /dev/null
+++ b/spec/functions/chop_spec.rb
@@ -0,0 +1,28 @@
+#! /usr/bin/env ruby -S rspec
+require 'spec_helper'
+
+describe "the chop function" do
+ let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
+
+ it "should exist" do
+ expect(Puppet::Parser::Functions.function("chop")).to eq("function_chop")
+ end
+
+ it "should raise a ParseError if there is less than 1 arguments" do
+ expect { scope.function_chop([]) }.to( raise_error(Puppet::ParseError))
+ end
+
+ it "should chop the end of a string" do
+ result = scope.function_chop(["asdf\n"])
+ expect(result).to(eq("asdf"))
+ end
+
+ it "should accept objects which extend String" do
+ class AlsoString < String
+ end
+
+ value = AlsoString.new("abc\n")
+ result = scope.function_chop([value])
+ result.should(eq('abc'))
+ end
+end
diff --git a/spec/functions/concat_spec.rb b/spec/functions/concat_spec.rb
new file mode 100755
index 0000000..49fa6bb
--- /dev/null
+++ b/spec/functions/concat_spec.rb
@@ -0,0 +1,50 @@
+#! /usr/bin/env ruby -S rspec
+require 'spec_helper'
+
+describe "the concat function" do
+ let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
+
+ it "should raise a ParseError if the client does not provide at least two arguments" do
+ expect { scope.function_concat([]) }.to(raise_error(Puppet::ParseError))
+ expect { scope.function_concat([[1]]) }.to(raise_error(Puppet::ParseError))
+ end
+
+ it "should raise a ParseError if the first parameter is not an array" do
+ expect { scope.function_concat([1, []])}.to(raise_error(Puppet::ParseError))
+ end
+
+ it "should not raise a ParseError if the client provides more than two arguments" do
+ expect { scope.function_concat([[1],[2],[3]]) }.not_to raise_error
+ end
+
+ it "should be able to concat an array" do
+ result = scope.function_concat([['1','2','3'],['4','5','6']])
+ expect(result).to(eq(['1','2','3','4','5','6']))
+ end
+
+ it "should be able to concat a primitive to an array" do
+ result = scope.function_concat([['1','2','3'],'4'])
+ expect(result).to(eq(['1','2','3','4']))
+ end
+
+ it "should not accidentally flatten nested arrays" do
+ result = scope.function_concat([['1','2','3'],[['4','5'],'6']])
+ expect(result).to(eq(['1','2','3',['4','5'],'6']))
+ end
+
+ it "should leave the original array intact" do
+ array_original = ['1','2','3']
+ result = scope.function_concat([array_original,['4','5','6']])
+ array_original.should(eq(['1','2','3']))
+ end
+
+ it "should be able to concat multiple arrays" do
+ result = scope.function_concat([['1','2','3'],['4','5','6'],['7','8','9']])
+ expect(result).to(eq(['1','2','3','4','5','6','7','8','9']))
+ end
+
+ it "should be able to concat mix of primitives and arrays to a final array" do
+ result = scope.function_concat([['1','2','3'],'4',['5','6','7']])
+ expect(result).to(eq(['1','2','3','4','5','6','7']))
+ end
+end
diff --git a/spec/unit/puppet/parser/functions/count_spec.rb b/spec/functions/count_spec.rb
index 2453815..f8f1d48 100644..100755
--- a/spec/unit/puppet/parser/functions/count_spec.rb
+++ b/spec/functions/count_spec.rb
@@ -6,23 +6,23 @@ describe "the count function" do
let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
it "should exist" do
- Puppet::Parser::Functions.function("count").should == "function_count"
+ expect(Puppet::Parser::Functions.function("count")).to eq("function_count")
end
it "should raise a ArgumentError if there is more than 2 arguments" do
- lambda { scope.function_count(['foo', 'bar', 'baz']) }.should( raise_error(ArgumentError))
+ expect { scope.function_count(['foo', 'bar', 'baz']) }.to( raise_error(ArgumentError))
end
it "should be able to count arrays" do
- scope.function_count([["1","2","3"]]).should(eq(3))
+ expect(scope.function_count([["1","2","3"]])).to(eq(3))
end
it "should be able to count matching elements in arrays" do
- scope.function_count([["1", "2", "2"], "2"]).should(eq(2))
+ expect(scope.function_count([["1", "2", "2"], "2"])).to(eq(2))
end
it "should not count nil or empty strings" do
- scope.function_count([["foo","bar",nil,""]]).should(eq(2))
+ expect(scope.function_count([["foo","bar",nil,""]])).to(eq(2))
end
it 'does not count an undefined hash key or an out of bound array index (which are both :undef)' do
diff --git a/spec/functions/deep_merge_spec.rb b/spec/functions/deep_merge_spec.rb
new file mode 100755
index 0000000..7087904
--- /dev/null
+++ b/spec/functions/deep_merge_spec.rb
@@ -0,0 +1,105 @@
+#! /usr/bin/env ruby -S rspec
+
+require 'spec_helper'
+
+describe Puppet::Parser::Functions.function(:deep_merge) do
+ let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
+
+ describe 'when calling deep_merge from puppet' do
+ it "should not compile when no arguments are passed" do
+ skip("Fails on 2.6.x, see bug #15912") if Puppet.version =~ /^2\.6\./
+ Puppet[:code] = '$x = deep_merge()'
+ expect {
+ scope.compiler.compile
+ }.to raise_error(Puppet::ParseError, /wrong number of arguments/)
+ end
+
+ it "should not compile when 1 argument is passed" do
+ skip("Fails on 2.6.x, see bug #15912") if Puppet.version =~ /^2\.6\./
+ Puppet[:code] = "$my_hash={'one' => 1}\n$x = deep_merge($my_hash)"
+ expect {
+ scope.compiler.compile
+ }.to raise_error(Puppet::ParseError, /wrong number of arguments/)
+ end
+ end
+
+ describe 'when calling deep_merge on the scope instance' do
+ it 'should require all parameters are hashes' do
+ expect { new_hash = scope.function_deep_merge([{}, '2'])}.to raise_error(Puppet::ParseError, /unexpected argument type String/)
+ expect { new_hash = scope.function_deep_merge([{}, 2])}.to raise_error(Puppet::ParseError, /unexpected argument type Fixnum/)
+ end
+
+ it 'should accept empty strings as puppet undef' do
+ expect { new_hash = scope.function_deep_merge([{}, ''])}.not_to raise_error
+ end
+
+ it 'should be able to deep_merge two hashes' do
+ new_hash = scope.function_deep_merge([{'one' => '1', 'two' => '1'}, {'two' => '2', 'three' => '2'}])
+ expect(new_hash['one']).to eq('1')
+ expect(new_hash['two']).to eq('2')
+ expect(new_hash['three']).to eq('2')
+ end
+
+ it 'should deep_merge multiple hashes' do
+ hash = scope.function_deep_merge([{'one' => 1}, {'one' => '2'}, {'one' => '3'}])
+ expect(hash['one']).to eq('3')
+ end
+
+ it 'should accept empty hashes' do
+ expect(scope.function_deep_merge([{},{},{}])).to eq({})
+ end
+
+ it 'should deep_merge subhashes' do
+ hash = scope.function_deep_merge([{'one' => 1}, {'two' => 2, 'three' => { 'four' => 4 } }])
+ expect(hash['one']).to eq(1)
+ expect(hash['two']).to eq(2)
+ expect(hash['three']).to eq({ 'four' => 4 })
+ end
+
+ it 'should append to subhashes' do
+ hash = scope.function_deep_merge([{'one' => { 'two' => 2 } }, { 'one' => { 'three' => 3 } }])
+ expect(hash['one']).to eq({ 'two' => 2, 'three' => 3 })
+ end
+
+ it 'should append to subhashes 2' do
+ hash = scope.function_deep_merge([{'one' => 1, 'two' => 2, 'three' => { 'four' => 4 } }, {'two' => 'dos', 'three' => { 'five' => 5 } }])
+ expect(hash['one']).to eq(1)
+ expect(hash['two']).to eq('dos')
+ expect(hash['three']).to eq({ 'four' => 4, 'five' => 5 })
+ end
+
+ it 'should append to subhashes 3' do
+ hash = scope.function_deep_merge([{ 'key1' => { 'a' => 1, 'b' => 2 }, 'key2' => { 'c' => 3 } }, { 'key1' => { 'b' => 99 } }])
+ expect(hash['key1']).to eq({ 'a' => 1, 'b' => 99 })
+ expect(hash['key2']).to eq({ 'c' => 3 })
+ end
+
+ it 'should not change the original hashes' do
+ hash1 = {'one' => { 'two' => 2 } }
+ hash2 = { 'one' => { 'three' => 3 } }
+ hash = scope.function_deep_merge([hash1, hash2])
+ expect(hash1).to eq({'one' => { 'two' => 2 } })
+ expect(hash2).to eq({ 'one' => { 'three' => 3 } })
+ expect(hash['one']).to eq({ 'two' => 2, 'three' => 3 })
+ end
+
+ it 'should not change the original hashes 2' do
+ hash1 = {'one' => { 'two' => [1,2] } }
+ hash2 = { 'one' => { 'three' => 3 } }
+ hash = scope.function_deep_merge([hash1, hash2])
+ expect(hash1).to eq({'one' => { 'two' => [1,2] } })
+ expect(hash2).to eq({ 'one' => { 'three' => 3 } })
+ expect(hash['one']).to eq({ 'two' => [1,2], 'three' => 3 })
+ end
+
+ it 'should not change the original hashes 3' do
+ hash1 = {'one' => { 'two' => [1,2, {'two' => 2} ] } }
+ hash2 = { 'one' => { 'three' => 3 } }
+ hash = scope.function_deep_merge([hash1, hash2])
+ expect(hash1).to eq({'one' => { 'two' => [1,2, {'two' => 2}] } })
+ expect(hash2).to eq({ 'one' => { 'three' => 3 } })
+ expect(hash['one']).to eq({ 'two' => [1,2, {'two' => 2} ], 'three' => 3 })
+ expect(hash['one']['two']).to eq([1,2, {'two' => 2}])
+ end
+ end
+end
diff --git a/spec/functions/defined_with_params_spec.rb b/spec/functions/defined_with_params_spec.rb
index 28dbab3..3590304 100644..100755
--- a/spec/functions/defined_with_params_spec.rb
+++ b/spec/functions/defined_with_params_spec.rb
@@ -4,16 +4,16 @@ require 'spec_helper'
require 'rspec-puppet'
describe 'defined_with_params' do
describe 'when a resource is not specified' do
- it { should run.with_params().and_raise_error(ArgumentError) }
+ it { is_expected.to run.with_params().and_raise_error(ArgumentError) }
end
describe 'when compared against a resource with no attributes' do
let :pre_condition do
'user { "dan": }'
end
it do
- should run.with_params('User[dan]', {}).and_return(true)
- should run.with_params('User[bob]', {}).and_return(false)
- should run.with_params('User[dan]', {'foo' => 'bar'}).and_return(false)
+ is_expected.to run.with_params('User[dan]', {}).and_return(true)
+ is_expected.to run.with_params('User[bob]', {}).and_return(false)
+ is_expected.to run.with_params('User[dan]', {'foo' => 'bar'}).and_return(false)
end
end
@@ -22,14 +22,14 @@ describe 'defined_with_params' do
'user { "dan": ensure => present, shell => "/bin/csh", managehome => false}'
end
it do
- should run.with_params('User[dan]', {}).and_return(true)
- should run.with_params('User[dan]', '').and_return(true)
- should run.with_params('User[dan]', {'ensure' => 'present'}
+ is_expected.to run.with_params('User[dan]', {}).and_return(true)
+ is_expected.to run.with_params('User[dan]', '').and_return(true)
+ is_expected.to run.with_params('User[dan]', {'ensure' => 'present'}
).and_return(true)
- should run.with_params('User[dan]',
+ is_expected.to run.with_params('User[dan]',
{'ensure' => 'present', 'managehome' => false}
).and_return(true)
- should run.with_params('User[dan]',
+ is_expected.to run.with_params('User[dan]',
{'ensure' => 'absent', 'managehome' => false}
).and_return(false)
end
diff --git a/spec/functions/delete_at_spec.rb b/spec/functions/delete_at_spec.rb
new file mode 100755
index 0000000..7c20aec
--- /dev/null
+++ b/spec/functions/delete_at_spec.rb
@@ -0,0 +1,25 @@
+#! /usr/bin/env ruby -S rspec
+require 'spec_helper'
+
+describe "the delete_at function" do
+ let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
+
+ it "should exist" do
+ expect(Puppet::Parser::Functions.function("delete_at")).to eq("function_delete_at")
+ end
+
+ it "should raise a ParseError if there is less than 1 arguments" do
+ expect { scope.function_delete_at([]) }.to( raise_error(Puppet::ParseError))
+ end
+
+ it "should delete an item at specified location from an array" do
+ result = scope.function_delete_at([['a','b','c'],1])
+ expect(result).to(eq(['a','c']))
+ end
+
+ it "should not change origin array passed as argument" do
+ origin_array = ['a','b','c','d']
+ result = scope.function_delete_at([origin_array, 1])
+ expect(origin_array).to(eq(['a','b','c','d']))
+ end
+end
diff --git a/spec/functions/delete_spec.rb b/spec/functions/delete_spec.rb
new file mode 100755
index 0000000..c8edd78
--- /dev/null
+++ b/spec/functions/delete_spec.rb
@@ -0,0 +1,61 @@
+#! /usr/bin/env ruby -S rspec
+require 'spec_helper'
+
+describe "the delete function" do
+ let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
+
+ it "should exist" do
+ expect(Puppet::Parser::Functions.function("delete")).to eq("function_delete")
+ end
+
+ it "should raise a ParseError if there are fewer than 2 arguments" do
+ expect { scope.function_delete([]) }.to(raise_error(Puppet::ParseError))
+ end
+
+ it "should raise a ParseError if there are greater than 2 arguments" do
+ expect { scope.function_delete([[], 'foo', 'bar']) }.to(raise_error(Puppet::ParseError))
+ end
+
+ it "should raise a TypeError if a number is passed as the first argument" do
+ expect { scope.function_delete([1, 'bar']) }.to(raise_error(TypeError))
+ end
+
+ it "should delete all instances of an element from an array" do
+ result = scope.function_delete([['a', 'b', 'c', 'b'], 'b'])
+ expect(result).to(eq(['a', 'c']))
+ end
+
+ it "should delete all instances of a substring from a string" do
+ result = scope.function_delete(['foobarbabarz', 'bar'])
+ expect(result).to(eq('foobaz'))
+ end
+
+ it "should delete a key from a hash" do
+ result = scope.function_delete([{'a' => 1, 'b' => 2, 'c' => 3}, 'b'])
+ expect(result).to(eq({'a' => 1, 'c' => 3}))
+ end
+
+ it 'should accept an array of items to delete' do
+ result = scope.function_delete([{'a' => 1, 'b' => 2, 'c' => 3}, ['b', 'c']])
+ expect(result).to(eq({'a' => 1}))
+ end
+
+ it "should not change origin array passed as argument" do
+ origin_array = ['a', 'b', 'c', 'd']
+ result = scope.function_delete([origin_array, 'b'])
+ expect(origin_array).to(eq(['a', 'b', 'c', 'd']))
+ end
+
+ it "should not change the origin string passed as argument" do
+ origin_string = 'foobarbabarz'
+ result = scope.function_delete([origin_string, 'bar'])
+ expect(origin_string).to(eq('foobarbabarz'))
+ end
+
+ it "should not change origin hash passed as argument" do
+ origin_hash = {'a' => 1, 'b' => 2, 'c' => 3}
+ result = scope.function_delete([origin_hash, 'b'])
+ expect(origin_hash).to(eq({'a' => 1, 'b' => 2, 'c' => 3}))
+ end
+
+end
diff --git a/spec/functions/delete_undef_values_spec.rb b/spec/functions/delete_undef_values_spec.rb
new file mode 100755
index 0000000..dc67953
--- /dev/null
+++ b/spec/functions/delete_undef_values_spec.rb
@@ -0,0 +1,41 @@
+#! /usr/bin/env ruby -S rspec
+require 'spec_helper'
+
+describe "the delete_undef_values function" do
+ let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
+
+ it "should exist" do
+ expect(Puppet::Parser::Functions.function("delete_undef_values")).to eq("function_delete_undef_values")
+ end
+
+ it "should raise a ParseError if there is less than 1 argument" do
+ expect { scope.function_delete_undef_values([]) }.to( raise_error(Puppet::ParseError))
+ end
+
+ it "should raise a ParseError if the argument is not Array nor Hash" do
+ expect { scope.function_delete_undef_values(['']) }.to( raise_error(Puppet::ParseError))
+ expect { scope.function_delete_undef_values([nil]) }.to( raise_error(Puppet::ParseError))
+ end
+
+ it "should delete all undef items from Array and only these" do
+ result = scope.function_delete_undef_values([['a',:undef,'c','undef']])
+ expect(result).to(eq(['a','c','undef']))
+ end
+
+ it "should delete all undef items from Hash and only these" do
+ result = scope.function_delete_undef_values([{'a'=>'A','b'=>:undef,'c'=>'C','d'=>'undef'}])
+ expect(result).to(eq({'a'=>'A','c'=>'C','d'=>'undef'}))
+ end
+
+ it "should not change origin array passed as argument" do
+ origin_array = ['a',:undef,'c','undef']
+ result = scope.function_delete_undef_values([origin_array])
+ expect(origin_array).to(eq(['a',:undef,'c','undef']))
+ end
+
+ it "should not change origin hash passed as argument" do
+ origin_hash = { 'a' => 1, 'b' => :undef, 'c' => 'undef' }
+ result = scope.function_delete_undef_values([origin_hash])
+ expect(origin_hash).to(eq({ 'a' => 1, 'b' => :undef, 'c' => 'undef' }))
+ end
+end
diff --git a/spec/functions/delete_values_spec.rb b/spec/functions/delete_values_spec.rb
new file mode 100755
index 0000000..4f4d411
--- /dev/null
+++ b/spec/functions/delete_values_spec.rb
@@ -0,0 +1,36 @@
+#! /usr/bin/env ruby -S rspec
+require 'spec_helper'
+
+describe "the delete_values function" do
+ let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
+
+ it "should exist" do
+ expect(Puppet::Parser::Functions.function("delete_values")).to eq("function_delete_values")
+ end
+
+ it "should raise a ParseError if there are fewer than 2 arguments" do
+ expect { scope.function_delete_values([]) }.to( raise_error(Puppet::ParseError))
+ end
+
+ it "should raise a ParseError if there are greater than 2 arguments" do
+ expect { scope.function_delete_values([[], 'foo', 'bar']) }.to( raise_error(Puppet::ParseError))
+ end
+
+ it "should raise a TypeError if the argument is not a hash" do
+ expect { scope.function_delete_values([1,'bar']) }.to( raise_error(TypeError))
+ expect { scope.function_delete_values(['foo','bar']) }.to( raise_error(TypeError))
+ expect { scope.function_delete_values([[],'bar']) }.to( raise_error(TypeError))
+ end
+
+ it "should delete all instances of a value from a hash" do
+ result = scope.function_delete_values([{ 'a'=>'A', 'b'=>'B', 'B'=>'C', 'd'=>'B' },'B'])
+ expect(result).to(eq({ 'a'=>'A', 'B'=>'C' }))
+ end
+
+ it "should not change origin hash passed as argument" do
+ origin_hash = { 'a' => 1, 'b' => 2, 'c' => 3 }
+ result = scope.function_delete_values([origin_hash, 2])
+ expect(origin_hash).to(eq({ 'a' => 1, 'b' => 2, 'c' => 3 }))
+ end
+
+end
diff --git a/spec/unit/puppet/parser/functions/difference_spec.rb b/spec/functions/difference_spec.rb
index 9feff09..24b2b1b 100644..100755
--- a/spec/unit/puppet/parser/functions/difference_spec.rb
+++ b/spec/functions/difference_spec.rb
@@ -5,15 +5,15 @@ describe "the difference function" do
let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
it "should exist" do
- Puppet::Parser::Functions.function("difference").should == "function_difference"
+ expect(Puppet::Parser::Functions.function("difference")).to eq("function_difference")
end
it "should raise a ParseError if there are fewer than 2 arguments" do
- lambda { scope.function_difference([]) }.should( raise_error(Puppet::ParseError) )
+ expect { scope.function_difference([]) }.to( raise_error(Puppet::ParseError) )
end
it "should return the difference between two arrays" do
result = scope.function_difference([["a","b","c"],["b","c","d"]])
- result.should(eq(["a"]))
+ expect(result).to(eq(["a"]))
end
end
diff --git a/spec/unit/puppet/parser/functions/dirname_spec.rb b/spec/functions/dirname_spec.rb
index fb3b4fe..8a3bcab 100755
--- a/spec/unit/puppet/parser/functions/dirname_spec.rb
+++ b/spec/functions/dirname_spec.rb
@@ -5,20 +5,20 @@ describe "the dirname function" do
let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
it "should exist" do
- Puppet::Parser::Functions.function("dirname").should == "function_dirname"
+ expect(Puppet::Parser::Functions.function("dirname")).to eq("function_dirname")
end
it "should raise a ParseError if there is less than 1 arguments" do
- lambda { scope.function_dirname([]) }.should( raise_error(Puppet::ParseError))
+ expect { scope.function_dirname([]) }.to( raise_error(Puppet::ParseError))
end
it "should return dirname for an absolute path" do
result = scope.function_dirname(['/path/to/a/file.ext'])
- result.should(eq('/path/to/a'))
+ expect(result).to(eq('/path/to/a'))
end
it "should return dirname for a relative path" do
result = scope.function_dirname(['path/to/a/file.ext'])
- result.should(eq('path/to/a'))
+ expect(result).to(eq('path/to/a'))
end
end
diff --git a/spec/unit/puppet/parser/functions/downcase_spec.rb b/spec/functions/downcase_spec.rb
index acef1f0..edebc44 100755
--- a/spec/unit/puppet/parser/functions/downcase_spec.rb
+++ b/spec/functions/downcase_spec.rb
@@ -5,20 +5,29 @@ describe "the downcase function" do
let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
it "should exist" do
- Puppet::Parser::Functions.function("downcase").should == "function_downcase"
+ expect(Puppet::Parser::Functions.function("downcase")).to eq("function_downcase")
end
it "should raise a ParseError if there is less than 1 arguments" do
- lambda { scope.function_downcase([]) }.should( raise_error(Puppet::ParseError))
+ expect { scope.function_downcase([]) }.to( raise_error(Puppet::ParseError))
end
it "should downcase a string" do
result = scope.function_downcase(["ASFD"])
- result.should(eq("asfd"))
+ expect(result).to(eq("asfd"))
end
it "should do nothing to a string that is already downcase" do
result = scope.function_downcase(["asdf asdf"])
- result.should(eq("asdf asdf"))
+ expect(result).to(eq("asdf asdf"))
+ end
+
+ it "should accept objects which extend String" do
+ class AlsoString < String
+ end
+
+ value = AlsoString.new("ASFD")
+ result = scope.function_downcase([value])
+ result.should(eq('asfd'))
end
end
diff --git a/spec/unit/puppet/parser/functions/empty_spec.rb b/spec/functions/empty_spec.rb
index 7745875..6a97c4c 100755
--- a/spec/unit/puppet/parser/functions/empty_spec.rb
+++ b/spec/functions/empty_spec.rb
@@ -4,20 +4,29 @@ require 'spec_helper'
describe "the empty function" do
let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
it "should exist" do
- Puppet::Parser::Functions.function("empty").should == "function_empty"
+ expect(Puppet::Parser::Functions.function("empty")).to eq("function_empty")
end
it "should raise a ParseError if there is less than 1 arguments" do
- lambda { scope.function_empty([]) }.should( raise_error(Puppet::ParseError))
+ expect { scope.function_empty([]) }.to( raise_error(Puppet::ParseError))
end
it "should return a true for an empty string" do
result = scope.function_empty([''])
- result.should(eq(true))
+ expect(result).to(eq(true))
end
it "should return a false for a non-empty string" do
result = scope.function_empty(['asdf'])
- result.should(eq(false))
+ expect(result).to(eq(false))
+ end
+
+ it "should accept objects which extend String" do
+ class AlsoString < String
+ end
+
+ value = AlsoString.new()
+ result = scope.function_empty([value])
+ result.should(eq(true))
end
end
diff --git a/spec/functions/ensure_packages_spec.rb b/spec/functions/ensure_packages_spec.rb
index 1c2a328..436be10 100644..100755
--- a/spec/functions/ensure_packages_spec.rb
+++ b/spec/functions/ensure_packages_spec.rb
@@ -2,41 +2,80 @@
require 'spec_helper'
require 'rspec-puppet'
+require 'puppet_spec/compiler'
describe 'ensure_packages' do
- let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
+ include PuppetSpec::Compiler
+
+ before :each do
+ Puppet::Parser::Functions.autoloader.loadall
+ Puppet::Parser::Functions.function(:ensure_packages)
+ Puppet::Parser::Functions.function(:ensure_resource)
+ Puppet::Parser::Functions.function(:defined_with_params)
+ Puppet::Parser::Functions.function(:create_resources)
+ end
+
+ let :node do Puppet::Node.new('localhost') end
+ let :compiler do Puppet::Parser::Compiler.new(node) end
+ let :scope do
+ if Puppet.version.to_f >= 3.0
+ Puppet::Parser::Scope.new(compiler)
+ else
+ newscope = Puppet::Parser::Scope.new
+ newscope.compiler = compiler
+ newscope.source = Puppet::Resource::Type.new(:node, :localhost)
+ newscope
+ end
+ end
describe 'argument handling' do
it 'fails with no arguments' do
- should run.with_params().and_raise_error(Puppet::ParseError)
+ expect {
+ scope.function_ensure_packages([])
+ }.to raise_error(Puppet::ParseError, /0 for 1 or 2/)
end
- it 'requires an array' do
- lambda { scope.function_ensure_packages([['foo']]) }.should_not raise_error
+
+ it 'accepts an array of values' do
+ scope.function_ensure_packages([['foo']])
end
- it 'fails when given a string' do
- should run.with_params('foo').and_raise_error(Puppet::ParseError)
+
+ it 'accepts a single package name as a string' do
+ scope.function_ensure_packages(['foo'])
end
end
- context 'given a catalog containing Package[puppet]{ensure => absent}' do
- let :pre_condition do
- 'package { puppet: ensure => absent }'
+ context 'given a catalog with puppet package => absent' do
+ let :catalog do
+ compile_to_catalog(<<-EOS
+ ensure_packages(['facter'])
+ package { puppet: ensure => absent }
+ EOS
+ )
end
- # NOTE: should run.with_params has the side effect of making the compiler
- # available to the test harness.
it 'has no effect on Package[puppet]' do
- should run.with_params(['puppet'])
- rsrc = compiler.catalog.resource('Package[puppet]')
- rsrc.to_hash.should == {:ensure => "absent"}
+ expect(catalog.resource(:package, 'puppet')['ensure']).to eq('absent')
end
end
context 'given a clean catalog' do
+ let :catalog do
+ compile_to_catalog('ensure_packages(["facter"])')
+ end
+
+ it 'declares package resources with ensure => present' do
+ expect(catalog.resource(:package, 'facter')['ensure']).to eq('present')
+ end
+ end
+
+ context 'given a clean catalog and specified defaults' do
+ let :catalog do
+ compile_to_catalog('ensure_packages(["facter"], {"provider" => "gem"})')
+ end
+
it 'declares package resources with ensure => present' do
- should run.with_params(['facter'])
- rsrc = compiler.catalog.resource('Package[facter]')
- rsrc.to_hash.should == {:name => "facter", :ensure => "present"}
+ expect(catalog.resource(:package, 'facter')['ensure']).to eq('present')
+ expect(catalog.resource(:package, 'facter')['provider']).to eq('gem')
end
end
end
diff --git a/spec/functions/ensure_resource_spec.rb b/spec/functions/ensure_resource_spec.rb
index 2e8aefc..33bcac0 100644..100755
--- a/spec/functions/ensure_resource_spec.rb
+++ b/spec/functions/ensure_resource_spec.rb
@@ -1,64 +1,113 @@
#! /usr/bin/env ruby -S rspec
require 'spec_helper'
-
require 'rspec-puppet'
+require 'puppet_spec/compiler'
+
describe 'ensure_resource' do
+ include PuppetSpec::Compiler
+
+ before :all do
+ Puppet::Parser::Functions.autoloader.loadall
+ Puppet::Parser::Functions.function(:ensure_packages)
+ end
+
+ let :node do Puppet::Node.new('localhost') end
+ let :compiler do Puppet::Parser::Compiler.new(node) end
+ let :scope do Puppet::Parser::Scope.new(compiler) end
+
describe 'when a type or title is not specified' do
- it { should run.with_params().and_raise_error(ArgumentError) }
- it { should run.with_params(['type']).and_raise_error(ArgumentError) }
+ it { expect { scope.function_ensure_resource([]) }.to raise_error }
+ it { expect { scope.function_ensure_resource(['type']) }.to raise_error }
end
describe 'when compared against a resource with no attributes' do
- let :pre_condition do
- 'user { "dan": }'
+ let :catalog do
+ compile_to_catalog(<<-EOS
+ user { "dan": }
+ ensure_resource('user', 'dan', {})
+ EOS
+ )
end
- it "should contain the the ensured resources" do
- subject.should run.with_params('user', 'dan', {})
- compiler.catalog.resource('User[dan]').to_s.should == 'User[dan]'
+
+ it 'should contain the the ensured resources' do
+ expect(catalog.resource(:user, 'dan').to_s).to eq('User[dan]')
end
end
- describe 'when compared against a resource with attributes' do
- let :pre_condition do
- 'user { "dan": ensure => present, shell => "/bin/csh", managehome => false}'
+ describe 'works when compared against a resource with non-conflicting attributes' do
+ [
+ "ensure_resource('User', 'dan', {})",
+ "ensure_resource('User', 'dan', '')",
+ "ensure_resource('User', 'dan', {'ensure' => 'present'})",
+ "ensure_resource('User', 'dan', {'ensure' => 'present', 'managehome' => false})"
+ ].each do |ensure_resource|
+ pp = <<-EOS
+ user { "dan": ensure => present, shell => "/bin/csh", managehome => false}
+ #{ensure_resource}
+ EOS
+
+ it { expect { compile_to_catalog(pp) }.to_not raise_error }
end
- # these first three should not fail
- it { should run.with_params('User', 'dan', {}) }
- it { should run.with_params('User', 'dan', '') }
- it { should run.with_params('User', 'dan', {'ensure' => 'present'}) }
- it { should run.with_params('User', 'dan', {'ensure' => 'present', 'managehome' => false}) }
- # test that this fails
- it { should run.with_params('User', 'dan', {'ensure' => 'absent', 'managehome' => false}).and_raise_error(Puppet::Error) }
+ end
+
+ describe 'fails when compared against a resource with conflicting attributes' do
+ pp = <<-EOS
+ user { "dan": ensure => present, shell => "/bin/csh", managehome => false}
+ ensure_resource('User', 'dan', {'ensure' => 'absent', 'managehome' => false})
+ EOS
+
+ it { expect { compile_to_catalog(pp) }.to raise_error }
end
describe 'when an array of new resources are passed in' do
- it "should contain the ensured resources" do
- subject.should run.with_params('User', ['dan', 'alex'], {})
- compiler.catalog.resource('User[dan]').to_s.should == 'User[dan]'
- compiler.catalog.resource('User[alex]').to_s.should == 'User[alex]'
+ let :catalog do
+ compile_to_catalog("ensure_resource('User', ['dan', 'alex'], {})")
+ end
+
+ it 'should contain the ensured resources' do
+ expect(catalog.resource('User[dan]').to_s).to eq('User[dan]')
+ expect(catalog.resource('User[alex]').to_s).to eq('User[alex]')
end
end
describe 'when an array of existing resources is compared against existing resources' do
- let :pre_condition do
- 'user { "dan": ensure => present; "alex": ensure => present }'
+ pp = <<-EOS
+ user { 'dan': ensure => present; 'alex': ensure => present }
+ ensure_resource('User', ['dan', 'alex'], {})
+ EOS
+
+ let :catalog do
+ compile_to_catalog(pp)
end
- it "should return the existing resources" do
- subject.should run.with_params('User', ['dan', 'alex'], {})
- compiler.catalog.resource('User[dan]').to_s.should == 'User[dan]'
- compiler.catalog.resource('User[alex]').to_s.should == 'User[alex]'
+
+ it 'should return the existing resources' do
+ expect(catalog.resource('User[dan]').to_s).to eq('User[dan]')
+ expect(catalog.resource('User[alex]').to_s).to eq('User[alex]')
end
end
- describe 'when compared against existing resources with attributes' do
- let :pre_condition do
- 'user { "dan": ensure => present; "alex": ensure => present }'
+ describe 'works when compared against existing resources with attributes' do
+ [
+ "ensure_resource('User', ['dan', 'alex'], {})",
+ "ensure_resource('User', ['dan', 'alex'], '')",
+ "ensure_resource('User', ['dan', 'alex'], {'ensure' => 'present'})",
+ ].each do |ensure_resource|
+ pp = <<-EOS
+ user { 'dan': ensure => present; 'alex': ensure => present }
+ #{ensure_resource}
+ EOS
+
+ it { expect { compile_to_catalog(pp) }.to_not raise_error }
end
- # These should not fail
- it { should run.with_params('User', ['dan', 'alex'], {}) }
- it { should run.with_params('User', ['dan', 'alex'], '') }
- it { should run.with_params('User', ['dan', 'alex'], {'ensure' => 'present'}) }
- # This should fail
- it { should run.with_params('User', ['dan', 'alex'], {'ensure' => 'absent'}).and_raise_error(Puppet::Error) }
end
+
+ describe 'fails when compared against existing resources with conflicting attributes' do
+ pp = <<-EOS
+ user { 'dan': ensure => present; 'alex': ensure => present }
+ ensure_resource('User', ['dan', 'alex'], {'ensure' => 'absent'})
+ EOS
+
+ it { expect { compile_to_catalog(pp) }.to raise_error }
+ end
+
end
diff --git a/spec/unit/puppet/parser/functions/flatten_spec.rb b/spec/functions/flatten_spec.rb
index dba7a6b..de8c66d 100755
--- a/spec/unit/puppet/parser/functions/flatten_spec.rb
+++ b/spec/functions/flatten_spec.rb
@@ -4,24 +4,24 @@ require 'spec_helper'
describe "the flatten function" do
let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
it "should exist" do
- Puppet::Parser::Functions.function("flatten").should == "function_flatten"
+ expect(Puppet::Parser::Functions.function("flatten")).to eq("function_flatten")
end
it "should raise a ParseError if there is less than 1 arguments" do
- lambda { scope.function_flatten([]) }.should( raise_error(Puppet::ParseError))
+ expect { scope.function_flatten([]) }.to( raise_error(Puppet::ParseError))
end
it "should raise a ParseError if there is more than 1 argument" do
- lambda { scope.function_flatten([[], []]) }.should( raise_error(Puppet::ParseError))
+ expect { scope.function_flatten([[], []]) }.to( raise_error(Puppet::ParseError))
end
it "should flatten a complex data structure" do
result = scope.function_flatten([["a","b",["c",["d","e"],"f","g"]]])
- result.should(eq(["a","b","c","d","e","f","g"]))
+ expect(result).to(eq(["a","b","c","d","e","f","g"]))
end
it "should do nothing to a structure that is already flat" do
result = scope.function_flatten([["a","b","c","d"]])
- result.should(eq(["a","b","c","d"]))
+ expect(result).to(eq(["a","b","c","d"]))
end
end
diff --git a/spec/unit/puppet/parser/functions/floor_spec.rb b/spec/functions/floor_spec.rb
index dbc8c77..12a6917 100644..100755
--- a/spec/unit/puppet/parser/functions/floor_spec.rb
+++ b/spec/functions/floor_spec.rb
@@ -6,34 +6,34 @@ describe "the floor function" do
let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
it "should exist" do
- Puppet::Parser::Functions.function("floor").should == "function_floor"
+ expect(Puppet::Parser::Functions.function("floor")).to eq("function_floor")
end
it "should raise a ParseError if there is less than 1 argument" do
- lambda { scope.function_floor([]) }.should( raise_error(Puppet::ParseError, /Wrong number of arguments/))
+ expect { scope.function_floor([]) }.to( raise_error(Puppet::ParseError, /Wrong number of arguments/))
end
it "should should raise a ParseError if input isn't numeric (eg. String)" do
- lambda { scope.function_floor(["foo"]) }.should( raise_error(Puppet::ParseError, /Wrong argument type/))
+ expect { scope.function_floor(["foo"]) }.to( raise_error(Puppet::ParseError, /Wrong argument type/))
end
it "should should raise a ParseError if input isn't numeric (eg. Boolean)" do
- lambda { scope.function_floor([true]) }.should( raise_error(Puppet::ParseError, /Wrong argument type/))
+ expect { scope.function_floor([true]) }.to( raise_error(Puppet::ParseError, /Wrong argument type/))
end
it "should return an integer when a numeric type is passed" do
result = scope.function_floor([12.4])
- result.is_a?(Integer).should(eq(true))
+ expect(result.is_a?(Integer)).to(eq(true))
end
it "should return the input when an integer is passed" do
result = scope.function_floor([7])
- result.should(eq(7))
+ expect(result).to(eq(7))
end
it "should return the largest integer less than or equal to the input" do
result = scope.function_floor([3.8])
- result.should(eq(3))
+ expect(result).to(eq(3))
end
end
diff --git a/spec/unit/puppet/parser/functions/fqdn_rotate_spec.rb b/spec/functions/fqdn_rotate_spec.rb
index 2577723..40057d4 100644..100755
--- a/spec/unit/puppet/parser/functions/fqdn_rotate_spec.rb
+++ b/spec/functions/fqdn_rotate_spec.rb
@@ -5,22 +5,22 @@ describe "the fqdn_rotate function" do
let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
it "should exist" do
- Puppet::Parser::Functions.function("fqdn_rotate").should == "function_fqdn_rotate"
+ expect(Puppet::Parser::Functions.function("fqdn_rotate")).to eq("function_fqdn_rotate")
end
it "should raise a ParseError if there is less than 1 arguments" do
- lambda { scope.function_fqdn_rotate([]) }.should( raise_error(Puppet::ParseError))
+ expect { scope.function_fqdn_rotate([]) }.to( raise_error(Puppet::ParseError))
end
it "should rotate a string and the result should be the same size" do
scope.expects(:lookupvar).with("::fqdn").returns("127.0.0.1")
result = scope.function_fqdn_rotate(["asdf"])
- result.size.should(eq(4))
+ expect(result.size).to(eq(4))
end
it "should rotate a string to give the same results for one host" do
scope.expects(:lookupvar).with("::fqdn").returns("127.0.0.1").twice
- scope.function_fqdn_rotate(["abcdefg"]).should eql(scope.function_fqdn_rotate(["abcdefg"]))
+ expect(scope.function_fqdn_rotate(["abcdefg"])).to eql(scope.function_fqdn_rotate(["abcdefg"]))
end
it "should rotate a string to give different values on different hosts" do
@@ -28,6 +28,16 @@ describe "the fqdn_rotate function" do
val1 = scope.function_fqdn_rotate(["abcdefghijklmnopqrstuvwxyz01234567890987654321"])
scope.expects(:lookupvar).with("::fqdn").returns("127.0.0.2")
val2 = scope.function_fqdn_rotate(["abcdefghijklmnopqrstuvwxyz01234567890987654321"])
- val1.should_not eql(val2)
+ expect(val1).not_to eql(val2)
+ end
+
+ it "should accept objects which extend String" do
+ class AlsoString < String
+ end
+
+ scope.expects(:lookupvar).with("::fqdn").returns("127.0.0.1")
+ value = AlsoString.new("asdf")
+ result = scope.function_fqdn_rotate([value])
+ result.size.should(eq(4))
end
end
diff --git a/spec/unit/puppet/parser/functions/get_module_path_spec.rb b/spec/functions/get_module_path_spec.rb
index 486bef6..38ce645 100644..100755
--- a/spec/unit/puppet/parser/functions/get_module_path_spec.rb
+++ b/spec/functions/get_module_path_spec.rb
@@ -29,18 +29,18 @@ describe Puppet::Parser::Functions.function(:get_module_path) do
it 'should be able to find module paths from the modulepath setting' do
Puppet::Module.expects(:find).with('foo', 'production').returns(path_of_module_foo)
- scope.function_get_module_path(['foo']).should == path_of_module_foo.path
+ expect(scope.function_get_module_path(['foo'])).to eq(path_of_module_foo.path)
end
it 'should be able to find module paths when the modulepath is a list' do
Puppet[:modulepath] = modulepath + ":/tmp"
Puppet::Module.expects(:find).with('foo', 'production').returns(path_of_module_foo)
- scope.function_get_module_path(['foo']).should == path_of_module_foo.path
+ expect(scope.function_get_module_path(['foo'])).to eq(path_of_module_foo.path)
end
it 'should respect the environment' do
- pending("Disabled on Puppet 2.6.x") if Puppet.version =~ /^2\.6\b/
+ skip("Disabled on Puppet 2.6.x") if Puppet.version =~ /^2\.6\b/
Puppet.settings[:environment] = 'danstestenv'
Puppet::Module.expects(:find).with('foo', 'danstestenv').returns(path_of_module_foo)
- scope('danstestenv').function_get_module_path(['foo']).should == path_of_module_foo.path
+ expect(scope('danstestenv').function_get_module_path(['foo'])).to eq(path_of_module_foo.path)
end
end
end
diff --git a/spec/functions/getparam_spec.rb b/spec/functions/getparam_spec.rb
index d9c50a6..833c4d4 100644..100755
--- a/spec/functions/getparam_spec.rb
+++ b/spec/functions/getparam_spec.rb
@@ -1,34 +1,76 @@
#! /usr/bin/env ruby -S rspec
require 'spec_helper'
-
require 'rspec-puppet'
+require 'puppet_spec/compiler'
+
describe 'getparam' do
- describe 'when a resource is not specified' do
- it do
- should run.with_params().and_raise_error(ArgumentError)
- should run.with_params('User[dan]').and_raise_error(ArgumentError)
- should run.with_params('User[dan]', {}).and_raise_error(ArgumentError)
- should run.with_params('User[dan]', '').and_return('')
+ include PuppetSpec::Compiler
+
+ before :each do
+ Puppet::Parser::Functions.autoloader.loadall
+ Puppet::Parser::Functions.function(:getparam)
+ end
+
+ let :node do Puppet::Node.new('localhost') end
+ let :compiler do Puppet::Parser::Compiler.new(node) end
+ if Puppet.version.to_f >= 3.0
+ let :scope do Puppet::Parser::Scope.new(compiler) end
+ else
+ let :scope do
+ newscope = Puppet::Parser::Scope.new
+ newscope.compiler = compiler
+ newscope.source = Puppet::Resource::Type.new(:node, :localhost)
+ newscope
end
end
+
+ it "should exist" do
+ expect(Puppet::Parser::Functions.function("getparam")).to eq("function_getparam")
+ end
+
+ describe 'when a resource is not specified' do
+ it { expect { scope.function_getparam([]) }.to raise_error }
+ it { expect { scope.function_getparam(['User[dan]']) }.to raise_error }
+ it { expect { scope.function_getparam(['User[dan]']) }.to raise_error }
+ it { expect { scope.function_getparam(['User[dan]', {}]) }.to raise_error }
+ # This seems to be OK because we just check for a string.
+ it { expect { scope.function_getparam(['User[dan]', '']) }.to_not raise_error }
+ end
+
describe 'when compared against a resource with no params' do
- let :pre_condition do
- 'user { "dan": }'
+ let :catalog do
+ compile_to_catalog(<<-EOS
+ user { "dan": }
+ EOS
+ )
end
+
it do
- should run.with_params('User[dan]', 'shell').and_return('')
+ expect(scope.function_getparam(['User[dan]', 'shell'])).to eq('')
end
end
describe 'when compared against a resource with params' do
- let :pre_condition do
- 'user { "dan": ensure => present, shell => "/bin/sh", managehome => false}'
+ let :catalog do
+ compile_to_catalog(<<-EOS
+ user { 'dan': ensure => present, shell => '/bin/sh', managehome => false}
+ $test = getparam(User[dan], 'shell')
+ EOS
+ )
end
+
it do
- should run.with_params('User[dan]', 'shell').and_return('/bin/sh')
- should run.with_params('User[dan]', '').and_return('')
- should run.with_params('User[dan]', 'ensure').and_return('present')
- should run.with_params('User[dan]', 'managehome').and_return(false)
+ resource = Puppet::Parser::Resource.new(:user, 'dan', {:scope => scope})
+ resource.set_parameter('ensure', 'present')
+ resource.set_parameter('shell', '/bin/sh')
+ resource.set_parameter('managehome', false)
+ compiler.add_resource(scope, resource)
+
+ expect(scope.function_getparam(['User[dan]', 'shell'])).to eq('/bin/sh')
+ expect(scope.function_getparam(['User[dan]', ''])).to eq('')
+ expect(scope.function_getparam(['User[dan]', 'ensure'])).to eq('present')
+ # TODO: Expected this to be false, figure out why we're getting '' back.
+ expect(scope.function_getparam(['User[dan]', 'managehome'])).to eq('')
end
end
end
diff --git a/spec/unit/puppet/parser/functions/getvar_spec.rb b/spec/functions/getvar_spec.rb
index 5ff834e..87ab9b5 100644..100755
--- a/spec/unit/puppet/parser/functions/getvar_spec.rb
+++ b/spec/functions/getvar_spec.rb
@@ -6,7 +6,7 @@ describe Puppet::Parser::Functions.function(:getvar) do
describe 'when calling getvar from puppet' do
it "should not compile when no arguments are passed" do
- pending("Fails on 2.6.x, see bug #15912") if Puppet.version =~ /^2\.6\./
+ skip("Fails on 2.6.x, see bug #15912") if Puppet.version =~ /^2\.6\./
Puppet[:code] = '$foo = getvar()'
expect {
scope.compiler.compile
@@ -14,7 +14,7 @@ describe Puppet::Parser::Functions.function(:getvar) do
end
it "should not compile when too many arguments are passed" do
- pending("Fails on 2.6.x, see bug #15912") if Puppet.version =~ /^2\.6\./
+ skip("Fails on 2.6.x, see bug #15912") if Puppet.version =~ /^2\.6\./
Puppet[:code] = '$foo = getvar("foo::bar", "baz")'
expect {
scope.compiler.compile
@@ -22,7 +22,7 @@ describe Puppet::Parser::Functions.function(:getvar) do
end
it "should lookup variables in other namespaces" do
- pending("Fails on 2.6.x, see bug #15912") if Puppet.version =~ /^2\.6\./
+ skip("Fails on 2.6.x, see bug #15912") if Puppet.version =~ /^2\.6\./
Puppet[:code] = <<-'ENDofPUPPETcode'
class site::data { $foo = 'baz' }
include site::data
diff --git a/spec/unit/puppet/parser/functions/grep_spec.rb b/spec/functions/grep_spec.rb
index a93b842..9c671dd 100755
--- a/spec/unit/puppet/parser/functions/grep_spec.rb
+++ b/spec/functions/grep_spec.rb
@@ -5,15 +5,15 @@ describe "the grep function" do
let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
it "should exist" do
- Puppet::Parser::Functions.function("grep").should == "function_grep"
+ expect(Puppet::Parser::Functions.function("grep")).to eq("function_grep")
end
it "should raise a ParseError if there is less than 1 arguments" do
- lambda { scope.function_grep([]) }.should( raise_error(Puppet::ParseError))
+ expect { scope.function_grep([]) }.to( raise_error(Puppet::ParseError))
end
it "should grep contents from an array" do
result = scope.function_grep([["aaabbb","bbbccc","dddeee"], "bbb"])
- result.should(eq(["aaabbb","bbbccc"]))
+ expect(result).to(eq(["aaabbb","bbbccc"]))
end
end
diff --git a/spec/unit/puppet/parser/functions/has_interface_with_spec.rb b/spec/functions/has_interface_with_spec.rb
index c5264e4..23e09a9 100755
--- a/spec/unit/puppet/parser/functions/has_interface_with_spec.rb
+++ b/spec/functions/has_interface_with_spec.rb
@@ -20,10 +20,10 @@ describe Puppet::Parser::Functions.function(:has_interface_with) do
scope.stubs(:lookupvar).with("interfaces").returns('lo0,gif0,stf0,en1,p2p0,fw0,en0,vmnet1,vmnet8,utun0')
end
it 'should have loopback (lo0)' do
- subject.call(['lo0']).should be_true
+ expect(subject.call(['lo0'])).to be_truthy
end
it 'should not have loopback (lo)' do
- subject.call(['lo']).should be_false
+ expect(subject.call(['lo'])).to be_falsey
end
end
context "On Linux Systems" do
@@ -37,28 +37,28 @@ describe Puppet::Parser::Functions.function(:has_interface_with) do
scope.stubs(:lookupvar).with('muppet_eth0').returns('kermit')
end
it 'should have loopback (lo)' do
- subject.call(['lo']).should be_true
+ expect(subject.call(['lo'])).to be_truthy
end
it 'should not have loopback (lo0)' do
- subject.call(['lo0']).should be_false
+ expect(subject.call(['lo0'])).to be_falsey
end
it 'should have ipaddress with 127.0.0.1' do
- subject.call(['ipaddress', '127.0.0.1']).should be_true
+ expect(subject.call(['ipaddress', '127.0.0.1'])).to be_truthy
end
it 'should have ipaddress with 10.0.0.1' do
- subject.call(['ipaddress', '10.0.0.1']).should be_true
+ expect(subject.call(['ipaddress', '10.0.0.1'])).to be_truthy
end
it 'should not have ipaddress with 10.0.0.2' do
- subject.call(['ipaddress', '10.0.0.2']).should be_false
+ expect(subject.call(['ipaddress', '10.0.0.2'])).to be_falsey
end
it 'should have muppet named kermit' do
- subject.call(['muppet', 'kermit']).should be_true
+ expect(subject.call(['muppet', 'kermit'])).to be_truthy
end
it 'should have muppet named mspiggy' do
- subject.call(['muppet', 'mspiggy']).should be_true
+ expect(subject.call(['muppet', 'mspiggy'])).to be_truthy
end
it 'should not have muppet named bigbird' do
- subject.call(['muppet', 'bigbird']).should be_false
+ expect(subject.call(['muppet', 'bigbird'])).to be_falsey
end
end
end
diff --git a/spec/unit/puppet/parser/functions/has_ip_address_spec.rb b/spec/functions/has_ip_address_spec.rb
index 5a68460..0df12a7 100755
--- a/spec/unit/puppet/parser/functions/has_ip_address_spec.rb
+++ b/spec/functions/has_ip_address_spec.rb
@@ -21,19 +21,19 @@ describe Puppet::Parser::Functions.function(:has_ip_address) do
end
it 'should have primary address (10.0.2.15)' do
- subject.call(['10.0.2.15']).should be_true
+ expect(subject.call(['10.0.2.15'])).to be_truthy
end
it 'should have lookupback address (127.0.0.1)' do
- subject.call(['127.0.0.1']).should be_true
+ expect(subject.call(['127.0.0.1'])).to be_truthy
end
it 'should not have other address' do
- subject.call(['192.1681.1.1']).should be_false
+ expect(subject.call(['192.1681.1.1'])).to be_falsey
end
it 'should not have "mspiggy" on an interface' do
- subject.call(['mspiggy']).should be_false
+ expect(subject.call(['mspiggy'])).to be_falsey
end
end
end
diff --git a/spec/unit/puppet/parser/functions/has_ip_network_spec.rb b/spec/functions/has_ip_network_spec.rb
index c3a289e..2a2578e 100755
--- a/spec/unit/puppet/parser/functions/has_ip_network_spec.rb
+++ b/spec/functions/has_ip_network_spec.rb
@@ -21,15 +21,15 @@ describe Puppet::Parser::Functions.function(:has_ip_network) do
end
it 'should have primary network (10.0.2.0)' do
- subject.call(['10.0.2.0']).should be_true
+ expect(subject.call(['10.0.2.0'])).to be_truthy
end
it 'should have loopback network (127.0.0.0)' do
- subject.call(['127.0.0.1']).should be_true
+ expect(subject.call(['127.0.0.1'])).to be_truthy
end
it 'should not have other network' do
- subject.call(['192.168.1.0']).should be_false
+ expect(subject.call(['192.168.1.0'])).to be_falsey
end
end
end
diff --git a/spec/unit/puppet/parser/functions/has_key_spec.rb b/spec/functions/has_key_spec.rb
index 490daea..6b71800 100644..100755
--- a/spec/unit/puppet/parser/functions/has_key_spec.rb
+++ b/spec/functions/has_key_spec.rb
@@ -6,7 +6,7 @@ describe Puppet::Parser::Functions.function(:has_key) do
describe 'when calling has_key from puppet' do
it "should not compile when no arguments are passed" do
- pending("Fails on 2.6.x, see bug #15912") if Puppet.version =~ /^2\.6\./
+ skip("Fails on 2.6.x, see bug #15912") if Puppet.version =~ /^2\.6\./
Puppet[:code] = '$x = has_key()'
expect {
scope.compiler.compile
@@ -14,7 +14,7 @@ describe Puppet::Parser::Functions.function(:has_key) do
end
it "should not compile when 1 argument is passed" do
- pending("Fails on 2.6.x, see bug #15912") if Puppet.version =~ /^2\.6\./
+ skip("Fails on 2.6.x, see bug #15912") if Puppet.version =~ /^2\.6\./
Puppet[:code] = "$x = has_key('foo')"
expect {
scope.compiler.compile
@@ -22,7 +22,7 @@ describe Puppet::Parser::Functions.function(:has_key) do
end
it "should require the first value to be a Hash" do
- pending("Fails on 2.6.x, see bug #15912") if Puppet.version =~ /^2\.6\./
+ skip("Fails on 2.6.x, see bug #15912") if Puppet.version =~ /^2\.6\./
Puppet[:code] = "$x = has_key('foo', 'bar')"
expect {
scope.compiler.compile
@@ -32,11 +32,11 @@ describe Puppet::Parser::Functions.function(:has_key) do
describe 'when calling the function has_key from a scope instance' do
it 'should detect existing keys' do
- scope.function_has_key([{'one' => 1}, 'one']).should be_true
+ expect(scope.function_has_key([{'one' => 1}, 'one'])).to be_truthy
end
it 'should detect existing keys' do
- scope.function_has_key([{'one' => 1}, 'two']).should be_false
+ expect(scope.function_has_key([{'one' => 1}, 'two'])).to be_falsey
end
end
end
diff --git a/spec/unit/puppet/parser/functions/hash_spec.rb b/spec/functions/hash_spec.rb
index 7c91be9..ec2988b 100644..100755
--- a/spec/unit/puppet/parser/functions/hash_spec.rb
+++ b/spec/functions/hash_spec.rb
@@ -5,15 +5,15 @@ describe "the hash function" do
let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
it "should exist" do
- Puppet::Parser::Functions.function("hash").should == "function_hash"
+ expect(Puppet::Parser::Functions.function("hash")).to eq("function_hash")
end
it "should raise a ParseError if there is less than 1 arguments" do
- lambda { scope.function_hash([]) }.should( raise_error(Puppet::ParseError))
+ expect { scope.function_hash([]) }.to( raise_error(Puppet::ParseError))
end
it "should convert an array to a hash" do
result = scope.function_hash([['a',1,'b',2,'c',3]])
- result.should(eq({'a'=>1,'b'=>2,'c'=>3}))
+ expect(result).to(eq({'a'=>1,'b'=>2,'c'=>3}))
end
end
diff --git a/spec/unit/puppet/parser/functions/intersection_spec.rb b/spec/functions/intersection_spec.rb
index fd44f7f..6361304 100644..100755
--- a/spec/unit/puppet/parser/functions/intersection_spec.rb
+++ b/spec/functions/intersection_spec.rb
@@ -5,15 +5,15 @@ describe "the intersection function" do
let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
it "should exist" do
- Puppet::Parser::Functions.function("intersection").should == "function_intersection"
+ expect(Puppet::Parser::Functions.function("intersection")).to eq("function_intersection")
end
it "should raise a ParseError if there are fewer than 2 arguments" do
- lambda { scope.function_intersection([]) }.should( raise_error(Puppet::ParseError) )
+ expect { scope.function_intersection([]) }.to( raise_error(Puppet::ParseError) )
end
it "should return the intersection of two arrays" do
result = scope.function_intersection([["a","b","c"],["b","c","d"]])
- result.should(eq(["b","c"]))
+ expect(result).to(eq(["b","c"]))
end
end
diff --git a/spec/unit/puppet/parser/functions/is_array_spec.rb b/spec/functions/is_array_spec.rb
index e7f4bcd..94920a4 100644..100755
--- a/spec/unit/puppet/parser/functions/is_array_spec.rb
+++ b/spec/functions/is_array_spec.rb
@@ -5,25 +5,25 @@ describe "the is_array function" do
let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
it "should exist" do
- Puppet::Parser::Functions.function("is_array").should == "function_is_array"
+ expect(Puppet::Parser::Functions.function("is_array")).to eq("function_is_array")
end
it "should raise a ParseError if there is less than 1 arguments" do
- lambda { scope.function_is_array([]) }.should( raise_error(Puppet::ParseError))
+ expect { scope.function_is_array([]) }.to( raise_error(Puppet::ParseError))
end
it "should return true if passed an array" do
result = scope.function_is_array([[1,2,3]])
- result.should(eq(true))
+ expect(result).to(eq(true))
end
it "should return false if passed a hash" do
result = scope.function_is_array([{'a'=>1}])
- result.should(eq(false))
+ expect(result).to(eq(false))
end
it "should return false if passed a string" do
result = scope.function_is_array(["asdf"])
- result.should(eq(false))
+ expect(result).to(eq(false))
end
end
diff --git a/spec/functions/is_bool_spec.rb b/spec/functions/is_bool_spec.rb
new file mode 100755
index 0000000..4a342ba
--- /dev/null
+++ b/spec/functions/is_bool_spec.rb
@@ -0,0 +1,44 @@
+#! /usr/bin/env ruby -S rspec
+require 'spec_helper'
+
+describe "the is_bool function" do
+ let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
+
+ it "should exist" do
+ expect(Puppet::Parser::Functions.function("is_bool")).to eq("function_is_bool")
+ end
+
+ it "should raise a ParseError if there is less than 1 arguments" do
+ expect { scope.function_is_bool([]) }.to( raise_error(Puppet::ParseError))
+ end
+
+ it "should return true if passed a TrueClass" do
+ result = scope.function_is_bool([true])
+ expect(result).to(eq(true))
+ end
+
+ it "should return true if passed a FalseClass" do
+ result = scope.function_is_bool([false])
+ expect(result).to(eq(true))
+ end
+
+ it "should return false if passed the string 'true'" do
+ result = scope.function_is_bool(['true'])
+ expect(result).to(eq(false))
+ end
+
+ it "should return false if passed the string 'false'" do
+ result = scope.function_is_bool(['false'])
+ expect(result).to(eq(false))
+ end
+
+ it "should return false if passed an array" do
+ result = scope.function_is_bool([["a","b"]])
+ expect(result).to(eq(false))
+ end
+
+ it "should return false if passed a hash" do
+ result = scope.function_is_bool([{"a" => "b"}])
+ expect(result).to(eq(false))
+ end
+end
diff --git a/spec/unit/puppet/parser/functions/is_domain_name_spec.rb b/spec/functions/is_domain_name_spec.rb
index f2ea76d..4d05f5c 100644..100755
--- a/spec/unit/puppet/parser/functions/is_domain_name_spec.rb
+++ b/spec/functions/is_domain_name_spec.rb
@@ -5,60 +5,60 @@ describe "the is_domain_name function" do
let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
it "should exist" do
- Puppet::Parser::Functions.function("is_domain_name").should == "function_is_domain_name"
+ expect(Puppet::Parser::Functions.function("is_domain_name")).to eq("function_is_domain_name")
end
it "should raise a ParseError if there is less than 1 arguments" do
- lambda { scope.function_is_domain_name([]) }.should( raise_error(Puppet::ParseError))
+ expect { scope.function_is_domain_name([]) }.to( raise_error(Puppet::ParseError))
end
it "should return true if a valid short domain name" do
result = scope.function_is_domain_name(["x.com"])
- result.should(be_true)
+ expect(result).to(be_truthy)
end
it "should return true if the domain is ." do
result = scope.function_is_domain_name(["."])
- result.should(be_true)
+ expect(result).to(be_truthy)
end
it "should return true if the domain is x.com." do
result = scope.function_is_domain_name(["x.com."])
- result.should(be_true)
+ expect(result).to(be_truthy)
end
it "should return true if a valid domain name" do
result = scope.function_is_domain_name(["foo.bar.com"])
- result.should(be_true)
+ expect(result).to(be_truthy)
end
it "should allow domain parts to start with numbers" do
result = scope.function_is_domain_name(["3foo.2bar.com"])
- result.should(be_true)
+ expect(result).to(be_truthy)
end
it "should allow domain to end with a dot" do
result = scope.function_is_domain_name(["3foo.2bar.com."])
- result.should(be_true)
+ expect(result).to(be_truthy)
end
it "should allow a single part domain" do
result = scope.function_is_domain_name(["orange"])
- result.should(be_true)
+ expect(result).to(be_truthy)
end
it "should return false if domain parts start with hyphens" do
result = scope.function_is_domain_name(["-3foo.2bar.com"])
- result.should(be_false)
+ expect(result).to(be_falsey)
end
it "should return true if domain contains hyphens" do
result = scope.function_is_domain_name(["3foo-bar.2bar-fuzz.com"])
- result.should(be_true)
+ expect(result).to(be_truthy)
end
it "should return false if domain name contains spaces" do
result = scope.function_is_domain_name(["not valid"])
- result.should(be_false)
+ expect(result).to(be_falsey)
end
end
diff --git a/spec/unit/puppet/parser/functions/is_float_spec.rb b/spec/functions/is_float_spec.rb
index b7d73b0..d926634 100644..100755
--- a/spec/unit/puppet/parser/functions/is_float_spec.rb
+++ b/spec/functions/is_float_spec.rb
@@ -5,29 +5,29 @@ describe "the is_float function" do
let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
it "should exist" do
- Puppet::Parser::Functions.function("is_float").should == "function_is_float"
+ expect(Puppet::Parser::Functions.function("is_float")).to eq("function_is_float")
end
it "should raise a ParseError if there is less than 1 arguments" do
- lambda { scope.function_is_float([]) }.should( raise_error(Puppet::ParseError))
+ expect { scope.function_is_float([]) }.to( raise_error(Puppet::ParseError))
end
it "should return true if a float" do
result = scope.function_is_float(["0.12"])
- result.should(eq(true))
+ expect(result).to(eq(true))
end
it "should return false if a string" do
result = scope.function_is_float(["asdf"])
- result.should(eq(false))
+ expect(result).to(eq(false))
end
it "should return false if an integer" do
result = scope.function_is_float(["3"])
- result.should(eq(false))
+ expect(result).to(eq(false))
end
it "should return true if a float is created from an arithmetical operation" do
result = scope.function_is_float([3.2*2])
- result.should(eq(true))
+ expect(result).to(eq(true))
end
end
diff --git a/spec/unit/puppet/parser/functions/is_function_available.rb b/spec/functions/is_function_available.rb
index bd40c51..3a9aa1b 100644..100755
--- a/spec/unit/puppet/parser/functions/is_function_available.rb
+++ b/spec/functions/is_function_available.rb
@@ -1,4 +1,4 @@
-#!/usr/bin/env rspec
+#!/usr/bin/env ruby -S rspec
require 'spec_helper'
describe "the is_function_available function" do
@@ -11,21 +11,21 @@ describe "the is_function_available function" do
end
it "should exist" do
- Puppet::Parser::Functions.function("is_function_available").should == "function_is_function_available"
+ expect(Puppet::Parser::Functions.function("is_function_available")).to eq("function_is_function_available")
end
it "should raise a ParseError if there is less than 1 arguments" do
- lambda { @scope.function_is_function_available([]) }.should( raise_error(Puppet::ParseError))
+ expect { @scope.function_is_function_available([]) }.to( raise_error(Puppet::ParseError))
end
it "should return false if a nonexistent function is passed" do
result = @scope.function_is_function_available(['jeff_mccunes_left_sock'])
- result.should(eq(false))
+ expect(result).to(eq(false))
end
it "should return true if an available function is passed" do
result = @scope.function_is_function_available(['require'])
- result.should(eq(true))
+ expect(result).to(eq(true))
end
end
diff --git a/spec/unit/puppet/parser/functions/is_hash_spec.rb b/spec/functions/is_hash_spec.rb
index bbebf39..a849411 100644..100755
--- a/spec/unit/puppet/parser/functions/is_hash_spec.rb
+++ b/spec/functions/is_hash_spec.rb
@@ -5,25 +5,25 @@ describe "the is_hash function" do
let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
it "should exist" do
- Puppet::Parser::Functions.function("is_hash").should == "function_is_hash"
+ expect(Puppet::Parser::Functions.function("is_hash")).to eq("function_is_hash")
end
it "should raise a ParseError if there is less than 1 arguments" do
- lambda { scope.function_is_hash([]) }.should( raise_error(Puppet::ParseError))
+ expect { scope.function_is_hash([]) }.to( raise_error(Puppet::ParseError))
end
it "should return true if passed a hash" do
result = scope.function_is_hash([{"a"=>1,"b"=>2}])
- result.should(eq(true))
+ expect(result).to(eq(true))
end
it "should return false if passed an array" do
result = scope.function_is_hash([["a","b"]])
- result.should(eq(false))
+ expect(result).to(eq(false))
end
it "should return false if passed a string" do
result = scope.function_is_hash(["asdf"])
- result.should(eq(false))
+ expect(result).to(eq(false))
end
end
diff --git a/spec/functions/is_integer_spec.rb b/spec/functions/is_integer_spec.rb
new file mode 100755
index 0000000..f0cbca8
--- /dev/null
+++ b/spec/functions/is_integer_spec.rb
@@ -0,0 +1,69 @@
+#! /usr/bin/env ruby -S rspec
+require 'spec_helper'
+
+describe "the is_integer function" do
+ let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
+
+ it "should exist" do
+ expect(Puppet::Parser::Functions.function("is_integer")).to eq("function_is_integer")
+ end
+
+ it "should raise a ParseError if there is less than 1 arguments" do
+ expect { scope.function_is_integer([]) }.to( raise_error(Puppet::ParseError))
+ end
+
+ it "should return true if an integer" do
+ result = scope.function_is_integer(["3"])
+ expect(result).to(eq(true))
+ end
+
+ it "should return true if a negative integer" do
+ result = scope.function_is_integer(["-7"])
+ expect(result).to(eq(true))
+ end
+
+ it "should return false if a float" do
+ result = scope.function_is_integer(["3.2"])
+ expect(result).to(eq(false))
+ end
+
+ it "should return false if a string" do
+ result = scope.function_is_integer(["asdf"])
+ expect(result).to(eq(false))
+ end
+
+ it "should return true if an integer is created from an arithmetical operation" do
+ result = scope.function_is_integer([3*2])
+ expect(result).to(eq(true))
+ end
+
+ it "should return false if an array" do
+ result = scope.function_is_numeric([["asdf"]])
+ expect(result).to(eq(false))
+ end
+
+ it "should return false if a hash" do
+ result = scope.function_is_numeric([{"asdf" => false}])
+ expect(result).to(eq(false))
+ end
+
+ it "should return false if a boolean" do
+ result = scope.function_is_numeric([true])
+ expect(result).to(eq(false))
+ end
+
+ it "should return false if a whitespace is in the string" do
+ result = scope.function_is_numeric([" -1324"])
+ expect(result).to(eq(false))
+ end
+
+ it "should return false if it is zero prefixed" do
+ result = scope.function_is_numeric(["0001234"])
+ expect(result).to(eq(false))
+ end
+
+ it "should return false if it is wrapped inside an array" do
+ result = scope.function_is_numeric([[1234]])
+ expect(result).to(eq(false))
+ end
+end
diff --git a/spec/unit/puppet/parser/functions/is_ip_address_spec.rb b/spec/functions/is_ip_address_spec.rb
index c0debb3..c16d12b 100644..100755
--- a/spec/unit/puppet/parser/functions/is_ip_address_spec.rb
+++ b/spec/functions/is_ip_address_spec.rb
@@ -5,35 +5,35 @@ describe "the is_ip_address function" do
let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
it "should exist" do
- Puppet::Parser::Functions.function("is_ip_address").should == "function_is_ip_address"
+ expect(Puppet::Parser::Functions.function("is_ip_address")).to eq("function_is_ip_address")
end
it "should raise a ParseError if there is less than 1 arguments" do
- lambda { scope.function_is_ip_address([]) }.should( raise_error(Puppet::ParseError))
+ expect { scope.function_is_ip_address([]) }.to( raise_error(Puppet::ParseError))
end
it "should return true if an IPv4 address" do
result = scope.function_is_ip_address(["1.2.3.4"])
- result.should(eq(true))
+ expect(result).to(eq(true))
end
it "should return true if a full IPv6 address" do
result = scope.function_is_ip_address(["fe80:0000:cd12:d123:e2f8:47ff:fe09:dd74"])
- result.should(eq(true))
+ expect(result).to(eq(true))
end
it "should return true if a compressed IPv6 address" do
result = scope.function_is_ip_address(["fe00::1"])
- result.should(eq(true))
+ expect(result).to(eq(true))
end
it "should return false if not valid" do
result = scope.function_is_ip_address(["asdf"])
- result.should(eq(false))
+ expect(result).to(eq(false))
end
it "should return false if IP octets out of range" do
result = scope.function_is_ip_address(["1.1.1.300"])
- result.should(eq(false))
+ expect(result).to(eq(false))
end
end
diff --git a/spec/unit/puppet/parser/functions/is_mac_address_spec.rb b/spec/functions/is_mac_address_spec.rb
index ca9c590..66edd19 100644..100755
--- a/spec/unit/puppet/parser/functions/is_mac_address_spec.rb
+++ b/spec/functions/is_mac_address_spec.rb
@@ -5,25 +5,25 @@ describe "the is_mac_address function" do
let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
it "should exist" do
- Puppet::Parser::Functions.function("is_mac_address").should == "function_is_mac_address"
+ expect(Puppet::Parser::Functions.function("is_mac_address")).to eq("function_is_mac_address")
end
it "should raise a ParseError if there is less than 1 arguments" do
- lambda { scope.function_is_mac_address([]) }.should( raise_error(Puppet::ParseError))
+ expect { scope.function_is_mac_address([]) }.to( raise_error(Puppet::ParseError))
end
it "should return true if a valid mac address" do
result = scope.function_is_mac_address(["00:a0:1f:12:7f:a0"])
- result.should(eq(true))
+ expect(result).to(eq(true))
end
it "should return false if octets are out of range" do
result = scope.function_is_mac_address(["00:a0:1f:12:7f:g0"])
- result.should(eq(false))
+ expect(result).to(eq(false))
end
it "should return false if not valid" do
result = scope.function_is_mac_address(["not valid"])
- result.should(eq(false))
+ expect(result).to(eq(false))
end
end
diff --git a/spec/functions/is_numeric_spec.rb b/spec/functions/is_numeric_spec.rb
new file mode 100755
index 0000000..4176961
--- /dev/null
+++ b/spec/functions/is_numeric_spec.rb
@@ -0,0 +1,119 @@
+#! /usr/bin/env ruby -S rspec
+require 'spec_helper'
+
+describe "the is_numeric function" do
+ let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
+
+ it "should exist" do
+ expect(Puppet::Parser::Functions.function("is_numeric")).to eq("function_is_numeric")
+ end
+
+ it "should raise a ParseError if there is less than 1 argument" do
+ expect { scope.function_is_numeric([]) }.to( raise_error(Puppet::ParseError))
+ end
+
+ it "should return true if an integer" do
+ result = scope.function_is_numeric(["3"])
+ expect(result).to(eq(true))
+ end
+
+ it "should return true if a float" do
+ result = scope.function_is_numeric(["3.2"])
+ expect(result).to(eq(true))
+ end
+
+ it "should return true if an integer is created from an arithmetical operation" do
+ result = scope.function_is_numeric([3*2])
+ expect(result).to(eq(true))
+ end
+
+ it "should return true if a float is created from an arithmetical operation" do
+ result = scope.function_is_numeric([3.2*2])
+ expect(result).to(eq(true))
+ end
+
+ it "should return false if a string" do
+ result = scope.function_is_numeric(["asdf"])
+ expect(result).to(eq(false))
+ end
+
+ it "should return false if an array" do
+ result = scope.function_is_numeric([["asdf"]])
+ expect(result).to(eq(false))
+ end
+
+ it "should return false if an array of integers" do
+ result = scope.function_is_numeric([[1,2,3,4]])
+ expect(result).to(eq(false))
+ end
+
+ it "should return false if a hash" do
+ result = scope.function_is_numeric([{"asdf" => false}])
+ expect(result).to(eq(false))
+ end
+
+ it "should return false if a hash with numbers in it" do
+ result = scope.function_is_numeric([{1 => 2}])
+ expect(result).to(eq(false))
+ end
+
+ it "should return false if a boolean" do
+ result = scope.function_is_numeric([true])
+ expect(result).to(eq(false))
+ end
+
+ it "should return true if a negative float with exponent" do
+ result = scope.function_is_numeric(["-342.2315e-12"])
+ expect(result).to(eq(true))
+ end
+
+ it "should return false if a negative integer with whitespaces before/after the dash" do
+ result = scope.function_is_numeric([" - 751"])
+ expect(result).to(eq(false))
+ end
+
+# it "should return true if a hexadecimal" do
+# result = scope.function_is_numeric(["0x52F8c"])
+# result.should(eq(true))
+# end
+#
+# it "should return true if a hexadecimal with uppercase 0X prefix" do
+# result = scope.function_is_numeric(["0X52F8c"])
+# result.should(eq(true))
+# end
+#
+# it "should return false if a hexadecimal without a prefix" do
+# result = scope.function_is_numeric(["52F8c"])
+# result.should(eq(false))
+# end
+#
+# it "should return true if a octal" do
+# result = scope.function_is_numeric(["0751"])
+# result.should(eq(true))
+# end
+#
+# it "should return true if a negative hexadecimal" do
+# result = scope.function_is_numeric(["-0x52F8c"])
+# result.should(eq(true))
+# end
+#
+# it "should return true if a negative octal" do
+# result = scope.function_is_numeric(["-0751"])
+# result.should(eq(true))
+# end
+#
+# it "should return false if a negative octal with whitespaces before/after the dash" do
+# result = scope.function_is_numeric([" - 0751"])
+# result.should(eq(false))
+# end
+#
+# it "should return false if a bad hexadecimal" do
+# result = scope.function_is_numeric(["0x23d7g"])
+# result.should(eq(false))
+# end
+#
+# it "should return false if a bad octal" do
+# result = scope.function_is_numeric(["0287"])
+# result.should(eq(false))
+# end
+end
diff --git a/spec/unit/puppet/parser/functions/is_string_spec.rb b/spec/functions/is_string_spec.rb
index 3756bea..6a0801a 100644..100755
--- a/spec/unit/puppet/parser/functions/is_string_spec.rb
+++ b/spec/functions/is_string_spec.rb
@@ -5,30 +5,30 @@ describe "the is_string function" do
let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
it "should exist" do
- Puppet::Parser::Functions.function("is_string").should == "function_is_string"
+ expect(Puppet::Parser::Functions.function("is_string")).to eq("function_is_string")
end
it "should raise a ParseError if there is less than 1 arguments" do
- lambda { scope.function_is_string([]) }.should( raise_error(Puppet::ParseError))
+ expect { scope.function_is_string([]) }.to( raise_error(Puppet::ParseError))
end
it "should return true if a string" do
result = scope.function_is_string(["asdf"])
- result.should(eq(true))
+ expect(result).to(eq(true))
end
it "should return false if an integer" do
result = scope.function_is_string(["3"])
- result.should(eq(false))
+ expect(result).to(eq(false))
end
it "should return false if a float" do
result = scope.function_is_string(["3.23"])
- result.should(eq(false))
+ expect(result).to(eq(false))
end
it "should return false if an array" do
result = scope.function_is_string([["a","b","c"]])
- result.should(eq(false))
+ expect(result).to(eq(false))
end
end
diff --git a/spec/unit/puppet/parser/functions/join_keys_to_values_spec.rb b/spec/functions/join_keys_to_values_spec.rb
index a52fb71..4a9ae87 100644..100755
--- a/spec/unit/puppet/parser/functions/join_keys_to_values_spec.rb
+++ b/spec/functions/join_keys_to_values_spec.rb
@@ -5,36 +5,36 @@ describe "the join_keys_to_values function" do
let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
it "should exist" do
- Puppet::Parser::Functions.function("join_keys_to_values").should == "function_join_keys_to_values"
+ expect(Puppet::Parser::Functions.function("join_keys_to_values")).to eq("function_join_keys_to_values")
end
it "should raise a ParseError if there are fewer than two arguments" do
- lambda { scope.function_join_keys_to_values([{}]) }.should raise_error Puppet::ParseError
+ expect { scope.function_join_keys_to_values([{}]) }.to raise_error Puppet::ParseError
end
it "should raise a ParseError if there are greater than two arguments" do
- lambda { scope.function_join_keys_to_values([{}, 'foo', 'bar']) }.should raise_error Puppet::ParseError
+ expect { scope.function_join_keys_to_values([{}, 'foo', 'bar']) }.to raise_error Puppet::ParseError
end
it "should raise a TypeError if the first argument is an array" do
- lambda { scope.function_join_keys_to_values([[1,2], ',']) }.should raise_error TypeError
+ expect { scope.function_join_keys_to_values([[1,2], ',']) }.to raise_error TypeError
end
it "should raise a TypeError if the second argument is an array" do
- lambda { scope.function_join_keys_to_values([{}, [1,2]]) }.should raise_error TypeError
+ expect { scope.function_join_keys_to_values([{}, [1,2]]) }.to raise_error TypeError
end
it "should raise a TypeError if the second argument is a number" do
- lambda { scope.function_join_keys_to_values([{}, 1]) }.should raise_error TypeError
+ expect { scope.function_join_keys_to_values([{}, 1]) }.to raise_error TypeError
end
it "should return an empty array given an empty hash" do
result = scope.function_join_keys_to_values([{}, ":"])
- result.should == []
+ expect(result).to eq([])
end
it "should join hash's keys to its values" do
result = scope.function_join_keys_to_values([{'a'=>1,2=>'foo',:b=>nil}, ":"])
- result.should =~ ['a:1','2:foo','b:']
+ expect(result).to match_array(['a:1','2:foo','b:'])
end
end
diff --git a/spec/unit/puppet/parser/functions/join_spec.rb b/spec/functions/join_spec.rb
index aafa1a7..793c36f 100644..100755
--- a/spec/unit/puppet/parser/functions/join_spec.rb
+++ b/spec/functions/join_spec.rb
@@ -5,15 +5,15 @@ describe "the join function" do
let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
it "should exist" do
- Puppet::Parser::Functions.function("join").should == "function_join"
+ expect(Puppet::Parser::Functions.function("join")).to eq("function_join")
end
it "should raise a ParseError if there is less than 1 arguments" do
- lambda { scope.function_join([]) }.should( raise_error(Puppet::ParseError))
+ expect { scope.function_join([]) }.to( raise_error(Puppet::ParseError))
end
it "should join an array into a string" do
result = scope.function_join([["a","b","c"], ":"])
- result.should(eq("a:b:c"))
+ expect(result).to(eq("a:b:c"))
end
end
diff --git a/spec/unit/puppet/parser/functions/keys_spec.rb b/spec/functions/keys_spec.rb
index fdd7a70..f2e7d42 100644..100755
--- a/spec/unit/puppet/parser/functions/keys_spec.rb
+++ b/spec/functions/keys_spec.rb
@@ -5,17 +5,17 @@ describe "the keys function" do
let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
it "should exist" do
- Puppet::Parser::Functions.function("keys").should == "function_keys"
+ expect(Puppet::Parser::Functions.function("keys")).to eq("function_keys")
end
it "should raise a ParseError if there is less than 1 arguments" do
- lambda { scope.function_keys([]) }.should( raise_error(Puppet::ParseError))
+ expect { scope.function_keys([]) }.to( raise_error(Puppet::ParseError))
end
it "should return an array of keys when given a hash" do
result = scope.function_keys([{'a'=>1, 'b'=>2}])
# =~ performs 'array with same elements' (set) matching
# For more info see RSpec::Matchers::MatchArray
- result.should =~ ['a','b']
+ expect(result).to match_array(['a','b'])
end
end
diff --git a/spec/functions/loadyaml_spec.rb b/spec/functions/loadyaml_spec.rb
new file mode 100755
index 0000000..cdc3d6f
--- /dev/null
+++ b/spec/functions/loadyaml_spec.rb
@@ -0,0 +1,25 @@
+#! /usr/bin/env ruby -S rspec
+require 'spec_helper'
+
+describe "the loadyaml function" do
+ include PuppetlabsSpec::Files
+
+ let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
+
+ it "should exist" do
+ expect(Puppet::Parser::Functions.function("loadyaml")).to eq("function_loadyaml")
+ end
+
+ it "should raise a ParseError if there is less than 1 arguments" do
+ expect { scope.function_loadyaml([]) }.to raise_error(Puppet::ParseError)
+ end
+
+ it "should convert YAML file to a data structure" do
+ yaml_file = tmpfilename ('yamlfile')
+ File.open(yaml_file, 'w') do |fh|
+ fh.write("---\n aaa: 1\n bbb: 2\n ccc: 3\n ddd: 4\n")
+ end
+ result = scope.function_loadyaml([yaml_file])
+ expect(result).to eq({"aaa" => 1, "bbb" => 2, "ccc" => 3, "ddd" => 4 })
+ end
+end
diff --git a/spec/functions/lstrip_spec.rb b/spec/functions/lstrip_spec.rb
new file mode 100755
index 0000000..68cca1c
--- /dev/null
+++ b/spec/functions/lstrip_spec.rb
@@ -0,0 +1,28 @@
+#! /usr/bin/env ruby -S rspec
+require 'spec_helper'
+
+describe "the lstrip function" do
+ let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
+
+ it "should exist" do
+ expect(Puppet::Parser::Functions.function("lstrip")).to eq("function_lstrip")
+ end
+
+ it "should raise a ParseError if there is less than 1 arguments" do
+ expect { scope.function_lstrip([]) }.to( raise_error(Puppet::ParseError))
+ end
+
+ it "should lstrip a string" do
+ result = scope.function_lstrip([" asdf"])
+ expect(result).to(eq('asdf'))
+ end
+
+ it "should accept objects which extend String" do
+ class AlsoString < String
+ end
+
+ value = AlsoString.new(" asdf")
+ result = scope.function_lstrip([value])
+ result.should(eq("asdf"))
+ end
+end
diff --git a/spec/unit/puppet/parser/functions/max_spec.rb b/spec/functions/max_spec.rb
index ff6f2b3..c3d8a13 100755
--- a/spec/unit/puppet/parser/functions/max_spec.rb
+++ b/spec/functions/max_spec.rb
@@ -6,22 +6,22 @@ describe "the max function" do
let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
it "should exist" do
- Puppet::Parser::Functions.function("max").should == "function_max"
+ expect(Puppet::Parser::Functions.function("max")).to eq("function_max")
end
it "should raise a ParseError if there is less than 1 arguments" do
- lambda { scope.function_max([]) }.should( raise_error(Puppet::ParseError))
+ expect { scope.function_max([]) }.to( raise_error(Puppet::ParseError))
end
it "should be able to compare strings" do
- scope.function_max(["albatross","dog","horse"]).should(eq("horse"))
+ expect(scope.function_max(["albatross","dog","horse"])).to(eq("horse"))
end
it "should be able to compare numbers" do
- scope.function_max([6,8,4]).should(eq(8))
+ expect(scope.function_max([6,8,4])).to(eq(8))
end
it "should be able to compare a number with a stringified number" do
- scope.function_max([1,"2"]).should(eq("2"))
+ expect(scope.function_max([1,"2"])).to(eq("2"))
end
end
diff --git a/spec/functions/member_spec.rb b/spec/functions/member_spec.rb
new file mode 100755
index 0000000..1a1d7c6
--- /dev/null
+++ b/spec/functions/member_spec.rb
@@ -0,0 +1,34 @@
+#! /usr/bin/env ruby -S rspec
+require 'spec_helper'
+
+describe "the member function" do
+ let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
+
+ it "should exist" do
+ expect(Puppet::Parser::Functions.function("member")).to eq("function_member")
+ end
+
+ it "should raise a ParseError if there is less than 1 arguments" do
+ expect { scope.function_member([]) }.to( raise_error(Puppet::ParseError))
+ end
+
+ it "should return true if a member is in an array" do
+ result = scope.function_member([["a","b","c"], "a"])
+ expect(result).to(eq(true))
+ end
+
+ it "should return false if a member is not in an array" do
+ result = scope.function_member([["a","b","c"], "d"])
+ expect(result).to(eq(false))
+ end
+
+ it "should return true if a member array is in an array" do
+ result = scope.function_member([["a","b","c"], ["a", "b"]])
+ expect(result).to(eq(true))
+ end
+
+ it "should return false if a member array is not in an array" do
+ result = scope.function_member([["a","b","c"], ["d", "e"]])
+ expect(result).to(eq(false))
+ end
+end
diff --git a/spec/unit/puppet/parser/functions/merge_spec.rb b/spec/functions/merge_spec.rb
index 8a170bb..2abf976 100644..100755
--- a/spec/unit/puppet/parser/functions/merge_spec.rb
+++ b/spec/functions/merge_spec.rb
@@ -7,7 +7,7 @@ describe Puppet::Parser::Functions.function(:merge) do
describe 'when calling merge from puppet' do
it "should not compile when no arguments are passed" do
- pending("Fails on 2.6.x, see bug #15912") if Puppet.version =~ /^2\.6\./
+ skip("Fails on 2.6.x, see bug #15912") if Puppet.version =~ /^2\.6\./
Puppet[:code] = '$x = merge()'
expect {
scope.compiler.compile
@@ -15,7 +15,7 @@ describe Puppet::Parser::Functions.function(:merge) do
end
it "should not compile when 1 argument is passed" do
- pending("Fails on 2.6.x, see bug #15912") if Puppet.version =~ /^2\.6\./
+ skip("Fails on 2.6.x, see bug #15912") if Puppet.version =~ /^2\.6\./
Puppet[:code] = "$my_hash={'one' => 1}\n$x = merge($my_hash)"
expect {
scope.compiler.compile
@@ -30,23 +30,23 @@ describe Puppet::Parser::Functions.function(:merge) do
end
it 'should accept empty strings as puppet undef' do
- expect { new_hash = scope.function_merge([{}, ''])}.not_to raise_error(Puppet::ParseError, /unexpected argument type String/)
+ expect { new_hash = scope.function_merge([{}, ''])}.not_to raise_error
end
it 'should be able to merge two hashes' do
new_hash = scope.function_merge([{'one' => '1', 'two' => '1'}, {'two' => '2', 'three' => '2'}])
- new_hash['one'].should == '1'
- new_hash['two'].should == '2'
- new_hash['three'].should == '2'
+ expect(new_hash['one']).to eq('1')
+ expect(new_hash['two']).to eq('2')
+ expect(new_hash['three']).to eq('2')
end
it 'should merge multiple hashes' do
hash = scope.function_merge([{'one' => 1}, {'one' => '2'}, {'one' => '3'}])
- hash['one'].should == '3'
+ expect(hash['one']).to eq('3')
end
it 'should accept empty hashes' do
- scope.function_merge([{},{},{}]).should == {}
+ expect(scope.function_merge([{},{},{}])).to eq({})
end
end
end
diff --git a/spec/unit/puppet/parser/functions/min_spec.rb b/spec/functions/min_spec.rb
index 71d593e..35a0890 100755
--- a/spec/unit/puppet/parser/functions/min_spec.rb
+++ b/spec/functions/min_spec.rb
@@ -6,22 +6,22 @@ describe "the min function" do
let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
it "should exist" do
- Puppet::Parser::Functions.function("min").should == "function_min"
+ expect(Puppet::Parser::Functions.function("min")).to eq("function_min")
end
it "should raise a ParseError if there is less than 1 arguments" do
- lambda { scope.function_min([]) }.should( raise_error(Puppet::ParseError))
+ expect { scope.function_min([]) }.to( raise_error(Puppet::ParseError))
end
it "should be able to compare strings" do
- scope.function_min(["albatross","dog","horse"]).should(eq("albatross"))
+ expect(scope.function_min(["albatross","dog","horse"])).to(eq("albatross"))
end
it "should be able to compare numbers" do
- scope.function_min([6,8,4]).should(eq(4))
+ expect(scope.function_min([6,8,4])).to(eq(4))
end
it "should be able to compare a number with a stringified number" do
- scope.function_min([1,"2"]).should(eq(1))
+ expect(scope.function_min([1,"2"])).to(eq(1))
end
end
diff --git a/spec/unit/puppet/parser/functions/num2bool_spec.rb b/spec/functions/num2bool_spec.rb
index b56196d..d0ba935 100644..100755
--- a/spec/unit/puppet/parser/functions/num2bool_spec.rb
+++ b/spec/functions/num2bool_spec.rb
@@ -5,63 +5,63 @@ describe "the num2bool function" do
let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
it "should exist" do
- Puppet::Parser::Functions.function("num2bool").should == "function_num2bool"
+ expect(Puppet::Parser::Functions.function("num2bool")).to eq("function_num2bool")
end
it "should raise a ParseError if there are no arguments" do
- lambda { scope.function_num2bool([]) }.should( raise_error(Puppet::ParseError))
+ expect { scope.function_num2bool([]) }.to( raise_error(Puppet::ParseError))
end
it "should raise a ParseError if there are more than 1 arguments" do
- lambda { scope.function_num2bool(["foo","bar"]) }.should( raise_error(Puppet::ParseError))
+ expect { scope.function_num2bool(["foo","bar"]) }.to( raise_error(Puppet::ParseError))
end
it "should raise a ParseError if passed something non-numeric" do
- lambda { scope.function_num2bool(["xyzzy"]) }.should( raise_error(Puppet::ParseError))
+ expect { scope.function_num2bool(["xyzzy"]) }.to( raise_error(Puppet::ParseError))
end
it "should return true if passed string 1" do
result = scope.function_num2bool(["1"])
- result.should(be_true)
+ expect(result).to(be_truthy)
end
it "should return true if passed string 1.5" do
result = scope.function_num2bool(["1.5"])
- result.should(be_true)
+ expect(result).to(be_truthy)
end
it "should return true if passed number 1" do
result = scope.function_num2bool([1])
- result.should(be_true)
+ expect(result).to(be_truthy)
end
it "should return false if passed string 0" do
result = scope.function_num2bool(["0"])
- result.should(be_false)
+ expect(result).to(be_falsey)
end
it "should return false if passed number 0" do
result = scope.function_num2bool([0])
- result.should(be_false)
+ expect(result).to(be_falsey)
end
it "should return false if passed string -1" do
result = scope.function_num2bool(["-1"])
- result.should(be_false)
+ expect(result).to(be_falsey)
end
it "should return false if passed string -1.5" do
result = scope.function_num2bool(["-1.5"])
- result.should(be_false)
+ expect(result).to(be_falsey)
end
it "should return false if passed number -1" do
result = scope.function_num2bool([-1])
- result.should(be_false)
+ expect(result).to(be_falsey)
end
it "should return false if passed float -1.5" do
result = scope.function_num2bool([-1.5])
- result.should(be_false)
+ expect(result).to(be_falsey)
end
end
diff --git a/spec/unit/puppet/parser/functions/parsejson_spec.rb b/spec/functions/parsejson_spec.rb
index f179ac1..1dd41b9 100644..100755
--- a/spec/unit/puppet/parser/functions/parsejson_spec.rb
+++ b/spec/functions/parsejson_spec.rb
@@ -5,11 +5,11 @@ describe "the parsejson function" do
let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
it "should exist" do
- Puppet::Parser::Functions.function("parsejson").should == "function_parsejson"
+ expect(Puppet::Parser::Functions.function("parsejson")).to eq("function_parsejson")
end
it "should raise a ParseError if there is less than 1 arguments" do
- lambda { scope.function_parsejson([]) }.should( raise_error(Puppet::ParseError))
+ expect { scope.function_parsejson([]) }.to( raise_error(Puppet::ParseError))
end
it "should convert JSON to a data structure" do
@@ -17,6 +17,6 @@ describe "the parsejson function" do
["aaa","bbb","ccc"]
EOS
result = scope.function_parsejson([json])
- result.should(eq(['aaa','bbb','ccc']))
+ expect(result).to(eq(['aaa','bbb','ccc']))
end
end
diff --git a/spec/unit/puppet/parser/functions/parseyaml_spec.rb b/spec/functions/parseyaml_spec.rb
index 0c7aea8..e5f145b 100644..100755
--- a/spec/unit/puppet/parser/functions/parseyaml_spec.rb
+++ b/spec/functions/parseyaml_spec.rb
@@ -5,11 +5,11 @@ describe "the parseyaml function" do
let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
it "should exist" do
- Puppet::Parser::Functions.function("parseyaml").should == "function_parseyaml"
+ expect(Puppet::Parser::Functions.function("parseyaml")).to eq("function_parseyaml")
end
it "should raise a ParseError if there is less than 1 arguments" do
- lambda { scope.function_parseyaml([]) }.should( raise_error(Puppet::ParseError))
+ expect { scope.function_parseyaml([]) }.to( raise_error(Puppet::ParseError))
end
it "should convert YAML to a data structure" do
@@ -19,6 +19,6 @@ describe "the parseyaml function" do
- ccc
EOS
result = scope.function_parseyaml([yaml])
- result.should(eq(['aaa','bbb','ccc']))
+ expect(result).to(eq(['aaa','bbb','ccc']))
end
end
diff --git a/spec/functions/pick_default_spec.rb b/spec/functions/pick_default_spec.rb
new file mode 100755
index 0000000..db10cc3
--- /dev/null
+++ b/spec/functions/pick_default_spec.rb
@@ -0,0 +1,58 @@
+#!/usr/bin/env ruby -S rspec
+require 'spec_helper'
+
+describe "the pick_default function" do
+ let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
+
+ it "should exist" do
+ expect(Puppet::Parser::Functions.function("pick_default")).to eq("function_pick_default")
+ end
+
+ it 'should return the correct value' do
+ expect(scope.function_pick_default(['first', 'second'])).to eq('first')
+ end
+
+ it 'should return the correct value if the first value is empty' do
+ expect(scope.function_pick_default(['', 'second'])).to eq('second')
+ end
+
+ it 'should skip empty string values' do
+ expect(scope.function_pick_default(['', 'first'])).to eq('first')
+ end
+
+ it 'should skip :undef values' do
+ expect(scope.function_pick_default([:undef, 'first'])).to eq('first')
+ end
+
+ it 'should skip :undefined values' do
+ expect(scope.function_pick_default([:undefined, 'first'])).to eq('first')
+ end
+
+ it 'should return the empty string if it is the last possibility' do
+ expect(scope.function_pick_default([:undef, :undefined, ''])).to eq('')
+ end
+
+ it 'should return :undef if it is the last possibility' do
+ expect(scope.function_pick_default(['', :undefined, :undef])).to eq(:undef)
+ end
+
+ it 'should return :undefined if it is the last possibility' do
+ expect(scope.function_pick_default([:undef, '', :undefined])).to eq(:undefined)
+ end
+
+ it 'should return the empty string if it is the only possibility' do
+ expect(scope.function_pick_default([''])).to eq('')
+ end
+
+ it 'should return :undef if it is the only possibility' do
+ expect(scope.function_pick_default([:undef])).to eq(:undef)
+ end
+
+ it 'should return :undefined if it is the only possibility' do
+ expect(scope.function_pick_default([:undefined])).to eq(:undefined)
+ end
+
+ it 'should error if no values are passed' do
+ expect { scope.function_pick_default([]) }.to raise_error(Puppet::Error, /Must receive at least one argument./)
+ end
+end
diff --git a/spec/functions/pick_spec.rb b/spec/functions/pick_spec.rb
new file mode 100755
index 0000000..8be8f58
--- /dev/null
+++ b/spec/functions/pick_spec.rb
@@ -0,0 +1,34 @@
+#!/usr/bin/env ruby -S rspec
+require 'spec_helper'
+
+describe "the pick function" do
+ let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
+
+ it "should exist" do
+ expect(Puppet::Parser::Functions.function("pick")).to eq("function_pick")
+ end
+
+ it 'should return the correct value' do
+ expect(scope.function_pick(['first', 'second'])).to eq('first')
+ end
+
+ it 'should return the correct value if the first value is empty' do
+ expect(scope.function_pick(['', 'second'])).to eq('second')
+ end
+
+ it 'should remove empty string values' do
+ expect(scope.function_pick(['', 'first'])).to eq('first')
+ end
+
+ it 'should remove :undef values' do
+ expect(scope.function_pick([:undef, 'first'])).to eq('first')
+ end
+
+ it 'should remove :undefined values' do
+ expect(scope.function_pick([:undefined, 'first'])).to eq('first')
+ end
+
+ it 'should error if no values are passed' do
+ expect { scope.function_pick([]) }.to( raise_error(Puppet::ParseError, "pick(): must receive at least one non empty value"))
+ end
+end
diff --git a/spec/functions/prefix_spec.rb b/spec/functions/prefix_spec.rb
new file mode 100755
index 0000000..34cac53
--- /dev/null
+++ b/spec/functions/prefix_spec.rb
@@ -0,0 +1,28 @@
+#! /usr/bin/env ruby -S rspec
+require 'spec_helper'
+
+describe "the prefix function" do
+ let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
+
+ it "raises a ParseError if there is less than 1 arguments" do
+ expect { scope.function_prefix([]) }.to raise_error(Puppet::ParseError, /number of arguments/)
+ end
+
+ it "raises an error if the first argument is not an array" do
+ expect {
+ scope.function_prefix([Object.new])
+ }.to raise_error(Puppet::ParseError, /expected first argument to be an Array/)
+ end
+
+
+ it "raises an error if the second argument is not a string" do
+ expect {
+ scope.function_prefix([['first', 'second'], 42])
+ }.to raise_error(Puppet::ParseError, /expected second argument to be a String/)
+ end
+
+ it "returns a prefixed array" do
+ result = scope.function_prefix([['a','b','c'], 'p'])
+ expect(result).to(eq(['pa','pb','pc']))
+ end
+end
diff --git a/spec/functions/private_spec.rb b/spec/functions/private_spec.rb
new file mode 100755
index 0000000..c70759f
--- /dev/null
+++ b/spec/functions/private_spec.rb
@@ -0,0 +1,55 @@
+#! /usr/bin/env ruby -S rspec
+require 'spec_helper'
+
+describe Puppet::Parser::Functions.function(:private) do
+ let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
+
+ subject do
+ function_name = Puppet::Parser::Functions.function(:private)
+ scope.method(function_name)
+ end
+
+ context "when called from inside module" do
+ it "should not fail" do
+ scope.expects(:lookupvar).with('module_name').returns('foo')
+ scope.expects(:lookupvar).with('caller_module_name').returns('foo')
+ expect {
+ subject.call []
+ }.not_to raise_error
+ end
+ end
+
+ context "with an explicit failure message" do
+ it "prints the failure message on error" do
+ scope.expects(:lookupvar).with('module_name').returns('foo')
+ scope.expects(:lookupvar).with('caller_module_name').returns('bar')
+ expect {
+ subject.call ['failure message!']
+ }.to raise_error Puppet::ParseError, /failure message!/
+ end
+ end
+
+ context "when called from private class" do
+ it "should fail with a class error message" do
+ scope.expects(:lookupvar).with('module_name').returns('foo')
+ scope.expects(:lookupvar).with('caller_module_name').returns('bar')
+ scope.source.expects(:name).returns('foo::baz')
+ scope.source.expects(:type).returns('hostclass')
+ expect {
+ subject.call []
+ }.to raise_error Puppet::ParseError, /Class foo::baz is private/
+ end
+ end
+
+ context "when called from private definition" do
+ it "should fail with a class error message" do
+ scope.expects(:lookupvar).with('module_name').returns('foo')
+ scope.expects(:lookupvar).with('caller_module_name').returns('bar')
+ scope.source.expects(:name).returns('foo::baz')
+ scope.source.expects(:type).returns('definition')
+ expect {
+ subject.call []
+ }.to raise_error Puppet::ParseError, /Definition foo::baz is private/
+ end
+ end
+end
diff --git a/spec/unit/puppet/parser/functions/range_spec.rb b/spec/functions/range_spec.rb
index 0e1ad37..ef86f97 100644..100755
--- a/spec/unit/puppet/parser/functions/range_spec.rb
+++ b/spec/functions/range_spec.rb
@@ -5,7 +5,7 @@ describe "the range function" do
let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
it "exists" do
- Puppet::Parser::Functions.function("range").should == "function_range"
+ expect(Puppet::Parser::Functions.function("range")).to eq("function_range")
end
it "raises a ParseError if there is less than 1 arguments" do
@@ -15,56 +15,72 @@ describe "the range function" do
describe 'with a letter range' do
it "returns a letter range" do
result = scope.function_range(["a","d"])
- result.should eq ['a','b','c','d']
+ expect(result).to eq ['a','b','c','d']
end
it "returns a letter range given a step of 1" do
result = scope.function_range(["a","d","1"])
- result.should eq ['a','b','c','d']
+ expect(result).to eq ['a','b','c','d']
end
it "returns a stepped letter range" do
result = scope.function_range(["a","d","2"])
- result.should eq ['a','c']
+ expect(result).to eq ['a','c']
end
it "returns a stepped letter range given a negative step" do
result = scope.function_range(["a","d","-2"])
- result.should eq ['a','c']
+ expect(result).to eq ['a','c']
end
end
describe 'with a number range' do
it "returns a number range" do
result = scope.function_range(["1","4"])
- result.should eq [1,2,3,4]
+ expect(result).to eq [1,2,3,4]
end
it "returns a number range given a step of 1" do
result = scope.function_range(["1","4","1"])
- result.should eq [1,2,3,4]
+ expect(result).to eq [1,2,3,4]
end
it "returns a stepped number range" do
result = scope.function_range(["1","4","2"])
- result.should eq [1,3]
+ expect(result).to eq [1,3]
end
it "returns a stepped number range given a negative step" do
result = scope.function_range(["1","4","-2"])
- result.should eq [1,3]
+ expect(result).to eq [1,3]
end
end
describe 'with a numeric-like string range' do
it "works with padded hostname like strings" do
expected = ("host01".."host10").to_a
- scope.function_range(["host01","host10"]).should eq expected
+ expect(scope.function_range(["host01","host10"])).to eq expected
end
it "coerces zero padded digits to integers" do
expected = (0..10).to_a
- scope.function_range(["00", "10"]).should eq expected
+ expect(scope.function_range(["00", "10"])).to eq expected
+ end
+ end
+
+ describe 'with a numeric range' do
+ it "returns a range of numbers" do
+ expected = (1..10).to_a
+ expect(scope.function_range([1,10])).to eq expected
+ end
+ it "returns a range of numbers with step parameter" do
+ expected = (1..10).step(2).to_a
+ expect(scope.function_range([1,10,2])).to eq expected
+ end
+ it "works with mixed numeric like strings and numeric arguments" do
+ expected = (1..10).to_a
+ expect(scope.function_range(['1',10])).to eq expected
+ expect(scope.function_range([1,'10'])).to eq expected
end
end
end
diff --git a/spec/unit/puppet/parser/functions/reject_spec.rb b/spec/functions/reject_spec.rb
index f2cb741..88a992e 100755
--- a/spec/unit/puppet/parser/functions/reject_spec.rb
+++ b/spec/functions/reject_spec.rb
@@ -6,15 +6,15 @@ describe "the reject function" do
let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
it "should exist" do
- Puppet::Parser::Functions.function("reject").should == "function_reject"
+ expect(Puppet::Parser::Functions.function("reject")).to eq("function_reject")
end
it "should raise a ParseError if there is less than 1 arguments" do
- lambda { scope.function_reject([]) }.should( raise_error(Puppet::ParseError))
+ expect { scope.function_reject([]) }.to( raise_error(Puppet::ParseError))
end
it "should reject contents from an array" do
result = scope.function_reject([["1111", "aaabbb","bbbccc","dddeee"], "bbb"])
- result.should(eq(["1111", "dddeee"]))
+ expect(result).to(eq(["1111", "dddeee"]))
end
end
diff --git a/spec/functions/reverse_spec.rb b/spec/functions/reverse_spec.rb
new file mode 100755
index 0000000..1f04794
--- /dev/null
+++ b/spec/functions/reverse_spec.rb
@@ -0,0 +1,28 @@
+#! /usr/bin/env ruby -S rspec
+require 'spec_helper'
+
+describe "the reverse function" do
+ let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
+
+ it "should exist" do
+ expect(Puppet::Parser::Functions.function("reverse")).to eq("function_reverse")
+ end
+
+ it "should raise a ParseError if there is less than 1 arguments" do
+ expect { scope.function_reverse([]) }.to( raise_error(Puppet::ParseError))
+ end
+
+ it "should reverse a string" do
+ result = scope.function_reverse(["asdfghijkl"])
+ expect(result).to(eq('lkjihgfdsa'))
+ end
+
+ it "should accept objects which extend String" do
+ class AlsoString < String
+ end
+
+ value = AlsoString.new('asdfghjkl')
+ result = scope.function_reverse([value])
+ result.should(eq('lkjhgfdsa'))
+ end
+end
diff --git a/spec/unit/puppet/parser/functions/rstrip_spec.rb b/spec/functions/rstrip_spec.rb
index d90de1d..f6b4838 100644..100755
--- a/spec/unit/puppet/parser/functions/rstrip_spec.rb
+++ b/spec/functions/rstrip_spec.rb
@@ -5,20 +5,29 @@ describe "the rstrip function" do
let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
it "should exist" do
- Puppet::Parser::Functions.function("rstrip").should == "function_rstrip"
+ expect(Puppet::Parser::Functions.function("rstrip")).to eq("function_rstrip")
end
it "should raise a ParseError if there is less than 1 arguments" do
- lambda { scope.function_rstrip([]) }.should( raise_error(Puppet::ParseError))
+ expect { scope.function_rstrip([]) }.to( raise_error(Puppet::ParseError))
end
it "should rstrip a string" do
result = scope.function_rstrip(["asdf "])
- result.should(eq('asdf'))
+ expect(result).to(eq('asdf'))
end
it "should rstrip each element in an array" do
result = scope.function_rstrip([["a ","b ", "c "]])
- result.should(eq(['a','b','c']))
+ expect(result).to(eq(['a','b','c']))
+ end
+
+ it "should accept objects which extend String" do
+ class AlsoString < String
+ end
+
+ value = AlsoString.new('asdf ')
+ result = scope.function_rstrip([value])
+ result.should(eq('asdf'))
end
end
diff --git a/spec/unit/puppet/parser/functions/shuffle_spec.rb b/spec/functions/shuffle_spec.rb
index 93346d5..a62c1fb 100644..100755
--- a/spec/unit/puppet/parser/functions/shuffle_spec.rb
+++ b/spec/functions/shuffle_spec.rb
@@ -5,20 +5,29 @@ describe "the shuffle function" do
let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
it "should exist" do
- Puppet::Parser::Functions.function("shuffle").should == "function_shuffle"
+ expect(Puppet::Parser::Functions.function("shuffle")).to eq("function_shuffle")
end
it "should raise a ParseError if there is less than 1 arguments" do
- lambda { scope.function_shuffle([]) }.should( raise_error(Puppet::ParseError))
+ expect { scope.function_shuffle([]) }.to( raise_error(Puppet::ParseError))
end
it "should shuffle a string and the result should be the same size" do
result = scope.function_shuffle(["asdf"])
- result.size.should(eq(4))
+ expect(result.size).to(eq(4))
end
it "should shuffle a string but the sorted contents should still be the same" do
result = scope.function_shuffle(["adfs"])
- result.split("").sort.join("").should(eq("adfs"))
+ expect(result.split("").sort.join("")).to(eq("adfs"))
+ end
+
+ it "should accept objects which extend String" do
+ class AlsoString < String
+ end
+
+ value = AlsoString.new('asdf')
+ result = scope.function_shuffle([value])
+ result.size.should(eq(4))
end
end
diff --git a/spec/unit/puppet/parser/functions/size_spec.rb b/spec/functions/size_spec.rb
index b1c435a..18eb48f 100644..100755
--- a/spec/unit/puppet/parser/functions/size_spec.rb
+++ b/spec/functions/size_spec.rb
@@ -5,20 +5,20 @@ describe "the size function" do
let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
it "should exist" do
- Puppet::Parser::Functions.function("size").should == "function_size"
+ expect(Puppet::Parser::Functions.function("size")).to eq("function_size")
end
it "should raise a ParseError if there is less than 1 arguments" do
- lambda { scope.function_size([]) }.should( raise_error(Puppet::ParseError))
+ expect { scope.function_size([]) }.to( raise_error(Puppet::ParseError))
end
it "should return the size of a string" do
result = scope.function_size(["asdf"])
- result.should(eq(4))
+ expect(result).to(eq(4))
end
it "should return the size of an array" do
result = scope.function_size([["a","b","c"]])
- result.should(eq(3))
+ expect(result).to(eq(3))
end
end
diff --git a/spec/unit/puppet/parser/functions/sort_spec.rb b/spec/functions/sort_spec.rb
index 3187a5a..4c2a66c 100644..100755
--- a/spec/unit/puppet/parser/functions/sort_spec.rb
+++ b/spec/functions/sort_spec.rb
@@ -5,20 +5,20 @@ describe "the sort function" do
let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
it "should exist" do
- Puppet::Parser::Functions.function("sort").should == "function_sort"
+ expect(Puppet::Parser::Functions.function("sort")).to eq("function_sort")
end
it "should raise a ParseError if there is not 1 arguments" do
- lambda { scope.function_sort(['','']) }.should( raise_error(Puppet::ParseError))
+ expect { scope.function_sort(['','']) }.to( raise_error(Puppet::ParseError))
end
it "should sort an array" do
result = scope.function_sort([["a","c","b"]])
- result.should(eq(['a','b','c']))
+ expect(result).to(eq(['a','b','c']))
end
it "should sort a string" do
result = scope.function_sort(["acb"])
- result.should(eq('abc'))
+ expect(result).to(eq('abc'))
end
end
diff --git a/spec/unit/puppet/parser/functions/squeeze_spec.rb b/spec/functions/squeeze_spec.rb
index 60e5a30..cd0eb37 100644..100755
--- a/spec/unit/puppet/parser/functions/squeeze_spec.rb
+++ b/spec/functions/squeeze_spec.rb
@@ -5,20 +5,20 @@ describe "the squeeze function" do
let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
it "should exist" do
- Puppet::Parser::Functions.function("squeeze").should == "function_squeeze"
+ expect(Puppet::Parser::Functions.function("squeeze")).to eq("function_squeeze")
end
it "should raise a ParseError if there is less than 2 arguments" do
- lambda { scope.function_squeeze([]) }.should( raise_error(Puppet::ParseError))
+ expect { scope.function_squeeze([]) }.to( raise_error(Puppet::ParseError))
end
it "should squeeze a string" do
result = scope.function_squeeze(["aaabbbbcccc"])
- result.should(eq('abc'))
+ expect(result).to(eq('abc'))
end
it "should squeeze all elements in an array" do
result = scope.function_squeeze([["aaabbbbcccc","dddfff"]])
- result.should(eq(['abc','df']))
+ expect(result).to(eq(['abc','df']))
end
end
diff --git a/spec/unit/puppet/parser/functions/str2bool_spec.rb b/spec/functions/str2bool_spec.rb
index ef6350f..1d205d7 100644..100755
--- a/spec/unit/puppet/parser/functions/str2bool_spec.rb
+++ b/spec/functions/str2bool_spec.rb
@@ -5,27 +5,27 @@ describe "the str2bool function" do
let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
it "should exist" do
- Puppet::Parser::Functions.function("str2bool").should == "function_str2bool"
+ expect(Puppet::Parser::Functions.function("str2bool")).to eq("function_str2bool")
end
it "should raise a ParseError if there is less than 1 arguments" do
- lambda { scope.function_str2bool([]) }.should( raise_error(Puppet::ParseError))
+ expect { scope.function_str2bool([]) }.to( raise_error(Puppet::ParseError))
end
it "should convert string 'true' to true" do
result = scope.function_str2bool(["true"])
- result.should(eq(true))
+ expect(result).to(eq(true))
end
it "should convert string 'undef' to false" do
result = scope.function_str2bool(["undef"])
- result.should(eq(false))
+ expect(result).to(eq(false))
end
-
+
it "should return the boolean it was called with" do
result = scope.function_str2bool([true])
- result.should(eq(true))
+ expect(result).to(eq(true))
result = scope.function_str2bool([false])
- result.should(eq(false))
+ expect(result).to(eq(false))
end
end
diff --git a/spec/unit/puppet/parser/functions/str2saltedsha512_spec.rb b/spec/functions/str2saltedsha512_spec.rb
index df8fb8e..ab7f57f 100644..100755
--- a/spec/unit/puppet/parser/functions/str2saltedsha512_spec.rb
+++ b/spec/functions/str2saltedsha512_spec.rb
@@ -5,7 +5,7 @@ describe "the str2saltedsha512 function" do
let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
it "should exist" do
- Puppet::Parser::Functions.function("str2saltedsha512").should == "function_str2saltedsha512"
+ expect(Puppet::Parser::Functions.function("str2saltedsha512")).to eq("function_str2saltedsha512")
end
it "should raise a ParseError if there is less than 1 argument" do
@@ -18,7 +18,7 @@ describe "the str2saltedsha512 function" do
it "should return a salted-sha512 password hash 136 characters in length" do
result = scope.function_str2saltedsha512(["password"])
- result.length.should(eq(136))
+ expect(result.length).to(eq(136))
end
it "should raise an error if you pass a non-string password" do
@@ -40,6 +40,6 @@ describe "the str2saltedsha512 function" do
# Combine the Binary Salt with 'password' and compare the end result
saltedpass = Digest::SHA512.digest(str_salt + 'password')
result = (str_salt + saltedpass).unpack('H*')[0]
- result.should == password_hash
+ expect(result).to eq(password_hash)
end
end
diff --git a/spec/unit/puppet/parser/functions/strftime_spec.rb b/spec/functions/strftime_spec.rb
index df42b6f..ebec54b 100644..100755
--- a/spec/unit/puppet/parser/functions/strftime_spec.rb
+++ b/spec/functions/strftime_spec.rb
@@ -5,25 +5,25 @@ describe "the strftime function" do
let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
it "should exist" do
- Puppet::Parser::Functions.function("strftime").should == "function_strftime"
+ expect(Puppet::Parser::Functions.function("strftime")).to eq("function_strftime")
end
it "should raise a ParseError if there is less than 1 arguments" do
- lambda { scope.function_strftime([]) }.should( raise_error(Puppet::ParseError))
+ expect { scope.function_strftime([]) }.to( raise_error(Puppet::ParseError))
end
it "using %s should be higher then when I wrote this test" do
result = scope.function_strftime(["%s"])
- result.to_i.should(be > 1311953157)
+ expect(result.to_i).to(be > 1311953157)
end
it "using %s should be lower then 1.5 trillion" do
result = scope.function_strftime(["%s"])
- result.to_i.should(be < 1500000000)
+ expect(result.to_i).to(be < 1500000000)
end
it "should return a date when given %Y-%m-%d" do
result = scope.function_strftime(["%Y-%m-%d"])
- result.should =~ /^\d{4}-\d{2}-\d{2}$/
+ expect(result).to match(/^\d{4}-\d{2}-\d{2}$/)
end
end
diff --git a/spec/functions/strip_spec.rb b/spec/functions/strip_spec.rb
new file mode 100755
index 0000000..4ac8daf
--- /dev/null
+++ b/spec/functions/strip_spec.rb
@@ -0,0 +1,27 @@
+#! /usr/bin/env ruby -S rspec
+require 'spec_helper'
+
+describe "the strip function" do
+ let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
+ it "should exist" do
+ expect(Puppet::Parser::Functions.function("strip")).to eq("function_strip")
+ end
+
+ it "should raise a ParseError if there is less than 1 arguments" do
+ expect { scope.function_strip([]) }.to( raise_error(Puppet::ParseError))
+ end
+
+ it "should strip a string" do
+ result = scope.function_strip([" ab cd "])
+ expect(result).to(eq('ab cd'))
+ end
+
+ it "should accept objects which extend String" do
+ class AlsoString < String
+ end
+
+ value = AlsoString.new(' as df ')
+ result = scope.function_strip([value])
+ result.should(eq('as df'))
+ end
+end
diff --git a/spec/functions/suffix_spec.rb b/spec/functions/suffix_spec.rb
new file mode 100755
index 0000000..c7783c6
--- /dev/null
+++ b/spec/functions/suffix_spec.rb
@@ -0,0 +1,27 @@
+#! /usr/bin/env ruby -S rspec
+require 'spec_helper'
+
+describe "the suffix function" do
+ let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
+
+ it "raises a ParseError if there is less than 1 arguments" do
+ expect { scope.function_suffix([]) }.to raise_error(Puppet::ParseError, /number of arguments/)
+ end
+
+ it "raises an error if the first argument is not an array" do
+ expect {
+ scope.function_suffix([Object.new])
+ }.to raise_error(Puppet::ParseError, /expected first argument to be an Array/)
+ end
+
+ it "raises an error if the second argument is not a string" do
+ expect {
+ scope.function_suffix([['first', 'second'], 42])
+ }.to raise_error(Puppet::ParseError, /expected second argument to be a String/)
+ end
+
+ it "returns a suffixed array" do
+ result = scope.function_suffix([['a','b','c'], 'p'])
+ expect(result).to(eq(['ap','bp','cp']))
+ end
+end
diff --git a/spec/functions/swapcase_spec.rb b/spec/functions/swapcase_spec.rb
new file mode 100755
index 0000000..791d1df
--- /dev/null
+++ b/spec/functions/swapcase_spec.rb
@@ -0,0 +1,28 @@
+#! /usr/bin/env ruby -S rspec
+require 'spec_helper'
+
+describe "the swapcase function" do
+ let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
+
+ it "should exist" do
+ expect(Puppet::Parser::Functions.function("swapcase")).to eq("function_swapcase")
+ end
+
+ it "should raise a ParseError if there is less than 1 arguments" do
+ expect { scope.function_swapcase([]) }.to( raise_error(Puppet::ParseError))
+ end
+
+ it "should swapcase a string" do
+ result = scope.function_swapcase(["aaBBccDD"])
+ expect(result).to(eq('AAbbCCdd'))
+ end
+
+ it "should accept objects which extend String" do
+ class AlsoString < String
+ end
+
+ value = AlsoString.new("aaBBccDD")
+ result = scope.function_swapcase([value])
+ result.should(eq("AAbbCCdd"))
+ end
+end
diff --git a/spec/unit/puppet/parser/functions/time_spec.rb b/spec/functions/time_spec.rb
index e9fb76e..6e22515 100644..100755
--- a/spec/unit/puppet/parser/functions/time_spec.rb
+++ b/spec/functions/time_spec.rb
@@ -5,25 +5,25 @@ describe "the time function" do
let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
it "should exist" do
- Puppet::Parser::Functions.function("time").should == "function_time"
+ expect(Puppet::Parser::Functions.function("time")).to eq("function_time")
end
it "should raise a ParseError if there is more than 2 arguments" do
- lambda { scope.function_time(['','']) }.should( raise_error(Puppet::ParseError))
+ expect { scope.function_time(['','']) }.to( raise_error(Puppet::ParseError))
end
it "should return a number" do
result = scope.function_time([])
- result.should be_an(Integer)
+ expect(result).to be_an(Integer)
end
it "should be higher then when I wrote this test" do
result = scope.function_time([])
- result.should(be > 1311953157)
+ expect(result).to(be > 1311953157)
end
it "should be lower then 1.5 trillion" do
result = scope.function_time([])
- result.should(be < 1500000000)
+ expect(result).to(be < 1500000000)
end
end
diff --git a/spec/functions/to_bytes_spec.rb b/spec/functions/to_bytes_spec.rb
new file mode 100755
index 0000000..0f6ade9
--- /dev/null
+++ b/spec/functions/to_bytes_spec.rb
@@ -0,0 +1,83 @@
+#! /usr/bin/env ruby -S rspec
+
+require 'spec_helper'
+
+describe "the to_bytes function" do
+ let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
+
+ it "should exist" do
+ expect(Puppet::Parser::Functions.function("to_bytes")).to eq("function_to_bytes")
+ end
+
+ it "should raise a ParseError if there is less than 1 arguments" do
+ expect { scope.function_to_bytes([]) }.to( raise_error(Puppet::ParseError))
+ end
+
+ it "should convert kB to B" do
+ result = scope.function_to_bytes(["4 kB"])
+ expect(result).to(eq(4096))
+ end
+
+ it "should convert MB to B" do
+ result = scope.function_to_bytes(["4 MB"])
+ expect(result).to(eq(4194304))
+ end
+
+ it "should convert GB to B" do
+ result = scope.function_to_bytes(["4 GB"])
+ expect(result).to(eq(4294967296))
+ end
+
+ it "should convert TB to B" do
+ result = scope.function_to_bytes(["4 TB"])
+ expect(result).to(eq(4398046511104))
+ end
+
+ it "should convert PB to B" do
+ result = scope.function_to_bytes(["4 PB"])
+ expect(result).to(eq(4503599627370496))
+ end
+
+ it "should convert PB to B" do
+ result = scope.function_to_bytes(["4 EB"])
+ expect(result).to(eq(4611686018427387904))
+ end
+
+ it "should work without B in unit" do
+ result = scope.function_to_bytes(["4 k"])
+ expect(result).to(eq(4096))
+ end
+
+ it "should work without a space before unit" do
+ result = scope.function_to_bytes(["4k"])
+ expect(result).to(eq(4096))
+ end
+
+ it "should work without a unit" do
+ result = scope.function_to_bytes(["5678"])
+ expect(result).to(eq(5678))
+ end
+
+ it "should convert fractions" do
+ result = scope.function_to_bytes(["1.5 kB"])
+ expect(result).to(eq(1536))
+ end
+
+ it "should convert scientific notation" do
+ result = scope.function_to_bytes(["1.5e2 B"])
+ expect(result).to(eq(150))
+ end
+
+ it "should do nothing with a positive number" do
+ result = scope.function_to_bytes([5678])
+ expect(result).to(eq(5678))
+ end
+
+ it "should should raise a ParseError if input isn't a number" do
+ expect { scope.function_to_bytes(["foo"]) }.to( raise_error(Puppet::ParseError))
+ end
+
+ it "should should raise a ParseError if prefix is unknown" do
+ expect { scope.function_to_bytes(["5 uB"]) }.to( raise_error(Puppet::ParseError))
+ end
+end
diff --git a/spec/functions/type3x_spec.rb b/spec/functions/type3x_spec.rb
new file mode 100644
index 0000000..d21236a
--- /dev/null
+++ b/spec/functions/type3x_spec.rb
@@ -0,0 +1,43 @@
+#! /usr/bin/env ruby -S rspec
+require 'spec_helper'
+
+describe "the type3x function" do
+ let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
+ it "should exist" do
+ expect(Puppet::Parser::Functions.function("type3x")).to eq("function_type3x")
+ end
+
+ it "should raise a ParseError if there is less than 1 arguments" do
+ expect { scope.function_type3x([]) }.to( raise_error(Puppet::ParseError))
+ end
+
+ it "should return string when given a string" do
+ result = scope.function_type3x(["aaabbbbcccc"])
+ expect(result).to(eq('string'))
+ end
+
+ it "should return array when given an array" do
+ result = scope.function_type3x([["aaabbbbcccc","asdf"]])
+ expect(result).to(eq('array'))
+ end
+
+ it "should return hash when given a hash" do
+ result = scope.function_type3x([{"a"=>1,"b"=>2}])
+ expect(result).to(eq('hash'))
+ end
+
+ it "should return integer when given an integer" do
+ result = scope.function_type3x(["1"])
+ expect(result).to(eq('integer'))
+ end
+
+ it "should return float when given a float" do
+ result = scope.function_type3x(["1.34"])
+ expect(result).to(eq('float'))
+ end
+
+ it "should return boolean when given a boolean" do
+ result = scope.function_type3x([true])
+ expect(result).to(eq('boolean'))
+ end
+end
diff --git a/spec/unit/puppet/parser/functions/type_spec.rb b/spec/functions/type_spec.rb
index 8fec88f..b683fcf 100644..100755
--- a/spec/unit/puppet/parser/functions/type_spec.rb
+++ b/spec/functions/type_spec.rb
@@ -4,40 +4,41 @@ require 'spec_helper'
describe "the type function" do
let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
it "should exist" do
- Puppet::Parser::Functions.function("type").should == "function_type"
+ expect(Puppet::Parser::Functions.function("type")).to eq("function_type")
end
- it "should raise a ParseError if there is less than 1 arguments" do
- lambda { scope.function_type([]) }.should( raise_error(Puppet::ParseError))
+ it "should give a deprecation warning when called" do
+ scope.expects(:warning).with("type() DEPRECATED: This function will cease to function on Puppet 4; please use type3x() before upgrading to puppet 4 for backwards-compatibility, or migrate to the new parser's typing system.")
+ scope.function_type(["aoeu"])
end
it "should return string when given a string" do
result = scope.function_type(["aaabbbbcccc"])
- result.should(eq('string'))
+ expect(result).to(eq('string'))
end
it "should return array when given an array" do
result = scope.function_type([["aaabbbbcccc","asdf"]])
- result.should(eq('array'))
+ expect(result).to(eq('array'))
end
it "should return hash when given a hash" do
result = scope.function_type([{"a"=>1,"b"=>2}])
- result.should(eq('hash'))
+ expect(result).to(eq('hash'))
end
it "should return integer when given an integer" do
result = scope.function_type(["1"])
- result.should(eq('integer'))
+ expect(result).to(eq('integer'))
end
it "should return float when given a float" do
result = scope.function_type(["1.34"])
- result.should(eq('float'))
+ expect(result).to(eq('float'))
end
it "should return boolean when given a boolean" do
result = scope.function_type([true])
- result.should(eq('boolean'))
+ expect(result).to(eq('boolean'))
end
end
diff --git a/spec/unit/puppet/parser/functions/union_spec.rb b/spec/functions/union_spec.rb
index 0d282ca..706f4cb 100644..100755
--- a/spec/unit/puppet/parser/functions/union_spec.rb
+++ b/spec/functions/union_spec.rb
@@ -5,15 +5,15 @@ describe "the union function" do
let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
it "should exist" do
- Puppet::Parser::Functions.function("union").should == "function_union"
+ expect(Puppet::Parser::Functions.function("union")).to eq("function_union")
end
it "should raise a ParseError if there are fewer than 2 arguments" do
- lambda { scope.function_union([]) }.should( raise_error(Puppet::ParseError) )
+ expect { scope.function_union([]) }.to( raise_error(Puppet::ParseError) )
end
it "should join two arrays together" do
result = scope.function_union([["a","b","c"],["b","c","d"]])
- result.should(eq(["a","b","c","d"]))
+ expect(result).to(eq(["a","b","c","d"]))
end
end
diff --git a/spec/unit/puppet/parser/functions/unique_spec.rb b/spec/functions/unique_spec.rb
index 5d48d49..7cd3a56 100644..100755
--- a/spec/unit/puppet/parser/functions/unique_spec.rb
+++ b/spec/functions/unique_spec.rb
@@ -5,20 +5,29 @@ describe "the unique function" do
let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
it "should exist" do
- Puppet::Parser::Functions.function("unique").should == "function_unique"
+ expect(Puppet::Parser::Functions.function("unique")).to eq("function_unique")
end
it "should raise a ParseError if there is less than 1 arguments" do
- lambda { scope.function_unique([]) }.should( raise_error(Puppet::ParseError))
+ expect { scope.function_unique([]) }.to( raise_error(Puppet::ParseError))
end
it "should remove duplicate elements in a string" do
result = scope.function_unique(["aabbc"])
- result.should(eq('abc'))
+ expect(result).to(eq('abc'))
end
it "should remove duplicate elements in an array" do
result = scope.function_unique([["a","a","b","b","c"]])
- result.should(eq(['a','b','c']))
+ expect(result).to(eq(['a','b','c']))
+ end
+
+ it "should accept objects which extend String" do
+ class AlsoString < String
+ end
+
+ value = AlsoString.new('aabbc')
+ result = scope.function_unique([value])
+ result.should(eq('abc'))
end
end
diff --git a/spec/unit/puppet/parser/functions/upcase_spec.rb b/spec/functions/upcase_spec.rb
index 5db5513..3cf8b05 100644..100755
--- a/spec/unit/puppet/parser/functions/upcase_spec.rb
+++ b/spec/functions/upcase_spec.rb
@@ -5,20 +5,29 @@ describe "the upcase function" do
let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
it "should exist" do
- Puppet::Parser::Functions.function("upcase").should == "function_upcase"
+ expect(Puppet::Parser::Functions.function("upcase")).to eq("function_upcase")
end
it "should raise a ParseError if there is less than 1 arguments" do
- lambda { scope.function_upcase([]) }.should( raise_error(Puppet::ParseError))
+ expect { scope.function_upcase([]) }.to( raise_error(Puppet::ParseError))
end
it "should upcase a string" do
result = scope.function_upcase(["abc"])
- result.should(eq('ABC'))
+ expect(result).to(eq('ABC'))
end
it "should do nothing if a string is already upcase" do
result = scope.function_upcase(["ABC"])
+ expect(result).to(eq('ABC'))
+ end
+
+ it "should accept objects which extend String" do
+ class AlsoString < String
+ end
+
+ value = AlsoString.new('abc')
+ result = scope.function_upcase([value])
result.should(eq('ABC'))
end
end
diff --git a/spec/unit/puppet/parser/functions/uriescape_spec.rb b/spec/functions/uriescape_spec.rb
index 7211c88..2321e5a 100644..100755
--- a/spec/unit/puppet/parser/functions/uriescape_spec.rb
+++ b/spec/functions/uriescape_spec.rb
@@ -5,20 +5,29 @@ describe "the uriescape function" do
let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
it "should exist" do
- Puppet::Parser::Functions.function("uriescape").should == "function_uriescape"
+ expect(Puppet::Parser::Functions.function("uriescape")).to eq("function_uriescape")
end
it "should raise a ParseError if there is less than 1 arguments" do
- lambda { scope.function_uriescape([]) }.should( raise_error(Puppet::ParseError))
+ expect { scope.function_uriescape([]) }.to( raise_error(Puppet::ParseError))
end
it "should uriescape a string" do
result = scope.function_uriescape([":/?#[]@!$&'()*+,;= \"{}"])
- result.should(eq(':/?%23[]@!$&\'()*+,;=%20%22%7B%7D'))
+ expect(result).to(eq(':/?%23[]@!$&\'()*+,;=%20%22%7B%7D'))
end
it "should do nothing if a string is already safe" do
result = scope.function_uriescape(["ABCdef"])
- result.should(eq('ABCdef'))
+ expect(result).to(eq('ABCdef'))
+ end
+
+ it "should accept objects which extend String" do
+ class AlsoString < String
+ end
+
+ value = AlsoString.new('abc')
+ result = scope.function_uriescape([value])
+ result.should(eq('abc'))
end
end
diff --git a/spec/unit/puppet/parser/functions/validate_absolute_path_spec.rb b/spec/functions/validate_absolute_path_spec.rb
index 08aaf78..36c836b 100644..100755
--- a/spec/unit/puppet/parser/functions/validate_absolute_path_spec.rb
+++ b/spec/functions/validate_absolute_path_spec.rb
@@ -1,3 +1,4 @@
+#! /usr/bin/env ruby -S rspec
require 'spec_helper'
describe Puppet::Parser::Functions.function(:validate_absolute_path) do
@@ -35,7 +36,12 @@ describe Puppet::Parser::Functions.function(:validate_absolute_path) do
end
valid_paths.each do |path|
it "validate_absolute_path(#{path.inspect}) should not fail" do
- expect { subject.call [path] }.not_to raise_error Puppet::ParseError
+ expect { subject.call [path] }.not_to raise_error
+ end
+ end
+ valid_paths do
+ it "validate_absolute_path(#{valid_paths.inspect}) should not fail" do
+ expect { subject.call [valid_paths] }.not_to raise_error
end
end
end
@@ -43,7 +49,12 @@ describe Puppet::Parser::Functions.function(:validate_absolute_path) do
context "Puppet without mocking" do
valid_paths.each do |path|
it "validate_absolute_path(#{path.inspect}) should not fail" do
- expect { subject.call [path] }.not_to raise_error Puppet::ParseError
+ expect { subject.call [path] }.not_to raise_error
+ end
+ end
+ valid_paths do
+ it "validate_absolute_path(#{valid_paths.inspect}) should not fail" do
+ expect { subject.call [valid_paths] }.not_to raise_error
end
end
end
@@ -54,6 +65,7 @@ describe Puppet::Parser::Functions.function(:validate_absolute_path) do
[
nil,
[ nil ],
+ [ nil, nil ],
{ 'foo' => 'bar' },
{ },
'',
@@ -65,19 +77,28 @@ describe Puppet::Parser::Functions.function(:validate_absolute_path) do
end
context 'Relative paths' do
- %w{
- relative1
- .
- ..
- ./foo
- ../foo
- etc/puppetlabs/puppet
- opt/puppet/bin
- }.each do |path|
+ def self.rel_paths
+ %w{
+ relative1
+ .
+ ..
+ ./foo
+ ../foo
+ etc/puppetlabs/puppet
+ opt/puppet/bin
+ }
+ end
+ rel_paths.each do |path|
it "validate_absolute_path(#{path.inspect}) should fail" do
expect { subject.call [path] }.to raise_error Puppet::ParseError
end
end
+ rel_paths do
+ it "validate_absolute_path(#{rel_paths.inspect}) should fail" do
+ expect { subject.call [rel_paths] }.to raise_error Puppet::ParseError
+ end
+ end
end
end
end
+
diff --git a/spec/unit/puppet/parser/functions/validate_array_spec.rb b/spec/functions/validate_array_spec.rb
index 4b31cfd..4b31cfd 100644..100755
--- a/spec/unit/puppet/parser/functions/validate_array_spec.rb
+++ b/spec/functions/validate_array_spec.rb
diff --git a/spec/unit/puppet/parser/functions/validate_augeas_spec.rb b/spec/functions/validate_augeas_spec.rb
index ab5c140..c695ba2 100644..100755
--- a/spec/unit/puppet/parser/functions/validate_augeas_spec.rb
+++ b/spec/functions/validate_augeas_spec.rb
@@ -1,3 +1,4 @@
+#! /usr/bin/env ruby -S rspec
require 'spec_helper'
describe Puppet::Parser::Functions.function(:validate_augeas), :if => Puppet.features.augeas? do
diff --git a/spec/unit/puppet/parser/functions/validate_bool_spec.rb b/spec/functions/validate_bool_spec.rb
index 261fb23..a352d3b 100644..100755
--- a/spec/unit/puppet/parser/functions/validate_bool_spec.rb
+++ b/spec/functions/validate_bool_spec.rb
@@ -1,4 +1,4 @@
-#! /usr/bin/env/ruby -S rspec
+#! /usr/bin/env ruby -S rspec
require 'spec_helper'
diff --git a/spec/functions/validate_cmd_spec.rb b/spec/functions/validate_cmd_spec.rb
new file mode 100755
index 0000000..7cb9782
--- /dev/null
+++ b/spec/functions/validate_cmd_spec.rb
@@ -0,0 +1,85 @@
+#! /usr/bin/env ruby -S rspec
+require 'spec_helper'
+
+TESTEXE = File.exists?('/usr/bin/test') ? '/usr/bin/test' : '/bin/test'
+TOUCHEXE = File.exists?('/usr/bin/touch') ? '/usr/bin/touch' : '/bin/touch'
+
+describe Puppet::Parser::Functions.function(:validate_cmd) do
+ let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
+
+ subject do
+ function_name = Puppet::Parser::Functions.function(:validate_cmd)
+ scope.method(function_name)
+ end
+
+ context 'with no % placeholder' do
+ describe "with an explicit failure message" do
+ it "prints the failure message on error" do
+ expect {
+ subject.call ['', '/bin/false', 'failure message!']
+ }.to raise_error Puppet::ParseError, /failure message!/
+ end
+ end
+
+ describe "on validation failure" do
+ it "includes the command error output" do
+ expect {
+ subject.call ['', "#{TOUCHEXE} /cant/touch/this"]
+ }.to raise_error Puppet::ParseError, /(cannot touch|o such file or)/
+ end
+
+ it "includes the command return value" do
+ expect {
+ subject.call ['', '/cant/run/this']
+ }.to raise_error Puppet::ParseError, /returned 1\b/
+ end
+ end
+
+ describe "when performing actual validation" do
+ it "can positively validate file content" do
+ expect { subject.call ["non-empty", "#{TESTEXE} -s"] }.to_not raise_error
+ end
+
+ it "can negatively validate file content" do
+ expect {
+ subject.call ["", "#{TESTEXE} -s"]
+ }.to raise_error Puppet::ParseError, /failed to validate.*test -s/
+ end
+ end
+ end
+
+ context 'with % placeholder' do
+ describe "with an explicit failure message" do
+ it "prints the failure message on error" do
+ expect {
+ subject.call ['', '/bin/false % -f', 'failure message!']
+ }.to raise_error Puppet::ParseError, /failure message!/
+ end
+ end
+ describe "on validation failure" do
+ it "includes the command error output" do
+ expect {
+ subject.call ['', "#{TOUCHEXE} /cant/touch/this"]
+ }.to raise_error Puppet::ParseError, /(cannot touch|o such file or)/
+ end
+
+ it "includes the command return value" do
+ expect {
+ subject.call ['', '/cant/run/this % -z']
+ }.to raise_error Puppet::ParseError, /Execution of '\/cant\/run\/this .+ -z' returned 1/
+ end
+ end
+
+ describe "when performing actual validation" do
+ it "can positively validate file content" do
+ expect { subject.call ["non-empty", "#{TESTEXE} -s %"] }.to_not raise_error
+ end
+
+ it "can negatively validate file content" do
+ expect {
+ subject.call ["", "#{TESTEXE} -s %"]
+ }.to raise_error Puppet::ParseError, /failed to validate.*test -s/
+ end
+ end
+ end
+end
diff --git a/spec/unit/puppet/parser/functions/validate_hash_spec.rb b/spec/functions/validate_hash_spec.rb
index a0c35c2..a0c35c2 100644..100755
--- a/spec/unit/puppet/parser/functions/validate_hash_spec.rb
+++ b/spec/functions/validate_hash_spec.rb
diff --git a/spec/unit/puppet/parser/functions/validate_ipv4_address_spec.rb b/spec/functions/validate_ipv4_address_spec.rb
index 85536d3..45401a4 100644..100755
--- a/spec/unit/puppet/parser/functions/validate_ipv4_address_spec.rb
+++ b/spec/functions/validate_ipv4_address_spec.rb
@@ -1,4 +1,4 @@
-#! /usr/bin/env/ruby -S rspec
+#! /usr/bin/env ruby -S rspec
require "spec_helper"
diff --git a/spec/unit/puppet/parser/functions/validate_ipv6_address_spec.rb b/spec/functions/validate_ipv6_address_spec.rb
index 1fe5304..a839d90 100644..100755
--- a/spec/unit/puppet/parser/functions/validate_ipv6_address_spec.rb
+++ b/spec/functions/validate_ipv6_address_spec.rb
@@ -1,4 +1,4 @@
-#! /usr/bin/env/ruby -S rspec
+#! /usr/bin/env ruby -S rspec
require "spec_helper"
diff --git a/spec/unit/puppet/parser/functions/validate_re_spec.rb b/spec/functions/validate_re_spec.rb
index d189efb..d29988b 100644..100755
--- a/spec/unit/puppet/parser/functions/validate_re_spec.rb
+++ b/spec/functions/validate_re_spec.rb
@@ -1,3 +1,4 @@
+#! /usr/bin/env ruby -S rspec
require 'spec_helper'
describe Puppet::Parser::Functions.function(:validate_re) do
diff --git a/spec/unit/puppet/parser/functions/validate_slength_spec.rb b/spec/functions/validate_slength_spec.rb
index 851835f..e23f61a 100755
--- a/spec/unit/puppet/parser/functions/validate_slength_spec.rb
+++ b/spec/functions/validate_slength_spec.rb
@@ -6,7 +6,7 @@ describe "the validate_slength function" do
let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
it "should exist" do
- Puppet::Parser::Functions.function("validate_slength").should == "function_validate_slength"
+ expect(Puppet::Parser::Functions.function("validate_slength")).to eq("function_validate_slength")
end
describe "validating the input argument types" do
diff --git a/spec/unit/puppet/parser/functions/validate_string_spec.rb b/spec/functions/validate_string_spec.rb
index 3b4fb3e..3b4fb3e 100644..100755
--- a/spec/unit/puppet/parser/functions/validate_string_spec.rb
+++ b/spec/functions/validate_string_spec.rb
diff --git a/spec/unit/puppet/parser/functions/values_at_spec.rb b/spec/functions/values_at_spec.rb
index 08e95a5..86e3c31 100644..100755
--- a/spec/unit/puppet/parser/functions/values_at_spec.rb
+++ b/spec/functions/values_at_spec.rb
@@ -5,34 +5,34 @@ describe "the values_at function" do
let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
it "should exist" do
- Puppet::Parser::Functions.function("values_at").should == "function_values_at"
+ expect(Puppet::Parser::Functions.function("values_at")).to eq("function_values_at")
end
it "should raise a ParseError if there is less than 1 arguments" do
- lambda { scope.function_values_at([]) }.should( raise_error(Puppet::ParseError))
+ expect { scope.function_values_at([]) }.to( raise_error(Puppet::ParseError))
end
it "should raise a ParseError if you try to use a range where stop is greater then start" do
- lambda { scope.function_values_at([['a','b'],["3-1"]]) }.should( raise_error(Puppet::ParseError))
+ expect { scope.function_values_at([['a','b'],["3-1"]]) }.to( raise_error(Puppet::ParseError))
end
it "should return a value at from an array" do
result = scope.function_values_at([['a','b','c'],"1"])
- result.should(eq(['b']))
+ expect(result).to(eq(['b']))
end
it "should return a value at from an array when passed a range" do
result = scope.function_values_at([['a','b','c'],"0-1"])
- result.should(eq(['a','b']))
+ expect(result).to(eq(['a','b']))
end
it "should return chosen values from an array when passed number of indexes" do
result = scope.function_values_at([['a','b','c'],["0","2"]])
- result.should(eq(['a','c']))
+ expect(result).to(eq(['a','c']))
end
it "should return chosen values from an array when passed ranges and multiple indexes" do
result = scope.function_values_at([['a','b','c','d','e','f','g'],["0","2","4-5"]])
- result.should(eq(['a','c','e','f']))
+ expect(result).to(eq(['a','c','e','f']))
end
end
diff --git a/spec/unit/puppet/parser/functions/values_spec.rb b/spec/functions/values_spec.rb
index 14ae417..08d21b0 100644..100755
--- a/spec/unit/puppet/parser/functions/values_spec.rb
+++ b/spec/functions/values_spec.rb
@@ -5,27 +5,27 @@ describe "the values function" do
let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
it "should exist" do
- Puppet::Parser::Functions.function("values").should == "function_values"
+ expect(Puppet::Parser::Functions.function("values")).to eq("function_values")
end
it "should raise a ParseError if there is less than 1 arguments" do
- lambda { scope.function_values([]) }.should( raise_error(Puppet::ParseError))
+ expect { scope.function_values([]) }.to( raise_error(Puppet::ParseError))
end
it "should return values from a hash" do
result = scope.function_values([{'a'=>'1','b'=>'2','c'=>'3'}])
# =~ is the RSpec::Matchers::MatchArray matcher.
# A.K.A. "array with same elements" (multiset) matching
- result.should =~ %w{ 1 2 3 }
+ expect(result).to match_array(%w{ 1 2 3 })
end
it "should return a multiset" do
result = scope.function_values([{'a'=>'1','b'=>'3','c'=>'3'}])
- result.should =~ %w{ 1 3 3 }
- result.should_not =~ %w{ 1 3 }
+ expect(result).to match_array(%w{ 1 3 3 })
+ expect(result).not_to match_array(%w{ 1 3 })
end
it "should raise a ParseError unless a Hash is provided" do
- lambda { scope.function_values([['a','b','c']]) }.should( raise_error(Puppet::ParseError))
+ expect { scope.function_values([['a','b','c']]) }.to( raise_error(Puppet::ParseError))
end
end
diff --git a/spec/functions/zip_spec.rb b/spec/functions/zip_spec.rb
new file mode 100755
index 0000000..f265fce
--- /dev/null
+++ b/spec/functions/zip_spec.rb
@@ -0,0 +1,31 @@
+#! /usr/bin/env ruby -S rspec
+require 'spec_helper'
+
+describe "the zip function" do
+ let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
+
+ it "should raise a ParseError if there is less than 1 arguments" do
+ expect { scope.function_zip([]) }.to( raise_error(Puppet::ParseError))
+ end
+
+ it "should be able to zip an array" do
+ result = scope.function_zip([['1','2','3'],['4','5','6']])
+ expect(result).to(eq([["1", "4"], ["2", "5"], ["3", "6"]]))
+ result = scope.function_zip([['1','2','3'],['4','5','6'], false])
+ result.should(eq([["1", "4"], ["2", "5"], ["3", "6"]]))
+ end
+
+ it "should be able to zip an array and flatten" do
+ result = scope.function_zip([['1','2','3'],['4','5','6'], true])
+ result.should(eq(["1", "4", "2", "5", "3", "6"]))
+ end
+
+ it "should accept objects which extend String for the second argument" do
+ class AlsoString < String
+ end
+
+ value = AlsoString.new('false')
+ result = scope.function_zip([['1','2','3'],['4','5','6'],value])
+ result.should(eq([["1", "4"], ["2", "5"], ["3", "6"]]))
+ end
+end
diff --git a/spec/lib/puppet_spec/compiler.rb b/spec/lib/puppet_spec/compiler.rb
new file mode 100755
index 0000000..2f0ae4d
--- /dev/null
+++ b/spec/lib/puppet_spec/compiler.rb
@@ -0,0 +1,47 @@
+#! /usr/bin/env ruby -S rspec
+module PuppetSpec::Compiler
+ def compile_to_catalog(string, node = Puppet::Node.new('foonode'))
+ Puppet[:code] = string
+ Puppet::Parser::Compiler.compile(node)
+ end
+
+ def compile_to_ral(manifest)
+ catalog = compile_to_catalog(manifest)
+ ral = catalog.to_ral
+ ral.finalize
+ ral
+ end
+
+ def compile_to_relationship_graph(manifest, prioritizer = Puppet::Graph::SequentialPrioritizer.new)
+ ral = compile_to_ral(manifest)
+ graph = Puppet::Graph::RelationshipGraph.new(prioritizer)
+ graph.populate_from(ral)
+ graph
+ end
+
+ if Puppet.version.to_f >= 3.3
+ def apply_compiled_manifest(manifest, prioritizer = Puppet::Graph::SequentialPrioritizer.new)
+ transaction = Puppet::Transaction.new(compile_to_ral(manifest),
+ Puppet::Transaction::Report.new("apply"),
+ prioritizer)
+ transaction.evaluate
+ transaction.report.finalize_report
+
+ transaction
+ end
+ else
+ def apply_compiled_manifest(manifest)
+ transaction = Puppet::Transaction.new(compile_to_ral(manifest), Puppet::Transaction::Report.new("apply"))
+ transaction.evaluate
+ transaction.report.finalize_report
+
+ transaction
+ end
+ end
+
+ def order_resources_traversed_in(relationships)
+ order_seen = []
+ relationships.traverse { |resource| order_seen << resource.ref }
+ order_seen
+ end
+end
diff --git a/spec/lib/puppet_spec/database.rb b/spec/lib/puppet_spec/database.rb
new file mode 100755
index 0000000..f5c2341
--- /dev/null
+++ b/spec/lib/puppet_spec/database.rb
@@ -0,0 +1,30 @@
+#! /usr/bin/env ruby -S rspec
+# This just makes some nice things available at global scope, and for setup of
+# tests to use a real fake database, rather than a fake stubs-that-don't-work
+# version of the same. Fun times.
+def sqlite?
+ if $sqlite.nil?
+ begin
+ require 'sqlite3'
+ $sqlite = true
+ rescue LoadError
+ $sqlite = false
+ end
+ end
+ $sqlite
+end
+
+def can_use_scratch_database?
+ sqlite? and Puppet.features.rails?
+end
+
+
+# This is expected to be called in your `before :each` block, and will get you
+# ready to roll with a serious database and all. Cleanup is handled
+# automatically for you. Nothing to do there.
+def setup_scratch_database
+ Puppet[:dbadapter] = 'sqlite3'
+ Puppet[:dblocation] = ':memory:'
+ Puppet[:railslog] = PuppetSpec::Files.tmpfile('storeconfigs.log')
+ Puppet::Rails.init
+end
diff --git a/spec/lib/puppet_spec/files.rb b/spec/lib/puppet_spec/files.rb
new file mode 100755
index 0000000..71b38ff
--- /dev/null
+++ b/spec/lib/puppet_spec/files.rb
@@ -0,0 +1,61 @@
+#! /usr/bin/env ruby -S rspec
+require 'fileutils'
+require 'tempfile'
+require 'tmpdir'
+require 'pathname'
+
+# A support module for testing files.
+module PuppetSpec::Files
+ def self.cleanup
+ $global_tempfiles ||= []
+ while path = $global_tempfiles.pop do
+ begin
+ Dir.unstub(:entries)
+ FileUtils.rm_rf path, :secure => true
+ rescue Errno::ENOENT
+ # nothing to do
+ end
+ end
+ end
+
+ def make_absolute(path) PuppetSpec::Files.make_absolute(path) end
+ def self.make_absolute(path)
+ path = File.expand_path(path)
+ path[0] = 'c' if Puppet.features.microsoft_windows?
+ path
+ end
+
+ def tmpfile(name, dir = nil) PuppetSpec::Files.tmpfile(name, dir) end
+ def self.tmpfile(name, dir = nil)
+ # Generate a temporary file, just for the name...
+ source = dir ? Tempfile.new(name, dir) : Tempfile.new(name)
+ path = source.path
+ source.close!
+
+ record_tmp(File.expand_path(path))
+
+ path
+ end
+
+ def file_containing(name, contents) PuppetSpec::Files.file_containing(name, contents) end
+ def self.file_containing(name, contents)
+ file = tmpfile(name)
+ File.open(file, 'wb') { |f| f.write(contents) }
+ file
+ end
+
+ def tmpdir(name) PuppetSpec::Files.tmpdir(name) end
+ def self.tmpdir(name)
+ dir = Dir.mktmpdir(name)
+
+ record_tmp(dir)
+
+ dir
+ end
+
+ def self.record_tmp(tmp)
+ # ...record it for cleanup,
+ $global_tempfiles ||= []
+ $global_tempfiles << tmp
+ end
+end
diff --git a/spec/lib/puppet_spec/fixtures.rb b/spec/lib/puppet_spec/fixtures.rb
new file mode 100755
index 0000000..81e9775
--- /dev/null
+++ b/spec/lib/puppet_spec/fixtures.rb
@@ -0,0 +1,29 @@
+#! /usr/bin/env ruby -S rspec
+module PuppetSpec::Fixtures
+ def fixtures(*rest)
+ File.join(PuppetSpec::FIXTURE_DIR, *rest)
+ end
+ def my_fixture_dir
+ callers = caller
+ while line = callers.shift do
+ next unless found = line.match(%r{/spec/(.*)_spec\.rb:})
+ return fixtures(found[1])
+ end
+ fail "sorry, I couldn't work out your path from the caller stack!"
+ end
+ def my_fixture(name)
+ file = File.join(my_fixture_dir, name)
+ unless File.readable? file then
+ fail Puppet::DevError, "fixture '#{name}' for #{my_fixture_dir} is not readable"
+ end
+ return file
+ end
+ def my_fixtures(glob = '*', flags = 0)
+ files = Dir.glob(File.join(my_fixture_dir, glob), flags)
+ unless files.length > 0 then
+ fail Puppet::DevError, "fixture '#{glob}' for #{my_fixture_dir} had no files!"
+ end
+ block_given? and files.each do |file| yield file end
+ files
+ end
+end
diff --git a/spec/lib/puppet_spec/matchers.rb b/spec/lib/puppet_spec/matchers.rb
new file mode 100755
index 0000000..093d77c
--- /dev/null
+++ b/spec/lib/puppet_spec/matchers.rb
@@ -0,0 +1,121 @@
+#! /usr/bin/env ruby -S rspec
+require 'stringio'
+
+########################################################################
+# Backward compatibility for Jenkins outdated environment.
+module RSpec
+ module Matchers
+ module BlockAliases
+ alias_method :to, :should unless method_defined? :to
+ alias_method :to_not, :should_not unless method_defined? :to_not
+ alias_method :not_to, :should_not unless method_defined? :not_to
+ end
+ end
+end
+
+
+########################################################################
+# Custom matchers...
+RSpec::Matchers.define :have_matching_element do |expected|
+ match do |actual|
+ actual.any? { |item| item =~ expected }
+ end
+end
+
+
+RSpec::Matchers.define :exit_with do |expected|
+ actual = nil
+ match do |block|
+ begin
+ block.call
+ rescue SystemExit => e
+ actual = e.status
+ end
+ actual and actual == expected
+ end
+ failure_message_for_should do |block|
+ "expected exit with code #{expected} but " +
+ (actual.nil? ? " exit was not called" : "we exited with #{actual} instead")
+ end
+ failure_message_for_should_not do |block|
+ "expected that exit would not be called with #{expected}"
+ end
+ description do
+ "expect exit with #{expected}"
+ end
+end
+
+class HavePrintedMatcher
+ attr_accessor :expected, :actual
+
+ def initialize(expected)
+ case expected
+ when String, Regexp
+ @expected = expected
+ else
+ @expected = expected.to_s
+ end
+ end
+
+ def matches?(block)
+ begin
+ $stderr = $stdout = StringIO.new
+ $stdout.set_encoding('UTF-8') if $stdout.respond_to?(:set_encoding)
+ block.call
+ $stdout.rewind
+ @actual = $stdout.read
+ ensure
+ $stdout = STDOUT
+ $stderr = STDERR
+ end
+
+ if @actual then
+ case @expected
+ when String
+ @actual.include? @expected
+ when Regexp
+ @expected.match @actual
+ end
+ else
+ false
+ end
+ end
+
+ def failure_message_for_should
+ if @actual.nil? then
+ "expected #{@expected.inspect}, but nothing was printed"
+ else
+ "expected #{@expected.inspect} to be printed; got:\n#{@actual}"
+ end
+ end
+
+ def failure_message_for_should_not
+ "expected #{@expected.inspect} to not be printed; got:\n#{@actual}"
+ end
+
+ def description
+ "expect #{@expected.inspect} to be printed"
+ end
+end
+
+def have_printed(what)
+ HavePrintedMatcher.new(what)
+end
+
+RSpec::Matchers.define :equal_attributes_of do |expected|
+ match do |actual|
+ actual.instance_variables.all? do |attr|
+ actual.instance_variable_get(attr) == expected.instance_variable_get(attr)
+ end
+ end
+end
+
+RSpec::Matchers.define :be_one_of do |*expected|
+ match do |actual|
+ expected.include? actual
+ end
+
+ failure_message_for_should do |actual|
+ "expected #{actual.inspect} to be one of #{expected.map(&:inspect).join(' or ')}"
+ end
+end
diff --git a/spec/lib/puppet_spec/modules.rb b/spec/lib/puppet_spec/modules.rb
new file mode 100755
index 0000000..910c6d9
--- /dev/null
+++ b/spec/lib/puppet_spec/modules.rb
@@ -0,0 +1,27 @@
+#! /usr/bin/env ruby -S rspec
+module PuppetSpec::Modules
+ class << self
+ def create(name, dir, options = {})
+ module_dir = File.join(dir, name)
+ FileUtils.mkdir_p(module_dir)
+
+ environment = options[:environment]
+
+ if metadata = options[:metadata]
+ metadata[:source] ||= 'github'
+ metadata[:author] ||= 'puppetlabs'
+ metadata[:version] ||= '9.9.9'
+ metadata[:license] ||= 'to kill'
+ metadata[:dependencies] ||= []
+
+ metadata[:name] = "#{metadata[:author]}/#{name}"
+
+ File.open(File.join(module_dir, 'metadata.json'), 'w') do |f|
+ f.write(metadata.to_pson)
+ end
+ end
+
+ Puppet::Module.new(name, module_dir, environment)
+ end
+ end
+end
diff --git a/spec/lib/puppet_spec/pops.rb b/spec/lib/puppet_spec/pops.rb
new file mode 100755
index 0000000..e056a52
--- /dev/null
+++ b/spec/lib/puppet_spec/pops.rb
@@ -0,0 +1,17 @@
+#! /usr/bin/env ruby -S rspec
+module PuppetSpec::Pops
+ extend RSpec::Matchers::DSL
+
+ # Checks if an Acceptor has a specific issue in its list of diagnostics
+ matcher :have_issue do |expected|
+ match do |actual|
+ actual.diagnostics.index { |i| i.issue == expected } != nil
+ end
+ failure_message_for_should do |actual|
+ "expected Acceptor[#{actual.diagnostics.collect { |i| i.issue.issue_code }.join(',')}] to contain issue #{expected.issue_code}"
+ end
+ failure_message_for_should_not do |actual|
+ "expected Acceptor[#{actual.diagnostics.collect { |i| i.issue.issue_code }.join(',')}] to not contain issue #{expected.issue_code}"
+ end
+ end
+end
diff --git a/spec/lib/puppet_spec/scope.rb b/spec/lib/puppet_spec/scope.rb
new file mode 100755
index 0000000..3847ede
--- /dev/null
+++ b/spec/lib/puppet_spec/scope.rb
@@ -0,0 +1,15 @@
+#! /usr/bin/env ruby -S rspec
+
+module PuppetSpec::Scope
+ # Initialize a new scope suitable for testing.
+ #
+ def create_test_scope_for_node(node_name)
+ node = Puppet::Node.new(node_name)
+ compiler = Puppet::Parser::Compiler.new(node)
+ scope = Puppet::Parser::Scope.new(compiler)
+ scope.source = Puppet::Resource::Type.new(:node, node_name)
+ scope.parent = compiler.topscope
+ scope
+ end
+
+end \ No newline at end of file
diff --git a/spec/lib/puppet_spec/settings.rb b/spec/lib/puppet_spec/settings.rb
new file mode 100755
index 0000000..8ddcb97
--- /dev/null
+++ b/spec/lib/puppet_spec/settings.rb
@@ -0,0 +1,16 @@
+#! /usr/bin/env ruby -S rspec
+module PuppetSpec::Settings
+
+ # It would probably be preferable to refactor defaults.rb such that the real definitions of
+ # these settings were available as a variable, which was then accessible for use during tests.
+ # However, I'm not doing that yet because I don't want to introduce any additional moving parts
+ # to this already very large changeset.
+ # Would be nice to clean this up later. --cprice 2012-03-20
+ TEST_APP_DEFAULT_DEFINITIONS = {
+ :name => { :default => "test", :desc => "name" },
+ :logdir => { :type => :directory, :default => "test", :desc => "logdir" },
+ :confdir => { :type => :directory, :default => "test", :desc => "confdir" },
+ :vardir => { :type => :directory, :default => "test", :desc => "vardir" },
+ :rundir => { :type => :directory, :default => "test", :desc => "rundir" },
+ }
+end
diff --git a/spec/lib/puppet_spec/verbose.rb b/spec/lib/puppet_spec/verbose.rb
new file mode 100755
index 0000000..b2683df
--- /dev/null
+++ b/spec/lib/puppet_spec/verbose.rb
@@ -0,0 +1,10 @@
+#! /usr/bin/env ruby -S rspec
+# Support code for running stuff with warnings disabled.
+module Kernel
+ def with_verbose_disabled
+ verbose, $VERBOSE = $VERBOSE, nil
+ result = yield
+ $VERBOSE = verbose
+ return result
+ end
+end
diff --git a/spec/monkey_patches/alias_should_to_must.rb b/spec/monkey_patches/alias_should_to_must.rb
index 1a11117..505e240 100755
--- a/spec/monkey_patches/alias_should_to_must.rb
+++ b/spec/monkey_patches/alias_should_to_must.rb
@@ -1,3 +1,4 @@
+#! /usr/bin/env ruby -S rspec
require 'rspec'
class Object
diff --git a/spec/monkey_patches/publicize_methods.rb b/spec/monkey_patches/publicize_methods.rb
index f3a1abf..3ae59f9 100755
--- a/spec/monkey_patches/publicize_methods.rb
+++ b/spec/monkey_patches/publicize_methods.rb
@@ -1,3 +1,4 @@
+#! /usr/bin/env ruby -S rspec
# Some monkey-patching to allow us to test private methods.
class Class
def publicize_methods(*methods)
diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb
index 931d35c..b490ca3 100644..100755
--- a/spec/spec_helper.rb
+++ b/spec/spec_helper.rb
@@ -1,21 +1,27 @@
+#! /usr/bin/env ruby -S rspec
dir = File.expand_path(File.dirname(__FILE__))
$LOAD_PATH.unshift File.join(dir, 'lib')
-# Don't want puppet getting the command line arguments for rake or autotest
-ARGV.clear
+# So everyone else doesn't have to include this base constant.
+module PuppetSpec
+ FIXTURE_DIR = File.join(dir = File.expand_path(File.dirname(__FILE__)), "fixtures") unless defined?(FIXTURE_DIR)
+end
require 'puppet'
-require 'facter'
-require 'mocha'
-gem 'rspec', '>=2.0.0'
-require 'rspec/expectations'
-
+require 'rspec-puppet'
require 'puppetlabs_spec_helper/module_spec_helper'
+require 'puppet_spec/verbose'
+require 'puppet_spec/files'
+require 'puppet_spec/settings'
+require 'puppet_spec/fixtures'
+require 'puppet_spec/matchers'
+require 'puppet_spec/database'
+require 'monkey_patches/alias_should_to_must'
+require 'mocha/setup'
+
+
RSpec.configure do |config|
- # FIXME REVISIT - We may want to delegate to Facter like we do in
- # Puppet::PuppetSpecInitializer.initialize_via_testhelper(config) because
- # this behavior is a duplication of the spec_helper in Facter.
config.before :each do
# Ensure that we don't accidentally cache facts and environment between
# test cases. This requires each example group to explicitly load the
diff --git a/spec/spec_helper_acceptance.rb b/spec/spec_helper_acceptance.rb
new file mode 100755
index 0000000..3203ce9
--- /dev/null
+++ b/spec/spec_helper_acceptance.rb
@@ -0,0 +1,50 @@
+#! /usr/bin/env ruby -S rspec
+require 'beaker-rspec'
+
+UNSUPPORTED_PLATFORMS = []
+
+unless ENV['RS_PROVISION'] == 'no' or ENV['BEAKER_provision'] == 'no'
+ foss_opts = {
+ :default_action => 'gem_install',
+ :version => (ENV['PUPPET_VERSION'] ? ENV['PUPPET_VERSION'] : '3.7.2'),
+ }
+
+ if default.is_pe?; then install_pe; else install_puppet( foss_opts ); end
+
+ hosts.each do |host|
+ if host['platform'] !~ /windows/i
+ if host.is_pe?
+ on host, 'mkdir -p /etc/puppetlabs/facter/facts.d'
+ else
+ on host, "/bin/touch #{host['puppetpath']}/hiera.yaml"
+ on host, "mkdir -p #{host['distmoduledir']}"
+ on host, 'mkdir -p /etc/facter/facts.d'
+ end
+ end
+ end
+end
+
+RSpec.configure do |c|
+ # Project root
+ proj_root = File.expand_path(File.join(File.dirname(__FILE__), '..'))
+
+ # Readable test descriptions
+ c.formatter = :documentation
+
+ # Configure all nodes in nodeset
+ c.before :suite do
+ if ENV['FUTURE_PARSER'] == 'true'
+ default[:default_apply_opts] ||= {}
+ default[:default_apply_opts].merge!({:parser => 'future'})
+ end
+
+ copy_root_module_to(default, :source => proj_root, :module_name => 'stdlib')
+ end
+end
+
+def is_future_parser_enabled?
+ if default[:default_apply_opts]
+ return default[:default_apply_opts][:parser] == 'future'
+ end
+ return false
+end
diff --git a/spec/unit/facter/facter_dot_d_spec.rb b/spec/unit/facter/facter_dot_d_spec.rb
new file mode 100755
index 0000000..0afadb2
--- /dev/null
+++ b/spec/unit/facter/facter_dot_d_spec.rb
@@ -0,0 +1,32 @@
+#! /usr/bin/env ruby -S rspec
+require 'spec_helper'
+require 'facter/facter_dot_d'
+
+describe Facter::Util::DotD do
+
+ context 'returns a simple fact' do
+ before :each do
+ Facter.stubs(:version).returns('1.6.1')
+ subject.stubs(:entries).returns(['/etc/facter/facts.d/fake_fact.txt'])
+ File.stubs(:readlines).with('/etc/facter/facts.d/fake_fact.txt').returns(['fake_fact=fake fact'])
+ subject.create
+ end
+
+ it 'should return successfully' do
+ expect(Facter.fact(:fake_fact).value).to eq('fake fact')
+ end
+ end
+
+ context 'returns a fact with equals signs' do
+ before :each do
+ Facter.stubs(:version).returns('1.6.1')
+ subject.stubs(:entries).returns(['/etc/facter/facts.d/foo.txt'])
+ File.stubs(:readlines).with('/etc/facter/facts.d/foo.txt').returns(['foo=1+1=2'])
+ subject.create
+ end
+
+ it 'should return successfully' do
+ expect(Facter.fact(:foo).value).to eq('1+1=2')
+ end
+ end
+end
diff --git a/spec/unit/facter/pe_required_facts_spec.rb b/spec/unit/facter/pe_required_facts_spec.rb
deleted file mode 100644
index f219b37..0000000
--- a/spec/unit/facter/pe_required_facts_spec.rb
+++ /dev/null
@@ -1,69 +0,0 @@
-# Puppet Enterprise requires the following facts to be set in order to operate.
-# These facts are set using the file ???? and the two facts are
-# `fact_stomp_port`, and `fact_stomp_server`.
-#
-
-require 'spec_helper'
-
-describe "External facts in /etc/puppetlabs/facter/facts.d/puppet_enterprise_installer.txt" do
- context "With Facter 1.6.17 which does not have external facts support" do
- before :each do
- Facter.stubs(:version).returns("1.6.17")
- # Stub out the filesystem for stdlib
- Dir.stubs(:entries).with("/etc/puppetlabs/facter/facts.d").
- returns(['puppet_enterprise_installer.txt'])
- Dir.stubs(:entries).with("/etc/facter/facts.d").returns([])
- File.stubs(:readlines).with('/etc/puppetlabs/facter/facts.d/puppet_enterprise_installer.txt').
- returns([
- "fact_stomp_port=61613\n",
- "fact_stomp_server=puppetmaster.acme.com\n",
- "fact_is_puppetagent=true\n",
- "fact_is_puppetmaster=false\n",
- "fact_is_puppetca=false\n",
- "fact_is_puppetconsole=false\n",
- ])
- if Facter.collection.respond_to? :load
- Facter.collection.load(:facter_dot_d)
- else
- Facter.collection.loader.load(:facter_dot_d)
- end
- end
-
- it 'defines fact_stomp_port' do
- Facter.fact(:fact_stomp_port).value.should == '61613'
- end
- it 'defines fact_stomp_server' do
- Facter.fact(:fact_stomp_server).value.should == 'puppetmaster.acme.com'
- end
- it 'defines fact_is_puppetagent' do
- Facter.fact(:fact_is_puppetagent).value.should == 'true'
- end
- it 'defines fact_is_puppetmaster' do
- Facter.fact(:fact_is_puppetmaster).value.should == 'false'
- end
- it 'defines fact_is_puppetca' do
- Facter.fact(:fact_is_puppetca).value.should == 'false'
- end
- it 'defines fact_is_puppetconsole' do
- Facter.fact(:fact_is_puppetconsole).value.should == 'false'
- end
- end
-
- [ '1.7.1', '2.0.1' ].each do |v|
- context "With Facter #{v} which has external facts support" do
- before :each do
- Facter.stubs(:version).returns(v)
- end
-
- it 'does not call Facter::Util::DotD.new' do
- Facter::Util::DotD.expects(:new).never
-
- if Facter.collection.respond_to? :load
- Facter.collection.load(:facter_dot_d)
- else
- Facter.collection.loader.load(:facter_dot_d)
- end
- end
- end
- end
-end
diff --git a/spec/unit/facter/pe_version_spec.rb b/spec/unit/facter/pe_version_spec.rb
index 931c6d4..4d0349e 100644..100755
--- a/spec/unit/facter/pe_version_spec.rb
+++ b/spec/unit/facter/pe_version_spec.rb
@@ -26,23 +26,23 @@ describe "PE Version specs" do
(major,minor,patch) = version.split(".")
it "Should return true" do
- Facter.fact(:is_pe).value.should == true
+ expect(Facter.fact(:is_pe).value).to eq(true)
end
it "Should have a version of #{version}" do
- Facter.fact(:pe_version).value.should == version
+ expect(Facter.fact(:pe_version).value).to eq(version)
end
it "Should have a major version of #{major}" do
- Facter.fact(:pe_major_version).value.should == major
+ expect(Facter.fact(:pe_major_version).value).to eq(major)
end
it "Should have a minor version of #{minor}" do
- Facter.fact(:pe_minor_version).value.should == minor
+ expect(Facter.fact(:pe_minor_version).value).to eq(minor)
end
it "Should have a patch version of #{patch}" do
- Facter.fact(:pe_patch_version).value.should == patch
+ expect(Facter.fact(:pe_patch_version).value).to eq(patch)
end
end
end
@@ -54,23 +54,23 @@ describe "PE Version specs" do
end
it "is_pe is false" do
- Facter.fact(:is_pe).value.should == false
+ expect(Facter.fact(:is_pe).value).to eq(false)
end
it "pe_version is nil" do
- Facter.fact(:pe_version).value.should be_nil
+ expect(Facter.fact(:pe_version).value).to be_nil
end
it "pe_major_version is nil" do
- Facter.fact(:pe_major_version).value.should be_nil
+ expect(Facter.fact(:pe_major_version).value).to be_nil
end
it "pe_minor_version is nil" do
- Facter.fact(:pe_minor_version).value.should be_nil
+ expect(Facter.fact(:pe_minor_version).value).to be_nil
end
it "Should have a patch version" do
- Facter.fact(:pe_patch_version).value.should be_nil
+ expect(Facter.fact(:pe_patch_version).value).to be_nil
end
end
end
diff --git a/spec/unit/facter/root_home_spec.rb b/spec/unit/facter/root_home_spec.rb
index ce80684..98fe141 100644..100755
--- a/spec/unit/facter/root_home_spec.rb
+++ b/spec/unit/facter/root_home_spec.rb
@@ -1,3 +1,4 @@
+#! /usr/bin/env ruby -S rspec
require 'spec_helper'
require 'facter/root_home'
@@ -8,7 +9,7 @@ describe Facter::Util::RootHome do
it "should return /" do
Facter::Util::Resolution.expects(:exec).with("getent passwd root").returns(root_ent)
- Facter::Util::RootHome.get_root_home.should == expected_root_home
+ expect(Facter::Util::RootHome.get_root_home).to eq(expected_root_home)
end
end
context "linux" do
@@ -17,16 +18,7 @@ describe Facter::Util::RootHome do
it "should return /root" do
Facter::Util::Resolution.expects(:exec).with("getent passwd root").returns(root_ent)
- Facter::Util::RootHome.get_root_home.should == expected_root_home
- end
- end
- context "macosx" do
- let(:root_ent) { "root:*:0:0:System Administrator:/var/root:/bin/sh" }
- let(:expected_root_home) { "/var/root" }
-
- it "should return /var/root" do
- Facter::Util::Resolution.expects(:exec).with("getent passwd root").returns(root_ent)
- Facter::Util::RootHome.get_root_home.should == expected_root_home
+ expect(Facter::Util::RootHome.get_root_home).to eq(expected_root_home)
end
end
context "windows" do
@@ -34,7 +26,27 @@ describe Facter::Util::RootHome do
Facter::Util::Resolution.expects(:exec).with("getent passwd root").returns(nil)
end
it "should be nil on windows" do
- Facter::Util::RootHome.get_root_home.should be_nil
+ expect(Facter::Util::RootHome.get_root_home).to be_nil
+ end
+ end
+end
+
+describe 'root_home', :type => :fact do
+ before { Facter.clear }
+ after { Facter.clear }
+
+ context "macosx" do
+ before do
+ Facter.fact(:kernel).stubs(:value).returns("Darwin")
+ Facter.fact(:osfamily).stubs(:value).returns("Darwin")
+ end
+ let(:expected_root_home) { "/var/root" }
+ sample_dscacheutil = File.read(fixtures('dscacheutil','root'))
+
+ it "should return /var/root" do
+ Facter::Util::Resolution.stubs(:exec).with("dscacheutil -q user -a name root").returns(sample_dscacheutil)
+ expect(Facter.fact(:root_home).value).to eq(expected_root_home)
end
end
+
end
diff --git a/spec/unit/facter/util/puppet_settings_spec.rb b/spec/unit/facter/util/puppet_settings_spec.rb
index c3ce6ea..c06137d 100644..100755
--- a/spec/unit/facter/util/puppet_settings_spec.rb
+++ b/spec/unit/facter/util/puppet_settings_spec.rb
@@ -1,3 +1,4 @@
+#! /usr/bin/env ruby -S rspec
require 'spec_helper'
require 'facter/util/puppet_settings'
@@ -10,11 +11,11 @@ describe Facter::Util::PuppetSettings do
end
it 'should be nil' do
- subject.with_puppet { Puppet[:vardir] }.should be_nil
+ expect(subject.with_puppet { Puppet[:vardir] }).to be_nil
end
it 'should not yield to the block' do
Puppet.expects(:[]).never
- subject.with_puppet { Puppet[:vardir] }.should be_nil
+ expect(subject.with_puppet { Puppet[:vardir] }).to be_nil
end
end
context "With Puppet loaded" do
@@ -28,7 +29,7 @@ describe Facter::Util::PuppetSettings do
subject.with_puppet { Puppet[:vardir] }
end
it 'should return the nodes vardir' do
- subject.with_puppet { Puppet[:vardir] }.should eq vardir
+ expect(subject.with_puppet { Puppet[:vardir] }).to eq vardir
end
end
end
diff --git a/spec/unit/puppet/functions/type_of_spec.rb b/spec/unit/puppet/functions/type_of_spec.rb
new file mode 100644
index 0000000..8afb624
--- /dev/null
+++ b/spec/unit/puppet/functions/type_of_spec.rb
@@ -0,0 +1,33 @@
+#! /usr/bin/env ruby -S rspec
+
+require 'spec_helper'
+
+if ENV["FUTURE_PARSER"] == 'yes' or Puppet.version >= "4"
+ require 'puppet/pops'
+ require 'puppet/loaders'
+
+ describe 'the type_of function' do
+ before(:all) do
+ loaders = Puppet::Pops::Loaders.new(Puppet::Node::Environment.create(:testing, [File.join(fixtures, "modules")]))
+ Puppet.push_context({:loaders => loaders}, "test-examples")
+ end
+
+ after(:all) do
+ Puppet::Pops::Loaders.clear
+ Puppet::pop_context()
+ end
+
+ let(:func) do
+ # Load the function from the environment modulepath's modules (ie, fixtures)
+ Puppet.lookup(:loaders).private_environment_loader.load(:function, 'type_of')
+ end
+
+ it 'gives the type of a string' do
+ expect(func.call({}, 'hello world')).to be_kind_of(Puppet::Pops::Types::PStringType)
+ end
+
+ it 'gives the type of an integer' do
+ expect(func.call({}, 5)).to be_kind_of(Puppet::Pops::Types::PIntegerType)
+ end
+ end
+end
diff --git a/spec/unit/puppet/parser/functions/basename_spec.rb b/spec/unit/puppet/parser/functions/basename_spec.rb
new file mode 100755
index 0000000..8a2d0dc
--- /dev/null
+++ b/spec/unit/puppet/parser/functions/basename_spec.rb
@@ -0,0 +1,46 @@
+#! /usr/bin/env ruby -S rspec
+require 'spec_helper'
+
+describe "the basename function" do
+ let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
+
+ it "should exist" do
+ Puppet::Parser::Functions.function("basename").should == "function_basename"
+ end
+
+ it "should raise a ParseError if there is less than 1 argument" do
+ lambda { scope.function_basename([]) }.should( raise_error(Puppet::ParseError))
+ end
+
+ it "should raise a ParseError if there are more than 2 arguments" do
+ lambda { scope.function_basename(['a', 'b', 'c']) }.should( raise_error(Puppet::ParseError))
+ end
+
+ it "should return basename for an absolute path" do
+ result = scope.function_basename(['/path/to/a/file.ext'])
+ result.should(eq('file.ext'))
+ end
+
+ it "should return basename for a relative path" do
+ result = scope.function_basename(['path/to/a/file.ext'])
+ result.should(eq('file.ext'))
+ end
+
+ it "should strip extention when extension specified (absolute path)" do
+ result = scope.function_basename(['/path/to/a/file.ext', '.ext'])
+ result.should(eq('file'))
+ end
+
+ it "should strip extention when extension specified (relative path)" do
+ result = scope.function_basename(['path/to/a/file.ext', '.ext'])
+ result.should(eq('file'))
+ end
+
+ it "should complain about non-string first argument" do
+ lambda { scope.function_basename([[]]) }.should( raise_error(Puppet::ParseError))
+ end
+
+ it "should complain about non-string second argument" do
+ lambda { scope.function_basename(['/path/to/a/file.ext', []]) }.should( raise_error(Puppet::ParseError))
+ end
+end
diff --git a/spec/unit/puppet/parser/functions/bool2num_spec.rb b/spec/unit/puppet/parser/functions/bool2num_spec.rb
deleted file mode 100755
index 518ac85..0000000
--- a/spec/unit/puppet/parser/functions/bool2num_spec.rb
+++ /dev/null
@@ -1,24 +0,0 @@
-#! /usr/bin/env ruby -S rspec
-require 'spec_helper'
-
-describe "the bool2num function" do
- let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
-
- it "should exist" do
- Puppet::Parser::Functions.function("bool2num").should == "function_bool2num"
- end
-
- it "should raise a ParseError if there is less than 1 arguments" do
- lambda { scope.function_bool2num([]) }.should( raise_error(Puppet::ParseError))
- end
-
- it "should convert true to 1" do
- result = scope.function_bool2num([true])
- result.should(eq(1))
- end
-
- it "should convert false to 0" do
- result = scope.function_bool2num([false])
- result.should(eq(0))
- end
-end
diff --git a/spec/unit/puppet/parser/functions/bool2str_spec.rb b/spec/unit/puppet/parser/functions/bool2str_spec.rb
new file mode 100755
index 0000000..b878891
--- /dev/null
+++ b/spec/unit/puppet/parser/functions/bool2str_spec.rb
@@ -0,0 +1,46 @@
+#! /usr/bin/env ruby -S rspec
+require 'spec_helper'
+
+describe "the bool2str function" do
+ let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
+
+ it "should exist" do
+ expect(Puppet::Parser::Functions.function("bool2str")).to eq("function_bool2str")
+ end
+
+ it "should raise a ParseError if there is less than 1 arguments" do
+ expect { scope.function_bool2str([]) }.to( raise_error(Puppet::ParseError))
+ end
+
+ it "should convert true to 'true'" do
+ result = scope.function_bool2str([true])
+ expect(result).to(eq('true'))
+ end
+
+ it "should convert true to a string" do
+ result = scope.function_bool2str([true])
+ expect(result.class).to(eq(String))
+ end
+
+ it "should convert false to 'false'" do
+ result = scope.function_bool2str([false])
+ expect(result).to(eq('false'))
+ end
+
+ it "should convert false to a string" do
+ result = scope.function_bool2str([false])
+ expect(result.class).to(eq(String))
+ end
+
+ it "should not accept a string" do
+ expect { scope.function_bool2str(["false"]) }.to( raise_error(Puppet::ParseError))
+ end
+
+ it "should not accept a nil value" do
+ expect { scope.function_bool2str([nil]) }.to( raise_error(Puppet::ParseError))
+ end
+
+ it "should not accept an undef" do
+ expect { scope.function_bool2str([:undef]) }.to( raise_error(Puppet::ParseError))
+ end
+end
diff --git a/spec/unit/puppet/parser/functions/camelcase_spec.rb b/spec/unit/puppet/parser/functions/camelcase_spec.rb
new file mode 100755
index 0000000..70382ad
--- /dev/null
+++ b/spec/unit/puppet/parser/functions/camelcase_spec.rb
@@ -0,0 +1,24 @@
+#! /usr/bin/env ruby -S rspec
+require 'spec_helper'
+
+describe "the camelcase function" do
+ let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
+
+ it "should exist" do
+ expect(Puppet::Parser::Functions.function("camelcase")).to eq("function_camelcase")
+ end
+
+ it "should raise a ParseError if there is less than 1 arguments" do
+ expect { scope.function_camelcase([]) }.to( raise_error(Puppet::ParseError))
+ end
+
+ it "should capitalize the beginning of a normal string" do
+ result = scope.function_camelcase(["abc"])
+ expect(result).to(eq("Abc"))
+ end
+
+ it "should camelcase an underscore-delimited string" do
+ result = scope.function_camelcase(["aa_bb_cc"])
+ expect(result).to(eq("AaBbCc"))
+ end
+end
diff --git a/spec/unit/puppet/parser/functions/capitalize_spec.rb b/spec/unit/puppet/parser/functions/capitalize_spec.rb
deleted file mode 100755
index 69c9758..0000000
--- a/spec/unit/puppet/parser/functions/capitalize_spec.rb
+++ /dev/null
@@ -1,19 +0,0 @@
-#! /usr/bin/env ruby -S rspec
-require 'spec_helper'
-
-describe "the capitalize function" do
- let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
-
- it "should exist" do
- Puppet::Parser::Functions.function("capitalize").should == "function_capitalize"
- end
-
- it "should raise a ParseError if there is less than 1 arguments" do
- lambda { scope.function_capitalize([]) }.should( raise_error(Puppet::ParseError))
- end
-
- it "should capitalize the beginning of a string" do
- result = scope.function_capitalize(["abc"])
- result.should(eq("Abc"))
- end
-end
diff --git a/spec/unit/puppet/parser/functions/chop_spec.rb b/spec/unit/puppet/parser/functions/chop_spec.rb
deleted file mode 100755
index 9e466de..0000000
--- a/spec/unit/puppet/parser/functions/chop_spec.rb
+++ /dev/null
@@ -1,19 +0,0 @@
-#! /usr/bin/env ruby -S rspec
-require 'spec_helper'
-
-describe "the chop function" do
- let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
-
- it "should exist" do
- Puppet::Parser::Functions.function("chop").should == "function_chop"
- end
-
- it "should raise a ParseError if there is less than 1 arguments" do
- lambda { scope.function_chop([]) }.should( raise_error(Puppet::ParseError))
- end
-
- it "should chop the end of a string" do
- result = scope.function_chop(["asdf\n"])
- result.should(eq("asdf"))
- end
-end
diff --git a/spec/unit/puppet/parser/functions/concat_spec.rb b/spec/unit/puppet/parser/functions/concat_spec.rb
deleted file mode 100644
index 123188b..0000000
--- a/spec/unit/puppet/parser/functions/concat_spec.rb
+++ /dev/null
@@ -1,15 +0,0 @@
-#! /usr/bin/env ruby -S rspec
-require 'spec_helper'
-
-describe "the concat function" do
- let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
-
- it "should raise a ParseError if there is less than 1 arguments" do
- lambda { scope.function_concat([]) }.should( raise_error(Puppet::ParseError))
- end
-
- it "should be able to concat an array" do
- result = scope.function_concat([['1','2','3'],['4','5','6']])
- result.should(eq(['1','2','3','4','5','6']))
- end
-end
diff --git a/spec/unit/puppet/parser/functions/delete_at_spec.rb b/spec/unit/puppet/parser/functions/delete_at_spec.rb
deleted file mode 100755
index d8d9618..0000000
--- a/spec/unit/puppet/parser/functions/delete_at_spec.rb
+++ /dev/null
@@ -1,19 +0,0 @@
-#! /usr/bin/env ruby -S rspec
-require 'spec_helper'
-
-describe "the delete_at function" do
- let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
-
- it "should exist" do
- Puppet::Parser::Functions.function("delete_at").should == "function_delete_at"
- end
-
- it "should raise a ParseError if there is less than 1 arguments" do
- lambda { scope.function_delete_at([]) }.should( raise_error(Puppet::ParseError))
- end
-
- it "should delete an item at specified location from an array" do
- result = scope.function_delete_at([['a','b','c'],1])
- result.should(eq(['a','c']))
- end
-end
diff --git a/spec/unit/puppet/parser/functions/delete_spec.rb b/spec/unit/puppet/parser/functions/delete_spec.rb
deleted file mode 100755
index 2f29c93..0000000
--- a/spec/unit/puppet/parser/functions/delete_spec.rb
+++ /dev/null
@@ -1,38 +0,0 @@
-#! /usr/bin/env ruby -S rspec
-require 'spec_helper'
-
-describe "the delete function" do
- let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
-
- it "should exist" do
- Puppet::Parser::Functions.function("delete").should == "function_delete"
- end
-
- it "should raise a ParseError if there are fewer than 2 arguments" do
- lambda { scope.function_delete([]) }.should( raise_error(Puppet::ParseError))
- end
-
- it "should raise a ParseError if there are greater than 2 arguments" do
- lambda { scope.function_delete([[], 'foo', 'bar']) }.should( raise_error(Puppet::ParseError))
- end
-
- it "should raise a TypeError if a number is passed as the first argument" do
- lambda { scope.function_delete([1, 'bar']) }.should( raise_error(TypeError))
- end
-
- it "should delete all instances of an element from an array" do
- result = scope.function_delete([['a','b','c','b'],'b'])
- result.should(eq(['a','c']))
- end
-
- it "should delete all instances of a substring from a string" do
- result = scope.function_delete(['foobarbabarz','bar'])
- result.should(eq('foobaz'))
- end
-
- it "should delete a key from a hash" do
- result = scope.function_delete([{ 'a' => 1, 'b' => 2, 'c' => 3 },'b'])
- result.should(eq({ 'a' => 1, 'c' => 3 }))
- end
-
-end
diff --git a/spec/unit/puppet/parser/functions/delete_undef_values_spec.rb b/spec/unit/puppet/parser/functions/delete_undef_values_spec.rb
deleted file mode 100644
index 0536641..0000000
--- a/spec/unit/puppet/parser/functions/delete_undef_values_spec.rb
+++ /dev/null
@@ -1,29 +0,0 @@
-#! /usr/bin/env ruby -S rspec
-require 'spec_helper'
-
-describe "the delete_undef_values function" do
- let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
-
- it "should exist" do
- Puppet::Parser::Functions.function("delete_undef_values").should == "function_delete_undef_values"
- end
-
- it "should raise a ParseError if there is less than 1 argument" do
- lambda { scope.function_delete_undef_values([]) }.should( raise_error(Puppet::ParseError))
- end
-
- it "should raise a ParseError if the argument is not Array nor Hash" do
- lambda { scope.function_delete_undef_values(['']) }.should( raise_error(Puppet::ParseError))
- lambda { scope.function_delete_undef_values([nil]) }.should( raise_error(Puppet::ParseError))
- end
-
- it "should delete all undef items from Array and only these" do
- result = scope.function_delete_undef_values([['a',:undef,'c','undef']])
- result.should(eq(['a','c','undef']))
- end
-
- it "should delete all undef items from Hash and only these" do
- result = scope.function_delete_undef_values([{'a'=>'A','b'=>:undef,'c'=>'C','d'=>'undef'}])
- result.should(eq({'a'=>'A','c'=>'C','d'=>'undef'}))
- end
-end
diff --git a/spec/unit/puppet/parser/functions/delete_values_spec.rb b/spec/unit/puppet/parser/functions/delete_values_spec.rb
deleted file mode 100644
index e15c366..0000000
--- a/spec/unit/puppet/parser/functions/delete_values_spec.rb
+++ /dev/null
@@ -1,30 +0,0 @@
-#! /usr/bin/env ruby -S rspec
-require 'spec_helper'
-
-describe "the delete_values function" do
- let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
-
- it "should exist" do
- Puppet::Parser::Functions.function("delete_values").should == "function_delete_values"
- end
-
- it "should raise a ParseError if there are fewer than 2 arguments" do
- lambda { scope.function_delete_values([]) }.should( raise_error(Puppet::ParseError))
- end
-
- it "should raise a ParseError if there are greater than 2 arguments" do
- lambda { scope.function_delete([[], 'foo', 'bar']) }.should( raise_error(Puppet::ParseError))
- end
-
- it "should raise a TypeError if the argument is not a hash" do
- lambda { scope.function_delete_values([1,'bar']) }.should( raise_error(TypeError))
- lambda { scope.function_delete_values(['foo','bar']) }.should( raise_error(TypeError))
- lambda { scope.function_delete_values([[],'bar']) }.should( raise_error(TypeError))
- end
-
- it "should delete all instances of a value from a hash" do
- result = scope.function_delete_values([{ 'a'=>'A', 'b'=>'B', 'B'=>'C', 'd'=>'B' },'B'])
- result.should(eq({ 'a'=>'A', 'B'=>'C' }))
- end
-
-end
diff --git a/spec/unit/puppet/parser/functions/is_integer_spec.rb b/spec/unit/puppet/parser/functions/is_integer_spec.rb
deleted file mode 100644
index 4335795..0000000
--- a/spec/unit/puppet/parser/functions/is_integer_spec.rb
+++ /dev/null
@@ -1,34 +0,0 @@
-#! /usr/bin/env ruby -S rspec
-require 'spec_helper'
-
-describe "the is_integer function" do
- let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
-
- it "should exist" do
- Puppet::Parser::Functions.function("is_integer").should == "function_is_integer"
- end
-
- it "should raise a ParseError if there is less than 1 arguments" do
- lambda { scope.function_is_integer([]) }.should( raise_error(Puppet::ParseError))
- end
-
- it "should return true if an integer" do
- result = scope.function_is_integer(["3"])
- result.should(eq(true))
- end
-
- it "should return false if a float" do
- result = scope.function_is_integer(["3.2"])
- result.should(eq(false))
- end
-
- it "should return false if a string" do
- result = scope.function_is_integer(["asdf"])
- result.should(eq(false))
- end
-
- it "should return true if an integer is created from an arithmetical operation" do
- result = scope.function_is_integer([3*2])
- result.should(eq(true))
- end
-end
diff --git a/spec/unit/puppet/parser/functions/is_numeric_spec.rb b/spec/unit/puppet/parser/functions/is_numeric_spec.rb
deleted file mode 100644
index d7440fb..0000000
--- a/spec/unit/puppet/parser/functions/is_numeric_spec.rb
+++ /dev/null
@@ -1,39 +0,0 @@
-#! /usr/bin/env ruby -S rspec
-require 'spec_helper'
-
-describe "the is_numeric function" do
- let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
-
- it "should exist" do
- Puppet::Parser::Functions.function("is_numeric").should == "function_is_numeric"
- end
-
- it "should raise a ParseError if there is less than 1 argument" do
- lambda { scope.function_is_numeric([]) }.should( raise_error(Puppet::ParseError))
- end
-
- it "should return true if an integer" do
- result = scope.function_is_numeric(["3"])
- result.should(eq(true))
- end
-
- it "should return true if a float" do
- result = scope.function_is_numeric(["3.2"])
- result.should(eq(true))
- end
-
- it "should return true if an integer is created from an arithmetical operation" do
- result = scope.function_is_numeric([3*2])
- result.should(eq(true))
- end
-
- it "should return true if a float is created from an arithmetical operation" do
- result = scope.function_is_numeric([3.2*2])
- result.should(eq(true))
- end
-
- it "should return false if a string" do
- result = scope.function_is_numeric(["asdf"])
- result.should(eq(false))
- end
-end
diff --git a/spec/unit/puppet/parser/functions/lstrip_spec.rb b/spec/unit/puppet/parser/functions/lstrip_spec.rb
deleted file mode 100644
index b280ae7..0000000
--- a/spec/unit/puppet/parser/functions/lstrip_spec.rb
+++ /dev/null
@@ -1,19 +0,0 @@
-#! /usr/bin/env ruby -S rspec
-require 'spec_helper'
-
-describe "the lstrip function" do
- let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
-
- it "should exist" do
- Puppet::Parser::Functions.function("lstrip").should == "function_lstrip"
- end
-
- it "should raise a ParseError if there is less than 1 arguments" do
- lambda { scope.function_lstrip([]) }.should( raise_error(Puppet::ParseError))
- end
-
- it "should lstrip a string" do
- result = scope.function_lstrip([" asdf"])
- result.should(eq('asdf'))
- end
-end
diff --git a/spec/unit/puppet/parser/functions/member_spec.rb b/spec/unit/puppet/parser/functions/member_spec.rb
deleted file mode 100644
index 6e9a023..0000000
--- a/spec/unit/puppet/parser/functions/member_spec.rb
+++ /dev/null
@@ -1,24 +0,0 @@
-#! /usr/bin/env ruby -S rspec
-require 'spec_helper'
-
-describe "the member function" do
- let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
-
- it "should exist" do
- Puppet::Parser::Functions.function("member").should == "function_member"
- end
-
- it "should raise a ParseError if there is less than 1 arguments" do
- lambda { scope.function_member([]) }.should( raise_error(Puppet::ParseError))
- end
-
- it "should return true if a member is in an array" do
- result = scope.function_member([["a","b","c"], "a"])
- result.should(eq(true))
- end
-
- it "should return false if a member is not in an array" do
- result = scope.function_member([["a","b","c"], "d"])
- result.should(eq(false))
- end
-end
diff --git a/spec/unit/puppet/parser/functions/pick_spec.rb b/spec/unit/puppet/parser/functions/pick_spec.rb
deleted file mode 100644
index 761db6b..0000000
--- a/spec/unit/puppet/parser/functions/pick_spec.rb
+++ /dev/null
@@ -1,34 +0,0 @@
-#!/usr/bin/env ruby -S rspec
-require 'spec_helper'
-
-describe "the pick function" do
- let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
-
- it "should exist" do
- Puppet::Parser::Functions.function("pick").should == "function_pick"
- end
-
- it 'should return the correct value' do
- scope.function_pick(['first', 'second']).should == 'first'
- end
-
- it 'should return the correct value if the first value is empty' do
- scope.function_pick(['', 'second']).should == 'second'
- end
-
- it 'should remove empty string values' do
- scope.function_pick(['', 'first']).should == 'first'
- end
-
- it 'should remove :undef values' do
- scope.function_pick([:undef, 'first']).should == 'first'
- end
-
- it 'should remove :undefined values' do
- scope.function_pick([:undefined, 'first']).should == 'first'
- end
-
- it 'should error if no values are passed' do
- expect { scope.function_pick([]) }.to raise_error(Puppet::Error, /Must provide non empty value./)
- end
-end
diff --git a/spec/unit/puppet/parser/functions/prefix_spec.rb b/spec/unit/puppet/parser/functions/prefix_spec.rb
deleted file mode 100644
index 5cf592b..0000000
--- a/spec/unit/puppet/parser/functions/prefix_spec.rb
+++ /dev/null
@@ -1,19 +0,0 @@
-#! /usr/bin/env ruby -S rspec
-require 'spec_helper'
-
-describe "the prefix function" do
- let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
-
- it "should exist" do
- Puppet::Parser::Functions.function("prefix").should == "function_prefix"
- end
-
- it "should raise a ParseError if there is less than 1 arguments" do
- lambda { scope.function_prefix([]) }.should( raise_error(Puppet::ParseError))
- end
-
- it "should return a prefixed array" do
- result = scope.function_prefix([['a','b','c'], 'p'])
- result.should(eq(['pa','pb','pc']))
- end
-end
diff --git a/spec/unit/puppet/parser/functions/reverse_spec.rb b/spec/unit/puppet/parser/functions/reverse_spec.rb
deleted file mode 100644
index 1b59206..0000000
--- a/spec/unit/puppet/parser/functions/reverse_spec.rb
+++ /dev/null
@@ -1,19 +0,0 @@
-#! /usr/bin/env ruby -S rspec
-require 'spec_helper'
-
-describe "the reverse function" do
- let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
-
- it "should exist" do
- Puppet::Parser::Functions.function("reverse").should == "function_reverse"
- end
-
- it "should raise a ParseError if there is less than 1 arguments" do
- lambda { scope.function_reverse([]) }.should( raise_error(Puppet::ParseError))
- end
-
- it "should reverse a string" do
- result = scope.function_reverse(["asdfghijkl"])
- result.should(eq('lkjihgfdsa'))
- end
-end
diff --git a/spec/unit/puppet/parser/functions/strip_spec.rb b/spec/unit/puppet/parser/functions/strip_spec.rb
deleted file mode 100644
index fccdd26..0000000
--- a/spec/unit/puppet/parser/functions/strip_spec.rb
+++ /dev/null
@@ -1,18 +0,0 @@
-#! /usr/bin/env ruby -S rspec
-require 'spec_helper'
-
-describe "the strip function" do
- let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
- it "should exist" do
- Puppet::Parser::Functions.function("strip").should == "function_strip"
- end
-
- it "should raise a ParseError if there is less than 1 arguments" do
- lambda { scope.function_strip([]) }.should( raise_error(Puppet::ParseError))
- end
-
- it "should strip a string" do
- result = scope.function_strip([" ab cd "])
- result.should(eq('ab cd'))
- end
-end
diff --git a/spec/unit/puppet/parser/functions/suffix_spec.rb b/spec/unit/puppet/parser/functions/suffix_spec.rb
deleted file mode 100644
index c28f719..0000000
--- a/spec/unit/puppet/parser/functions/suffix_spec.rb
+++ /dev/null
@@ -1,19 +0,0 @@
-#! /usr/bin/env ruby -S rspec
-require 'spec_helper'
-
-describe "the suffix function" do
- let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
-
- it "should exist" do
- Puppet::Parser::Functions.function("suffix").should == "function_suffix"
- end
-
- it "should raise a ParseError if there is less than 1 arguments" do
- lambda { scope.function_suffix([]) }.should( raise_error(Puppet::ParseError))
- end
-
- it "should return a suffixed array" do
- result = scope.function_suffix([['a','b','c'], 'p'])
- result.should(eq(['ap','bp','cp']))
- end
-end
diff --git a/spec/unit/puppet/parser/functions/swapcase_spec.rb b/spec/unit/puppet/parser/functions/swapcase_spec.rb
deleted file mode 100644
index 808b415..0000000
--- a/spec/unit/puppet/parser/functions/swapcase_spec.rb
+++ /dev/null
@@ -1,19 +0,0 @@
-#! /usr/bin/env ruby -S rspec
-require 'spec_helper'
-
-describe "the swapcase function" do
- let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
-
- it "should exist" do
- Puppet::Parser::Functions.function("swapcase").should == "function_swapcase"
- end
-
- it "should raise a ParseError if there is less than 1 arguments" do
- lambda { scope.function_swapcase([]) }.should( raise_error(Puppet::ParseError))
- end
-
- it "should swapcase a string" do
- result = scope.function_swapcase(["aaBBccDD"])
- result.should(eq('AAbbCCdd'))
- end
-end
diff --git a/spec/unit/puppet/parser/functions/to_bytes_spec.rb b/spec/unit/puppet/parser/functions/to_bytes_spec.rb
deleted file mode 100755
index d1ea4c8..0000000
--- a/spec/unit/puppet/parser/functions/to_bytes_spec.rb
+++ /dev/null
@@ -1,58 +0,0 @@
-#! /usr/bin/env ruby -S rspec
-
-require 'spec_helper'
-
-describe "the to_bytes function" do
- let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
-
- it "should exist" do
- Puppet::Parser::Functions.function("to_bytes").should == "function_to_bytes"
- end
-
- it "should raise a ParseError if there is less than 1 arguments" do
- lambda { scope.function_to_bytes([]) }.should( raise_error(Puppet::ParseError))
- end
-
- it "should convert kB to B" do
- result = scope.function_to_bytes(["4 kB"])
- result.should(eq(4096))
- end
-
- it "should work without B in unit" do
- result = scope.function_to_bytes(["4 k"])
- result.should(eq(4096))
- end
-
- it "should work without a space before unit" do
- result = scope.function_to_bytes(["4k"])
- result.should(eq(4096))
- end
-
- it "should work without a unit" do
- result = scope.function_to_bytes(["5678"])
- result.should(eq(5678))
- end
-
- it "should convert fractions" do
- result = scope.function_to_bytes(["1.5 kB"])
- result.should(eq(1536))
- end
-
- it "should convert scientific notation" do
- result = scope.function_to_bytes(["1.5e2 B"])
- result.should(eq(150))
- end
-
- it "should do nothing with a positive number" do
- result = scope.function_to_bytes([5678])
- result.should(eq(5678))
- end
-
- it "should should raise a ParseError if input isn't a number" do
- lambda { scope.function_to_bytes(["foo"]) }.should( raise_error(Puppet::ParseError))
- end
-
- it "should should raise a ParseError if prefix is unknown" do
- lambda { scope.function_to_bytes(["5 uB"]) }.should( raise_error(Puppet::ParseError))
- end
-end
diff --git a/spec/unit/puppet/parser/functions/validate_cmd_spec.rb b/spec/unit/puppet/parser/functions/validate_cmd_spec.rb
deleted file mode 100644
index 69ea7f4..0000000
--- a/spec/unit/puppet/parser/functions/validate_cmd_spec.rb
+++ /dev/null
@@ -1,81 +0,0 @@
-require 'spec_helper'
-
-describe Puppet::Parser::Functions.function(:validate_cmd) do
- let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
-
- # The subject of these examplres is the method itself.
- subject do
- # This makes sure the function is loaded within each test
- function_name = Puppet::Parser::Functions.function(:validate_cmd)
- scope.method(function_name)
- end
-
- context 'Using Puppet::Parser::Scope.new' do
-
- describe 'Garbage inputs' do
- inputs = [
- [ nil ],
- [ [ nil ] ],
- [ { 'foo' => 'bar' } ],
- [ { } ],
- [ '' ],
- [ "one", "one", "MSG to User", "4th arg" ],
- ]
-
- inputs.each do |input|
- it "validate_cmd(#{input.inspect}) should fail" do
- expect { subject.call [input] }.to raise_error Puppet::ParseError
- end
- end
- end
-
- describe 'Valid inputs' do
- inputs = [
- [ '/full/path/to/something', '/bin/echo' ],
- [ '/full/path/to/something', '/bin/cat' ],
- ]
-
- inputs.each do |input|
- it "validate_cmd(#{input.inspect}) should not fail" do
- expect { subject.call input }.not_to raise_error
- end
- end
- end
-
- describe "Valid inputs which should raise an exception without a message" do
- # The intent here is to make sure valid inputs raise exceptions when they
- # don't specify an error message to display. This is the behvior in
- # 2.2.x and prior.
- inputs = [
- [ "hello", "/bin/false" ],
- ]
-
- inputs.each do |input|
- it "validate_cmd(#{input.inspect}) should fail" do
- expect { subject.call input }.to raise_error /validate_cmd.*?failed to validate content with command/
- end
- end
- end
-
- describe "Nicer Error Messages" do
- # The intent here is to make sure the function returns the 3rd argument
- # in the exception thrown
- inputs = [
- [ "hello", [ "bye", "later", "adios" ], "MSG to User" ],
- [ "greetings", "salutations", "Error, greetings does not match salutations" ],
- ]
-
- inputs.each do |input|
- it "validate_cmd(#{input.inspect}) should fail" do
- expect { subject.call input }.to raise_error /#{input[2]}/
- end
- end
- end
-
- describe "Test output message" do
- it "validate_cmd('whatever', 'kthnksbye') should fail" do
- expect { subject.call ['whatever', 'kthnksbye'] }.to raise_error /kthnksbye.* returned 1/
- end
- end
- end
-end
diff --git a/spec/unit/puppet/parser/functions/zip_spec.rb b/spec/unit/puppet/parser/functions/zip_spec.rb
deleted file mode 100644
index f45ab17..0000000
--- a/spec/unit/puppet/parser/functions/zip_spec.rb
+++ /dev/null
@@ -1,15 +0,0 @@
-#! /usr/bin/env ruby -S rspec
-require 'spec_helper'
-
-describe "the zip function" do
- let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
-
- it "should raise a ParseError if there is less than 1 arguments" do
- lambda { scope.function_zip([]) }.should( raise_error(Puppet::ParseError))
- end
-
- it "should be able to zip an array" do
- result = scope.function_zip([['1','2','3'],['4','5','6']])
- result.should(eq([["1", "4"], ["2", "5"], ["3", "6"]]))
- end
-end
diff --git a/spec/unit/puppet/provider/file_line/ruby_spec.rb b/spec/unit/puppet/provider/file_line/ruby_spec.rb
index 648c05b..d2a129c 100644..100755
--- a/spec/unit/puppet/provider/file_line/ruby_spec.rb
+++ b/spec/unit/puppet/provider/file_line/ruby_spec.rb
@@ -1,35 +1,39 @@
-require 'puppet'
+#! /usr/bin/env ruby -S rspec
+require 'spec_helper'
require 'tempfile'
provider_class = Puppet::Type.type(:file_line).provider(:ruby)
describe provider_class do
context "when adding" do
- before :each do
- # TODO: these should be ported over to use the PuppetLabs spec_helper
- # file fixtures once the following pull request has been merged:
- # https://github.com/puppetlabs/puppetlabs-stdlib/pull/73/files
+ let :tmpfile do
tmp = Tempfile.new('tmp')
- @tmpfile = tmp.path
+ path = tmp.path
tmp.close!
- @resource = Puppet::Type::File_line.new(
- {:name => 'foo', :path => @tmpfile, :line => 'foo'}
+ path
+ end
+ let :resource do
+ Puppet::Type::File_line.new(
+ {:name => 'foo', :path => tmpfile, :line => 'foo'}
)
- @provider = provider_class.new(@resource)
end
+ let :provider do
+ provider_class.new(resource)
+ end
+
it 'should detect if the line exists in the file' do
- File.open(@tmpfile, 'w') do |fh|
+ File.open(tmpfile, 'w') do |fh|
fh.write('foo')
end
- @provider.exists?.should be_true
+ expect(provider.exists?).to be_truthy
end
it 'should detect if the line does not exist in the file' do
- File.open(@tmpfile, 'w') do |fh|
+ File.open(tmpfile, 'w') do |fh|
fh.write('foo1')
end
- @provider.exists?.should be_nil
+ expect(provider.exists?).to be_nil
end
it 'should append to an existing file when creating' do
- @provider.create
- File.read(@tmpfile).chomp.should == 'foo'
+ provider.create
+ expect(File.read(tmpfile).chomp).to eq('foo')
end
end
@@ -52,71 +56,132 @@ describe provider_class do
@provider = provider_class.new(@resource)
end
- it 'should raise an error if more than one line matches, and should not have modified the file' do
- File.open(@tmpfile, 'w') do |fh|
- fh.write("foo1\nfoo=blah\nfoo2\nfoo=baz")
+ describe 'using match' do
+ it 'should raise an error if more than one line matches, and should not have modified the file' do
+ File.open(@tmpfile, 'w') do |fh|
+ fh.write("foo1\nfoo=blah\nfoo2\nfoo=baz")
+ end
+ expect(@provider.exists?).to be_nil
+ expect { @provider.create }.to raise_error(Puppet::Error, /More than one line.*matches/)
+ expect(File.read(@tmpfile)).to eql("foo1\nfoo=blah\nfoo2\nfoo=baz")
end
- @provider.exists?.should be_nil
- expect { @provider.create }.to raise_error(Puppet::Error, /More than one line.*matches/)
- File.read(@tmpfile).should eql("foo1\nfoo=blah\nfoo2\nfoo=baz")
- end
- it 'should replace all lines that matches' do
- @resource = Puppet::Type::File_line.new(
+ it 'should replace all lines that matches' do
+ @resource = Puppet::Type::File_line.new(
{
- :name => 'foo',
- :path => @tmpfile,
- :line => 'foo = bar',
- :match => '^foo\s*=.*$',
- :multiple => true
+ :name => 'foo',
+ :path => @tmpfile,
+ :line => 'foo = bar',
+ :match => '^foo\s*=.*$',
+ :multiple => true
}
- )
- @provider = provider_class.new(@resource)
- File.open(@tmpfile, 'w') do |fh|
- fh.write("foo1\nfoo=blah\nfoo2\nfoo=baz")
+ )
+ @provider = provider_class.new(@resource)
+ File.open(@tmpfile, 'w') do |fh|
+ fh.write("foo1\nfoo=blah\nfoo2\nfoo=baz")
+ end
+ expect(@provider.exists?).to be_nil
+ @provider.create
+ expect(File.read(@tmpfile).chomp).to eql("foo1\nfoo = bar\nfoo2\nfoo = bar")
+ end
+
+ it 'should raise an error with invalid values' do
+ expect {
+ @resource = Puppet::Type::File_line.new(
+ {
+ :name => 'foo',
+ :path => @tmpfile,
+ :line => 'foo = bar',
+ :match => '^foo\s*=.*$',
+ :multiple => 'asgadga'
+ }
+ )
+ }.to raise_error(Puppet::Error, /Invalid value "asgadga"\. Valid values are true, false\./)
+ end
+
+ it 'should replace a line that matches' do
+ File.open(@tmpfile, 'w') do |fh|
+ fh.write("foo1\nfoo=blah\nfoo2")
+ end
+ expect(@provider.exists?).to be_nil
+ @provider.create
+ expect(File.read(@tmpfile).chomp).to eql("foo1\nfoo = bar\nfoo2")
+ end
+ it 'should add a new line if no lines match' do
+ File.open(@tmpfile, 'w') do |fh|
+ fh.write("foo1\nfoo2")
+ end
+ expect(@provider.exists?).to be_nil
+ @provider.create
+ expect(File.read(@tmpfile)).to eql("foo1\nfoo2\nfoo = bar\n")
+ end
+ it 'should do nothing if the exact line already exists' do
+ File.open(@tmpfile, 'w') do |fh|
+ fh.write("foo1\nfoo = bar\nfoo2")
+ end
+ expect(@provider.exists?).to be_truthy
+ @provider.create
+ expect(File.read(@tmpfile).chomp).to eql("foo1\nfoo = bar\nfoo2")
end
- @provider.exists?.should be_nil
- @provider.create
- File.read(@tmpfile).chomp.should eql("foo1\nfoo = bar\nfoo2\nfoo = bar")
end
- it 'should raise an error with invalid values' do
- expect {
- @resource = Puppet::Type::File_line.new(
+ describe 'using after' do
+ let :resource do
+ Puppet::Type::File_line.new(
{
- :name => 'foo',
- :path => @tmpfile,
- :line => 'foo = bar',
- :match => '^foo\s*=.*$',
- :multiple => 'asgadga'
+ :name => 'foo',
+ :path => @tmpfile,
+ :line => 'inserted = line',
+ :after => '^foo1',
}
)
- }.to raise_error(Puppet::Error, /Invalid value "asgadga"\. Valid values are true, false\./)
- end
+ end
- it 'should replace a line that matches' do
- File.open(@tmpfile, 'w') do |fh|
- fh.write("foo1\nfoo=blah\nfoo2")
+ let :provider do
+ provider_class.new(resource)
end
- @provider.exists?.should be_nil
- @provider.create
- File.read(@tmpfile).chomp.should eql("foo1\nfoo = bar\nfoo2")
- end
- it 'should add a new line if no lines match' do
- File.open(@tmpfile, 'w') do |fh|
- fh.write("foo1\nfoo2")
+
+ context 'with one line matching the after expression' do
+ before :each do
+ File.open(@tmpfile, 'w') do |fh|
+ fh.write("foo1\nfoo = blah\nfoo2\nfoo = baz")
+ end
+ end
+
+ it 'inserts the specified line after the line matching the "after" expression' do
+ provider.create
+ expect(File.read(@tmpfile).chomp).to eql("foo1\ninserted = line\nfoo = blah\nfoo2\nfoo = baz")
+ end
end
- @provider.exists?.should be_nil
- @provider.create
- File.read(@tmpfile).should eql("foo1\nfoo2\nfoo = bar\n")
- end
- it 'should do nothing if the exact line already exists' do
- File.open(@tmpfile, 'w') do |fh|
- fh.write("foo1\nfoo = bar\nfoo2")
+
+ context 'with two lines matching the after expression' do
+ before :each do
+ File.open(@tmpfile, 'w') do |fh|
+ fh.write("foo1\nfoo = blah\nfoo2\nfoo1\nfoo = baz")
+ end
+ end
+
+ it 'errors out stating "One or no line must match the pattern"' do
+ expect { provider.create }.to raise_error(Puppet::Error, /One or no line must match the pattern/)
+ end
+ end
+
+ context 'with no lines matching the after expression' do
+ let :content do
+ "foo3\nfoo = blah\nfoo2\nfoo = baz\n"
+ end
+
+ before :each do
+ File.open(@tmpfile, 'w') do |fh|
+ fh.write(content)
+ end
+ end
+
+ it 'appends the specified line to the file' do
+ provider.create
+ expect(File.read(@tmpfile)).to eq(content << resource[:line] << "\n")
+ end
end
- @provider.exists?.should be_true
- @provider.create
- File.read(@tmpfile).chomp.should eql("foo1\nfoo = bar\nfoo2")
end
end
@@ -138,7 +203,7 @@ describe provider_class do
fh.write("foo1\nfoo\nfoo2")
end
@provider.destroy
- File.read(@tmpfile).should eql("foo1\nfoo2")
+ expect(File.read(@tmpfile)).to eql("foo1\nfoo2")
end
it 'should remove the line without touching the last new line' do
@@ -146,7 +211,7 @@ describe provider_class do
fh.write("foo1\nfoo\nfoo2\n")
end
@provider.destroy
- File.read(@tmpfile).should eql("foo1\nfoo2\n")
+ expect(File.read(@tmpfile)).to eql("foo1\nfoo2\n")
end
it 'should remove any occurence of the line' do
@@ -154,7 +219,7 @@ describe provider_class do
fh.write("foo1\nfoo\nfoo2\nfoo\nfoo")
end
@provider.destroy
- File.read(@tmpfile).should eql("foo1\nfoo2\n")
+ expect(File.read(@tmpfile)).to eql("foo1\nfoo2\n")
end
end
end
diff --git a/spec/unit/puppet/type/anchor_spec.rb b/spec/unit/puppet/type/anchor_spec.rb
index 2030b83..c738a27 100644..100755
--- a/spec/unit/puppet/type/anchor_spec.rb
+++ b/spec/unit/puppet/type/anchor_spec.rb
@@ -1,11 +1,11 @@
#!/usr/bin/env ruby
-require 'puppet'
+require 'spec_helper'
anchor = Puppet::Type.type(:anchor).new(:name => "ntp::begin")
describe anchor do
it "should stringify normally" do
- anchor.to_s.should == "Anchor[ntp::begin]"
+ expect(anchor.to_s).to eq("Anchor[ntp::begin]")
end
end
diff --git a/spec/unit/puppet/type/file_line_spec.rb b/spec/unit/puppet/type/file_line_spec.rb
index edc64bd..410d0bf 100644..100755
--- a/spec/unit/puppet/type/file_line_spec.rb
+++ b/spec/unit/puppet/type/file_line_spec.rb
@@ -1,4 +1,5 @@
-require 'puppet'
+#! /usr/bin/env ruby -S rspec
+require 'spec_helper'
require 'tempfile'
describe Puppet::Type.type(:file_line) do
let :file_line do
@@ -6,22 +7,22 @@ describe Puppet::Type.type(:file_line) do
end
it 'should accept a line and path' do
file_line[:line] = 'my_line'
- file_line[:line].should == 'my_line'
+ expect(file_line[:line]).to eq('my_line')
file_line[:path] = '/my/path'
- file_line[:path].should == '/my/path'
+ expect(file_line[:path]).to eq('/my/path')
end
it 'should accept a match regex' do
file_line[:match] = '^foo.*$'
- file_line[:match].should == '^foo.*$'
+ expect(file_line[:match]).to eq('^foo.*$')
end
- it 'should not accept a match regex that does not match the specified line' do
+ it 'should accept a match regex that does not match the specified line' do
expect {
Puppet::Type.type(:file_line).new(
:name => 'foo',
:path => '/my/path',
:line => 'foo=bar',
:match => '^bar=blah$'
- )}.to raise_error(Puppet::Error, /the value must be a regex that matches/)
+ )}.not_to raise_error
end
it 'should accept a match regex that does match the specified line' do
expect {
@@ -34,7 +35,7 @@ describe Puppet::Type.type(:file_line) do
end
it 'should accept posix filenames' do
file_line[:path] = '/tmp/path'
- file_line[:path].should == '/tmp/path'
+ expect(file_line[:path]).to eq('/tmp/path')
end
it 'should not accept unqualified path' do
expect { file_line[:path] = 'file' }.to raise_error(Puppet::Error, /File paths must be fully qualified/)
@@ -46,7 +47,7 @@ describe Puppet::Type.type(:file_line) do
expect { Puppet::Type.type(:file_line).new(:name => 'foo', :line => 'path') }.to raise_error(Puppet::Error, /Both line and path are required attributes/)
end
it 'should default to ensure => present' do
- file_line[:ensure].should eq :present
+ expect(file_line[:ensure]).to eq :present
end
it "should autorequire the file it manages" do
@@ -58,12 +59,12 @@ describe Puppet::Type.type(:file_line) do
relationship = file_line.autorequire.find do |rel|
(rel.source.to_s == "File[/tmp/path]") and (rel.target.to_s == file_line.to_s)
end
- relationship.should be_a Puppet::Relationship
+ expect(relationship).to be_a Puppet::Relationship
end
it "should not autorequire the file it manages if it is not managed" do
catalog = Puppet::Resource::Catalog.new
catalog.add_resource file_line
- file_line.autorequire.should be_empty
+ expect(file_line.autorequire).to be_empty
end
end
diff --git a/spec/watchr.rb b/spec/watchr.rb
deleted file mode 100644
index 885ef1d..0000000
--- a/spec/watchr.rb
+++ /dev/null
@@ -1,86 +0,0 @@
-ENV['FOG_MOCK'] ||= 'true'
-ENV['AUTOTEST'] = 'true'
-ENV['WATCHR'] = '1'
-
-system 'clear'
-
-def growl(message)
- growlnotify = `which growlnotify`.chomp
- title = "Watchr Test Results"
- image = case message
- when /(\d+)\s+?(failure|error)/i
- ($1.to_i == 0) ? "~/.watchr_images/passed.png" : "~/.watchr_images/failed.png"
- else
- '~/.watchr_images/unknown.png'
- end
- options = "-w -n Watchr --image '#{File.expand_path(image)}' -m '#{message}' '#{title}'"
- system %(#{growlnotify} #{options} &)
-end
-
-def run(cmd)
- puts(cmd)
- `#{cmd}`
-end
-
-def run_spec_test(file)
- if File.exist? file
- result = run "rspec --format p --color #{file}"
- growl result.split("\n").last
- puts result
- else
- puts "FIXME: No test #{file} [#{Time.now}]"
- end
-end
-
-def filter_rspec(data)
- data.split("\n").find_all do |l|
- l =~ /^(\d+)\s+exampl\w+.*?(\d+).*?failur\w+.*?(\d+).*?pending/
- end.join("\n")
-end
-
-def run_all_tests
- system('clear')
- files = Dir.glob("spec/**/*_spec.rb").join(" ")
- result = run "rspec #{files}"
- growl_results = filter_rspec result
- growl growl_results
- puts result
- puts "GROWL: #{growl_results}"
-end
-
-# Ctrl-\
-Signal.trap 'QUIT' do
- puts " --- Running all tests ---\n\n"
- run_all_tests
-end
-
-@interrupted = false
-
-# Ctrl-C
-Signal.trap 'INT' do
- if @interrupted then
- @wants_to_quit = true
- abort("\n")
- else
- puts "Interrupt a second time to quit"
- @interrupted = true
- Kernel.sleep 1.5
- # raise Interrupt, nil # let the run loop catch it
- run_suite
- end
-end
-
-def file2spec(file)
- result = file.sub('lib/puppet/', 'spec/unit/puppet/').gsub(/\.rb$/, '_spec.rb')
- result = file.sub('lib/facter/', 'spec/unit/facter/').gsub(/\.rb$/, '_spec.rb')
-end
-
-
-watch( 'spec/.*_spec\.rb' ) do |md|
- #run_spec_test(md[0])
- run_all_tests
-end
-watch( 'lib/.*\.rb' ) do |md|
- # run_spec_test(file2spec(md[0]))
- run_all_tests
-end