sauce_ruby 3.5.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (72) hide show
  1. checksums.yaml +7 -0
  2. data/bin/sauce +103 -0
  3. data/lib/childprocess/process.rb +34 -0
  4. data/lib/generators/sauce/install/install_generator.rb +54 -0
  5. data/lib/parallel_tests/cli_patch.rb +23 -0
  6. data/lib/parallel_tests/saucecucumber/runner.rb +43 -0
  7. data/lib/parallel_tests/saucerspec/runner.rb +40 -0
  8. data/lib/sauce.rb +33 -0
  9. data/lib/sauce/capybara.rb +189 -0
  10. data/lib/sauce/client.rb +40 -0
  11. data/lib/sauce/config.rb +434 -0
  12. data/lib/sauce/driver_pool.rb +5 -0
  13. data/lib/sauce/heroku.rb +18 -0
  14. data/lib/sauce/job.rb +159 -0
  15. data/lib/sauce/parallel.rb +16 -0
  16. data/lib/sauce/parallel/test_broker.rb +110 -0
  17. data/lib/sauce/parallel/test_group.rb +24 -0
  18. data/lib/sauce/railtie.rb +11 -0
  19. data/lib/sauce/raketasks.rb +83 -0
  20. data/lib/sauce/rspec/rspec.rb +186 -0
  21. data/lib/sauce/rspec/rspec_formatter.rb +20 -0
  22. data/lib/sauce/rspec/rspec_one_support.rb +66 -0
  23. data/lib/sauce/selenium.rb +95 -0
  24. data/lib/sauce/test_base.rb +21 -0
  25. data/lib/sauce/test_unit.rb +111 -0
  26. data/lib/sauce/utilities.rb +80 -0
  27. data/lib/sauce/utilities/connect.rb +45 -0
  28. data/lib/sauce/utilities/rails_server.rb +95 -0
  29. data/lib/sauce/utilities/rake.rb +32 -0
  30. data/lib/sauce/version.rb +9 -0
  31. data/lib/sauce/webmock.rb +16 -0
  32. data/lib/tasks/parallel_testing.rb +148 -0
  33. data/spec/cucumber_helper.rb +42 -0
  34. data/spec/integration/connect/spec/spec_helper.rb +21 -0
  35. data/spec/integration/connect/spec/start_tunnel_spec.rb +9 -0
  36. data/spec/integration/connect/spec/with_capybara_spec.rb +10 -0
  37. data/spec/integration/connect_integration_spec.rb +99 -0
  38. data/spec/integration/rspec-capybara/spec/capybara_required_last_spec.rb +18 -0
  39. data/spec/integration/rspec-capybara/spec/integration_spec.rb +17 -0
  40. data/spec/integration/rspec-capybara/spec/sauce_config_spec.rb +13 -0
  41. data/spec/integration/rspec-capybara/spec/sauce_required_last_spec.rb +21 -0
  42. data/spec/integration/rspec-capybara/spec/selenium/selenium_with_capybara.rb +12 -0
  43. data/spec/integration/rspec-capybara/spec/spec_helper.rb +37 -0
  44. data/spec/integration/rspec/spec/integration_spec.rb +13 -0
  45. data/spec/integration/rspec/spec/selenium/selenium_directory_spec.rb +20 -0
  46. data/spec/integration/rspec/spec/spec_helper.rb +52 -0
  47. data/spec/integration/rspec/spec/tagging/selenium_tagging_spec.rb +29 -0
  48. data/spec/integration/testunit/test/capybara_integration_test.rb +37 -0
  49. data/spec/integration/testunit/test/integration_test.rb +21 -0
  50. data/spec/integration/testunit/test/test_helper.rb +13 -0
  51. data/spec/parallel_tests/sauce_rspec_runner_spec.rb +23 -0
  52. data/spec/sauce/capybara_spec.rb +386 -0
  53. data/spec/sauce/config/browser_spec.rb +73 -0
  54. data/spec/sauce/config/config_spec.rb +400 -0
  55. data/spec/sauce/config/default_browsers_spec.rb +46 -0
  56. data/spec/sauce/config/environment_config_spec.rb +106 -0
  57. data/spec/sauce/config/load_defaults_spec.rb +50 -0
  58. data/spec/sauce/config/perfile_browser_spec.rb +105 -0
  59. data/spec/sauce/connect_spec.rb +21 -0
  60. data/spec/sauce/cucumber_spec.rb +212 -0
  61. data/spec/sauce/driver_pool_spec.rb +8 -0
  62. data/spec/sauce/file_detector_spec.rb +15 -0
  63. data/spec/sauce/jasmine_spec.rb +30 -0
  64. data/spec/sauce/parallel/test_broker_spec.rb +77 -0
  65. data/spec/sauce/selenium_spec.rb +60 -0
  66. data/spec/sauce/tasks_spec.rb +180 -0
  67. data/spec/sauce/utilities/rails_server_spec.rb +109 -0
  68. data/spec/sauce/utilities/rake_spec.rb +46 -0
  69. data/spec/sauce/utilities/utilities_spec.rb +137 -0
  70. data/spec/sauce_helper.rb +8 -0
  71. data/spec/spec_helper.rb +27 -0
  72. metadata +390 -0
@@ -0,0 +1,95 @@
1
+ require 'childprocess'
2
+ require 'childprocess/process'
3
+
4
+ module Sauce
5
+ module Utilities
6
+ class RailsServer
7
+ include Sauce::Utilities
8
+
9
+ def self.start_if_required(config)
10
+ if config[:start_local_application] && self.is_rails_app?
11
+ server = new
12
+ server.start
13
+
14
+ return server
15
+ end
16
+
17
+ return server
18
+ end
19
+
20
+ def self.is_rails_app?
21
+ return !major_version.nil?
22
+ end
23
+
24
+ def self.major_version
25
+ paths = ["script/server", "script/rails", "bin/rails"]
26
+ startup_script = paths.detect {|path| File.exists? path}
27
+
28
+ case startup_script
29
+ when 'script/server'
30
+ return 2
31
+ when 'script/rails'
32
+ return 3
33
+ when 'bin/rails'
34
+ return 4
35
+ else
36
+ return nil
37
+ end
38
+ end
39
+
40
+ def self.process_arguments
41
+ case major_version
42
+ when 2
43
+ ["ruby", "script/server"]
44
+ else
45
+ ["bundle", "exec", "rails", "server"]
46
+ end
47
+ end
48
+
49
+ def self.server_pool
50
+ @@server_pool ||= {}
51
+ end
52
+
53
+ attr_reader :port
54
+
55
+ def start
56
+ @port = Sauce::Config.new[:application_port]
57
+
58
+ if ENV["TEST_ENV_NUMBER"]
59
+ @test_env = ENV["TEST_ENV_NUMBER"].to_i
60
+ end
61
+
62
+ STDERR.puts "Starting Rails server on port #{@port}..."
63
+
64
+ @process_args = RailsServer.process_arguments
65
+ @process_args.push *["-e", "test", "--port", "#{@port}"]
66
+
67
+ if @test_env
68
+ @process_args.push *["--pid", "#{Dir.pwd}/tmp/pids/server-#{@test_env}"]
69
+ end
70
+
71
+ @server = ChildProcess.build *@process_args
72
+ @server.io.inherit!
73
+ @server.start
74
+
75
+ wait_for_server_on_port(@port)
76
+
77
+ at_exit do
78
+ @server.stop(3, "INT")
79
+ RailsServer.server_pool.delete Thread.current.object_id
80
+ end
81
+ STDERR.puts "Rails server running!"
82
+
83
+ RailsServer.server_pool[Thread.current.object_id] = @server
84
+ end
85
+
86
+ def stop
87
+ begin
88
+ @server.stop(3, "INT")
89
+ rescue
90
+ STDERR.puts "Rails server could not be killed. Did it fail to start?"
91
+ end
92
+ end
93
+ end
94
+ end
95
+ end
@@ -0,0 +1,32 @@
1
+ module Sauce
2
+ module Utilities
3
+ module Rake
4
+
5
+ def self.sauce_helper
6
+ helper_text = <<-ENDHEADER
7
+ # You should edit this file with the browsers you wish to use
8
+ # For options, check out http://saucelabs.com/docs/platforms
9
+ require "sauce"
10
+ ENDHEADER
11
+
12
+ helper_text << "require \"sauce/capybara\"" if Object.const_defined? "Capybara"
13
+ helper_text << <<-ENDFILE
14
+
15
+ Sauce.config do |config|
16
+ config[:browsers] = [
17
+ ["OS", "BROWSER", "VERSION"],
18
+ ["OS", "BROWSER", "VERSION"]
19
+ ]
20
+ config[:sauce_connect_4_executable] = # path to Sauce Connect 4 executable
21
+ end
22
+ ENDFILE
23
+ if Object.const_defined? "Capybara"
24
+ helper_text << "Capybara.default_driver = :sauce \n"
25
+ helper_text << "Capybara.javascript_driver = :sauce"
26
+ end
27
+
28
+ return helper_text
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,9 @@
1
+ module Sauce
2
+ MAJOR_VERSION = '3.5'
3
+ PATCH_VERSION = '6'
4
+
5
+ def version
6
+ "#{MAJOR_VERSION}.#{PATCH_VERSION}"
7
+ end
8
+ module_function :version
9
+ end
@@ -0,0 +1,16 @@
1
+ require 'webmock/config'
2
+
3
+ config = WebMock::Config.instance
4
+
5
+ unless config.allow_net_connect
6
+ allow_localhost = config.allow_localhost
7
+ allow = config.allow || []
8
+ allow << /saucelabs.com/
9
+ connect_on_start = config.net_http_connect_on_start
10
+
11
+ WebMock.disable_net_connect!(
12
+ :allow_localhost => allow_localhost,
13
+ :allow => allow,
14
+ :net_http_connect_on_start => connect_on_start
15
+ )
16
+ end
@@ -0,0 +1,148 @@
1
+ require "sauce/parallel/test_broker"
2
+ require "parallel_tests"
3
+ require "parallel_tests/tasks"
4
+ require "parallel_tests/cli_patch"
5
+ require "shellwords"
6
+
7
+ namespace :sauce do
8
+ desc "Run specs in parallel on Sauce Labs"
9
+ task :spec, :files, :concurrency, :test_options, :parallel_options do |t, args|
10
+ ::RSpec::Core::Runner.disable_autorun!
11
+ run_parallel_tests(t, args, :rspec)
12
+ end
13
+
14
+ desc "Run features in parallel on Sauce Labs"
15
+ task :features, :files, :concurrency, :test_options, :parallel_options do |t, args|
16
+ run_parallel_tests(t, args, :cucumber)
17
+ end
18
+
19
+ namespace :install do
20
+ desc "Set up your Cucumber features to run in parallel on Sauce Labs"
21
+ task :features do
22
+ Rake::Task["sauce:install:create_helper"].execute(:helper_type => :features)
23
+ puts <<-ENDLINE
24
+ -----------------------------------------------------------------------
25
+ The Sauce gem is now installed!
26
+
27
+ Next steps:
28
+
29
+ 1. Edit features/support/sauce_helper.rb with your required platforms
30
+ 2. Set the SAUCE_USERNAME and SAUCE_ACCESS_KEY environment variables
31
+ 3. Run your tests with 'rake sauce:features'
32
+ -----------------------------------------------------------------------
33
+ ENDLINE
34
+ end
35
+
36
+ desc "Set up your specs to run in parallel on Sauce Labs"
37
+ task :spec do
38
+ Rake::Task["sauce:install:create_helper"].execute(:helper_type => :spec)
39
+ helper_path = File.exist?("spec/rails_helper.rb") ? "spec/rails_helper.rb" : "spec/spec_helper.rb"
40
+ unless File.open(helper_path) { |f| f.read.match "require \"sauce_helper\""}
41
+ File.open(helper_path, "a") do |f|
42
+ f.write "require \"sauce_helper\""
43
+ end
44
+ else
45
+ STDERR.puts "WARNING - The Sauce gem is already integrated into your rspec setup"
46
+ end
47
+ puts <<-ENDLINE
48
+ --------------------------------------------------------------------------------
49
+ The Sauce gem is now installed!
50
+
51
+ Next steps:
52
+
53
+ 1. Edit spec/sauce_helper.rb with your required platforms & Sauce Connect 4 path
54
+ 2. Make sure we've not mangled your spec/*_helper.rb requiring sauce_helper
55
+ 3. Set the SAUCE_USERNAME and SAUCE_ACCESS_KEY environment variables
56
+ 3. Run your tests with 'rake sauce:spec'
57
+ --------------------------------------------------------------------------------
58
+ ENDLINE
59
+ end
60
+
61
+ task :create_helper, [:helper_type] do |t, args|
62
+ path = args[:helper_type].to_sym == :features ? "features/support/sauce_helper.rb" : "spec/sauce_helper.rb"
63
+ unless File.exists? path
64
+ File.open(path, "w") do |f|
65
+ f.write(Sauce::Utilities::Rake.sauce_helper)
66
+ end
67
+ else
68
+ STDERR.puts "WARNING - sauce_helper has already been created."
69
+ end
70
+ end
71
+ end
72
+ end
73
+
74
+ def run_parallel_tests(t, args, command)
75
+ if ParallelTests.number_of_running_processes == 0
76
+ username = ENV["SAUCE_USERNAME"].to_s
77
+ access_key = ENV["SAUCE_ACCESS_KEY"].to_s
78
+ if(!username.empty? && !access_key.empty?)
79
+ parallel_arguments = parse_task_args(command, args)
80
+ ParallelTests::CLI.new.run(parallel_arguments)
81
+ else
82
+ puts <<-ENDLINE
83
+ -----------------------------------------------------------------------
84
+ Your Sauce username and/or access key are unavailable. Please:
85
+ 1. Set the SAUCE_USERNAME and SAUCE_ACCESS_KEY environment variables.
86
+ 2. Rerun your tests.
87
+ -----------------------------------------------------------------------
88
+ ENDLINE
89
+ end
90
+ else
91
+ puts <<-ENDLINE
92
+ ---------------------------------------------------------------------------
93
+ There are already parallel_tests processes running. This can interfere
94
+ with test startup and shutdown.
95
+
96
+ If you're not running other parallel tests, this might be caused by zombie
97
+ processes (The worst kind of processes). Kill `em off and try again.
98
+ ---------------------------------------------------------------------------
99
+ ENDLINE
100
+ exit(1)
101
+ end
102
+ end
103
+
104
+ def parse_task_args(test_tool=:rspec, args)
105
+ default = {
106
+ :concurrency => [Sauce::TestBroker.concurrency, 20].min
107
+ }
108
+
109
+ if test_tool == :rspec
110
+ default[:test_options] = '-t sauce'
111
+ default[:files] = 'spec'
112
+ end
113
+
114
+ if test_tool == :cucumber
115
+ default[:files] = 'features'
116
+ end
117
+
118
+ env_args = {
119
+ :concurrency => ENV['concurrency'],
120
+ :features => ENV['features'],
121
+ :parallel_options => ENV['parallel_test_options'],
122
+ :test_options => ENV['test_options'],
123
+ :files => ENV['test_files']
124
+ }
125
+
126
+ concurrency = args[:concurrency] || env_args[:concurrency] || default[:concurrency]
127
+ test_options = args[:test_options] || env_args[:test_options] || default[:test_options]
128
+ parallel_options = args[:parallel_options] || env_args[:parallel_options]
129
+ files = args[:files] || env_args[:files] || default[:files]
130
+
131
+ return_args = [
132
+ '-n', concurrency.to_s,
133
+ '--type'
134
+ ]
135
+
136
+ return_args.push 'saucerspec' if test_tool == :rspec
137
+ return_args.push 'saucecucumber' if test_tool == :cucumber
138
+
139
+ if test_options
140
+ return_args.push '-o'
141
+ return_args.push test_options
142
+ end
143
+
144
+ return_args.push *(parallel_options.split(' ')) if parallel_options
145
+ return_args.concat files.split
146
+
147
+ return return_args
148
+ end
@@ -0,0 +1,42 @@
1
+ # NOTE: This file is verbatim "borrowed" from the cucumber source tree:
2
+ # <https://github.com/cucumber/cucumber/blob/master/spec/cucumber/formatter/spec_helper.rb>
3
+
4
+ require 'cucumber'
5
+
6
+ module Sauce
7
+ module Cucumber
8
+ module SpecHelper
9
+ def run_defined_feature(content)
10
+ features = load_features(content || raise("No feature content defined!"))
11
+ run(features)
12
+ end
13
+
14
+ def step_mother
15
+ @step_mother ||= ::Cucumber::Runtime.new
16
+ end
17
+
18
+ def load_features(content)
19
+ feature_file = ::Cucumber::FeatureFile.new('mock.feature', content)
20
+ features = ::Cucumber::Ast::Features.new
21
+ filters = []
22
+ feature = feature_file.parse(filters, {})
23
+ features.add_feature(feature) if feature
24
+ features
25
+ end
26
+
27
+ def run(features)
28
+ configuration = ::Cucumber::Configuration.default
29
+ tree_walker = ::Cucumber::Ast::TreeWalker.new(step_mother, [@formatter], configuration)
30
+ tree_walker.visit_features(features)
31
+ end
32
+
33
+ def define_steps(&block)
34
+ rb = step_mother.load_programming_language('rb')
35
+ dsl = Object.new
36
+ dsl.extend ::Cucumber::RbSupport::RbDsl
37
+ dsl.instance_exec &block
38
+ end
39
+ end
40
+ end
41
+ end
42
+
@@ -0,0 +1,21 @@
1
+ require "simplecov"
2
+
3
+ SimpleCov.start do
4
+ SimpleCov.root "#{Dir.pwd}/../../../"
5
+ command_name 'Connect Integration'
6
+ use_merging true
7
+ merge_timeout 6000
8
+ end
9
+
10
+ require "sauce"
11
+ require "capybara/rspec"
12
+ require "sauce/capybara"
13
+
14
+ Sauce.config do |c|
15
+ c[:start_tunnel] = true
16
+ c[:warn_on_skipped_integration] = false
17
+ c[:sauce_connect_4_executable] = ENV["SAUCE_CONNECT_4_EXECUTABLE"]
18
+ end
19
+
20
+ app = proc { |env| [200, {}, ["Hello Sauce!"]]}
21
+ Capybara.app = app
@@ -0,0 +1,9 @@
1
+ require "spec_helper"
2
+
3
+ describe "Sauce::Config" do
4
+ it "should start Connect when start_tunnel is set" do
5
+ tunnel = Sauce::Utilities::Connect.tunnel
6
+ tunnel.should_not be_nil
7
+ tunnel.status.should eq "running"
8
+ end
9
+ end
@@ -0,0 +1,10 @@
1
+ require "spec_helper"
2
+
3
+ describe "Capybara" do
4
+ describe "Without :sauce tagging", :js => true, :type => :feature do
5
+ it "should connect using the port", :js => true do
6
+ visit "/"
7
+ expect(page).to have_content "Hello Sauce!"
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,99 @@
1
+ require 'spec_helper'
2
+ require 'sauce/connect'
3
+
4
+ describe 'Sauce::Connect integration testing' do
5
+ def make_connection
6
+ Sauce::Connect.new({})
7
+ end
8
+
9
+ def backup_and_wipe_env_var(var)
10
+ self.instance_variable_set("@env_#{var}", ENV[var])
11
+ ENV[var] = nil
12
+ end
13
+
14
+ def restore_env_var(var)
15
+ value_of_variable = self.instance_variable_get("@env_#{var}")
16
+ ENV[var] = value_of_variable unless value_of_variable.nil?
17
+ end
18
+
19
+ before :each do
20
+ Sauce.clear_config
21
+ end
22
+
23
+ context 'assuming valid Sauce Labs authentication' do
24
+ # Defining a nil in the let since the before block will run after the let.
25
+ # Running make_connection inside of a `let` block could end up with us
26
+ # using the previous test's Sauce.config. BAD NEWS
27
+ before :each do
28
+ @conn = make_connection
29
+ end
30
+
31
+ it 'should have start with an uninitialized status' do
32
+ @conn.status.should == 'uninitialized'
33
+ end
34
+
35
+ it 'should have a "running" status if the tunnel is connected' do
36
+ @conn.connect
37
+ @conn.wait_until_ready
38
+ @conn.status.should == 'running'
39
+ end
40
+
41
+ after :each do
42
+ @conn.disconnect if @conn
43
+ end
44
+ end
45
+
46
+ context 'assuming an invalid/nonexistent username' do
47
+ before :each do
48
+ Sauce.config do |config|
49
+ config[:username] = nil
50
+ config[:access_key] = nil
51
+ end
52
+ end
53
+
54
+ it 'should fail if the SAUCE_USERNAME is empty' do
55
+ expect {
56
+ backup_and_wipe_env_var "SAUCE_USERNAME"
57
+ ENV['SAUCE_USERNAME'] = nil
58
+ make_connection
59
+ }.to raise_error(ArgumentError)
60
+ end
61
+
62
+ it 'should fail if the SAUCE_ACCESS_KEY is empty' do
63
+ expect {
64
+ backup_and_wipe_env_var "SAUCE_ACCESS_KEY"
65
+ backup_and_wipe_env_var "SAUCE_USERNAME"
66
+
67
+ ENV['SAUCE_USERNAME'] = 'testman'
68
+ make_connection
69
+ }.to raise_error(ArgumentError)
70
+
71
+ end
72
+
73
+ after :each do
74
+ restore_env_var "SAUCE_USERNAME"
75
+ restore_env_var "SAUCE_ACCESS_KEY"
76
+ end
77
+ end
78
+
79
+ context 'assuming the "fail" username' do
80
+ let(:conn) { Sauce::Connect.new(:host => 'saucelabs.com',
81
+ :port => 80,
82
+ :username => 'fail',
83
+ :access_key => 'edededdedededeee') }
84
+
85
+ it 'should set the error status' do
86
+ start = Time.now
87
+ conn.connect
88
+ while ((Time.now - start) < 60) && !conn.error
89
+ sleep 0.5
90
+ end
91
+
92
+ conn.error.should_not be nil
93
+ end
94
+
95
+ after :each do
96
+ conn.disconnect
97
+ end
98
+ end
99
+ end