class Sauce::RSpec::SeleniumExampleGroup

Attributes

s[R]
selenium[R]

Public Class Methods

context_example() click to toggle source
# File lib/sauce/rspec/rspec.rb, line 107
def self.context_example
  lambda { |context| context.example }
end
current_example() click to toggle source
# File lib/sauce/rspec/rspec.rb, line 115
def self.current_example
  @@current_example_fetcher ||= find_example_method
end
find_example_method() click to toggle source
# File lib/sauce/rspec/rspec.rb, line 111
def self.find_example_method
  ::RSpec.respond_to?(:current_example) ? rspec_current_example : context_example 
end
included(othermod) click to toggle source
# File lib/sauce/rspec/rspec.rb, line 129
def self.included(othermod)
  Sauce.logger.debug "Sauce RSpec module was included by #{othermod.name}"
  othermod.around do |the_test|
    config = Sauce::Config.new
    description = the_test.metadata[:full_description]
    file = the_test.metadata[:file_path]
    exceptions = {}
    test_each config.caps_for_location(file), description do |selenium, caps|

      Sauce.logger.debug "Running RSpec test for #{file} with #{caps}."
      example = SeleniumExampleGroup.current_example.call(self)
      example.instance_variable_set(:@exception, nil)
      
      @selenium = selenium
      thread_id = Thread.current.object_id
      Sauce.logger.debug "RSpec - Thread #{thread_id} storing driver #{@selenium.session_id} in driver pool."
      Sauce.driver_pool[thread_id] = @selenium
      example.metadata[:sauce_public_link] = SauceWhisk.public_link(@selenium.session_id)

      begin
        Sauce.logger.debug "About to initiate test #{description}"
        the_test.run
        success = example.exception.nil?
      ensure
        @selenium.stop
        begin
          os = caps[:os]
          browser = caps[:browser]
          version = caps[:version]
          unless success
            exceptions["#{os} - #{browser} #{version}"] = example.exception
          end
          platform = {:os => os, :browser => browser, :version => version}
          config.run_post_job_hooks(@selenium.session_id, platform, description, success)
        rescue Exception => e
          Sauce.logger.error "Error running post job hooks"
          Sauce.logger.error e
        end
        Sauce.logger.debug "RSpec - Removing driver for #{Thread.current.object_id} from driver pool."
        Sauce.driver_pool.delete Thread.current.object_id
      end
      if (exceptions.length > 0)
        example.instance_variable_set(:@exception, exceptions.first[1])
      end
    end
  end
end
inclusion_params() click to toggle source
# File lib/sauce/rspec/rspec.rb, line 177
def self.inclusion_params
  params = [self]
  gem_version = Gem::Version.new ::RSpec::Core::Version::STRING
  file_path_hash = {:file_path => Regexp.compile('spec[\\\/]selenium')}
  if (gem_version >= Gem::Version.new('2.99.0'))
    params = params + [file_path_hash]
  else
    params = params + [{:example_group => file_path_hash}]
  end
  params
end
inherited(subclass) click to toggle source
Calls superclass method
# File lib/sauce/rspec/rspec_one_support.rb, line 15
def self.inherited(subclass)
  # only setup tunnel if somebody needs it
  @@need_tunnel = true
  super(subclass)
end
rspec_current_example() click to toggle source
# File lib/sauce/rspec/rspec.rb, line 103
def self.rspec_current_example
  lambda { |context| ::RSpec.current_example }
end

Public Instance Methods

execute(*args) click to toggle source
Calls superclass method
# File lib/sauce/rspec/rspec_one_support.rb, line 40
def execute(*args)
  config = Sauce::Config.new
  description = [self.class.description, self.description].join(" ")
  config[:browsers].each do |os, browser, version|
    @selenium = Sauce::Selenium2.new({:os => os, :browser => browser,
                                      :browser_version => version,
                                      :job_name => description})

    begin
      success = super(*args)
      SauceWhisk::Jobs.change_status @selenium.session_id, success
    ensure
      @selenium.stop
    end
  end
end
page() click to toggle source

TODO V4 – Remove this entirely

# File lib/sauce/rspec/rspec.rb, line 120
def page
  if self.class.included_modules.any? {|m| m.name == 'Capybara::DSL'}
    ::Capybara.current_session
  else
    warn Sauce::Utilities.page_deprecation_message
    @selenium
  end
end