Sha256: c14fe419fe64dbb51cb5a0bd1720b1ebd00f5084c6601a50b42782463cbaf743

Contents?: true

Size: 1.81 KB

Versions: 1

Compression:

Stored size: 1.81 KB

Contents

module JsSpec
  module Resources
    class Runners
      class FirefoxRunner
        class << self
          def resume(guid, text)
            runner = instances.delete(guid)
            runner.finalize(text)
          end

          def register_instance(runner)
            instances[runner.guid] = runner
          end

          protected
          def instances
            @instances ||= {}
          end
        end

        include FileUtils
        attr_reader :guid, :profile_dir, :request, :response, :connection, :driver

        def initialize(request, response)
          profile_base = "#{::Dir.tmpdir}/js_spec/firefox"
          mkdir_p profile_base
          @profile_dir = "#{profile_base}/#{Time.now.to_i}"
          @guid = UUID.new
          @request = request
          @response = response
          @connection = Server.connection
        end

        def post(request, response)
          FirefoxRunner.register_instance self
          spec_url = (request && request['spec_url']) ? request['spec_url'] : spec_suite_url
          parsed_spec_url = URI.parse(spec_url)
          @driver = Selenium::SeleniumDriver.new(
            request['selenium_host'] || 'localhost',
            (request['selenium_port'] || 4444).to_i,
            '*firefox',
            "#{parsed_spec_url.scheme}://#{parsed_spec_url.host}:#{parsed_spec_url.port}"
          )
          driver.start
          Thread.start do
            url = "#{spec_url}?guid=#{guid}"
            driver.open(url)
          end
          response.status = nil
        end

        def finalize(text)
          driver.stop
          response.status = 200
          response.body = text
          connection.send_response(*response.finish)
        end

        protected

        def spec_suite_url
          "#{Server.root_url}/specs"
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
js_spec-0.2.0 lib/js_spec/resources/runners/firefox_runner.rb