Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added ability to transform an option (to_i, to_f, etc.)
- Loading branch information
Showing
2 changed files
with
103 additions
and
3 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
describe NagiosCheck do | ||
context "when no options specified" do | ||
subject do | ||
Class::new do | ||
include NagiosCheck | ||
end.new | ||
end | ||
|
||
specify { subject.send :parse_options, [] } | ||
end | ||
|
||
context "when warning is specified" do | ||
subject do | ||
Class::new do | ||
include NagiosCheck | ||
enable_warning | ||
end.new | ||
end | ||
|
||
it("works with no arguments"){ subject.send :parse_options, %w{} } | ||
specify { subject.send :parse_options, %w{-w 10} } | ||
|
||
it "fails if -w has no argument" do | ||
lambda { | ||
subject.send :parse_options, %w{-w} | ||
}.should raise_error(OptionParser::MissingArgument) | ||
end | ||
it "fails if -c is given" do | ||
lambda { | ||
subject.send :parse_options, %w{-c} | ||
}.should raise_error(OptionParser::InvalidOption) | ||
end | ||
end | ||
|
||
context "when critical is specified" do | ||
subject do | ||
Class::new do | ||
include NagiosCheck | ||
enable_critical | ||
end.new | ||
end | ||
|
||
it("works with no arguments"){ subject.send :parse_options, %w{} } | ||
specify { subject.send :parse_options, %w{-c 10} } | ||
|
||
it "fails if -c has no argument" do | ||
lambda { | ||
subject.send :parse_options, %w{-c} | ||
}.should raise_error(OptionParser::MissingArgument) | ||
end | ||
|
||
it "fails if -w is given" do | ||
lambda { | ||
subject.send :parse_options, %w{-w} | ||
}.should raise_error(OptionParser::InvalidOption) | ||
end | ||
end | ||
|
||
context "when a non mandatory option is specified" do | ||
subject do | ||
Class::new do | ||
include NagiosCheck | ||
on "-a VALUE", &store(:a) | ||
on "-b VALUE", &store(:b, transform: :to_i) | ||
end.new | ||
end | ||
|
||
it("works with no arguments"){ subject.send :parse_options, %w{} } | ||
|
||
it "works with '-a 10'" do | ||
subject.send :parse_options, %w{-a 10} | ||
subject.options.a.should == "10" | ||
end | ||
|
||
it "works with '-b 20' and converts to int" do | ||
subject.send :parse_options, %w{-b 20} | ||
subject.options.b.should == 20 | ||
end | ||
|
||
it "fails if -a has no argument" do | ||
lambda { | ||
subject.send :parse_options, %w{-a} | ||
}.should raise_error(OptionParser::MissingArgument) | ||
end | ||
|
||
it "fails if -w is given" do | ||
lambda { | ||
subject.send :parse_options, %w{-w} | ||
}.should raise_error(OptionParser::InvalidOption) | ||
end | ||
end | ||
end |