<commit_before>require 'sauce/utilities'

begin
  require 'spec'
  module Sauce
    module RSpec
      class SeleniumExampleGroup < Spec::Example::ExampleGroup
        attr_reader :selenium
        @@need_tunnel = false

        def self.inherited(subclass)
          # only setup tunnel if somebody needs it
          @@need_tunnel = true
          super(subclass)
        end

        before :suite do
          config = Sauce::Config.new
          if @@need_tunnel
            if config.application_host && !config.local?
              @@tunnel = Sauce::Connect.new(:host => config.application_host, :port => config.application_port || 80)
              @@tunnel.connect
              @@tunnel.wait_until_ready
            end
            if Sauce::Utilities::RailsServer.is_rails_app?
              @@server = Sauce::Utilities::RailsServer.new
              @@server.start
            end
          end
        end

        after :suite do
          @@tunnel.disconnect if defined? @@tunnel
          @@server.stop if defined? @@server
        end

        def execute(*args)
          config = Sauce::Config.new
          description = [self.class.description, self.description].join(" ")
          config.browsers.each do |os, browser, version|
            if config.single_session?
              if config.local?
                @selenium = Sauce.cached_session(:host => "127.0.0.1", :port => 4444, :browser => "*" +
                                                browser, :url => "http://127.0.0.1:#{config.local_application_port}/")
              else
                @selenium = Sauce.cached_session({:os => os, :browser => browser, :browser_version => version,
                               :job_name => self.class.description})
              end
              super(*args)
            else
              if config.local?
                @selenium = ::Selenium::Client::Driver.new(:host => "127.0.0.1",
                                                           :port => 4444,
                                                           :browser => "*" + browser,
                                                           :url => "http://127.0.0.1:#{config.local_application_port}/")
              else
                @selenium = Sauce::Selenium.new({:os => os, :browser => browser, :browser_version => version,
                                                :job_name => "#{description}"})
              end
              @selenium.start_new_browser_session(:captureNetworkTraffic => config.capture_traffic?)
              super(*args)
              @selenium.stop
            end
          end
        end

        alias_method :page, :selenium
        alias_method :s, :selenium

        Spec::Example::ExampleGroupFactory.register(:selenium, self)
      end
    end
  end
rescue LoadError
  # User doesn't have RSpec 1.x installed
end

begin
  require 'rspec'
  module Sauce
    module RSpec
      module SeleniumExampleGroup
        attr_reader :selenium
        alias_method :page, :selenium
        alias_method :s, :selenium

        def self.included(othermod)
          othermod.around do |the_test|
            config = Sauce::Config.new
            description = the_test.metadata[:full_description]
            config.browsers.each do |os, browser, version|
              if config.local?
                @selenium = ::Selenium::Client::Driver.new(:host => "127.0.0.1",
                                                           :port => 4444,
                                                           :browser => "*" + browser,
                                                           :url => "http://127.0.0.1:#{config.local_application_port}/")
              else
                @selenium = Sauce::Selenium.new({:os => os, :browser => browser, :browser_version => version,
                                                :job_name => "#{description}"})
              end
              @selenium.start_new_browser_session(:captureNetworkTraffic => config.capture_traffic?)
              begin
                the_test.run
              ensure
                @selenium.stop
              end
            end
          end
        end

        ::RSpec.configuration.include(self, :example_group => {
              :file_path => Regexp.compile('spec[\\\/]selenium')
            })
        ::RSpec.configuration.before :suite do
          need_tunnel = false
          config = Sauce::Config.new
          files_to_run = ::Rspec.configuration.respond_to?(:files_to_run) ? ::Rspec.configuration.files_to_run :
            ::RSpec.configuration.settings[:files_to_run]
          if config.application_host && !config.local?
            need_tunnel = files_to_run.any? {|file| file =~ /spec\/selenium\//}
          end
          if need_tunnel
            @@tunnel = Sauce::Connect.new(:host => config.application_host, :port => config.application_port || 80)
            @@tunnel.connect
            @@tunnel.wait_until_ready
          end

          if files_to_run.any? {|file| file =~ /spec\/selenium\//} &&
            Sauce::Utilities::RailsServer.is_rails_app?<commit_msg>Reference a properly-cased RSpec module.<commit_after>require 'sauce/utilities'

begin
  require 'spec'
  module Sauce
    module RSpec
      class SeleniumExampleGroup < Spec::Example::ExampleGroup
        attr_reader :selenium
        @@need_tunnel = false

        def self.inherited(subclass)
          # only setup tunnel if somebody needs it
          @@need_tunnel = true
          super(subclass)
        end

        before :suite do
          config = Sauce::Config.new
          if @@need_tunnel
            if config.application_host && !config.local?
              @@tunnel = Sauce::Connect.new(:host => config.application_host, :port => config.application_port || 80)
              @@tunnel.connect
              @@tunnel.wait_until_ready
            end
            if Sauce::Utilities::RailsServer.is_rails_app?
              @@server = Sauce::Utilities::RailsServer.new
              @@server.start
            end
          end
        end

        after :suite do
          @@tunnel.disconnect if defined? @@tunnel
          @@server.stop if defined? @@server
        end

        def execute(*args)
          config = Sauce::Config.new
          description = [self.class.description, self.description].join(" ")
          config.browsers.each do |os, browser, version|
            if config.single_session?
              if config.local?
                @selenium = Sauce.cached_session(:host => "127.0.0.1", :port => 4444, :browser => "*" +
                                                browser, :url => "http://127.0.0.1:#{config.local_application_port}/")
              else
                @selenium = Sauce.cached_session({:os => os, :browser => browser, :browser_version => version,
                               :job_name => self.class.description})
              end
              super(*args)
            else
              if config.local?
                @selenium = ::Selenium::Client::Driver.new(:host => "127.0.0.1",
                                                           :port => 4444,
                                                           :browser => "*" + browser,
                                                           :url => "http://127.0.0.1:#{config.local_application_port}/")
              else
                @selenium = Sauce::Selenium.new({:os => os, :browser => browser, :browser_version => version,
                                                :job_name => "#{description}"})
              end
              @selenium.start_new_browser_session(:captureNetworkTraffic => config.capture_traffic?)
              super(*args)
              @selenium.stop
            end
          end
        end

        alias_method :page, :selenium
        alias_method :s, :selenium

        Spec::Example::ExampleGroupFactory.register(:selenium, self)
      end
    end
  end
rescue LoadError
  # User doesn't have RSpec 1.x installed
end

begin
  require 'rspec'
  module Sauce
    module RSpec
      module SeleniumExampleGroup
        attr_reader :selenium
        alias_method :page, :selenium
        alias_method :s, :selenium

        def self.included(othermod)
          othermod.around do |the_test|
            config = Sauce::Config.new
            description = the_test.metadata[:full_description]
            config.browsers.each do |os, browser, version|
              if config.local?
                @selenium = ::Selenium::Client::Driver.new(:host => "127.0.0.1",
                                                           :port => 4444,
                                                           :browser => "*" + browser,
                                                           :url => "http://127.0.0.1:#{config.local_application_port}/")
              else
                @selenium = Sauce::Selenium.new({:os => os, :browser => browser, :browser_version => version,
                                                :job_name => "#{description}"})
              end
              @selenium.start_new_browser_session(:captureNetworkTraffic => config.capture_traffic?)
              begin
                the_test.run
              ensure
                @selenium.stop
              end
            end
          end
        end

        ::RSpec.configuration.include(self, :example_group => {
              :file_path => Regexp.compile('spec[\\\/]selenium')
            })
        ::RSpec.configuration.before :suite do
          need_tunnel = false
          config = Sauce::Config.new
          files_to_run = ::RSpec.configuration.respond_to?(:files_to_run) ? ::RSpec.configuration.files_to_run :
            ::RSpec.configuration.settings[:files_to_run]
          if config.application_host && !config.local?
            need_tunnel = files_to_run.any? {|file| file =~ /spec\/selenium\//}
          end
          if need_tunnel
            @@tunnel = Sauce::Connect.new(:host => config.application_host, :port => config.application_port || 80)
            @@tunnel.connect
            @@tunnel.wait_until_ready
          end

          if files_to_run.any? {|file| file =~ /spec\/selenium\//} &&
            Sauce::Utilities::RailsServer.is_rails_app?
{'fraction_non_alphanumeric': 0.10819255932037887, 'fraction_numerical': 0.010350551703935163, 'mean_word_length': 1.4626112046164943, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 67, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 12, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 36, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6686562', 'n_tokens_mistral': 2759, 'n_tokens_neox': 2570, 'n_words': 521}