Sha256: 0d2aa56abbf3a6cf76a73159e02b4a94069f7bc37d1b7cf105bf84bc422a8fa8

Contents?: true

Size: 1.26 KB

Versions: 5

Compression:

Stored size: 1.26 KB

Contents

module CukeQ
  class Runner

    DEFAULT_TRIGGER_URI = URI.parse("http://localhost:9292/")

    def self.execute(args)
      opts = parse(args)
      uri = opts.delete(:uri)

      EM.run {
        http = EM::P::HttpClient.request(
          :host    => uri.host,
          :port    => uri.port,
          :verb    => "POST",
          :request => uri.path.empty? ? "/" : uri.path,
          :content => opts.to_json
        )

        http.callback do |response|
          log :success, response
          EM.stop
        end

        http.errback do |error|
          log :error, error[:status], uri.to_s

          EM.stop
        end

      }
    end

    private

    def self.parse(argv)
      options = {:uri => DEFAULT_TRIGGER_URI}

      argv.extend OptionParser::Arguable
      argv.options do |opts|
        opts.on("-u", "--uri URI (default: #{DEFAULT_TRIGGER_URI})") do |str|
          options[:uri] = URI.parse(str)
        end

        opts.on("-i", "--id RUN_ID") do |str|
          options[:run_id] = str
        end
      end.parse!

      if argv.empty?
        raise "must provide list of features"
      end

      unless options[:run_id]
        raise "must provide --id"
      end

      options[:features] = argv

      options
    end

  end # Runner
end # CukeQ

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
cukeq-0.0.1.dev5 lib/cukeq/runner.rb
cukeq-0.0.1.dev4 lib/cukeq/runner.rb
cukeq-0.0.1.dev3 lib/cukeq/runner.rb
cukeq-0.0.1.dev2 lib/cukeq/runner.rb
cukeq-0.0.1.dev lib/cukeq/runner.rb