summaryrefslogtreecommitdiff
path: root/spec/unit/interface/action_spec.rb
AgeCommit message (Collapse)AuthorFilesLines
2013-03-26(Maint) Re-structure require statements to avoid loopAndrew Parker1-1/+1
The way in which the require statements for the puppet/interface module worked caused a dependency loop that could only be resolved by using the modules and classes in a very specific order. The tests showed this problem if they were run in a different order: /export/home/jenkins/workspace/Puppet Specs Solaris (master)/solaris10-i386/solaris10-i386/lib/puppet/interface/action_builder.rb:128: uninitialized constant Puppet::Interface::Action (NameError) from /opt/csw/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:36:in `gem_original_require' from /opt/csw/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:36:in `require' from /export/home/jenkins/workspace/Puppet Specs Solaris (master)/solaris10-i386/solaris10-i386/lib/puppet/interface/action_manager.rb:2 from /opt/csw/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:36:in `gem_original_require' from /opt/csw/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:36:in `require' from /export/home/jenkins/workspace/Puppet Specs Solaris (master)/solaris10-i386/solaris10-i386/lib/puppet/interface.rb:13 from /opt/csw/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:36:in `gem_original_require' from /opt/csw/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:36:in `require' from /export/home/jenkins/workspace/Puppet Specs Solaris (master)/solaris10-i386/solaris10-i386/lib/puppet/interface/action.rb:1 from /opt/csw/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:36:in `gem_original_require' from /opt/csw/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:36:in `require' from /export/home/jenkins/workspace/Puppet Specs Solaris (master)/solaris10-i386/solaris10-i386/spec/unit/interface/action_spec.rb:3 from /opt/csw/lib/ruby/gems/1.8/gems/rspec-core-2.9.0/lib/rspec/core/configuration.rb:746:in `load' from /opt/csw/lib/ruby/gems/1.8/gems/rspec-core-2.9.0/lib/rspec/core/configuration.rb:746:in `load_spec_files' from /opt/csw/lib/ruby/gems/1.8/gems/rspec-core-2.9.0/lib/rspec/core/configuration.rb:746:in `map' from /opt/csw/lib/ruby/gems/1.8/gems/rspec-core-2.9.0/lib/rspec/core/configuration.rb:746:in `load_spec_files' from /opt/csw/lib/ruby/gems/1.8/gems/rspec-core-2.9.0/lib/rspec/core/command_line.rb:22:in `run' from /opt/csw/lib/ruby/gems/1.8/gems/rspec-core-2.9.0/lib/rspec/core/runner.rb:69:in `run' from /opt/csw/lib/ruby/gems/1.8/gems/rspec-core-2.9.0/lib/rspec/core/runner.rb:10:in `autorun' from /opt/csw/bin/rspec:19 This re-orders the requires so that only the top level module (Puppet::Interface) requires all of the components that are part of it. Paired-with: patrick@puppetlabs.com
2012-09-26(Maint) Remove rspec from shebang lineJeff McCune1-1/+1
Without this patch Ruby 1.9 is still complaining loudly about trying to parse the spec files. The previous attempt to clean up this problem in edc3ddf works for Ruby 1.8 but not 1.9. I'd prefer to remove the shebang lines entirely, but doing so will cause encoding errors in Ruby 1.9. This patch strives for a happy middle ground of convincing Ruby it is actually working with Ruby while not confusing it to think it should exec() to rspec. This patch is the result of the following command run against the source tree: find spec -type f -print0 | \ xargs -0 perl -pl -i -e 's,^\#\!\s?/(.*)rspec,\#! /usr/bin/env ruby,'
2012-07-24Merge branch '2.7.x' into 3.xPatrick Carlisle1-3/+4
* 2.7.x: Use rspec 2.11 compatible block syntax Conflicts: spec/integration/faces/ca_spec.rb spec/integration/network/server/mongrel_spec.rb spec/unit/application_spec.rb spec/unit/face/help_spec.rb spec/unit/network/handler/fileserver_spec.rb spec/unit/parser/functions/create_resources_spec.rb spec/unit/provider/nameservice/directoryservice_spec.rb spec/unit/type/file_spec.rb spec/unit/type_spec.rb
2012-07-23Use rspec 2.11 compatible block syntaxPatrick Carlisle1-3/+4
In rspec 2.11, expectations on a block must take the form of expect...to or lambda...should. Other combinations of those are no longer accepted. This commit converts all mixed cases to use expect...to, as it seems to be the preferred syntax now.
2012-07-02(maint) Standardize on /usr/bin/env ruby -S rspecJeff McCune1-1/+1
Without this patch some spec files are using `ruby -S rspec` and others are using `rspec`. We should standardize on a single form of the interpreter used for spec files. `ruby -S rspec` is the best choice because it correctly informs editors such as Vim with Syntastic that the file is a Ruby file rather than an Rspec file.
2011-07-28(#8690) Accept 'global' options in Puppet FacesDaniel Pittman1-1/+7
When we introduced verification of options, we forgot to handle the case that global options from the Puppet settings system could be passed to the face. This, in turn, means that the system would fail if you used any of those. This remediates that, and now these work as expected. Reviewed-By: Pieter van de Bruggen <pieter@puppetlabs.com>
2011-07-22(#8561, #7290) Implement the option contract fully.Daniel Pittman1-5/+6
Rewrite the process of validating and updating the options to fully reflect the contract - we fail if there are unknown options passed, report nicely errors of duplicate names, pass only the canonical names to the action code, and generally enforce nicely. Reviewed-By: Pieter van de Bruggen <pieter@puppetlabs.com>
2011-07-22(#8561) Unify validation and modification of action arguments.Daniel Pittman1-3/+3
Rather than having multiple, separate operations that modify and validate the arguments to an action, a single pass makes sense. This also means less walks across the set of data, and a few less expensive method calls in Ruby. Additionally, we work on a duplicate of the arguments hash rather than directly modifying the original. Because everything we do is at the top level key/value mapping, this is sufficient to isolate the original. While mostly theoretical, we now don't mutilate the hash passed in, so the user won't get nastily surprised by the fact that we could have done so. Reviewed-By: Pieter van de Bruggen <pieter@puppetlabs.com>
2011-07-22(#7290) Fail on unknown options.Daniel Pittman1-0/+10
Part of the "social contract" of Faces, Actions and Options is that the metadata we collect is authoritative: it covers everything that is possible. In the initial release we didn't enforce that around options. If you passed an unknown option in the hash, we just silently ignored it in validation and made it available down in the action. Now, instead, we enforce that rule. If you pass an unknown option we raise an error and complain; anything that gets to the action will be listed in the set of inspectable options. Cases that depended on this behaviour to pass arbitrary content in the hash should be rewritten to move that content down a level: take a hash value for one option, and use that for your free content. Reviewed-By: Pieter van de Bruggen <pieter@puppetlabs.com>
2011-07-22(#8561) Use canonical names for options to actions.Daniel Pittman1-6/+20
When we invoke an action, we parse a set of options. These have a canonical name, and optionally a set of aliases. For example, :bar might have :b as an alias to allow a short name to be given. Previously we would just pass this on as received; if you passed :bar you got :bar, and if you passed :b you got :b. This works, but means that every action has to write the same code to extract the appropriate version of an option from whatever set of aliases might be passed. Now, instead, we centralize that and always pass options as their canonical name to the action code. This makes it simpler to work with. (This happens before any validation, or other user-supplied, code to simplify everything that handles options.) Reviewed-By: Pieter van de Bruggen <pieter@puppetlabs.com>
2011-07-20(#7123) Support runtime setting of 'default' on actions.Daniel Pittman1-0/+18
Given the inheritance model for actions, we are sometimes going to need to set them to 'default' at runtime, rather than during their static declaration. Add tests to verify that this works correctly, and update the code to ensure that happens. This gives up caching of the default action, but this should be an extremely rare operation - pretty much only CLI invocation, really. Reviewed-By: Pieter van de Bruggen <pieter@puppetlabs.com>
2011-07-20(#6787) Add `default_to` for options.Daniel Pittman1-0/+45
This implement support for options with default values, allowing faces to set those values when not invoked. This can eliminate substantial duplicate code from actions, especially when there are face-level options in use. Reviewed-By: Pieter van de Bruggen <pieter@puppetlabs.com>
2011-07-13(#7699) Help command should only list options onceDan Bode1-0/+10
The problem was caused by the fact that the options method returns a list of options that treated the aliases as seperate options. The fix is to only maintain a list of options and not add all aliases to the options list.
2011-07-10Revert "Merge branch 'ticket/2.7.x/7699_fix_help_listing_options_twice' into ↵Jeff McCune1-9/+0
2.7.x" This reverts commit b7ee0258ab40478329c20177eda9b250f27ede18, reversing changes made to 8fe2e555ac3d57f5b6503ffe1a5466db8d6e190a.
2011-07-10(#7699) - Help should only show options onceDan Bode1-0/+9
puppet help was reprinting every option once for every alias that is had. This fix involves only storing the option.name in the @options instance var for both face and actions options. The @options_hash still maintains the list of options and aliases as its keys. Reviewed-by: Daniel Pittman (puppet-dev list)
2011-05-17(#7507) Fix when_invoked action specs in Ruby 1.9Matt Robinson1-30/+29
Ruby 1.9 is strict about argument arity for methods that are metaprogrammatically defined. A ton of specs that were setting up when_invoked didn't pass options even though they should have been. Reviewed-by: Daniel Pittman <daniel@puppetlabs.com>
2011-05-02Merge branch 'bug/2.7.x/7282-fail-when-no-invocation-given-for-action' into ↵Daniel Pittman1-6/+18
2.7.x
2011-05-02(#7282) action without `when_invoked` should fail...Daniel Pittman1-6/+18
We used to let actions be declared without the `when_invoked` block, which was usually a sign of either someone writing their method code direct in action declaration, or someone forgetting to add their code at all. This was just let silently by: the error only showed up when you finally tried to invoke the action, and a NoMethod error was raised by the face. ...except for our own testing. We took advantage of this a whole pile of times in there; fixing the original UI issue means fixing all those too. Reviewed-By: Nick Lewis <nick@puppetlabs.com>
2011-04-29(Maint.) Fix accidental debug output in tests.Pieter van de Bruggen1-1/+1
Reviewed-By: Daniel Pittman
2011-04-29Merge branch 'tickets/2.7.x/7289' into 2.7.xPieter van de Bruggen1-109/+176
2011-04-29(#7248) Fail if two aliases of one option are passed...Daniel Pittman1-0/+19
From the command line, and other facades, it is fairly difficult to call an action with two aliases of the same option in the invocation, but from the Ruby API it would be relatively easy to achieve. This is now checked, and raises an error, so that we don't accidentally have strange or unusual behaviour coming out of the whole system. Reviewed-By: Pieter van de Bruggen <pieter@puppetlabs.com>
2011-04-29(#7289) Specify order for option decorations.Pieter van de Bruggen1-109/+176
`before_action` decorations should always resolve in resolution order from most general (inherited from furthest away) to most specific (declared on the instance), and should always execute Face-level option decorations before action-level option decorations. `after_action` decorations should execute in the opposite order. Reviewed-By: Daniel Pittman
2011-04-26(#7251) Let exceptions raised in decorators rise.Pieter van de Bruggen1-2/+2
This allows users to write before_action advice that does basic option validation very easily. Reviewed-By: Daniel Pittman
2011-04-20(#7062) better argument handling in the action wrapper methodsDaniel Pittman1-0/+56
We previously used *args to collect all arguments to the action when_invoked block, then tried vaguely to massage some little bits of them into the right shape. Methods defined with blocks, in Ruby 1.8, also have some fun behaviours. The most special is that if you pass more than one argument to a block defined with only one Ruby will automatically coerce the arguments into an array – and this is preserved when it is bound to a method. This led to routine situations where we would pass the wrong number of arguments to the block because, say, the user gave an extra argument on the command line. Instead of failing this would transmogrify the arguments in counterintuitive ways, and end up with horrible stack traces when that interacted badly with the code as written. Now, instead, we work out the right argument format based on the arguments that the when_invoked block takes. This gives much better (albeit perhaps not so user friendly) behaviour at the interface level. Which is, at least, consistent with other Ruby API. Reviewed-By: Max Martin <max@puppetlabs.com>
2011-04-19Merge branch 'bug/2.7.x/6752-allow-action-specific-render-methods'Daniel Pittman1-0/+9
Fix the conflicts over changes in my previous commit.
2011-04-19(#7013) Support 'when_rendering' and 'render_as' in actions.Daniel Pittman1-0/+9
These define the API used by folks writing actions that supports their rendering hooks. 'when_rendering' defines a helper method on the interface, which runs the users code in their expected context. 'render_as' just sets the default rendering format; by default this is :for_humans. Reviewed-By: Max Martin <max@puppetlabs.com>
2011-04-19Merge branch 'bug/2.7.x/7132-a-summary-with-a-newline-is-accepted' into 2.7.xDaniel Pittman1-0/+9
2011-04-19(#6962) Add 'description' to faces and action.Daniel Pittman1-20/+1
This adds the 'description' method to the faces and actions, as well as structured testing to ensure that the DSL works as expected. Reviewed-By: Max Martin <max@puppetlabs.com>
2011-04-19(#7132) Reject 'summary' text with newlines embedded.Daniel Pittman1-0/+28
Our summary documentation is used to provide single-line context to faces, actions, and other items. To support this we hard-fail if someone tries to use the summary to embed the long documentation, and point them to the right place to add the extended text. Reviewed-By: Max Martin <max@puppetlabs.com>
2011-04-17(#7013) Add support for required options.Pieter van de Bruggen1-2/+25
This adds another hook into the generated wrapper, which invokes a method to validate arguments. This is used to raise an exception when required options have not been passed to the method. Reviewed-By: Daniel Pittman <daniel@puppetlabs.com>
2011-04-15(#6978) Enforce the calling convention of option hooks.Daniel Pittman1-13/+21
We require that hooks take exactly three arguments; now we enforce that in the DSL, to ensure we give good, and early, errors to users who do the wrong thing. Paired-With: Max Martin <max@puppetlabs.com>
2011-04-15(#6978) Add before and after decorators to actions from options.Daniel Pittman1-1/+172
Options can now add before_action and after_action blocks; these are invoked before or after any action is invoked on the face. This allows these options to declare common behaviour and have it automatically applied to the actions invoked. Option hooks have no defined order of invocation: they will run in a completely random order. Where there are dependencies they should be on the value of the options hash passed to the invocation, not on side-effects of the other invocations. You are not able to influence the arguments, options, or calling of the action body in a before or after decorator. This is by design. The invocation passes to the hook: 1. The action object representing this action. 2. The arguments to the action, as an array. 3. The options for the action, as a hash. Paired-With: Max Martin <max@puppetlabs.com>
2011-04-13maint: clean up the spec test headers in bulk.Daniel Pittman1-2/+1
We now use a shebang of: #!/usr/bin/env rspec This enables the direct execution of spec tests again, which was lost earlier during the transition to more directly using the rspec2 runtime environment.
2011-04-08maint: just require 'spec_helper', thanks rspec2Daniel Pittman1-1/+1
rspec2 automatically sets a bunch of load-path stuff we were by hand, so we can just stop. As a side-effect we can now avoid a whole pile of stupid things to try and include the spec_helper.rb file... ...and then we can stop protecting spec_helper from evaluating twice, since we now require it with a consistent name. Yay. Reviewed-By: Pieter van de Bruggen <pieter@puppetlabs.com>
2011-04-07(#7012) Split plumbing into Puppet::InterfaceDaniel Pittman1-0/+173
This splits out the plumbing into the Puppet::Interface namespace, and uses Puppet::Faces for all the public-facing code. The fault line is "what you care about if you are using or writing a face", which is public, against "what you care about to enable either of those two", which is the plumbing.
2011-03-28MAINT: the API is officially named "string" as of this moment.Daniel Pittman1-75/+0
Now that we have settled on the final public name for the API, "Puppet::String", mass-rename and mass-edit all the files to follow. Reviewed-By: Randall Hansen <randall@puppetlabs.com>
2011-03-25(#6770) Refactor Puppet::Interface#initialize.Pieter van de Bruggen1-2/+2
P::I#initialize now takes a name and a version (and an optional block). The options hash has been removed, though it may be reintroduced if a legitimate use case can be made for it (so far, it's only been used for the version number). Reviewed-By: Jacob Helwig
2011-03-23(#6770) Changing versioning to semver.Pieter van de Bruggen1-2/+2
More information about the versioning scheme can be found at http://semver.org. Paired-With: Nick Lewis
2011-03-23(#6770) Add basic versioning for interfaces.Pieter van de Bruggen1-2/+2
Reviewed-By: Nick Lewis
2011-03-22(#6814) Create a dedicated Action classNick Lewis1-0/+75
This class will represents an action, and allows us to store metadata for an action, and programmatically introspect and invoke them. A helper class ActionBuilder represents the DSL for defining an action. Also defined an "invoke" DSL method to handle the functionality of defining the method for an action. Reviewed-By: Daniel Pittman