Skip to content

Commit 9022295

Browse files
committed
Adding more tests
1 parent 8a269c6 commit 9022295

File tree

8 files changed

+280
-1
lines changed

8 files changed

+280
-1
lines changed

spec/acceptance/parsejson_spec.rb

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
require 'spec_helper_acceptance'
2+
3+
describe 'parsejson function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do
4+
describe 'success' do
5+
it 'parses valid json' do
6+
pp = <<-EOS
7+
$a = '{"hunter": "washere", "tests": "passing"}'
8+
$ao = parsejson($a)
9+
$tests = $ao['tests']
10+
notice(inline_template('tests are <%= @tests.inspect %>'))
11+
EOS
12+
13+
apply_manifest(pp, :catch_failures => true) do |r|
14+
expect(r.stdout).to match(/tests are "passing"/)
15+
end
16+
end
17+
end
18+
describe 'failure' do
19+
it 'raises error on incorrect json' do
20+
pp = <<-EOS
21+
$a = '{"hunter": "washere", "tests": "passing",}'
22+
$ao = parsejson($a)
23+
notice(inline_template('a is <%= @ao.inspect %>'))
24+
EOS
25+
26+
apply_manifest(pp, :expect_failures => true) do |r|
27+
expect(r.stderr).to match(/expected next name/)
28+
end
29+
end
30+
31+
it 'raises error on incorrect number of arguments'
32+
end
33+
end

spec/acceptance/parseyaml_spec.rb

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
require 'spec_helper_acceptance'
2+
3+
describe 'parseyaml function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do
4+
describe 'success' do
5+
it 'parses valid yaml' do
6+
pp = <<-EOS
7+
$a = "---\nhunter: washere\ntests: passing\n"
8+
$o = parseyaml($a)
9+
$tests = $o['tests']
10+
notice(inline_template('tests are <%= @tests.inspect %>'))
11+
EOS
12+
13+
apply_manifest(pp, :catch_failures => true) do |r|
14+
expect(r.stdout).to match(/tests are "passing"/)
15+
end
16+
end
17+
end
18+
describe 'failure' do
19+
it 'raises error on incorrect yaml' do
20+
pp = <<-EOS
21+
$a = "---\nhunter: washere\ntests: passing\n:"
22+
$o = parseyaml($a)
23+
$tests = $o['tests']
24+
notice(inline_template('tests are <%= @tests.inspect %>'))
25+
EOS
26+
27+
apply_manifest(pp, :expect_failures => true) do |r|
28+
expect(r.stderr).to match(/syntax error/)
29+
end
30+
end
31+
32+
it 'raises error on incorrect number of arguments'
33+
end
34+
end

spec/acceptance/pick_spec.rb

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
require 'spec_helper_acceptance'
2+
3+
describe 'pick function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do
4+
describe 'success' do
5+
it 'picks a default value' do
6+
pp = <<-EOS
7+
$a = undef
8+
$o = pick($a, 'default')
9+
notice(inline_template('picked is <%= @o.inspect %>'))
10+
EOS
11+
12+
apply_manifest(pp, :catch_failures => true) do |r|
13+
expect(r.stdout).to match(/picked is "default"/)
14+
end
15+
end
16+
it 'picks the first set value' do
17+
pp = <<-EOS
18+
$a = "something"
19+
$b = "long"
20+
$o = pick($a, $b, 'default')
21+
notice(inline_template('picked is <%= @o.inspect %>'))
22+
EOS
23+
24+
apply_manifest(pp, :catch_failures => true) do |r|
25+
expect(r.stdout).to match(/picked is "something"/)
26+
end
27+
end
28+
end
29+
describe 'failure' do
30+
it 'raises error with all undef values' do
31+
pp = <<-EOS
32+
$a = undef
33+
$b = undef
34+
$o = pick($a, $b)
35+
notice(inline_template('picked is <%= @o.inspect %>'))
36+
EOS
37+
38+
apply_manifest(pp, :expect_failures => true) do |r|
39+
expect(r.stderr).to match(/must receive at least one non empty value/)
40+
end
41+
end
42+
end
43+
end

spec/acceptance/prefix_spec.rb

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
require 'spec_helper_acceptance'
2+
3+
describe 'prefix function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do
4+
describe 'success' do
5+
it 'prefixes array of values' do
6+
pp = <<-EOS
7+
$o = prefix(['a','b','c'],'p')
8+
notice(inline_template('prefix is <%= @o.inspect %>'))
9+
EOS
10+
11+
apply_manifest(pp, :catch_failures => true) do |r|
12+
expect(r.stdout).to match(/prefix is \["pa", "pb", "pc"\]/)
13+
end
14+
end
15+
it 'prefixs with empty array' do
16+
pp = <<-EOS
17+
$o = prefix([],'p')
18+
notice(inline_template('prefix is <%= @o.inspect %>'))
19+
EOS
20+
21+
apply_manifest(pp, :catch_failures => true) do |r|
22+
expect(r.stdout).to match(/prefix is \[\]/)
23+
end
24+
end
25+
it 'prefixs array of values with undef' do
26+
pp = <<-EOS
27+
$o = prefix(['a','b','c'], undef)
28+
notice(inline_template('prefix is <%= @o.inspect %>'))
29+
EOS
30+
31+
apply_manifest(pp, :catch_failures => true) do |r|
32+
expect(r.stdout).to match(/prefix is \["a", "b", "c"\]/)
33+
end
34+
end
35+
end
36+
describe 'failure' do
37+
it 'fails with no arguments'
38+
it 'fails when first argument is not array'
39+
it 'fails when second argument is not string'
40+
end
41+
end

spec/acceptance/reject_spec.rb

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
require 'spec_helper_acceptance'
2+
3+
describe 'reject function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do
4+
describe 'success' do
5+
it 'rejects array of values' do
6+
pp = <<-EOS
7+
$o = reject(['aaa','bbb','ccc','aaaddd'], 'aaa')
8+
notice(inline_template('reject is <%= @o.inspect %>'))
9+
EOS
10+
11+
apply_manifest(pp, :catch_failures => true) do |r|
12+
expect(r.stdout).to match(/reject is \["bbb", "ccc"\]/)
13+
end
14+
end
15+
it 'rejects with empty array' do
16+
pp = <<-EOS
17+
$o = reject([],'aaa')
18+
notice(inline_template('reject is <%= @o.inspect %>'))
19+
EOS
20+
21+
apply_manifest(pp, :catch_failures => true) do |r|
22+
expect(r.stdout).to match(/reject is \[\]/)
23+
end
24+
end
25+
it 'rejects array of values with undef' do
26+
pp = <<-EOS
27+
$o = reject(['aaa','bbb','ccc','aaaddd'], undef)
28+
notice(inline_template('reject is <%= @o.inspect %>'))
29+
EOS
30+
31+
apply_manifest(pp, :catch_failures => true) do |r|
32+
expect(r.stdout).to match(/reject is \["aaa", "bbb", "ccc", "aaaddd"\]/)
33+
end
34+
end
35+
end
36+
describe 'failure' do
37+
it 'fails with no arguments'
38+
it 'fails when first argument is not array'
39+
it 'fails when second argument is not string'
40+
end
41+
end

spec/acceptance/size_spec.rb

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
require 'spec_helper_acceptance'
2+
3+
describe 'size function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do
4+
describe 'success' do
5+
it 'single string size' do
6+
pp = <<-EOS
7+
$a = 'discombobulate'
8+
$o =size($a)
9+
notice(inline_template('size is <%= @o.inspect %>'))
10+
EOS
11+
12+
apply_manifest(pp, :catch_failures => true) do |r|
13+
expect(r.stdout).to match(/size is 14/)
14+
end
15+
end
16+
it 'with empty string' do
17+
pp = <<-EOS
18+
$a = ''
19+
$o =size($a)
20+
notice(inline_template('size is <%= @o.inspect %>'))
21+
EOS
22+
23+
apply_manifest(pp, :catch_failures => true) do |r|
24+
expect(r.stdout).to match(/size is 0/)
25+
end
26+
end
27+
it 'with undef' do
28+
pp = <<-EOS
29+
$a = undef
30+
$o =size($a)
31+
notice(inline_template('size is <%= @o.inspect %>'))
32+
EOS
33+
34+
apply_manifest(pp, :catch_failures => true) do |r|
35+
expect(r.stdout).to match(/size is 0/)
36+
end
37+
end
38+
it 'strings in array' do
39+
pp = <<-EOS
40+
$a = ['discombobulate', 'moo']
41+
$o =size($a)
42+
notice(inline_template('size is <%= @o.inspect %>'))
43+
EOS
44+
45+
apply_manifest(pp, :catch_failures => true) do |r|
46+
expect(r.stdout).to match(/size is 2/)
47+
end
48+
end
49+
end
50+
describe 'failure' do
51+
it 'handles no arguments'
52+
it 'handles non strings or arrays'
53+
end
54+
end

spec/acceptance/sort_spec.rb

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
require 'spec_helper_acceptance'
2+
3+
describe 'sort function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do
4+
describe 'success' do
5+
it 'sorts arrays' do
6+
pp = <<-EOS
7+
$a = ["the","public","art","galleries"]
8+
# Anagram: Large picture halls, I bet
9+
$o =sort($a)
10+
notice(inline_template('sort is <%= @o.inspect %>'))
11+
EOS
12+
13+
apply_manifest(pp, :catch_failures => true) do |r|
14+
expect(r.stdout).to match(/sort is \["art", "galleries", "public", "the"\]/)
15+
end
16+
end
17+
it 'sorts strings' do
18+
pp = <<-EOS
19+
$a = "blowzy night-frumps vex'd jack q"
20+
$o =sort($a)
21+
notice(inline_template('sort is <%= @o.inspect %>'))
22+
EOS
23+
24+
apply_manifest(pp, :catch_failures => true) do |r|
25+
expect(r.stdout).to match(/sort is " '-abcdefghijklmnopqrstuvwxyz"/)
26+
end
27+
end
28+
end
29+
describe 'failure' do
30+
it 'handles no arguments'
31+
it 'handles non strings or arrays'
32+
end
33+
end

spec/spec_helper_acceptance.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
UNSUPPORTED_PLATFORMS = []
44

5-
unless ENV['RS_PROVISION'] == 'no'
5+
unless ENV['RS_PROVISION'] == 'no' or ENV['BEAKER_provision'] == 'no'
66
hosts.each do |host|
77
# Install Puppet
88
if host.is_pe?

0 commit comments

Comments
 (0)