class RPerft::Client
Public Class Methods
new(suite_name)
click to toggle source
# File lib/rperft/client.rb, line 23 def initialize(suite_name) @suite_name = suite_name @test_results = [] @configuration = nil end
Public Instance Methods
add_result(description, repetitions, elapsed_seconds, options={})
click to toggle source
# File lib/rperft/client.rb, line 55 def add_result(description, repetitions, elapsed_seconds, options={}) result = TestResult.new(description, repetitions, elapsed_seconds) result.tags = options[:tags] || [] @test_results << result end
configure!(config_path=nil)
click to toggle source
# File lib/rperft/client.rb, line 29 def configure!(config_path=nil) # If a config path wasn't specified, let's assume it's in the working # directory. config_path ||= File.join(Dir.pwd, ".perft-config") @configuration = YAML.load_file(config_path) @host = @configuration["host"] @project = @configuration["project"] @machine = @configuration["machine"] @api_key = @configuration["api_key"] RPerft::Client.base_uri @host RPerft::Client.basic_auth @machine, @api_key end
configured?()
click to toggle source
# File lib/rperft/client.rb, line 44 def configured? !!@configuration end
run_test(description, repetitions, options={}, &block)
click to toggle source
# File lib/rperft/client.rb, line 48 def run_test(description, repetitions, options={}, &block) measurement = Benchmark.measure do repetitions.times(&block) end add_result(description, repetitions, measurement.total, options) end
submit_results(options={})
click to toggle source
# File lib/rperft/client.rb, line 61 def submit_results(options={}) configure! if !configured? changeset = nil comment = nil if options[:final] || (`git status --porcelain`).empty? changeset, comment = `git log --oneline HEAD^..HEAD`.split(/\s+/, 2) end changes = `git diff HEAD HEAD^` results = @test_results.map do |result| { :description => result.description, :elapsed_seconds => result.elapsed_seconds, :repetitions => result.repetitions, :tags => result.tags } end RPerft::Client.post("/projects/#{@project}/#{CGI.escape(@suite_name)}", { :body => { :results => results, :changeset => changeset, :version => options[:version], :comment => comment, :changes => changes, :append => options[:append] }, :headers => { "Content-Type" => "application/x-www-form-urlencoded" } }) end