Permalink
Browse files

Push some Jenkins and Scenario related information to Sauce Labs afte…

…r a Scenario completes


Fixes #69
  • Loading branch information...
1 parent 8bc50c2 commit be15d7417a1841eaaedc57ca5ab5a6271156d435 @rtyler rtyler committed May 12, 2012
Showing with 19 additions and 2 deletions.
  1. +13 −0 lib/sauce/capybara/cucumber.rb
  2. +3 −2 lib/sauce/job.rb
  3. +3 −0 spec/sauce/capybara/cucumber_spec.rb
@@ -1,5 +1,6 @@
require 'capybara'
require 'cucumber'
+require 'sauce/job'
module Sauce
module Capybara
@@ -42,6 +43,10 @@ def before_hook
def around_hook(scenario, block)
::Capybara.current_driver = :sauce
driver = ::Capybara.current_session.driver
+ # This session_id is the job ID used by Sauce Labs, we're pulling it
+ # off of the driver now to make sure we have it after `block.call`
+ session_id = driver.browser.session_id
+
Sauce.config do |c|
c[:name] = Sauce::Capybara::Cucumber.name_from_scenario(scenario)
end
@@ -68,6 +73,14 @@ def around_hook(scenario, block)
# Quit the driver to allow for the generation of a new session_id
driver.browser.quit
driver.instance_variable_set(:@browser, nil)
+
+ custom_data = {:commit => ENV['GIT_COMMIT'] || ENV['SVN_COMMIT'],
+ :node_name => ENV['NODE_NAME'],
+ :job_name => ENV['JOB_NAME']}
+ job = Sauce::Job.new('id' => session_id,
+ 'passed' => !scenario.failed?,
+ 'custom-data' => custom_data)
+ job.save unless job.nil?
end
module_function :around_hook
end
View
@@ -10,7 +10,7 @@ class CannotDeleteJobError < StandardError; end #:nodoc
attr_accessor :name, :browser, :browser_version, :os
attr_accessor :creation_time, :start_time, :end_time
attr_accessor :public, :video_url, :log_url, :tags
- attr_accessor :passed
+ attr_accessor :passed, :custom_data
# Get the class @@client.
# TODO: Consider metaprogramming this away
@@ -99,6 +99,7 @@ def save
def to_json(options={})
json = {
:id => @id,
+ :'custom-data' => @custom_data,
:owner => @owner,
:status => @status,
:error => @error,
@@ -130,7 +131,6 @@ def delete
# Sets all internal variables from a hash
def build!(options)
- #puts "\tBuild with: #{options.inspect}"
# Massage JSON
options.each { |key,value| options[key] = false if options[key] == "false" }
@@ -150,6 +150,7 @@ def build!(options)
@public = options["public"]
@tags = options["tags"]
@passed = options["passed"]
+ @custom_data = options['custom-data']
raise NoIDError if @id.nil? or @id.empty?
end
@@ -55,15 +55,18 @@ module Sauce::Capybara
end
context 'Around hook' do
+ let(:session_id) { 'deadbeef' }
let(:driver) do
driver = mock('Sauce::Selenium2 Driver')
driver.stub_chain(:browser, :quit)
+ driver.stub_chain(:browser, :session_id).and_return(session_id)
driver
end
before :each do
# Need to create our nice mocked Capybara driver
Capybara.stub_chain(:current_session, :driver).and_return(driver)
+ Sauce::Job.stub(:save)
end
context 'with a scenario outline' do

0 comments on commit be15d74

Please sign in to comment.