Update stdlib and concat to 6.1.0 both
[mirror/dsa-puppet.git] / 3rdparty / modules / stdlib / spec / functions / bool2num_spec.rb
old mode 100755 (executable)
new mode 100644 (file)
index 3904d7e..7402f3a
@@ -1,38 +1,18 @@
-#! /usr/bin/env ruby -S rspec
 require 'spec_helper'
 
-describe "the bool2num function" do
-  let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
+describe 'bool2num' do
+  it { is_expected.not_to eq(nil) }
+  it { is_expected.to run.with_params.and_raise_error(Puppet::ParseError) }
 
-  it "should exist" do
-    expect(Puppet::Parser::Functions.function("bool2num")).to eq("function_bool2num")
+  [true, 'true', 't', '1', 'y', 'yes', AlsoString.new('true')].each do |truthy|
+    it { is_expected.to run.with_params(truthy).and_return(1) }
   end
 
-  it "should raise a ParseError if there is less than 1 arguments" do
-    expect { scope.function_bool2num([]) }.to( raise_error(Puppet::ParseError))
+  [false, 'false', 'f', '0', 'n', 'no', AlsoString.new('false')].each do |falsey|
+    it { is_expected.to run.with_params(falsey).and_return(0) }
   end
 
-  it "should convert true to 1" do
-    result = scope.function_bool2num([true])
-    expect(result).to(eq(1))
-  end
-
-  it "should convert 'true' to 1" do
-    result = scope.function_bool2num(['true'])
-    result.should(eq(1))
-  end
-
-  it "should convert 'false' to 0" do
-    result = scope.function_bool2num(['false'])
-    expect(result).to(eq(0))
-  end
-
-  it "should accept objects which extend String" do
-    class AlsoString < String
-    end
-
-    value = AlsoString.new('true')
-    result = scope.function_bool2num([value])
-    result.should(eq(1))
+  [[], 10, 'invalid', 1.0].each do |falsey|
+    it { is_expected.to run.with_params(falsey).and_raise_error(Puppet::ParseError) }
   end
 end