Created
August 27, 2012 12:18
-
-
Save opsb/3487957 to your computer and use it in GitHub Desktop.
Spinach adaptor for testingbot/capybara
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 'testingbot/config' | |
| require 'testingbot/capybara' | |
| require 'testingbot/api' | |
| module Spinach | |
| class Scenario | |
| def fail! | |
| @failed = true | |
| end | |
| def failed? | |
| @failed | |
| end | |
| def title | |
| "#{name.split("\n").first} - #{feature.name}" | |
| end | |
| end | |
| end | |
| begin | |
| current_scenario = nil | |
| Spinach.hooks.before_scenario do |scenario| | |
| current_scenario = scenario | |
| ::Capybara.current_driver = :testingbot | |
| 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.after_scenario do |scenario| | |
| if !TestingBot.get_config[:client_key].nil? | |
| begin | |
| driver = ::Capybara.current_session.driver | |
| if driver.browser.respond_to?(:session_id) | |
| session_id = driver.browser.session_id | |
| else | |
| session_id = driver.browser.instance_variable_get("@bridge").instance_variable_get("@session_id") | |
| end | |
| api = TestingBot::Api.new | |
| params = { | |
| "session_id" => session_id, | |
| "status_message" => (scenario.failed? ? scenario.exception.message : ""), | |
| "success" => !scenario.failed? ? 1 : 0, | |
| "name" => scenario.title, | |
| "kind" => 2 | |
| } | |
| data = api.update_test(session_id, params) | |
| rescue Exception => e | |
| p "Could not determine sessionID, can not send results to TestingBot.com #{e.message}" | |
| end | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment