summaryrefslogtreecommitdiff
path: root/spec/functions
diff options
context:
space:
mode:
authorJoseph Yaworski <joseph.yaworski@fireeye.com>2016-05-11 13:21:24 -0400
committerJoseph Yaworski <joseph.yaworski@fireeye.com>2016-05-13 13:25:35 -0400
commitdd71c0288052dd3a96e730ff198f5c0a8d640946 (patch)
treefd55b7e18c892092ac37276e998356e91388bdce /spec/functions
parentecfdbb2690359434f1737d05ce723cf2f5d05c4e (diff)
Add a delete_regex function
To maintain backwards compatibility, add a delete_regex function instead of modifying delete itself.
Diffstat (limited to 'spec/functions')
-rwxr-xr-xspec/functions/delete_regex_spec.rb54
-rwxr-xr-xspec/functions/delete_spec.rb3
2 files changed, 54 insertions, 3 deletions
diff --git a/spec/functions/delete_regex_spec.rb b/spec/functions/delete_regex_spec.rb
new file mode 100755
index 0000000..f27a946
--- /dev/null
+++ b/spec/functions/delete_regex_spec.rb
@@ -0,0 +1,54 @@
+require 'spec_helper'
+
+describe 'delete_regex' do
+ it { is_expected.not_to eq(nil) }
+ it { is_expected.to run.with_params().and_raise_error(Puppet::ParseError) }
+ it { is_expected.to run.with_params([]).and_raise_error(Puppet::ParseError) }
+ it { is_expected.to run.with_params([], 'two') }
+ it { is_expected.to run.with_params({}, 'two') }
+ it { is_expected.to run.with_params([], 'two', 'three').and_raise_error(Puppet::ParseError) }
+ it { is_expected.to run.with_params([], 'two', 'three', 'four').and_raise_error(Puppet::ParseError) }
+ it { is_expected.to run.with_params(1, 'two').and_raise_error(TypeError) }
+
+ describe 'deleting from an array' do
+ it { is_expected.to run.with_params([], '').and_return([]) }
+ it { is_expected.to run.with_params([], 'two').and_return([]) }
+ it { is_expected.to run.with_params(['two'], 'two').and_return([]) }
+ it { is_expected.to run.with_params(['two', 'two'], 'two').and_return([]) }
+ it { is_expected.to run.with_params(['one', 'two', 'three'], '^t.*').and_return(['one']) }
+ it { is_expected.to run.with_params(['ab', 'b', 'c', 'b'], 'b').and_return(['ab', 'c']) }
+ it { is_expected.to run.with_params(['one', 'two', 'three'], 'four').and_return(['one', 'two', 'three']) }
+ it { is_expected.to run.with_params(['one', 'two', 'three'], 'e').and_return(['one', 'two', 'three']) }
+ it { is_expected.to run.with_params(['one', 'two', 'three'], 'two').and_return(['one', 'three']) }
+ it { is_expected.to run.with_params(['two', 'one', 'two', 'three', 'two'], 'two').and_return(['one', 'three']) }
+ it { is_expected.to run.with_params(['abracadabra'], 'abr').and_return(['abracadabra']) }
+ it { is_expected.to run.with_params(['abracadabra'], '^.*jimbob.*$').and_return(['abracadabra']) }
+ end
+
+ describe 'deleting from an array' do
+ it { is_expected.to run.with_params({}, '').and_return({}) }
+ it { is_expected.to run.with_params({}, 'key').and_return({}) }
+ it { is_expected.to run.with_params({'key' => 'value'}, 'key').and_return({}) }
+ it { is_expected.to run \
+ .with_params({'key1' => 'value1', 'key2' => 'value2', 'key3' => 'value3'}, 'key2') \
+ .and_return( {'key1' => 'value1', 'key3' => 'value3'})
+ }
+ it { is_expected.to run \
+ .with_params({'key1' => 'value1', 'key2' => 'value2', 'key3' => 'value3'}, ['key1', 'key2']) \
+ .and_return( {'key3' => 'value3'})
+ }
+ end
+
+ it "should leave the original array intact" do
+ argument1 = ['one','two','three']
+ original1 = argument1.dup
+ subject.call([argument1,'two'])
+ expect(argument1).to eq(original1)
+ end
+ it "should leave the original hash intact" do
+ argument1 = {'key1' => 'value1', 'key2' => 'value2', 'key3' => 'value3'}
+ original1 = argument1.dup
+ subject.call([argument1,'key2'])
+ expect(argument1).to eq(original1)
+ end
+end
diff --git a/spec/functions/delete_spec.rb b/spec/functions/delete_spec.rb
index fd2a8ad..b44accf 100755
--- a/spec/functions/delete_spec.rb
+++ b/spec/functions/delete_spec.rb
@@ -13,15 +13,12 @@ describe 'delete' do
it { is_expected.to run.with_params([], 'two').and_return([]) }
it { is_expected.to run.with_params(['two'], 'two').and_return([]) }
it { is_expected.to run.with_params(['two', 'two'], 'two').and_return([]) }
- it { is_expected.to run.with_params(['one', 'two', 'three'], '^t.*').and_return(['one']) }
it { is_expected.to run.with_params(['ab', 'b', 'c', 'b'], 'b').and_return(['ab', 'c']) }
it { is_expected.to run.with_params(['one', 'two', 'three'], 'four').and_return(['one', 'two', 'three']) }
it { is_expected.to run.with_params(['one', 'two', 'three'], 'e').and_return(['one', 'two', 'three']) }
it { is_expected.to run.with_params(['one', 'two', 'three'], 'two').and_return(['one', 'three']) }
it { is_expected.to run.with_params(['two', 'one', 'two', 'three', 'two'], 'two').and_return(['one', 'three']) }
it { is_expected.to run.with_params(['one', 'two', 'three', 'two'], ['one', 'two']).and_return(['three']) }
- it { is_expected.to run.with_params(['abracadabra'], 'abr').and_return(['abracadabra']) }
- it { is_expected.to run.with_params(['abracadabra'], '^.*jimbob.*$').and_return(['abracadabra']) }
end
describe 'deleting from a string' do