summaryrefslogtreecommitdiff
path: root/spec/functions/squeeze_spec.rb
diff options
context:
space:
mode:
authorDavid Schmitt <david.schmitt@puppetlabs.com>2015-06-01 12:21:59 +0100
committerDavid Schmitt <david.schmitt@puppetlabs.com>2015-06-01 18:02:22 +0100
commitf3e79ddcd56a221c7799b35efde7e9803a5c7923 (patch)
tree730386688574c94169d47d37f79af77c2cda2f08 /spec/functions/squeeze_spec.rb
parentb62dff0c6e09faf9bacfb02575e689ed09ee5e56 (diff)
Convert tests to use plain rspec-puppet
Tests in the new style produces the following documentation output: abs should not eq nil should run abs() and raise an Puppet::ParseError should run abs(-34) and return 34 should run abs("-34") and return 34 should run abs(34) and return 34 should run abs("34") and return 34
Diffstat (limited to 'spec/functions/squeeze_spec.rb')
-rwxr-xr-xspec/functions/squeeze_spec.rb50
1 files changed, 35 insertions, 15 deletions
diff --git a/spec/functions/squeeze_spec.rb b/spec/functions/squeeze_spec.rb
index cd0eb37..7f09c30 100755
--- a/spec/functions/squeeze_spec.rb
+++ b/spec/functions/squeeze_spec.rb
@@ -1,24 +1,44 @@
-#! /usr/bin/env ruby -S rspec
require 'spec_helper'
-describe "the squeeze function" do
- let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
+describe 'squeeze' do
+ it { is_expected.not_to eq(nil) }
+ it { is_expected.to run.with_params().and_raise_error(Puppet::ParseError, /wrong number of arguments/i) }
+ it { is_expected.to run.with_params('', '', '').and_raise_error(Puppet::ParseError, /wrong number of arguments/i) }
+ it { is_expected.to run.with_params(1).and_raise_error(NoMethodError) }
+ it { is_expected.to run.with_params({}).and_raise_error(NoMethodError) }
+ it { is_expected.to run.with_params(true).and_raise_error(NoMethodError) }
- it "should exist" do
- expect(Puppet::Parser::Functions.function("squeeze")).to eq("function_squeeze")
+ context 'when squeezing a single string' do
+ it { is_expected.to run.with_params('').and_return('') }
+ it { is_expected.to run.with_params('a').and_return('a') }
+ it { is_expected.to run.with_params('aaaaaaaaa').and_return('a') }
+ it { is_expected.to run.with_params('aaaaaaaaa', 'a').and_return('a') }
+ it { is_expected.to run.with_params('aaaaaaaaabbbbbbbbbbcccccccccc', 'b-c').and_return('aaaaaaaaabc') }
end
- it "should raise a ParseError if there is less than 2 arguments" do
- expect { scope.function_squeeze([]) }.to( raise_error(Puppet::ParseError))
+ context 'when squeezing values in an array' do
+ it {
+ is_expected.to run \
+ .with_params(['', 'a', 'aaaaaaaaa', 'aaaaaaaaabbbbbbbbbbcccccccccc']) \
+ .and_return( ['', 'a', 'a', 'abc'])
+ }
+ it {
+ is_expected.to run \
+ .with_params(['', 'a', 'aaaaaaaaa', 'aaaaaaaaabbbbbbbbbbcccccccccc'], 'a') \
+ .and_return( ['', 'a', 'a', 'abbbbbbbbbbcccccccccc'])
+ }
+ it {
+ is_expected.to run \
+ .with_params(['', 'a', 'aaaaaaaaa', 'aaaaaaaaabbbbbbbbbbcccccccccc'], 'b-c') \
+ .and_return( ['', 'a', 'aaaaaaaaa', 'aaaaaaaaabc'])
+ }
end
- it "should squeeze a string" do
- result = scope.function_squeeze(["aaabbbbcccc"])
- expect(result).to(eq('abc'))
- end
-
- it "should squeeze all elements in an array" do
- result = scope.function_squeeze([["aaabbbbcccc","dddfff"]])
- expect(result).to(eq(['abc','df']))
+ context 'when using a class extending String' do
+ it 'should call its squeeze method' do
+ value = AlsoString.new('aaaaaaaaa')
+ value.expects(:squeeze).returns('foo')
+ expect(subject).to run.with_params(value).and_return('foo')
+ end
end
end