diff options
| author | Daniel Pittman <daniel@puppetlabs.com> | 2011-04-28 00:04:00 -0700 |
|---|---|---|
| committer | Daniel Pittman <daniel@puppetlabs.com> | 2011-04-28 10:51:05 -0700 |
| commit | 632a0a0042ebf2e7ef209ce30005833ccee6e77b (patch) | |
| tree | 124ebc6761561c0d94f9a314e1a169aae90a8355 /spec/unit | |
| parent | 80adaea6319b2aca81fd3d9b1d0061152b6c7db2 (diff) | |
| download | puppet-632a0a0042ebf2e7ef209ce30005833ccee6e77b.tar.gz puppet-632a0a0042ebf2e7ef209ce30005833ccee6e77b.tar.xz puppet-632a0a0042ebf2e7ef209ce30005833ccee6e77b.zip | |
(#7269) Better error reporting for bad render formats.
Previously we would try and send `nil` to a class to render an unsupported
format, which was bad. Worse, we would only discover this *after* the fact,
when we tried to render, so the entire action had run and the result was lost
to the world.
Instead, validate the parameter early and fail during option parsing. This
has less nice error reporting than we can get handling it later[1], but it
gets us a much better overall set of behaviour.
[1] puppet/application.rb will print and exit, rather than raising, when the
option handler fails; this will improve when we unify face and application
options properly.
Reviewed-By: Max Martin <max@puppetlabs.com>
Diffstat (limited to 'spec/unit')
| -rwxr-xr-x | spec/unit/application/face_base_spec.rb | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/spec/unit/application/face_base_spec.rb b/spec/unit/application/face_base_spec.rb index e84e6766f..0c75236f8 100755 --- a/spec/unit/application/face_base_spec.rb +++ b/spec/unit/application/face_base_spec.rb @@ -304,5 +304,18 @@ EOT json.should =~ /"two":\s*2\b/ PSON.parse(json).should == { "one" => 1, "two" => 2 } end + + it "should fail early if asked to render an invalid format" do + app.command_line.stubs(:args).returns %w{--render-as interpretive-dance help help} + # We shouldn't get here, thanks to the exception, and our expectation on + # it, but this helps us fail if that slips up and all. --daniel 2011-04-27 + Puppet::Face[:help, :current].expects(:help).never + + # ...and this is just annoying. Thanks, puppet/application.rb. + $stderr.expects(:puts). + with "Could not parse options: I don't know how to render 'interpretive-dance'" + + expect { app.run }.to exit_with 1 + end end end |
