diff --git a/lib/thor/actions.rb b/lib/thor/actions.rb index 552eb135c..af5bcbd2c 100644 --- a/lib/thor/actions.rb +++ b/lib/thor/actions.rb @@ -161,6 +161,8 @@ def find_in_source_paths(file) # to the block you provide. The path is set back to the previous path when # the method exits. # + # Returns the value yielded by the block. + # # ==== Parameters # dir:: the directory to move to. # config:: give :verbose => true to log and use padding. @@ -179,16 +181,18 @@ def inside(dir = "", config = {}, &block) FileUtils.mkdir_p(destination_root) end + result = nil if pretend # In pretend mode, just yield down to the block - block.arity == 1 ? yield(destination_root) : yield + result = block.arity == 1 ? yield(destination_root) : yield else require "fileutils" - FileUtils.cd(destination_root) { block.arity == 1 ? yield(destination_root) : yield } + FileUtils.cd(destination_root) { result = block.arity == 1 ? yield(destination_root) : yield } end @destination_stack.pop shell.padding -= 1 if verbose + result end # Goes to the root and execute the given block. diff --git a/spec/actions_spec.rb b/spec/actions_spec.rb index 47416e148..ffdeef265 100644 --- a/spec/actions_spec.rb +++ b/spec/actions_spec.rb @@ -165,11 +165,19 @@ def file end end + it "returns the value yielded by the block" do + expect(runner.inside("foo") { 123 }).to eq(123) + end + describe "when pretending" do it "no directories should be created" do runner.inside("bar", :pretend => true) {} expect(File.exist?("bar")).to be false end + + it "returns the value yielded by the block" do + expect(runner.inside("foo") { 123 }).to eq(123) + end end describe "when verbose" do