-
-
Save gabrieljoelc/8fee9e29186ac2bfa87e to your computer and use it in GitHub Desktop.
Spinach adapter for Sauce Connect
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ENV['RAILS_ENV'] = 'test' | |
require './config/environment' | |
require 'minitest/spec' | |
require 'spinach/capybara' | |
require_relative 'spinach_helper' | |
require_relative 'sauce' | |
Spinach::Scenario.send(:prepend, SpinachHelper::Scenario) | |
begin | |
current_scenario = nil | |
Spinach.hooks.before_scenario do |scenario| | |
current_scenario = scenario | |
end | |
Spinach.hooks.around_scenario do |scenario, &block| | |
Sauce::Capybara::Spinach.around_hook(scenario, block) if ::Capybara.current_driver = :sauce | |
end | |
Spinach.hooks.on_failed_step do |step| | |
current_scenario.fail! | |
end | |
Spinach.hooks.on_error_step do |step| | |
current_scenario.fail! | |
end | |
end | |
Spinach.hooks.on_tag('sauce') do | |
::Capybara.current_driver = :sauce | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'capybara' | |
require 'sauce/job' | |
require 'sauce/capybara' | |
module Sauce | |
module Capybara | |
module Spinach | |
def name_from_scenario(scenario) | |
scenario = scenario.name.split("\n").first | |
feature = scenario.feature.name | |
"#{feature} - #{scenario}" | |
end | |
module_function :name_from_scenario | |
def sauce_scenario_name(scenario_name) | |
Sauce.config do |c| | |
c[:name] = scenario_name | |
end | |
end | |
module_function :sauce_scenario_name | |
def create_job(id, scenario_name) | |
job = Sauce::Job.new( | |
'id' => id, | |
'name' => scenario_name, | |
'custom-data' => {}) | |
job.save | |
job | |
end | |
module_function :create_job | |
def quit_browser | |
# Quit the driver to allow for the generation of a new session_id | |
::Capybara.current_session.driver.browser.quit | |
::Capybara.current_session.driver.instance_variable_set(:@browser, nil) | |
end | |
module_function :quit_browser | |
def around_hook(scenario, block) | |
scenario_name = Sauce::Capybara::Spinach.name_from_scenario(scenario) | |
job = create_job(::Capybara.current_session.driver.browser.session_id, scenario_name) | |
sauce_scenario_name(scenario_name) | |
block.call | |
quit_browser | |
job.passed = !scenario.failed? | |
job.save | |
end | |
module_function :around_hook | |
end | |
end | |
end | |
Sauce.config do |c| | |
c[:browsers] = [ | |
['Windows 8', 'Internet Explorer', '10'], | |
['Windows 7', 'Firefox', '20'], | |
['OS X 10.8', 'Safari', '6'], | |
['Linux', 'Chrome', nil] | |
] | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module SpinachHelper | |
module Scenario | |
def fail! | |
@failed = true | |
super | |
end | |
def failed? | |
@failed | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment