On Mon, Mar 7, 2011 at 7:55 PM, Markus Roberts <[email protected]>wrote:
> Thinking about it though (and after looking at the code), do you need the
> little bit at the top there to be executed? Why can't you just do something
> like:
>
> Puppet::Util.expects(:execute).with { |command,options| ... }
>
>
This was the first approach I tried. There were three reasons it didn't
work very well:
1. Puppet::Util is a module, which means that Mocha can't stub it out
directly; you have to stub the individual classes that mix it in. That
means that you have to use e.g.
Puppet::Type::Mount::ProviderParsed.expects(:execute)..., which
unfortunately makes the test more fragile because it only stubs out calls to
Puppet::Util.execute() from that one particular class.
2. Puppet::Util.execute is very generous in the arguments it allows--the
"command" can be an arbitrarily nested array (which is automatically
flattened), and the "options" are an optional hash that has some parameters
filled in by default if they are not specified by the caller. If we stub
using Puppet::Util.expects(:execute), then our tests become sensitive to how
execute() is being called. Of course, in the long run I'd like to modify
execute() to be less permissive about the form of arguments it accepts, but
since it is part of the types and providers API, that's going to be a long
term project.
3. My primary purpose in creating this stubbing mechanism was to encourage
people to write better integration tests for types and providers, by putting
a simple state machine in the test that simulates the effect of the commands
executed by the provider. Mocha's mechanism for writing state machines it
quite clumsy, and after struggling with it for some time I realized that I
didn't want to subject other test writers to it.
> To be clear this time, I'm not proclaiming that I have a better answer,
> just expressing my hope that there is one.
Thanks, Markus. My feeling is that in this case there isn't, but I'm open
to further discussion. I'd be especially appreciative if you (or anyone
else) wanted to take a shot at writing some type and provider integration
tests using this mechanism, and see how well it works for you. So far I've
written four tests of the mount provider and discovered three bugs (see
subject line "Maint: Begin adding integration tests for the mount
provider").
--
You received this message because you are subscribed to the Google Groups
"Puppet Developers" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/puppet-dev?hl=en.