Skip to content

Commit

Permalink
Merge pull request #12 from browserstack/args_fix
Browse files Browse the repository at this point in the history
fixed issue with args affecting proxy and localIdentifer
  • Loading branch information
nidhimj22 authored Jul 6, 2016
2 parents 030dd8f + 65e6715 commit 677a308
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 16 deletions.
4 changes: 2 additions & 2 deletions browserstack-local.gemspec
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Gem::Specification.new do |s|
s.name = 'browserstack-local'
s.version = '0.2.0'
s.date = '2016-05-04'
s.version = '1.0.0'
s.date = '2016-07-06'
s.summary = "BrowserStack Local"
s.description = "Ruby bindings for BrowserStack Local"
s.authors = ["BrowserStack"]
Expand Down
35 changes: 26 additions & 9 deletions lib/browserstack/local.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,18 @@ def add_args(key, value=nil)
elsif key == "forcelocal" && value.to_s != "false"
@force_local_flag = "-forcelocal"
elsif key == "localIdentifier"
@local_identifier_flag = "-localIdentifier '#{value}'"
@local_identifier_flag = value
elsif key == "f"
@folder_flag = "-f"
@folder_path = "'#{value}'"
@folder_path = value
elsif key == "proxyHost"
@proxy_host = "-proxyHost '#{value}'"
@proxy_host = value
elsif key == "proxyPort"
@proxy_port = "-proxyPort #{value}"
@proxy_port = value
elsif key == "proxyUser"
@proxy_user = "-proxyUser '#{value}'"
@proxy_user = value
elsif key == "proxyPass"
@proxy_pass = "-proxyPass '#{value}'"
@proxy_pass = value
elsif key == "hosts"
@hosts = value
elsif key == "logfile"
Expand All @@ -53,7 +53,7 @@ def add_args(key, value=nil)
if value.to_s.downcase.eql?("true")
@user_arguments << "-#{key}"
else
@user_arguments << "-#{key} '#{value}'"
@user_arguments += ["-#{key}", value]
end
end
end
Expand Down Expand Up @@ -122,11 +122,28 @@ def command
end

def start_command
"#{@binary_path} -d start -logFile '#{@logfile}' #{@folder_flag} #{@key} #{@folder_path} #{@force_local_flag} #{@local_identifier_flag} #{@only_flag} #{@only_automate_flag} #{@proxy_host} #{@proxy_port} #{@proxy_user} #{@proxy_pass} #{@force_proxy_flag} #{@force_flag} #{@verbose_flag} #{@hosts} #{@user_arguments.join(" ")} 2>&1".strip
cmd = "#{@binary_path} -d start -logFile '#{@logfile}' #{@folder_flag} #{@key} #{@folder_path} #{@force_local_flag}"
cmd += " -localIdentifier #{@local_identifier_flag}" if @local_identifier_flag
cmd += " #{@only_flag} #{@only_automate_flag}"
cmd += " -proxyHost #{@proxy_host}" if @proxy_host
cmd += " -proxyPort #{@proxy_port}" if @proxy_port
cmd += " -proxyUser #{@proxy_user}" if @proxy_user
cmd += " -proxyPass #{@proxy_pass}" if @proxy_pass
cmd += " #{@force_proxy_flag} #{@force_flag} #{@verbose_flag} #{@hosts} #{@user_arguments.join(" ")} 2>&1"
cmd.strip
end

def start_command_args
args = ["#{@binary_path}", "-d", "start", "-logFile", "#{@logfile}", "#{@key}", "#{@folder_flag}", "#{@folder_path}", "#{@force_local_flag}", "#{@local_identifier_flag}", "#{@only_flag}", "#{@only_automate_flag}", "#{@proxy_host}", "#{@proxy_port}", "#{@proxy_user}", "#{@proxy_pass}", "#{@force_proxy_flag}","#{@force_flag}", "#{@verbose_flag}", "#{@hosts}", "#{@user_arguments.join(" ")}"]
args = [@binary_path, "-d", "start", "-logFile", @logfile, @key, @folder_flag, @folder_path, @force_local_flag]
args += ["-localIdentifier", local_identifier_flag] if @local_identifier_flag
args += [@only_flag, @only_automate_flag]
args += ["-proxyHost", @proxy_host] if @proxy_host
args += ["-proxyPort", @proxy_port] if @proxy_port
args += ["-proxyUser", @proxy_user] if @proxy_user
args += ["-proxyPass", @proxy_pass] if @proxy_pass
args += [@force_proxy_flag, @force_flag, @verbose_flag, @hosts]
args += @user_arguments

args = args.select {|a| a.to_s != "" }
args.push(:err => [:child, :out])
args
Expand Down
10 changes: 5 additions & 5 deletions test/browserstack-local-test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def test_enable_verbose
def test_set_folder
@bs_local.add_args 'f', "/"
assert_match /\-f/, @bs_local.command
assert_match /\'\/\'/, @bs_local.command
assert_match /\//, @bs_local.command
end

def test_enable_force
Expand All @@ -61,7 +61,7 @@ def test_enable_force_local

def test_set_local_identifier
@bs_local.add_args "localIdentifier", "randomString"
assert_match /\-localIdentifier \'randomString\'/, @bs_local.command
assert_match /\-localIdentifier randomString/, @bs_local.command
end

def test_custom_boolean_argument
Expand All @@ -72,8 +72,8 @@ def test_custom_boolean_argument
end

def test_custom_keyval
@bs_local.add_args "customKey1", "custom value1"
@bs_local.add_args "customKey2", "custom value2"
@bs_local.add_args "customKey1", "'custom value1'"
@bs_local.add_args "customKey2", "'custom value2'"
assert_match /\-customKey1 \'custom value1\'/, @bs_local.command
assert_match /\-customKey2 \'custom value2\'/, @bs_local.command
end
Expand All @@ -83,7 +83,7 @@ def test_set_proxy
@bs_local.add_args "proxyPort", 8080
@bs_local.add_args "proxyUser", "user"
@bs_local.add_args "proxyPass", "pass"
assert_match /\-proxyHost \'localhost\' \-proxyPort 8080 \-proxyUser \'user\' \-proxyPass \'pass\'/, @bs_local.command
assert_match /\-proxyHost localhost \-proxyPort 8080 \-proxyUser user \-proxyPass pass/, @bs_local.command
end

def test_force_proxy
Expand Down

0 comments on commit 677a308

Please sign in to comment.