diff options
author | Chris Roberts <chrisroberts.code@gmail.com> | 2013-04-18 10:49:32 -0700 |
---|---|---|
committer | Chris Roberts <chrisroberts.code@gmail.com> | 2013-04-18 10:49:32 -0700 |
commit | 47a51f58bf8f84718e6cc2dbeaf21028b4d711d3 (patch) | |
tree | 169983c67b80364221b821c59a86401adb2f440e /spec | |
parent | 83e161811cbe483759790d737229efbca2f93021 (diff) | |
download | mixlib-cli-47a51f58bf8f84718e6cc2dbeaf21028b4d711d3.tar.gz |
Properly pass options during inheritance. Full dup to ensure proper option isolation.
Diffstat (limited to 'spec')
-rw-r--r-- | spec/mixlib/cli_spec.rb | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/spec/mixlib/cli_spec.rb b/spec/mixlib/cli_spec.rb index 39740b4..9175506 100644 --- a/spec/mixlib/cli_spec.rb +++ b/spec/mixlib/cli_spec.rb @@ -235,6 +235,42 @@ describe Mixlib::CLI do end + context "when subclassed" do + before do + TestCLI.options = {:arg1 => {:boolean => true}} + end + + it "should retain previously defined options from parent" do + class T1 < TestCLI + option :arg2, :boolean => true + end + T1.options[:arg1].should be_a(Hash) + T1.options[:arg2].should be_a(Hash) + TestCLI.options[:arg2].should be_nil + end + + it "should not be able to modify parent classes options" do + class T2 < TestCLI + option :arg2, :boolean => true + end + T2.options[:arg1][:boolean] = false + T2.options[:arg1][:boolean].should be_false + T1.options[:arg1][:boolean].should be_true + end + + it "should pass its options onto child" do + class T3 < TestCLI + option :arg2, :boolean => true + end + class T4 < T3 + option :arg3, :boolean => true + end + 3.times do |i| + T4.options["arg#{i + 1}".to_sym].should be_a(Hash) + end + end + end + end |