Skip to content

Commit

Permalink
Fix return value for Ruby < 2.6
Browse files Browse the repository at this point in the history
`FileUtils.cd` only returns the value of the block in Ruby >= 2.6.
  • Loading branch information
jordan-brough committed Jan 28, 2020
1 parent 6c14044 commit 3d5e96f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
7 changes: 4 additions & 3 deletions lib/thor/actions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -181,12 +181,13 @@ def inside(dir = "", config = {}, &block)
FileUtils.mkdir_p(destination_root)
end

result = if pretend
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
Expand Down
4 changes: 4 additions & 0 deletions spec/actions_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,10 @@ def file
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
Expand Down

0 comments on commit 3d5e96f

Please sign in to comment.