thor 0.16.0 → 0.17.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of thor might be problematic. Click here for more details.
- data/.rspec +1 -0
 - data/.travis.yml +2 -1
 - data/CHANGELOG.rdoc +8 -0
 - data/Gemfile +12 -8
 - data/lib/thor.rb +79 -10
 - data/lib/thor/actions.rb +13 -13
 - data/lib/thor/actions/directory.rb +29 -10
 - data/lib/thor/actions/file_manipulation.rb +8 -2
 - data/lib/thor/base.rb +24 -11
 - data/lib/thor/core_ext/hash_with_indifferent_access.rb +5 -0
 - data/lib/thor/group.rb +5 -5
 - data/lib/thor/parser/options.rb +63 -25
 - data/lib/thor/rake_compat.rb +3 -2
 - data/lib/thor/runner.rb +1 -1
 - data/lib/thor/shell/basic.rb +16 -16
 - data/lib/thor/shell/color.rb +9 -9
 - data/lib/thor/shell/html.rb +9 -9
 - data/lib/thor/task.rb +2 -2
 - data/lib/thor/version.rb +1 -1
 - data/spec/actions/create_file_spec.rb +30 -30
 - data/spec/actions/create_link_spec.rb +12 -12
 - data/spec/actions/directory_spec.rb +34 -27
 - data/spec/actions/empty_directory_spec.rb +16 -16
 - data/spec/actions/file_manipulation_spec.rb +62 -50
 - data/spec/actions/inject_into_file_spec.rb +18 -18
 - data/spec/actions_spec.rb +56 -56
 - data/spec/base_spec.rb +69 -69
 - data/spec/core_ext/hash_with_indifferent_access_spec.rb +19 -14
 - data/spec/core_ext/ordered_hash_spec.rb +29 -29
 - data/spec/exit_condition_spec.rb +3 -3
 - data/spec/fixtures/preserve/script.sh +3 -0
 - data/spec/fixtures/script.thor +5 -0
 - data/spec/group_spec.rb +55 -55
 - data/spec/invocation_spec.rb +26 -26
 - data/spec/parser/argument_spec.rb +12 -12
 - data/spec/parser/arguments_spec.rb +12 -12
 - data/spec/parser/option_spec.rb +47 -47
 - data/spec/parser/options_spec.rb +137 -72
 - data/spec/rake_compat_spec.rb +11 -11
 - data/spec/register_spec.rb +70 -8
 - data/spec/runner_spec.rb +38 -38
 - data/spec/shell/basic_spec.rb +49 -37
 - data/spec/shell/color_spec.rb +13 -13
 - data/spec/shell/html_spec.rb +3 -3
 - data/spec/shell_spec.rb +7 -7
 - data/spec/spec_helper.rb +4 -0
 - data/spec/task_spec.rb +11 -11
 - data/spec/thor_spec.rb +161 -91
 - data/spec/util_spec.rb +42 -42
 - data/thor.gemspec +1 -7
 - metadata +8 -118
 - data/lib/thor/core_ext/dir_escape.rb +0 -0
 
| 
         @@ -7,37 +7,42 @@ describe Thor::CoreExt::HashWithIndifferentAccess do 
     | 
|
| 
       7 
7 
     | 
    
         
             
              end
         
     | 
| 
       8 
8 
     | 
    
         | 
| 
       9 
9 
     | 
    
         
             
              it "has values accessible by either strings or symbols" do
         
     | 
| 
       10 
     | 
    
         
            -
                @hash['foo']. 
     | 
| 
       11 
     | 
    
         
            -
                @hash[:foo]. 
     | 
| 
      
 10 
     | 
    
         
            +
                expect(@hash['foo']).to eq('bar')
         
     | 
| 
      
 11 
     | 
    
         
            +
                expect(@hash[:foo]).to eq('bar')
         
     | 
| 
       12 
12 
     | 
    
         | 
| 
       13 
     | 
    
         
            -
                @hash.values_at(:foo, :baz). 
     | 
| 
       14 
     | 
    
         
            -
                @hash.delete(:foo). 
     | 
| 
      
 13 
     | 
    
         
            +
                expect(@hash.values_at(:foo, :baz)).to eq(['bar', 'bee'])
         
     | 
| 
      
 14 
     | 
    
         
            +
                expect(@hash.delete(:foo)).to eq('bar')
         
     | 
| 
       15 
15 
     | 
    
         
             
              end
         
     | 
| 
       16 
16 
     | 
    
         | 
| 
       17 
17 
     | 
    
         
             
              it "handles magic boolean predicates" do
         
     | 
| 
       18 
     | 
    
         
            -
                @hash.force 
     | 
| 
       19 
     | 
    
         
            -
                @hash.foo 
     | 
| 
       20 
     | 
    
         
            -
                @hash.nothing 
     | 
| 
      
 18 
     | 
    
         
            +
                expect(@hash.force?).to be_true
         
     | 
| 
      
 19 
     | 
    
         
            +
                expect(@hash.foo?).to be_true
         
     | 
| 
      
 20 
     | 
    
         
            +
                expect(@hash.nothing?).to be_false
         
     | 
| 
       21 
21 
     | 
    
         
             
              end
         
     | 
| 
       22 
22 
     | 
    
         | 
| 
       23 
23 
     | 
    
         
             
              it "handles magic comparisions" do
         
     | 
| 
       24 
     | 
    
         
            -
                @hash.foo?('bar'). 
     | 
| 
       25 
     | 
    
         
            -
                @hash.foo?('bee'). 
     | 
| 
      
 24 
     | 
    
         
            +
                expect(@hash.foo?('bar')).to be_true
         
     | 
| 
      
 25 
     | 
    
         
            +
                expect(@hash.foo?('bee')).to be_false
         
     | 
| 
       26 
26 
     | 
    
         
             
              end
         
     | 
| 
       27 
27 
     | 
    
         | 
| 
       28 
28 
     | 
    
         
             
              it "maps methods to keys" do
         
     | 
| 
       29 
     | 
    
         
            -
                @hash.foo. 
     | 
| 
      
 29 
     | 
    
         
            +
                expect(@hash.foo).to eq(@hash['foo'])
         
     | 
| 
       30 
30 
     | 
    
         
             
              end
         
     | 
| 
       31 
31 
     | 
    
         | 
| 
       32 
32 
     | 
    
         
             
              it "merges keys independent if they are symbols or strings" do
         
     | 
| 
       33 
33 
     | 
    
         
             
                @hash.merge!('force' => false, :baz => "boom")
         
     | 
| 
       34 
     | 
    
         
            -
                @hash[:force]. 
     | 
| 
       35 
     | 
    
         
            -
                @hash[:baz]. 
     | 
| 
      
 34 
     | 
    
         
            +
                expect(@hash[:force]).to eq(false)
         
     | 
| 
      
 35 
     | 
    
         
            +
                expect(@hash[:baz]).to eq("boom")
         
     | 
| 
       36 
36 
     | 
    
         
             
              end
         
     | 
| 
       37 
37 
     | 
    
         | 
| 
       38 
38 
     | 
    
         
             
              it "creates a new hash by merging keys independent if they are symbols or strings" do
         
     | 
| 
       39 
39 
     | 
    
         
             
                other = @hash.merge('force' => false, :baz => "boom")
         
     | 
| 
       40 
     | 
    
         
            -
                other[:force]. 
     | 
| 
       41 
     | 
    
         
            -
                other[:baz]. 
     | 
| 
      
 40 
     | 
    
         
            +
                expect(other[:force]).to eq(false)
         
     | 
| 
      
 41 
     | 
    
         
            +
                expect(other[:baz]).to eq("boom")
         
     | 
| 
      
 42 
     | 
    
         
            +
              end
         
     | 
| 
      
 43 
     | 
    
         
            +
             
     | 
| 
      
 44 
     | 
    
         
            +
              it "converts to a traditional hash" do
         
     | 
| 
      
 45 
     | 
    
         
            +
                expect(@hash.to_hash.class).to eq(Hash)
         
     | 
| 
      
 46 
     | 
    
         
            +
                expect(@hash).to eq({ 'foo' => 'bar', 'baz' => 'bee', 'force' => true })
         
     | 
| 
       42 
47 
     | 
    
         
             
              end
         
     | 
| 
       43 
48 
     | 
    
         
             
            end
         
     | 
| 
         @@ -8,7 +8,7 @@ describe Thor::CoreExt::OrderedHash do 
     | 
|
| 
       8 
8 
     | 
    
         | 
| 
       9 
9 
     | 
    
         
             
              describe "without any items" do
         
     | 
| 
       10 
10 
     | 
    
         
             
                it "returns nil for an undefined key" do
         
     | 
| 
       11 
     | 
    
         
            -
                  @hash["foo"]. 
     | 
| 
      
 11 
     | 
    
         
            +
                  expect(@hash["foo"]).to be_nil
         
     | 
| 
       12 
12 
     | 
    
         
             
                end
         
     | 
| 
       13 
13 
     | 
    
         | 
| 
       14 
14 
     | 
    
         
             
                it "doesn't iterate through any items" do
         
     | 
| 
         @@ -16,12 +16,12 @@ describe Thor::CoreExt::OrderedHash do 
     | 
|
| 
       16 
16 
     | 
    
         
             
                end
         
     | 
| 
       17 
17 
     | 
    
         | 
| 
       18 
18 
     | 
    
         
             
                it "has an empty key and values list" do
         
     | 
| 
       19 
     | 
    
         
            -
                  @hash.keys. 
     | 
| 
       20 
     | 
    
         
            -
                  @hash.values. 
     | 
| 
      
 19 
     | 
    
         
            +
                  expect(@hash.keys).to be_empty
         
     | 
| 
      
 20 
     | 
    
         
            +
                  expect(@hash.values).to be_empty
         
     | 
| 
       21 
21 
     | 
    
         
             
                end
         
     | 
| 
       22 
22 
     | 
    
         | 
| 
       23 
23 
     | 
    
         
             
                it "must be empty" do
         
     | 
| 
       24 
     | 
    
         
            -
                  @hash. 
     | 
| 
      
 24 
     | 
    
         
            +
                  expect(@hash).to be_empty
         
     | 
| 
       25 
25 
     | 
    
         
             
                end
         
     | 
| 
       26 
26 
     | 
    
         
             
              end
         
     | 
| 
       27 
27 
     | 
    
         | 
| 
         @@ -35,15 +35,15 @@ describe Thor::CoreExt::OrderedHash do 
     | 
|
| 
       35 
35 
     | 
    
         
             
                end
         
     | 
| 
       36 
36 
     | 
    
         | 
| 
       37 
37 
     | 
    
         
             
                it "returns nil for an undefined key" do
         
     | 
| 
       38 
     | 
    
         
            -
                  @hash[:boom]. 
     | 
| 
      
 38 
     | 
    
         
            +
                  expect(@hash[:boom]).to be_nil
         
     | 
| 
       39 
39 
     | 
    
         
             
                end
         
     | 
| 
       40 
40 
     | 
    
         | 
| 
       41 
41 
     | 
    
         
             
                it "returns the value for each key" do
         
     | 
| 
       42 
     | 
    
         
            -
                  @hash[:foo]. 
     | 
| 
       43 
     | 
    
         
            -
                  @hash[:bar]. 
     | 
| 
       44 
     | 
    
         
            -
                  @hash[:baz]. 
     | 
| 
       45 
     | 
    
         
            -
                  @hash[:bop]. 
     | 
| 
       46 
     | 
    
         
            -
                  @hash[:bat]. 
     | 
| 
      
 42 
     | 
    
         
            +
                  expect(@hash[:foo]).to eq("Foo!")
         
     | 
| 
      
 43 
     | 
    
         
            +
                  expect(@hash[:bar]).to eq("Bar!")
         
     | 
| 
      
 44 
     | 
    
         
            +
                  expect(@hash[:baz]).to eq("Baz!")
         
     | 
| 
      
 45 
     | 
    
         
            +
                  expect(@hash[:bop]).to eq("Bop!")
         
     | 
| 
      
 46 
     | 
    
         
            +
                  expect(@hash[:bat]).to eq("Bat!")
         
     | 
| 
       47 
47 
     | 
    
         
             
                end
         
     | 
| 
       48 
48 
     | 
    
         | 
| 
       49 
49 
     | 
    
         
             
                it "iterates through the keys and values in order of assignment" do
         
     | 
| 
         @@ -51,27 +51,27 @@ describe Thor::CoreExt::OrderedHash do 
     | 
|
| 
       51 
51 
     | 
    
         
             
                  @hash.each do |key, value|
         
     | 
| 
       52 
52 
     | 
    
         
             
                    arr << [key, value]
         
     | 
| 
       53 
53 
     | 
    
         
             
                  end
         
     | 
| 
       54 
     | 
    
         
            -
                  arr. 
     | 
| 
       55 
     | 
    
         
            -
                                 [:bop, "Bop!"], [:bat, "Bat!"]]
         
     | 
| 
      
 54 
     | 
    
         
            +
                  expect(arr).to eq([[:foo, "Foo!"], [:bar, "Bar!"], [:baz, "Baz!"],
         
     | 
| 
      
 55 
     | 
    
         
            +
                                 [:bop, "Bop!"], [:bat, "Bat!"]])
         
     | 
| 
       56 
56 
     | 
    
         
             
                end
         
     | 
| 
       57 
57 
     | 
    
         | 
| 
       58 
58 
     | 
    
         
             
                it "returns the keys in order of insertion" do
         
     | 
| 
       59 
     | 
    
         
            -
                  @hash.keys. 
     | 
| 
      
 59 
     | 
    
         
            +
                  expect(@hash.keys).to eq([:foo, :bar, :baz, :bop, :bat])
         
     | 
| 
       60 
60 
     | 
    
         
             
                end
         
     | 
| 
       61 
61 
     | 
    
         | 
| 
       62 
62 
     | 
    
         
             
                it "returns the values in order of insertion" do
         
     | 
| 
       63 
     | 
    
         
            -
                  @hash.values. 
     | 
| 
      
 63 
     | 
    
         
            +
                  expect(@hash.values).to eq(["Foo!", "Bar!", "Baz!", "Bop!", "Bat!"])
         
     | 
| 
       64 
64 
     | 
    
         
             
                end
         
     | 
| 
       65 
65 
     | 
    
         | 
| 
       66 
66 
     | 
    
         
             
                it "does not move an overwritten node to the end of the ordering" do
         
     | 
| 
       67 
67 
     | 
    
         
             
                  @hash[:baz] = "Bip!"
         
     | 
| 
       68 
     | 
    
         
            -
                  @hash.values. 
     | 
| 
      
 68 
     | 
    
         
            +
                  expect(@hash.values).to eq(["Foo!", "Bar!", "Bip!", "Bop!", "Bat!"])
         
     | 
| 
       69 
69 
     | 
    
         | 
| 
       70 
70 
     | 
    
         
             
                  @hash[:foo] = "Bip!"
         
     | 
| 
       71 
     | 
    
         
            -
                  @hash.values. 
     | 
| 
      
 71 
     | 
    
         
            +
                  expect(@hash.values).to eq(["Bip!", "Bar!", "Bip!", "Bop!", "Bat!"])
         
     | 
| 
       72 
72 
     | 
    
         | 
| 
       73 
73 
     | 
    
         
             
                  @hash[:bat] = "Bip!"
         
     | 
| 
       74 
     | 
    
         
            -
                  @hash.values. 
     | 
| 
      
 74 
     | 
    
         
            +
                  expect(@hash.values).to eq(["Bip!", "Bar!", "Bip!", "Bop!", "Bip!"])
         
     | 
| 
       75 
75 
     | 
    
         
             
                end
         
     | 
| 
       76 
76 
     | 
    
         | 
| 
       77 
77 
     | 
    
         
             
                it "appends another ordered hash while preserving ordering" do
         
     | 
| 
         @@ -79,37 +79,37 @@ describe Thor::CoreExt::OrderedHash do 
     | 
|
| 
       79 
79 
     | 
    
         
             
                  other_hash[1] = "one"
         
     | 
| 
       80 
80 
     | 
    
         
             
                  other_hash[2] = "two"
         
     | 
| 
       81 
81 
     | 
    
         
             
                  other_hash[3] = "three"
         
     | 
| 
       82 
     | 
    
         
            -
                  @hash.merge(other_hash).values. 
     | 
| 
      
 82 
     | 
    
         
            +
                  expect(@hash.merge(other_hash).values).to eq(["Foo!", "Bar!", "Baz!", "Bop!", "Bat!", "one", "two", "three"])
         
     | 
| 
       83 
83 
     | 
    
         
             
                end
         
     | 
| 
       84 
84 
     | 
    
         | 
| 
       85 
85 
     | 
    
         
             
                it "overwrites hash keys with matching appended keys" do
         
     | 
| 
       86 
86 
     | 
    
         
             
                  other_hash = Thor::CoreExt::OrderedHash.new
         
     | 
| 
       87 
87 
     | 
    
         
             
                  other_hash[:bar] = "bar"
         
     | 
| 
       88 
     | 
    
         
            -
                  @hash.merge(other_hash)[:bar]. 
     | 
| 
       89 
     | 
    
         
            -
                  @hash[:bar]. 
     | 
| 
      
 88 
     | 
    
         
            +
                  expect(@hash.merge(other_hash)[:bar]).to eq("bar")
         
     | 
| 
      
 89 
     | 
    
         
            +
                  expect(@hash[:bar]).to eq("Bar!")
         
     | 
| 
       90 
90 
     | 
    
         
             
                end
         
     | 
| 
       91 
91 
     | 
    
         | 
| 
       92 
92 
     | 
    
         
             
                it "converts to an array" do
         
     | 
| 
       93 
     | 
    
         
            -
                  @hash.to_a. 
     | 
| 
      
 93 
     | 
    
         
            +
                  expect(@hash.to_a).to eq([[:foo, "Foo!"], [:bar, "Bar!"], [:baz, "Baz!"], [:bop, "Bop!"], [:bat, "Bat!"]])
         
     | 
| 
       94 
94 
     | 
    
         
             
                end
         
     | 
| 
       95 
95 
     | 
    
         | 
| 
       96 
96 
     | 
    
         
             
                it "must not be empty" do
         
     | 
| 
       97 
     | 
    
         
            -
                  @hash. 
     | 
| 
      
 97 
     | 
    
         
            +
                  expect(@hash).not_to be_empty
         
     | 
| 
       98 
98 
     | 
    
         
             
                end
         
     | 
| 
       99 
99 
     | 
    
         | 
| 
       100 
100 
     | 
    
         
             
                it "deletes values from hash" do
         
     | 
| 
       101 
     | 
    
         
            -
                  @hash.delete(:baz). 
     | 
| 
       102 
     | 
    
         
            -
                  @hash.values. 
     | 
| 
      
 101 
     | 
    
         
            +
                  expect(@hash.delete(:baz)).to eq("Baz!")
         
     | 
| 
      
 102 
     | 
    
         
            +
                  expect(@hash.values).to eq(["Foo!", "Bar!", "Bop!", "Bat!"])
         
     | 
| 
       103 
103 
     | 
    
         | 
| 
       104 
     | 
    
         
            -
                  @hash.delete(:foo). 
     | 
| 
       105 
     | 
    
         
            -
                  @hash.values. 
     | 
| 
      
 104 
     | 
    
         
            +
                  expect(@hash.delete(:foo)).to eq("Foo!")
         
     | 
| 
      
 105 
     | 
    
         
            +
                  expect(@hash.values).to eq(["Bar!", "Bop!", "Bat!"])
         
     | 
| 
       106 
106 
     | 
    
         | 
| 
       107 
     | 
    
         
            -
                  @hash.delete(:bat). 
     | 
| 
       108 
     | 
    
         
            -
                  @hash.values. 
     | 
| 
      
 107 
     | 
    
         
            +
                  expect(@hash.delete(:bat)).to eq("Bat!")
         
     | 
| 
      
 108 
     | 
    
         
            +
                  expect(@hash.values).to eq(["Bar!", "Bop!"])
         
     | 
| 
       109 
109 
     | 
    
         
             
                end
         
     | 
| 
       110 
110 
     | 
    
         | 
| 
       111 
111 
     | 
    
         
             
                it "returns nil if the value to be deleted can't be found" do
         
     | 
| 
       112 
     | 
    
         
            -
                  @hash.delete(:nothing). 
     | 
| 
      
 112 
     | 
    
         
            +
                  expect(@hash.delete(:nothing)).to be_nil
         
     | 
| 
       113 
113 
     | 
    
         
             
                end
         
     | 
| 
       114 
114 
     | 
    
         
             
              end
         
     | 
| 
       115 
115 
     | 
    
         
             
            end
         
     | 
    
        data/spec/exit_condition_spec.rb
    CHANGED
    
    | 
         @@ -2,7 +2,7 @@ require File.expand_path(File.dirname(__FILE__) + '/spec_helper') 
     | 
|
| 
       2 
2 
     | 
    
         
             
            require 'thor/base'
         
     | 
| 
       3 
3 
     | 
    
         | 
| 
       4 
4 
     | 
    
         
             
            describe "Exit conditions" do
         
     | 
| 
       5 
     | 
    
         
            -
              it " 
     | 
| 
      
 5 
     | 
    
         
            +
              it "exits 0, not bubble up EPIPE, if EPIPE is raised" do
         
     | 
| 
       6 
6 
     | 
    
         
             
                epiped = false
         
     | 
| 
       7 
7 
     | 
    
         | 
| 
       8 
8 
     | 
    
         
             
                task = Class.new(Thor) do
         
     | 
| 
         @@ -13,7 +13,7 @@ describe "Exit conditions" do 
     | 
|
| 
       13 
13 
     | 
    
         
             
                  end
         
     | 
| 
       14 
14 
     | 
    
         
             
                end
         
     | 
| 
       15 
15 
     | 
    
         | 
| 
       16 
     | 
    
         
            -
                 
     | 
| 
       17 
     | 
    
         
            -
                epiped. 
     | 
| 
      
 16 
     | 
    
         
            +
                expect{ task.start(["my_action"]) }.to raise_error(SystemExit)
         
     | 
| 
      
 17 
     | 
    
         
            +
                expect(epiped).to eq(true)
         
     | 
| 
       18 
18 
     | 
    
         
             
              end
         
     | 
| 
       19 
19 
     | 
    
         
             
            end
         
     | 
    
        data/spec/fixtures/script.thor
    CHANGED
    
    
    
        data/spec/group_spec.rb
    CHANGED
    
    | 
         @@ -3,36 +3,36 @@ require File.expand_path(File.dirname(__FILE__) + '/spec_helper') 
     | 
|
| 
       3 
3 
     | 
    
         
             
            describe Thor::Group do
         
     | 
| 
       4 
4 
     | 
    
         
             
              describe "task" do
         
     | 
| 
       5 
5 
     | 
    
         
             
                it "allows to use private methods from parent class as tasks" do
         
     | 
| 
       6 
     | 
    
         
            -
                  ChildGroup.start. 
     | 
| 
       7 
     | 
    
         
            -
                  ChildGroup.new.baz("bar"). 
     | 
| 
      
 6 
     | 
    
         
            +
                  expect(ChildGroup.start).to eq(["bar", "foo", "baz"])
         
     | 
| 
      
 7 
     | 
    
         
            +
                  expect(ChildGroup.new.baz("bar")).to eq("bar")
         
     | 
| 
       8 
8 
     | 
    
         
             
                end
         
     | 
| 
       9 
9 
     | 
    
         
             
              end
         
     | 
| 
       10 
10 
     | 
    
         | 
| 
       11 
11 
     | 
    
         
             
              describe "#start" do
         
     | 
| 
       12 
12 
     | 
    
         
             
                it "invokes all the tasks under the Thor group" do
         
     | 
| 
       13 
     | 
    
         
            -
                  MyCounter.start(["1", "2", "--third", "3"]). 
     | 
| 
      
 13 
     | 
    
         
            +
                  expect(MyCounter.start(["1", "2", "--third", "3"])).to eq([ 1, 2, 3 ])
         
     | 
| 
       14 
14 
     | 
    
         
             
                end
         
     | 
| 
       15 
15 
     | 
    
         | 
| 
       16 
16 
     | 
    
         
             
                it "uses argument default value" do
         
     | 
| 
       17 
     | 
    
         
            -
                  MyCounter.start(["1", "--third", "3"]). 
     | 
| 
      
 17 
     | 
    
         
            +
                  expect(MyCounter.start(["1", "--third", "3"])).to eq([ 1, 2, 3 ])
         
     | 
| 
       18 
18 
     | 
    
         
             
                end
         
     | 
| 
       19 
19 
     | 
    
         | 
| 
       20 
20 
     | 
    
         
             
                it "invokes all the tasks in the Thor group and his parents" do
         
     | 
| 
       21 
     | 
    
         
            -
                  BrokenCounter.start(["1", "2", "--third", "3"]). 
     | 
| 
      
 21 
     | 
    
         
            +
                  expect(BrokenCounter.start(["1", "2", "--third", "3"])).to eq([ nil, 2, 3, false, 5 ])
         
     | 
| 
       22 
22 
     | 
    
         
             
                end
         
     | 
| 
       23 
23 
     | 
    
         | 
| 
       24 
24 
     | 
    
         
             
                it "raises an error if a required argument is added after a non-required" do
         
     | 
| 
       25 
     | 
    
         
            -
                   
     | 
| 
      
 25 
     | 
    
         
            +
                  expect {
         
     | 
| 
       26 
26 
     | 
    
         
             
                    MyCounter.argument(:foo, :type => :string)
         
     | 
| 
       27 
     | 
    
         
            -
                  }. 
     | 
| 
      
 27 
     | 
    
         
            +
                  }.to raise_error(ArgumentError, 'You cannot have "foo" as required argument after the non-required argument "second".')
         
     | 
| 
       28 
28 
     | 
    
         
             
                end
         
     | 
| 
       29 
29 
     | 
    
         | 
| 
       30 
30 
     | 
    
         
             
                it "raises when an exception happens within the task call" do
         
     | 
| 
       31 
     | 
    
         
            -
                   
     | 
| 
      
 31 
     | 
    
         
            +
                  expect{ BrokenCounter.start(["1", "2", "--fail"]) }.to raise_error
         
     | 
| 
       32 
32 
     | 
    
         
             
                end
         
     | 
| 
       33 
33 
     | 
    
         | 
| 
       34 
34 
     | 
    
         
             
                it "raises an error when a Thor group task expects arguments" do
         
     | 
| 
       35 
     | 
    
         
            -
                   
     | 
| 
      
 35 
     | 
    
         
            +
                  expect{ WhinyGenerator.start }.to raise_error(ArgumentError, /thor wrong_arity takes 1 argument, but it should not/)
         
     | 
| 
       36 
36 
     | 
    
         
             
                end
         
     | 
| 
       37 
37 
     | 
    
         | 
| 
       38 
38 
     | 
    
         
             
                it "invokes help message if any of the shortcuts is given" do
         
     | 
| 
         @@ -43,135 +43,135 @@ describe Thor::Group do 
     | 
|
| 
       43 
43 
     | 
    
         | 
| 
       44 
44 
     | 
    
         
             
              describe "#desc" do
         
     | 
| 
       45 
45 
     | 
    
         
             
                it "sets the description for a given class" do
         
     | 
| 
       46 
     | 
    
         
            -
                  MyCounter.desc. 
     | 
| 
      
 46 
     | 
    
         
            +
                  expect(MyCounter.desc).to eq("Description:\n  This generator runs three tasks: one, two and three.\n")
         
     | 
| 
       47 
47 
     | 
    
         
             
                end
         
     | 
| 
       48 
48 
     | 
    
         | 
| 
       49 
49 
     | 
    
         
             
                it "can be inherited" do
         
     | 
| 
       50 
     | 
    
         
            -
                  BrokenCounter.desc. 
     | 
| 
      
 50 
     | 
    
         
            +
                  expect(BrokenCounter.desc).to eq("Description:\n  This generator runs three tasks: one, two and three.\n")
         
     | 
| 
       51 
51 
     | 
    
         
             
                end
         
     | 
| 
       52 
52 
     | 
    
         | 
| 
       53 
53 
     | 
    
         
             
                it "can be nil" do
         
     | 
| 
       54 
     | 
    
         
            -
                  WhinyGenerator.desc. 
     | 
| 
      
 54 
     | 
    
         
            +
                  expect(WhinyGenerator.desc).to be_nil
         
     | 
| 
       55 
55 
     | 
    
         
             
                end
         
     | 
| 
       56 
56 
     | 
    
         
             
              end
         
     | 
| 
       57 
57 
     | 
    
         | 
| 
       58 
58 
     | 
    
         
             
              describe "#help" do
         
     | 
| 
       59 
59 
     | 
    
         
             
                before do
         
     | 
| 
       60 
     | 
    
         
            -
                  @content = capture(:stdout){ MyCounter.help(Thor::Base.shell.new) }
         
     | 
| 
      
 60 
     | 
    
         
            +
                  @content = capture(:stdout) { MyCounter.help(Thor::Base.shell.new) }
         
     | 
| 
       61 
61 
     | 
    
         
             
                end
         
     | 
| 
       62 
62 
     | 
    
         | 
| 
       63 
63 
     | 
    
         
             
                it "provides usage information" do
         
     | 
| 
       64 
     | 
    
         
            -
                  @content. 
     | 
| 
      
 64 
     | 
    
         
            +
                  expect(@content).to match(/my_counter N \[N\]/)
         
     | 
| 
       65 
65 
     | 
    
         
             
                end
         
     | 
| 
       66 
66 
     | 
    
         | 
| 
       67 
67 
     | 
    
         
             
                it "shows description" do
         
     | 
| 
       68 
     | 
    
         
            -
                  @content. 
     | 
| 
       69 
     | 
    
         
            -
                  @content. 
     | 
| 
      
 68 
     | 
    
         
            +
                  expect(@content).to match(/Description:/)
         
     | 
| 
      
 69 
     | 
    
         
            +
                  expect(@content).to match(/This generator runs three tasks: one, two and three./)
         
     | 
| 
       70 
70 
     | 
    
         
             
                end
         
     | 
| 
       71 
71 
     | 
    
         | 
| 
       72 
72 
     | 
    
         
             
                it "shows options information" do
         
     | 
| 
       73 
     | 
    
         
            -
                  @content. 
     | 
| 
       74 
     | 
    
         
            -
                  @content. 
     | 
| 
      
 73 
     | 
    
         
            +
                  expect(@content).to match(/Options/)
         
     | 
| 
      
 74 
     | 
    
         
            +
                  expect(@content).to match(/\[\-\-third=THREE\]/)
         
     | 
| 
       75 
75 
     | 
    
         
             
                end
         
     | 
| 
       76 
76 
     | 
    
         
             
              end
         
     | 
| 
       77 
77 
     | 
    
         | 
| 
       78 
78 
     | 
    
         
             
              describe "#invoke" do
         
     | 
| 
       79 
79 
     | 
    
         
             
                before do
         
     | 
| 
       80 
     | 
    
         
            -
                  @content = capture(:stdout){ E.start }
         
     | 
| 
      
 80 
     | 
    
         
            +
                  @content = capture(:stdout) { E.start }
         
     | 
| 
       81 
81 
     | 
    
         
             
                end
         
     | 
| 
       82 
82 
     | 
    
         | 
| 
       83 
83 
     | 
    
         
             
                it "allows to invoke a class from the class binding" do
         
     | 
| 
       84 
     | 
    
         
            -
                  @content. 
     | 
| 
      
 84 
     | 
    
         
            +
                  expect(@content).to match(/1\n2\n3\n4\n5\n/)
         
     | 
| 
       85 
85 
     | 
    
         
             
                end
         
     | 
| 
       86 
86 
     | 
    
         | 
| 
       87 
87 
     | 
    
         
             
                it "shows invocation information to the user" do
         
     | 
| 
       88 
     | 
    
         
            -
                  @content. 
     | 
| 
      
 88 
     | 
    
         
            +
                  expect(@content).to match(/invoke  Defined/)
         
     | 
| 
       89 
89 
     | 
    
         
             
                end
         
     | 
| 
       90 
90 
     | 
    
         | 
| 
       91 
91 
     | 
    
         
             
                it "uses padding on status generated by the invoked class" do
         
     | 
| 
       92 
     | 
    
         
            -
                  @content. 
     | 
| 
      
 92 
     | 
    
         
            +
                  expect(@content).to match(/finished    counting/)
         
     | 
| 
       93 
93 
     | 
    
         
             
                end
         
     | 
| 
       94 
94 
     | 
    
         | 
| 
       95 
95 
     | 
    
         
             
                it "allows invocation to be configured with blocks" do
         
     | 
| 
       96 
96 
     | 
    
         
             
                  capture(:stdout) do
         
     | 
| 
       97 
     | 
    
         
            -
                    F.start. 
     | 
| 
      
 97 
     | 
    
         
            +
                    expect(F.start).to eq(["Valim, Jose"])
         
     | 
| 
       98 
98 
     | 
    
         
             
                  end
         
     | 
| 
       99 
99 
     | 
    
         
             
                end
         
     | 
| 
       100 
100 
     | 
    
         | 
| 
       101 
101 
     | 
    
         
             
                it "shows invoked options on help" do
         
     | 
| 
       102 
     | 
    
         
            -
                  content = capture(:stdout){ E.help(Thor::Base.shell.new) }
         
     | 
| 
       103 
     | 
    
         
            -
                  content. 
     | 
| 
       104 
     | 
    
         
            -
                  content. 
     | 
| 
       105 
     | 
    
         
            -
                  content. 
     | 
| 
      
 102 
     | 
    
         
            +
                  content = capture(:stdout) { E.help(Thor::Base.shell.new) }
         
     | 
| 
      
 103 
     | 
    
         
            +
                  expect(content).to match(/Defined options:/)
         
     | 
| 
      
 104 
     | 
    
         
            +
                  expect(content).to match(/\[--unused\]/)
         
     | 
| 
      
 105 
     | 
    
         
            +
                  expect(content).to match(/# This option has no use/)
         
     | 
| 
       106 
106 
     | 
    
         
             
                end
         
     | 
| 
       107 
107 
     | 
    
         
             
              end
         
     | 
| 
       108 
108 
     | 
    
         | 
| 
       109 
109 
     | 
    
         
             
              describe "#invoke_from_option" do
         
     | 
| 
       110 
110 
     | 
    
         
             
                describe "with default type" do
         
     | 
| 
       111 
111 
     | 
    
         
             
                  before do
         
     | 
| 
       112 
     | 
    
         
            -
                    @content = capture(:stdout){ G.start }
         
     | 
| 
      
 112 
     | 
    
         
            +
                    @content = capture(:stdout) { G.start }
         
     | 
| 
       113 
113 
     | 
    
         
             
                  end
         
     | 
| 
       114 
114 
     | 
    
         | 
| 
       115 
115 
     | 
    
         
             
                  it "allows to invoke a class from the class binding by a default option" do
         
     | 
| 
       116 
     | 
    
         
            -
                    @content. 
     | 
| 
      
 116 
     | 
    
         
            +
                    expect(@content).to match(/1\n2\n3\n4\n5\n/)
         
     | 
| 
       117 
117 
     | 
    
         
             
                  end
         
     | 
| 
       118 
118 
     | 
    
         | 
| 
       119 
119 
     | 
    
         
             
                  it "does not invoke if the option is nil" do
         
     | 
| 
       120 
     | 
    
         
            -
                    capture(:stdout){ G.start(["--skip-invoked"]) }. 
     | 
| 
      
 120 
     | 
    
         
            +
                    expect(capture(:stdout) { G.start(["--skip-invoked"]) }).not_to match(/invoke/)
         
     | 
| 
       121 
121 
     | 
    
         
             
                  end
         
     | 
| 
       122 
122 
     | 
    
         | 
| 
       123 
123 
     | 
    
         
             
                  it "prints a message if invocation cannot be found" do
         
     | 
| 
       124 
     | 
    
         
            -
                    content = capture(:stdout){ G.start(["--invoked", "unknown"]) }
         
     | 
| 
       125 
     | 
    
         
            -
                    content. 
     | 
| 
      
 124 
     | 
    
         
            +
                    content = capture(:stdout) { G.start(["--invoked", "unknown"]) }
         
     | 
| 
      
 125 
     | 
    
         
            +
                    expect(content).to match(/error  unknown \[not found\]/)
         
     | 
| 
       126 
126 
     | 
    
         
             
                  end
         
     | 
| 
       127 
127 
     | 
    
         | 
| 
       128 
128 
     | 
    
         
             
                  it "allows to invoke a class from the class binding by the given option" do
         
     | 
| 
       129 
     | 
    
         
            -
                    content = capture(:stdout){ G.start(["--invoked", "e"]) }
         
     | 
| 
       130 
     | 
    
         
            -
                    content. 
     | 
| 
      
 129 
     | 
    
         
            +
                    content = capture(:stdout) { G.start(["--invoked", "e"]) }
         
     | 
| 
      
 130 
     | 
    
         
            +
                    expect(content).to match(/invoke  e/)
         
     | 
| 
       131 
131 
     | 
    
         
             
                  end
         
     | 
| 
       132 
132 
     | 
    
         | 
| 
       133 
133 
     | 
    
         
             
                  it "shows invocation information to the user" do
         
     | 
| 
       134 
     | 
    
         
            -
                    @content. 
     | 
| 
      
 134 
     | 
    
         
            +
                    expect(@content).to match(/invoke  defined/)
         
     | 
| 
       135 
135 
     | 
    
         
             
                  end
         
     | 
| 
       136 
136 
     | 
    
         | 
| 
       137 
137 
     | 
    
         
             
                  it "uses padding on status generated by the invoked class" do
         
     | 
| 
       138 
     | 
    
         
            -
                    @content. 
     | 
| 
      
 138 
     | 
    
         
            +
                    expect(@content).to match(/finished    counting/)
         
     | 
| 
       139 
139 
     | 
    
         
             
                  end
         
     | 
| 
       140 
140 
     | 
    
         | 
| 
       141 
141 
     | 
    
         
             
                  it "shows invoked options on help" do
         
     | 
| 
       142 
     | 
    
         
            -
                    content = capture(:stdout){ G.help(Thor::Base.shell.new) }
         
     | 
| 
       143 
     | 
    
         
            -
                    content. 
     | 
| 
       144 
     | 
    
         
            -
                    content. 
     | 
| 
       145 
     | 
    
         
            -
                    content. 
     | 
| 
      
 142 
     | 
    
         
            +
                    content = capture(:stdout) { G.help(Thor::Base.shell.new) }
         
     | 
| 
      
 143 
     | 
    
         
            +
                    expect(content).to match(/defined options:/)
         
     | 
| 
      
 144 
     | 
    
         
            +
                    expect(content).to match(/\[--unused\]/)
         
     | 
| 
      
 145 
     | 
    
         
            +
                    expect(content).to match(/# This option has no use/)
         
     | 
| 
       146 
146 
     | 
    
         
             
                  end
         
     | 
| 
       147 
147 
     | 
    
         
             
                end
         
     | 
| 
       148 
148 
     | 
    
         | 
| 
       149 
149 
     | 
    
         
             
                describe "with boolean type" do
         
     | 
| 
       150 
150 
     | 
    
         
             
                  before do
         
     | 
| 
       151 
     | 
    
         
            -
                    @content = capture(:stdout){ H.start }
         
     | 
| 
      
 151 
     | 
    
         
            +
                    @content = capture(:stdout) { H.start }
         
     | 
| 
       152 
152 
     | 
    
         
             
                  end
         
     | 
| 
       153 
153 
     | 
    
         | 
| 
       154 
154 
     | 
    
         
             
                  it "allows to invoke a class from the class binding by a default option" do
         
     | 
| 
       155 
     | 
    
         
            -
                    @content. 
     | 
| 
      
 155 
     | 
    
         
            +
                    expect(@content).to match(/1\n2\n3\n4\n5\n/)
         
     | 
| 
       156 
156 
     | 
    
         
             
                  end
         
     | 
| 
       157 
157 
     | 
    
         | 
| 
       158 
158 
     | 
    
         
             
                  it "does not invoke if the option is false" do
         
     | 
| 
       159 
     | 
    
         
            -
                    capture(:stdout){ H.start(["--no-defined"]) }. 
     | 
| 
      
 159 
     | 
    
         
            +
                    expect(capture(:stdout) { H.start(["--no-defined"]) }).not_to match(/invoke/)
         
     | 
| 
       160 
160 
     | 
    
         
             
                  end
         
     | 
| 
       161 
161 
     | 
    
         | 
| 
       162 
162 
     | 
    
         
             
                  it "shows invocation information to the user" do
         
     | 
| 
       163 
     | 
    
         
            -
                    @content. 
     | 
| 
      
 163 
     | 
    
         
            +
                    expect(@content).to match(/invoke  defined/)
         
     | 
| 
       164 
164 
     | 
    
         
             
                  end
         
     | 
| 
       165 
165 
     | 
    
         | 
| 
       166 
166 
     | 
    
         
             
                  it "uses padding on status generated by the invoked class" do
         
     | 
| 
       167 
     | 
    
         
            -
                    @content. 
     | 
| 
      
 167 
     | 
    
         
            +
                    expect(@content).to match(/finished    counting/)
         
     | 
| 
       168 
168 
     | 
    
         
             
                  end
         
     | 
| 
       169 
169 
     | 
    
         | 
| 
       170 
170 
     | 
    
         
             
                  it "shows invoked options on help" do
         
     | 
| 
       171 
     | 
    
         
            -
                    content = capture(:stdout){ H.help(Thor::Base.shell.new) }
         
     | 
| 
       172 
     | 
    
         
            -
                    content. 
     | 
| 
       173 
     | 
    
         
            -
                    content. 
     | 
| 
       174 
     | 
    
         
            -
                    content. 
     | 
| 
      
 171 
     | 
    
         
            +
                    content = capture(:stdout) { H.help(Thor::Base.shell.new) }
         
     | 
| 
      
 172 
     | 
    
         
            +
                    expect(content).to match(/defined options:/)
         
     | 
| 
      
 173 
     | 
    
         
            +
                    expect(content).to match(/\[--unused\]/)
         
     | 
| 
      
 174 
     | 
    
         
            +
                    expect(content).to match(/# This option has no use/)
         
     | 
| 
       175 
175 
     | 
    
         
             
                  end
         
     | 
| 
       176 
176 
     | 
    
         
             
                end
         
     | 
| 
       177 
177 
     | 
    
         
             
              end
         
     | 
| 
         @@ -189,9 +189,9 @@ describe Thor::Group do 
     | 
|
| 
       189 
189 
     | 
    
         
             
                    end
         
     | 
| 
       190 
190 
     | 
    
         
             
                  end
         
     | 
| 
       191 
191 
     | 
    
         | 
| 
       192 
     | 
    
         
            -
                  klass.start(["jose"]). 
     | 
| 
       193 
     | 
    
         
            -
                  klass.start(["jose", "--loud"]). 
     | 
| 
       194 
     | 
    
         
            -
                  klass.start(["--loud", "jose"]). 
     | 
| 
      
 192 
     | 
    
         
            +
                  expect(klass.start(["jose"])).to eq(["Hi jose"])
         
     | 
| 
      
 193 
     | 
    
         
            +
                  expect(klass.start(["jose", "--loud"])).to eq(["Hi JOSE"])
         
     | 
| 
      
 194 
     | 
    
         
            +
                  expect(klass.start(["--loud", "jose"])).to eq(["Hi JOSE"])
         
     | 
| 
       195 
195 
     | 
    
         
             
                end
         
     | 
| 
       196 
196 
     | 
    
         | 
| 
       197 
197 
     | 
    
         
             
                it "provides extra args as `args`" do
         
     | 
| 
         @@ -208,9 +208,9 @@ describe Thor::Group do 
     | 
|
| 
       208 
208 
     | 
    
         
             
                    end
         
     | 
| 
       209 
209 
     | 
    
         
             
                  end
         
     | 
| 
       210 
210 
     | 
    
         | 
| 
       211 
     | 
    
         
            -
                  klass.start(["jose"]). 
     | 
| 
       212 
     | 
    
         
            -
                  klass.start(["jose", "--loud"]). 
     | 
| 
       213 
     | 
    
         
            -
                  klass.start(["--loud", "jose"]). 
     | 
| 
      
 211 
     | 
    
         
            +
                  expect(klass.start(["jose"])).to eq(["Hi jose"])
         
     | 
| 
      
 212 
     | 
    
         
            +
                  expect(klass.start(["jose", "--loud"])).to eq(["Hi JOSE"])
         
     | 
| 
      
 213 
     | 
    
         
            +
                  expect(klass.start(["--loud", "jose"])).to eq(["Hi JOSE"])
         
     | 
| 
       214 
214 
     | 
    
         
             
                end
         
     | 
| 
       215 
215 
     | 
    
         
             
              end
         
     | 
| 
       216 
216 
     | 
    
         
             
            end
         
     |