Skip to content

Instantly share code, notes, and snippets.

@mose
Created May 10, 2013 09:13
Show Gist options
  • Save mose/5553378 to your computer and use it in GitHub Desktop.
Save mose/5553378 to your computer and use it in GitHub Desktop.
saucelabs rspec trick
if ENV['sauce']
module Job
extend self
def id
@__jobid || 'undefined'
end
def id=(j)
@__jobid ||= j
end
def failed?
!!@__failed
end
def fails
@__failed = true
end
def build
Time.now.to_i.to_s
end
end
require 'sauce/capybara'
require 'rest_client'
Capybara.javascript_driver = :sauce
Sauce.config do |c|
c[:browsers] = [
["Windows 7", "iehta", "9"]
]
end
RSpec.configure do |config|
config.after :each do
Job.id = page.driver.browser.send(:bridge).session_id
Job.fails unless example.exception.nil?
end
config.after :suite do
http = "https://saucelabs.com/rest/v1/#{ENV["SAUCE_USERNAME"]}/jobs/#{Job.id}"
body = {
name: "RailsI18nterface",
passed: !Job.failed?,
public: 'public',
tags: ['rails-i18nterface'],
build: Job.build,
"custom-data" => { version: RailsI18nterface::VERSION }
}.to_json
# puts 'http: ' + http
# puts 'body: ' + body
RestClient::Request.execute(
:method => :put,
:url => http,
:user => ENV["SAUCE_USERNAME"],
:password => ENV["SAUCE_ACCESS_KEY"],
:headers => {:content_type => "application/json"},
:payload => body
)
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment