Class: JsSpec::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/js_spec/client.rb

Class Method Summary collapse

Class Method Details

.run(params = {}) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/js_spec/client.rb', line 4

def run(params={})
  data = []
  data << "selenium_host=#{CGI.escape(params[:selenium_host] || 'localhost')}"
  data << "selenium_port=#{CGI.escape((params[:selenium_port] || 4444).to_s)}"
  data << "spec_url=#{CGI.escape(params[:spec_url])}" if params[:spec_url]
  response = Net::HTTP.start(DEFAULT_HOST, DEFAULT_PORT) do |http|
    http.post('/runners/firefox', data.join("&"))
  end

  body = response.body
  if body.empty?
    puts "SUCCESS"
    return true
  else
    puts "FAILURE"
    puts body
    return false
  end
end

.run_argv(argv) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/js_spec/client.rb', line 24

def run_argv(argv)
  params = {}
  parser = OptionParser.new do |o|
    o.banner = "JsSpec Runner"
    o.banner << "\nUsage: #{$0} [options] [-- untouched arguments]"

    o.on
    o.on('-h', '--selenium_host=SELENIUM_HOST', "The host name of the Selenium Server relative to where this file is executed") do |host|
      params[:selenium_host] = host
    end

    o.on('-p', '--selenium_port=SELENIUM_PORT', "The port of the Selenium Server relative to where this file is executed") do |port|
      params[:selenium_port] = port
    end

    o.on('-u', '--spec_url=SPEC_URL', "The url of the js spec server, relative to the browsers running via the Selenium Server") do |spec_url|
      params[:spec_url] = spec_url
    end

    o.on_tail
  end
  parser.order!(argv)
  run params
end