Created
December 6, 2013 00:19
-
-
Save glarizza/7816581 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # <modulepath>/custom_functions/spec/unit/puppet/parser/functions/extract_spec.rb | |
| require 'puppet' | |
| require 'rspec-puppet' | |
| describe Puppet::Parser::Functions.function(:extract) do | |
| let :scope do | |
| PuppetlabsSpec::PuppetInternals.scope | |
| end | |
| let(:email) { '[email protected]' } | |
| let(:path) { '/fake/path/to/file' } | |
| let(:yaml) { { 'foo' => email } } | |
| it "should call YAML.load_file to read from a file" do | |
| YAML.expects(:load_file).with(path).returns(yaml) | |
| scope.function_extract([path, 'foo']) | |
| end | |
| it "should extract yaml data from a file and return the correct value for a key" do | |
| YAML.stubs(:load_file).with(path).returns(yaml) | |
| scope.function_extract([path, 'foo']).should == email | |
| end | |
| it "should return nil if a value wasn't found" do | |
| YAML.stubs(:load_file).with(path).returns(yaml) | |
| scope.function_extract([path, 'notfound']).should == nil | |
| end | |
| it "should raise an error if you don't pass two arguments" do | |
| expect { scope.function_extract(['/bad/fail']) }.to raise_error Puppet::Error, /#extract: accepts only two arguments/ | |
| end | |
| it "should raise an error if the YAML file wasn't found" do | |
| expect { scope.function_extract(['/bad/fail', 'key']) }.to raise_error Puppet::Error, /#extract: file \/bad\/fail not found, please try again/ | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment