Skip to content

Commit 143a007

Browse files
author
Ashley Penney
committed
Merge pull request #244 from hunner/add_tests
Add more specs
2 parents f8bfe46 + 80590a9 commit 143a007

27 files changed

+733
-47
lines changed

spec/acceptance/pick_default_spec.rb

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
require 'spec_helper_acceptance'
2+
3+
describe 'pick_default function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do
4+
describe 'success' do
5+
it 'pick_defaults a default value' do
6+
pp = <<-EOS
7+
$a = undef
8+
$o = pick_default($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 'pick_defaults with no value' do
17+
pp = <<-EOS
18+
$a = undef
19+
$b = undef
20+
$o = pick_default($a,$b)
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 ""/)
26+
end
27+
end
28+
it 'pick_defaults the first set value' do
29+
pp = <<-EOS
30+
$a = "something"
31+
$b = "long"
32+
$o = pick_default($a, $b, 'default')
33+
notice(inline_template('picked is <%= @o.inspect %>'))
34+
EOS
35+
36+
apply_manifest(pp, :catch_failures => true) do |r|
37+
expect(r.stdout).to match(/picked is "something"/)
38+
end
39+
end
40+
end
41+
describe 'failure' do
42+
it 'raises error with no values' do
43+
pp = <<-EOS
44+
$o = pick_default()
45+
notice(inline_template('picked is <%= @o.inspect %>'))
46+
EOS
47+
48+
apply_manifest(pp, :expect_failures => true) do |r|
49+
expect(r.stderr).to match(/Must receive at least one argument/)
50+
end
51+
end
52+
end
53+
end

spec/acceptance/range_spec.rb

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
require 'spec_helper_acceptance'
2+
3+
describe 'range function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do
4+
describe 'success' do
5+
it 'ranges letters' do
6+
pp = <<-EOS
7+
$o = range('a','d')
8+
notice(inline_template('range is <%= @o.inspect %>'))
9+
EOS
10+
11+
apply_manifest(pp, :catch_failures => true) do |r|
12+
expect(r.stdout).to match(/range is \["a", "b", "c", "d"\]/)
13+
end
14+
end
15+
it 'ranges letters with a step' do
16+
pp = <<-EOS
17+
$o = range('a','d', '2')
18+
notice(inline_template('range is <%= @o.inspect %>'))
19+
EOS
20+
21+
apply_manifest(pp, :catch_failures => true) do |r|
22+
expect(r.stdout).to match(/range is \["a", "c"\]/)
23+
end
24+
end
25+
it 'ranges letters with a negative step'
26+
it 'ranges numbers'
27+
it 'ranges numbers with a step'
28+
it 'ranges numbers with a negative step'
29+
it 'ranges numeric strings'
30+
it 'ranges zero padded numbers'
31+
end
32+
describe 'failure' do
33+
it 'fails with no arguments'
34+
end
35+
end

spec/acceptance/reject_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
EOS
3030

3131
apply_manifest(pp, :catch_failures => true) do |r|
32-
expect(r.stdout).to match(/reject is \["aaa", "bbb", "ccc", "aaaddd"\]/)
32+
expect(r.stdout).to match(/reject is \[\]/)
3333
end
3434
end
3535
end

spec/acceptance/reverse_spec.rb

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
require 'spec_helper_acceptance'
2+
3+
describe 'reverse function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do
4+
describe 'success' do
5+
it 'reverses strings' do
6+
pp = <<-EOS
7+
$a = "the public art galleries"
8+
# Anagram: Large picture halls, I bet
9+
$o = reverse($a)
10+
notice(inline_template('reverse is <%= @o.inspect %>'))
11+
EOS
12+
13+
apply_manifest(pp, :catch_failures => true) do |r|
14+
expect(r.stdout).to match(/reverse is "seirellag tra cilbup eht"/)
15+
end
16+
end
17+
end
18+
describe 'failure' do
19+
it 'handles no arguments'
20+
it 'handles non strings or arrays'
21+
end
22+
end

spec/acceptance/rstrip_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 'rstrip function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do
4+
describe 'success' do
5+
it 'rstrips arrays' do
6+
pp = <<-EOS
7+
$a = [" the "," public "," art","galleries "]
8+
# Anagram: Large picture halls, I bet
9+
$o = rstrip($a)
10+
notice(inline_template('rstrip is <%= @o.inspect %>'))
11+
EOS
12+
13+
apply_manifest(pp, :catch_failures => true) do |r|
14+
expect(r.stdout).to match(/rstrip is \[" the", " public", " art", "galleries"\]/)
15+
end
16+
end
17+
it 'rstrips strings' do
18+
pp = <<-EOS
19+
$a = " blowzy night-frumps vex'd jack q "
20+
$o = rstrip($a)
21+
notice(inline_template('rstrip is <%= @o.inspect %>'))
22+
EOS
23+
24+
apply_manifest(pp, :catch_failures => true) do |r|
25+
expect(r.stdout).to match(/rstrip is " blowzy night-frumps vex'd jack q"/)
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/acceptance/shuffle_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 'shuffle function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do
4+
describe 'success' do
5+
it 'shuffles arrays' do
6+
pp = <<-EOS
7+
$a = ["the","public","art","galleries"]
8+
# Anagram: Large picture halls, I bet
9+
$o = shuffle($a)
10+
notice(inline_template('shuffle is <%= @o.inspect %>'))
11+
EOS
12+
13+
apply_manifest(pp, :catch_failures => true) do |r|
14+
expect(r.stdout).to_not match(/shuffle is \["the", "public", "art", "galleries"\]/)
15+
end
16+
end
17+
it 'shuffles strings' do
18+
pp = <<-EOS
19+
$a = "blowzy night-frumps vex'd jack q"
20+
$o = shuffle($a)
21+
notice(inline_template('shuffle is <%= @o.inspect %>'))
22+
EOS
23+
24+
apply_manifest(pp, :catch_failures => true) do |r|
25+
expect(r.stdout).to_not match(/shuffle is "blowzy night-frumps vex'd jack q"/)
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/acceptance/size_spec.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
it 'single string size' do
66
pp = <<-EOS
77
$a = 'discombobulate'
8-
$o =size($a)
8+
$o = size($a)
99
notice(inline_template('size is <%= @o.inspect %>'))
1010
EOS
1111

@@ -16,7 +16,7 @@
1616
it 'with empty string' do
1717
pp = <<-EOS
1818
$a = ''
19-
$o =size($a)
19+
$o = size($a)
2020
notice(inline_template('size is <%= @o.inspect %>'))
2121
EOS
2222

@@ -27,7 +27,7 @@
2727
it 'with undef' do
2828
pp = <<-EOS
2929
$a = undef
30-
$o =size($a)
30+
$o = size($a)
3131
notice(inline_template('size is <%= @o.inspect %>'))
3232
EOS
3333

@@ -38,7 +38,7 @@
3838
it 'strings in array' do
3939
pp = <<-EOS
4040
$a = ['discombobulate', 'moo']
41-
$o =size($a)
41+
$o = size($a)
4242
notice(inline_template('size is <%= @o.inspect %>'))
4343
EOS
4444

spec/acceptance/sort_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
pp = <<-EOS
77
$a = ["the","public","art","galleries"]
88
# Anagram: Large picture halls, I bet
9-
$o =sort($a)
9+
$o = sort($a)
1010
notice(inline_template('sort is <%= @o.inspect %>'))
1111
EOS
1212

@@ -17,7 +17,7 @@
1717
it 'sorts strings' do
1818
pp = <<-EOS
1919
$a = "blowzy night-frumps vex'd jack q"
20-
$o =sort($a)
20+
$o = sort($a)
2121
notice(inline_template('sort is <%= @o.inspect %>'))
2222
EOS
2323

spec/acceptance/squeeze_spec.rb

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
require 'spec_helper_acceptance'
2+
3+
describe 'squeeze function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do
4+
describe 'success' do
5+
it 'squeezes arrays' do
6+
pp = <<-EOS
7+
# Real words!
8+
$a = ["wallless", "laparohysterosalpingooophorectomy", "brrr", "goddessship"]
9+
$o = squeeze($a)
10+
notice(inline_template('squeeze is <%= @o.inspect %>'))
11+
EOS
12+
13+
apply_manifest(pp, :catch_failures => true) do |r|
14+
expect(r.stdout).to match(/squeeze is \["wales", "laparohysterosalpingophorectomy", "br", "godeship"\]/)
15+
end
16+
end
17+
it 'squeezez arrays with an argument'
18+
it 'squeezes strings' do
19+
pp = <<-EOS
20+
$a = "wallless laparohysterosalpingooophorectomy brrr goddessship"
21+
$o = squeeze($a)
22+
notice(inline_template('squeeze is <%= @o.inspect %>'))
23+
EOS
24+
25+
apply_manifest(pp, :catch_failures => true) do |r|
26+
expect(r.stdout).to match(/squeeze is "wales laparohysterosalpingophorectomy br godeship"/)
27+
end
28+
end
29+
30+
it 'squeezes strings with an argument' do
31+
pp = <<-EOS
32+
$a = "countessship duchessship governessship hostessship"
33+
$o = squeeze($a, 's')
34+
notice(inline_template('squeeze is <%= @o.inspect %>'))
35+
EOS
36+
37+
apply_manifest(pp, :catch_failures => true) do |r|
38+
expect(r.stdout).to match(/squeeze is "counteship ducheship governeship hosteship"/)
39+
end
40+
end
41+
end
42+
describe 'failure' do
43+
it 'handles no arguments'
44+
it 'handles non strings or arrays'
45+
end
46+
end

spec/acceptance/str2bool_spec.rb

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
require 'spec_helper_acceptance'
2+
3+
describe 'str2bool function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do
4+
describe 'success' do
5+
it 'works with "y"' do
6+
pp = <<-EOS
7+
$o = str2bool('y')
8+
notice(inline_template('str2bool is <%= @o.inspect %>'))
9+
EOS
10+
11+
apply_manifest(pp, :catch_failures => true) do |r|
12+
expect(r.stdout).to match(/str2bool is true/)
13+
end
14+
end
15+
it 'works with "Y"'
16+
it 'works with "yes"'
17+
it 'works with "1"'
18+
it 'works with "true"'
19+
it 'works with "n"'
20+
it 'works with "N"'
21+
it 'works with "no"'
22+
it 'works with "0"'
23+
it 'works with "false"'
24+
it 'works with undef'
25+
end
26+
describe 'failure' do
27+
it 'handles no arguments'
28+
it 'handles non arrays or strings'
29+
end
30+
end

0 commit comments

Comments
 (0)