diff options
author | Thom May <thom@may.lt> | 2016-05-04 18:45:17 +0100 |
---|---|---|
committer | Thom May <thom@may.lt> | 2016-05-04 18:45:17 +0100 |
commit | d4a68ec78296443a2a08495de18c7a944d30dd71 (patch) | |
tree | 4cf178ec12c1ff73ab24f9d251e28dae4a4c76cd /spec | |
parent | ce357df7c2e418fc7543a1a4f105e8edbf35f6f8 (diff) | |
parent | a32834ee7755b6668047af4683c4384fb45c93ab (diff) | |
download | mixlib-cli-d4a68ec78296443a2a08495de18c7a944d30dd71.tar.gz |
Merge pull request #13 from chrisroberts/enhancement/option-inheritance
[MIXLIB-14] Option inheritance
Diffstat (limited to 'spec')
-rw-r--r-- | spec/mixlib/cli_spec.rb | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/spec/mixlib/cli_spec.rb b/spec/mixlib/cli_spec.rb index cd07435..034fe25 100644 --- a/spec/mixlib/cli_spec.rb +++ b/spec/mixlib/cli_spec.rb @@ -262,6 +262,54 @@ 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 + TestCLI.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 + + it "should also work with an option that's an array" do + class T5 < TestCLI + option :arg2, :default => [] + end + + class T6 < T5 + end + + T6.options[:arg2].should be_a(Hash) + end + + end + end # option :config_file, |