|
| 1 | +require 'spec_helper' |
| 2 | + |
| 3 | +describe 'seeded_rand_string' do |
| 4 | + it { is_expected.not_to be(nil) } |
| 5 | + |
| 6 | + # Test for erroneous params |
| 7 | + it { is_expected.to run.with_params.and_raise_error(ArgumentError, %r{expects between.+got none}i) } |
| 8 | + it { is_expected.to run.with_params(1).and_raise_error(ArgumentError, %r{expects between.+got 1}i) } |
| 9 | + it { is_expected.to run.with_params('1', 'hello').and_raise_error(ArgumentError, %r{parameter 'length' expects an Integer value}i) } |
| 10 | + it { is_expected.to run.with_params(1, 1).and_raise_error(ArgumentError, %r{parameter 'seed' expects a String value}i) } |
| 11 | + it { is_expected.to run.with_params(1, 'hello', 1).and_raise_error(ArgumentError, %r{parameter 'charset' expects a.+String}i) } |
| 12 | + |
| 13 | + # Test regular run |
| 14 | + it { is_expected.to run.with_params(100, 'hello') } |
| 15 | + |
| 16 | + # Test custom charsets |
| 17 | + it { is_expected.to run.with_params(100, 'hello', 'abcd').and_return(%r{[a-d]{100}}) } |
| 18 | + it { is_expected.to run.with_params(100, 'hello', 'abcdefgh').and_return(%r{[a-h]{100}}) } |
| 19 | + it { is_expected.to run.with_params(100, 'hello', 'ab,|').and_return(%r{[ab,|]{100}}) } |
| 20 | + |
| 21 | + # Test behavior |
| 22 | + it 'generates the same string with the same seed' do |
| 23 | + rand_str_one = call_function(:seeded_rand_string, 300, 'my_seed') |
| 24 | + rand_str_two = call_function(:seeded_rand_string, 300, 'my_seed') |
| 25 | + |
| 26 | + expect(rand_str_one).to eq(rand_str_two) |
| 27 | + end |
| 28 | + it 'generates different strings if seeded differently' do |
| 29 | + rand_str_one = call_function(:seeded_rand_string, 300, 'my_seed_one') |
| 30 | + rand_str_two = call_function(:seeded_rand_string, 300, 'my_seed_two') |
| 31 | + |
| 32 | + expect(rand_str_one).not_to eq(rand_str_two) |
| 33 | + end |
| 34 | +end |
0 commit comments