-describe "the fqdn_rand_string function" do
- let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
-
- it "should exist" do
- expect(Puppet::Parser::Functions.function("fqdn_rand_string")).to eq("function_fqdn_rand_string")
- end
-
- it "should raise an ArgumentError if there is less than 1 argument" do
- expect { fqdn_rand_string() }.to( raise_error(ArgumentError, /wrong number of arguments/))
- end
-
- it "should raise an ArgumentError if argument 1 isn't a positive integer" do
- expect { fqdn_rand_string(0) }.to( raise_error(ArgumentError, /first argument must be a positive integer/))
- expect { fqdn_rand_string(-1) }.to( raise_error(ArgumentError, /first argument must be a positive integer/))
- expect { fqdn_rand_string(0.5) }.to( raise_error(ArgumentError, /first argument must be a positive integer/))
- end
-
- it "provides a valid alphanumeric string when no character set is provided" do
- length = 100
- string = %r{\A[a-zA-Z0-9]{#{length}}\z}
- expect(fqdn_rand_string(length).match(string)).not_to eq(nil)
- end
-
- it "provides a valid alphanumeric string when an undef character set is provided" do
- length = 100
- string = %r{\A[a-zA-Z0-9]{#{length}}\z}
- expect(fqdn_rand_string(length, :charset => nil).match(string)).not_to eq(nil)
- end
-
- it "provides a valid alphanumeric string when an empty character set is provided" do
- length = 100
- string = %r{\A[a-zA-Z0-9]{#{length}}\z}
- expect(fqdn_rand_string(length, :charset => '').match(string)).not_to eq(nil)
- end
-
- it "uses a provided character set" do
- length = 100
- charset = '!@#$%^&*()-_=+'
- string = %r{\A[#{charset}]{#{length}}\z}
- expect(fqdn_rand_string(length, :charset => charset).match(string)).not_to eq(nil)
- end
-
- it "provides a random string exactly as long as the given length" do
- expect(fqdn_rand_string(10).size).to eql(10)
- end
+describe 'fqdn_rand_string' do
+ let(:default_charset) { %r{\A[a-zA-Z0-9]{100}\z} }
+
+ it { is_expected.not_to eq(nil) }
+ it { is_expected.to run.with_params.and_raise_error(ArgumentError, %r{wrong number of arguments}i) }
+ it { is_expected.to run.with_params(0).and_raise_error(ArgumentError, %r{first argument must be a positive integer}) }
+ it { is_expected.to run.with_params(1.5).and_raise_error(ArgumentError, %r{first argument must be a positive integer}) }
+ it { is_expected.to run.with_params(-10).and_raise_error(ArgumentError, %r{first argument must be a positive integer}) }
+ it { is_expected.to run.with_params('-10').and_raise_error(ArgumentError, %r{first argument must be a positive integer}) }
+ it { is_expected.to run.with_params('string').and_raise_error(ArgumentError, %r{first argument must be a positive integer}) }
+ it { is_expected.to run.with_params([]).and_raise_error(ArgumentError, %r{first argument must be a positive integer}) }
+ it { is_expected.to run.with_params({}).and_raise_error(ArgumentError, %r{first argument must be a positive integer}) }
+ it { is_expected.to run.with_params(1, 1).and_raise_error(ArgumentError, %r{second argument must be undef or a string}) }
+ it { is_expected.to run.with_params(1, []).and_raise_error(ArgumentError, %r{second argument must be undef or a string}) }
+ it { is_expected.to run.with_params(1, {}).and_raise_error(ArgumentError, %r{second argument must be undef or a string}) }
+ it { is_expected.to run.with_params(100).and_return(default_charset) }
+ it { is_expected.to run.with_params('100').and_return(default_charset) }
+ it { is_expected.to run.with_params(100, nil).and_return(default_charset) }
+ it { is_expected.to run.with_params(100, '').and_return(default_charset) }
+ it { is_expected.to run.with_params(100, 'a').and_return(%r{\Aa{100}\z}) }
+ it { is_expected.to run.with_params(100, 'ab').and_return(%r{\A[ab]{100}\z}) }
+ it { is_expected.to run.with_params(100, 'ãβ').and_return(%r{\A[ãβ]{100}\z}) }