Skip to content

Commit

Permalink
Convert params to a String before working on them
Browse files Browse the repository at this point in the history
By converting `params` to a String using `#to_s`, this allows the end
user to pass anything string-like, including Symbols and `nil`.

Also fixes #98.
  • Loading branch information
mike-burns authored and Jon Yurek committed Feb 2, 2018
1 parent fdcb2f4 commit 0fd7b76
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 8 deletions.
8 changes: 3 additions & 5 deletions lib/terrapin/command_line.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,16 +50,14 @@ def best_runner

def initialize(binary, params = "", options = {})
@binary = binary.dup
if params.nil?
raise ArgumentError, "2nd argument to CommandLine.new should be a " \
"string representing the command line options"
end
@params = params.dup
@params = params.to_s.dup

if options.nil?
raise ArgumentError, "3rd argument to CommandLine.new should be a" \
"hash of values that will be interpolated into the command line"
end
@options = options.dup

@runner = @options.delete(:runner) || self.class.runner
@logger = @options.delete(:logger) || self.class.logger
@swallow_stderr = @options.delete(:swallow_stderr)
Expand Down
6 changes: 3 additions & 3 deletions spec/terrapin/command_line_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
end

describe ".new" do
it "raises when given nil params" do
expect { Terrapin::CommandLine.new("echo", nil) }
.to raise_error(ArgumentError)
it "treats nil params as blank" do
cmd = Terrapin::CommandLine.new("echo", nil)
expect(cmd.run).to eq("\n")
end

it "raises when given nil options" do
Expand Down

0 comments on commit 0fd7b76

Please sign in to comment.