-
Notifications
You must be signed in to change notification settings - Fork 580
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
(#12345) hiera enabled function for stdlib #32
(#12345) hiera enabled function for stdlib #32
Conversation
adds ability to test if hiera is enabled in your environment
# rescue LoadError => e | ||
# false | ||
# end | ||
#true if Puppet.features.hiera? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Comments?
removing extraneous code that was commented out
Whoops! Thank Hunter, I removed those lines and added another commit. |
it "should fail if hiera is not installed" do | ||
Puppet.features.stubs(:hiera?).returns false | ||
Puppet::Parser::Functions.stubs(:function).with(:hiera).returns false | ||
@scope.function_hiera_enabled([]).should be_false |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that all the .stubs should be .expects - setup an expectation that the function call (or features call) IS made so that if that call is ever NOT made then you know something broke. As it stands now, we're saying "IF you call this function, just return false" when in reality we want to say "YES, this function SHOULD be called, AND it should return FALSE".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/.stubs/.expects and the first test now fails and I'm not sure why
"/opt/puppet/share/puppet/modules/stdlib/spec"
F...
Failures:
- function_hiera_enabled should fail if hiera is not installed
Failure/Error: Puppet::Parser::Functions.expects(:function).with(:hiera).returns false
Mocha::ExpectationError:
not all expectations were satisfied
unsatisfied expectations:
- expected exactly once, not yet invoked: Puppet::Parser::Functions.function(:hiera)
satisfied expectations:
- allowed any number of times, not yet invoked: Signal.trap(any_parameters)
- expected exactly once, invoked once: #Puppet::Util::Feature:0xb7c8190c.hiera?(any_parameters)
./spec/unit/puppet/parser/functions/hiera_enabled_spec.rb:15
Finished in 0.00799 seconds
4 examples, 1 failure
Failed examples:
rspec ./spec/unit/puppet/parser/functions/hiera_enabled_spec.rb:13 # function_hiera_enabled should fail if hiera is not installed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When this happens it's because the thing you're stubbing never actually receives a message. Switching the stub to an expectation means it will fail if it's never sent a message.
When this happens to me, it's almost always because the thing I thought I was calling isn't actually the thing being called.
Does this help?
Git HygieneGramatical MoodA few comments about good commit messages:
The first line should be imperative present tense. This is important because the output of RebasingIt's important to rebase commits before merging into the integration branch because once it's merged we can't re-write history. It's perfectly fine to re-write history in a topic branch though. I notice these two commits have the same summary line and the second appears to undo the first. This is a perfect place to squash them together and reword the commit message using the
This commit should be squashed into the commit where the typo was first introduced. It'll be like it never happened. You can use
The spec helper fixup in commit 85ea966 should be squashed into d54fa78 which is the commit that introduced the
Describe the behavior without the patch and with the patchIt's important to describe in the commit message the behavior of the code without a commit applied, with a commit applied and why the commit should be applied. Without this information people reading the commit log have much less information about why the change was introduced into the codebase. None of these commit messages describe the behavior with the patch, without the patch or why the patch should be applied: My recommendation is to commit 85ea966
commit 773cb47
commit 15c7137
commit a78cdf2
commit d54fa78
|
Spec TestsRegarding the tests themselves, I'm not confident they're testing the things you intend to test. I mentioned this the last time I reviewed this. Switching all of your
|
Unaddressed Review Comments@ghoneycutt These comments were made in the first review and remain unaddressed: |
end | ||
it "should fail if hiera is not installed but the function, hiera(), is available" do | ||
Puppet.features.stubs(:hiera?).returns false | ||
Puppet::Parser::Functions.stubs(:function).with(:hiera).returns true |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These stubs shouldn't actually return true
but instead a String
. It's important to match up the return value of a mocked object with what would actually be returned in code, otherwise we risk testing behaviors that will never happen in the real world.
A quick way to find out what would actually be returned from a real object rather than a mocked object is to drop into an interactive debugger right before setting up your mock. For example:
Does Puppet::Parser::Functions.function(:template)
return true
or some other object?
% rdebug -- rspec spec/unit/puppet/parser/functions/hiera_enabled_spec.rb
[4, 13] in /Users/jeff/.rvm/gems/ruby-1.8.7-p334@puppet/bin/rspec
4 #
5 # The application 'rspec-core' is installed as part of a gem, and
6 # this file is here to facilitate running it.
7 #
8
=> 9 require 'rubygems'
10
11 version = ">= 0"
12
13 if ARGV.first =~ /^_(.*)_$/ and Gem::Version.correct? $1 then
/Users/jeff/.rvm/gems/ruby-1.8.7-p334@puppet/bin/rspec:9
require 'rubygems'
(rdb:1) c
"/Users/jeff/vms/puppet/modules/stdlib/spec"
...[18, 26] in /Users/jeff/vms/puppet/modules/stdlib/spec/unit/puppet/parser/functions/hiera_enabled_spec.rb
18 @scope.function_hiera_enabled([]).should be_false
19 end
20 it "should succeed if hiera is installed and the function, hiera(), is available" do
21 Puppet.features.expects(:hiera?).returns true
22 debugger
=> 23 Puppet::Parser::Functions.expects(:function).with(:hiera).returns true
24 @scope.function_hiera_enabled([]).should be_true
25 end
26 end
/Users/jeff/vms/puppet/modules/stdlib/spec/unit/puppet/parser/functions/hiera_enabled_spec.rb:23
Puppet::Parser::Functions.expects(:function).with(:hiera).returns true
(rdb:1) Puppet::Parser::Functions.function(:template)
"function_template"
Ah, it looks like a valid function returns a string rather than true
. This tells me the mocked object isn't behaving like the real object since the mock is returning true
instead of the string.
@ghoneycutt Please ping code-reviewers once you've addressed this round of comments. I'm going to switch back to my other milestone deadlines and won't poll this pull request to see when it's ready to merge. |
@ghoneycutt Just wanted to follow up on this, we haven't cut a 2.3.x release for stdlib yet, but once we do this will likely be the version we ship in PE 2.5. If you'd like this new function to be included in PE 2.5 please try and address the comments and rebase the topic branch off of 2.3.x rather than master. |
Bump? |
@jeffmccune This PR is pretty old now, and since puppet 3 always includes hiera, I don't see a reason for putting this in. I suggest that we just close it down and reject the associated ticket. |
I'm going to go ahead and close this pull request for the time being. Please re-open this pull request once the next actions are addressed, new information is available, or you have a question related to this pull request. We've become aware of difficulties re-opening pull requests, in the event you cannot please mention jeffmccune or adrienthebo with an @ sign in front and we'll re-open this pull request. Closing the pull request doesn't mean we don't consider this change valuable, just that there are things that need to be addressed before it can be merged. If you have any questions or concerns, please don't hesitate to ping us in #puppet-dev on irc.freenode.net. |
adds ability to test if hiera is enabled in your environment