X-Git-Url: https://git.adam-barratt.org.uk/?a=blobdiff_plain;f=3rdparty%2Fmodules%2Fstdlib%2Fspec%2Ffunctions%2Fseeded_rand_spec.rb;fp=3rdparty%2Fmodules%2Fstdlib%2Fspec%2Ffunctions%2Fseeded_rand_spec.rb;h=0bd8d6d28dd50801ddd48674238e610985eb4a88;hb=131e09855e065be940e104d9ab0f18940cc76257;hp=ac108f455139f0751e902a3bb7fc3d3b165ff8e4;hpb=407d322498f4fde815abf381007fbecfe5c10b2b;p=mirror%2Fdsa-puppet.git diff --git a/3rdparty/modules/stdlib/spec/functions/seeded_rand_spec.rb b/3rdparty/modules/stdlib/spec/functions/seeded_rand_spec.rb index ac108f455..0bd8d6d28 100644 --- a/3rdparty/modules/stdlib/spec/functions/seeded_rand_spec.rb +++ b/3rdparty/modules/stdlib/spec/functions/seeded_rand_spec.rb @@ -2,41 +2,41 @@ require 'spec_helper' describe 'seeded_rand' do it { is_expected.not_to eq(nil) } - it { is_expected.to run.with_params().and_raise_error(ArgumentError, /wrong number of arguments/i) } - it { is_expected.to run.with_params(1).and_raise_error(ArgumentError, /wrong number of arguments/i) } - it { is_expected.to run.with_params(0, '').and_raise_error(ArgumentError, /first argument must be a positive integer/) } - it { is_expected.to run.with_params(1.5, '').and_raise_error(ArgumentError, /first argument must be a positive integer/) } - it { is_expected.to run.with_params(-10, '').and_raise_error(ArgumentError, /first argument must be a positive integer/) } - it { is_expected.to run.with_params("-10", '').and_raise_error(ArgumentError, /first argument must be a positive integer/) } - it { is_expected.to run.with_params("string", '').and_raise_error(ArgumentError, /first argument must be a positive integer/) } - it { is_expected.to run.with_params([], '').and_raise_error(ArgumentError, /first argument must be a positive integer/) } - it { is_expected.to run.with_params({}, '').and_raise_error(ArgumentError, /first argument must be a positive integer/) } - it { is_expected.to run.with_params(1, 1).and_raise_error(ArgumentError, /second argument must be a string/) } - it { is_expected.to run.with_params(1, []).and_raise_error(ArgumentError, /second argument must be a string/) } - it { is_expected.to run.with_params(1, {}).and_raise_error(ArgumentError, /second argument must be a string/) } - - it "provides a random number strictly less than the given max" do - expect(seeded_rand(3, 'seed')).to satisfy {|n| n.to_i < 3 } + it { is_expected.to run.with_params.and_raise_error(ArgumentError, %r{wrong number of arguments}i) } + it { is_expected.to run.with_params(1).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 a string}) } + it { is_expected.to run.with_params(1, []).and_raise_error(ArgumentError, %r{second argument must be a string}) } + it { is_expected.to run.with_params(1, {}).and_raise_error(ArgumentError, %r{second argument must be a string}) } + + it 'provides a random number strictly less than the given max' do + expect(seeded_rand(3, 'seed')).to satisfy { |n| n.to_i < 3 } # rubocop:disable Lint/AmbiguousBlockAssociation : Cannot parenthesize without break code or violating other Rubocop rules end - it "provides a random number greater or equal to zero" do - expect(seeded_rand(3, 'seed')).to satisfy {|n| n.to_i >= 0 } + it 'provides a random number greater or equal to zero' do + expect(seeded_rand(3, 'seed')).to satisfy { |n| n.to_i >= 0 } # rubocop:disable Lint/AmbiguousBlockAssociation : Cannot parenthesize without break code or violating other Rubocop rules end it "provides the same 'random' value on subsequent calls for the same host" do expect(seeded_rand(10, 'seed')).to eql(seeded_rand(10, 'seed')) end - it "allows seed to control the random value on a single host" do + it 'allows seed to control the random value on a single host' do first_random = seeded_rand(1000, 'seed1') second_different_random = seeded_rand(1000, 'seed2') expect(first_random).not_to eql(second_different_random) end - it "should not return different values for different hosts" do - val1 = seeded_rand(1000, 'foo', :host => "first.host.com") - val2 = seeded_rand(1000, 'foo', :host => "second.host.com") + it 'does not return different values for different hosts' do + val1 = seeded_rand(1000, 'foo', :host => 'first.host.com') + val2 = seeded_rand(1000, 'foo', :host => 'second.host.com') expect(val1).to eql(val2) end @@ -46,13 +46,13 @@ describe 'seeded_rand' do # workaround not being able to use let(:facts) because some tests need # multiple different hostnames in one context - scope.stubs(:lookupvar).with("::fqdn", {}).returns(host) + allow(scope).to receive(:lookupvar).with('::fqdn', {}).and_return(host) scope.function_seeded_rand([max, seed]) end - context 'should run with UTF8 and double byte characters' do - it { is_expected.to run.with_params(1000, 'ǿňè')} - it { is_expected.to run.with_params(1000, '文字列')} + context 'with UTF8 and double byte characters' do + it { is_expected.to run.with_params(1000, 'ǿňè') } + it { is_expected.to run.with_params(1000, '文字列') } end end