diff --git a/README.md b/README.md index a84cc6c..70648b5 100644 --- a/README.md +++ b/README.md @@ -107,7 +107,7 @@ bs_local_args = { "key" => "" , "v" => "true", "logfile" To build gem, `rake build`. -To run the test suite run, `rake test`. +To run the test suite run, `BROWSERSTACK_ACCESS_KEY= rake test`. ### Reporting bugs diff --git a/lib/browserstack/local.rb b/lib/browserstack/local.rb index 32bc89c..a7906d5 100644 --- a/lib/browserstack/local.rb +++ b/lib/browserstack/local.rb @@ -102,7 +102,11 @@ def start(options = {}) end def isRunning - return true if (!@pid.nil? && Process.kill(0, @pid)) rescue false + begin + (!@pid.nil? && Process.kill(0, @pid)) ? true : false + rescue + false + end end def stop @@ -150,12 +154,14 @@ def start_command_args end def stop_command - "#{@binary_path} -d stop #{@local_identifier_flag}".strip + cmd = "#{@binary_path} -d stop" + cmd += " -localIdentifier #{@local_identifier_flag}" if @local_identifier_flag + cmd.strip end def stop_command_args - args = ["#{@binary_path}", "-d", "stop", "#{@local_identifier_flag}"] - args = args.select {|a| a.to_s != "" } + args = ["#{@binary_path}", "-d", "stop"] + args += ["-localIdentifier", @local_identifier_flag] if @local_identifier_flag args.push(:err => [:child, :out]) args end diff --git a/test/browserstack-local-test.rb b/test/browserstack-local-test.rb index 00efef8..27fc218 100644 --- a/test/browserstack-local-test.rb +++ b/test/browserstack-local-test.rb @@ -28,6 +28,28 @@ def test_multiple_binary File.delete(second_log_file) end + def test_localId_independence + @bs_local.start + bs_local_by_ID = BrowserStack::Local.new + bs_local_by_ID.start({'localIdentifier' => "uniqueID"}) + assert_equal true, @bs_local.isRunning + assert_equal true, bs_local_by_ID.isRunning + bs_local_by_ID.stop + assert_equal true, @bs_local.isRunning + assert_equal false, bs_local_by_ID.isRunning + end + + def test_isRunning_stopped + @bs_local.instance_variable_set(:@pid,nil) + assert_equal false, @bs_local.isRunning + end + + def test_isRunning_crashed + @bs_local.instance_variable_set(:@pid,1000000000) # probably non-existant pid + assert_equal false, @bs_local.isRunning + @bs_local.instance_variable_set(:@pid,nil) + end + def test_enable_verbose @bs_local.add_args('v') assert_match /\-v/, @bs_local.command