sauce 2.3.4 → 2.3.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -40,12 +40,12 @@ module Sauce
40
40
  require 'sauce'
41
41
 
42
42
  Sauce.config do |conf|
43
- conf.browsers = [
43
+ conf[:browsers] = [
44
44
  ["Windows 2003", "firefox", "3.6."]
45
45
  ]
46
- conf.application_host = "127.0.0.1"
47
- conf.application_port = "3001"
48
- conf.browser_url = "http://localhost:3001/"
46
+ conf[:application_host] = "127.0.0.1"
47
+ conf[:application_port] = "3001"
48
+ conf[:browser_url] = "http://localhost:3001/"
49
49
  end
50
50
  CONFIG
51
51
  end
data/lib/sauce.rb CHANGED
@@ -5,3 +5,9 @@ require 'sauce/client'
5
5
  require 'sauce/config'
6
6
  require 'sauce/selenium'
7
7
  require 'sauce/integrations'
8
+
9
+ module Sauce
10
+ def self.driver_pool
11
+ @@driver_pool ||= {}
12
+ end
13
+ end
@@ -85,21 +85,40 @@ module Sauce
85
85
  end
86
86
 
87
87
  def browser
88
- unless @browser
89
- if Sauce.get_config[:start_tunnel]
90
- Sauce::Capybara.connect_tunnel(:quiet => true)
91
- end
92
-
93
- @browser = Sauce::Selenium2.new
94
- at_exit do
95
- finish!
88
+ unless existing_browser?
89
+ unless @browser = rspec_browser
90
+ if Sauce.get_config[:start_tunnel]
91
+ Sauce::Capybara.connect_tunnel(:quiet => true)
92
+ end
93
+
94
+ @browser = Sauce::Selenium2.new
95
+ at_exit do
96
+ finish!
97
+ end
96
98
  end
97
99
  end
98
100
  @browser
99
101
  end
100
102
 
103
+ def rspec_browser
104
+ if browser = Sauce.driver_pool[Thread.current.object_id]
105
+ @using_rspec_browser = true
106
+ else
107
+ @using_rspec_browser = false
108
+ end
109
+ browser
110
+ end
111
+
112
+ def existing_browser?
113
+ if @using_rspec_browser
114
+ @browser == Sauce.driver_pool[Thread.current.object_id]
115
+ else
116
+ @browser
117
+ end
118
+ end
119
+
101
120
  def finish!
102
- @browser.quit if @browser
121
+ @browser.quit if existing_browser?
103
122
  @browser = nil
104
123
  $sauce_tunnel.disconnect if $sauce_tunnel
105
124
  end
@@ -17,7 +17,7 @@ begin
17
17
  before :suite do
18
18
  config = Sauce::Config.new
19
19
  if @@need_tunnel
20
- if config.application_host
20
+ if config[:application_host]
21
21
  @@tunnel = Sauce::Connect.new(:host => config.application_host, :port => config.application_port || 80)
22
22
  @@tunnel.connect
23
23
  @@tunnel.wait_until_ready
@@ -37,7 +37,7 @@ begin
37
37
  def execute(*args)
38
38
  config = Sauce::Config.new
39
39
  description = [self.class.description, self.description].join(" ")
40
- config.browsers.each do |os, browser, version|
40
+ config[:browsers].each do |os, browser, version|
41
41
  @selenium = Sauce::Selenium2.new({:os => os, :browser => browser,
42
42
  :browser_version => version,
43
43
  :job_name => description})
@@ -77,10 +77,13 @@ begin
77
77
  :browser => browser,
78
78
  :browser_version => version,
79
79
  :job_name => description})
80
+ Sauce.driver_pool[Thread.current.object_id] = @selenium
81
+
80
82
  begin
81
83
  the_test.run
82
84
  ensure
83
85
  @selenium.stop
86
+ Sauce.driver_pool.delete Thread.current.object_id
84
87
  end
85
88
  end
86
89
  end
@@ -94,7 +97,7 @@ begin
94
97
  config = Sauce::Config.new
95
98
  files_to_run = ::RSpec.configuration.respond_to?(:files_to_run) ? ::RSpec.configuration.files_to_run :
96
99
  ::RSpec.configuration.settings[:files_to_run]
97
- if config.application_host
100
+ if config[:application_host]
98
101
  need_tunnel = files_to_run.any? {|file| file =~ /spec\/selenium\//}
99
102
  end
100
103
  if need_tunnel
@@ -138,7 +141,7 @@ module Sauce
138
141
  end
139
142
  unless my_name =~ /^default_test/
140
143
  config = Sauce::Config.new
141
- if config.application_host
144
+ if config[:application_host]
142
145
  unless ENV['TEST_ENV_NUMBER'].to_i > 1
143
146
  Sauce::Connect.ensure_connected(:host => config.application_host, :port => config.application_port || 80)
144
147
  end
@@ -156,7 +159,7 @@ module Sauce
156
159
  end
157
160
  end
158
161
 
159
- config.browsers.each do |os, browser, version|
162
+ config[:browsers].each do |os, browser, version|
160
163
  options = self.class.sauce_config
161
164
  options.merge!({:os => os, :browser => browser,
162
165
  :browser_version => version,
@@ -0,0 +1,24 @@
1
+ require "spec_helper"
2
+ require "sauce"
3
+
4
+ Sauce.config do |c|
5
+ c.browsers = [
6
+ ["Windows 2008", "iexplore", "9"],
7
+ ["Linux", "opera", 12]
8
+ ]
9
+ end
10
+
11
+ describe "Specs in the Selenium Directory" do
12
+
13
+ before :all do
14
+ $EXECUTIONS = 0
15
+ end
16
+
17
+ after :all do
18
+ $EXECUTIONS.should be 2
19
+ end
20
+
21
+ it "should get run on every defined browser" do
22
+ $EXECUTIONS += 1
23
+ end
24
+ end
@@ -0,0 +1,36 @@
1
+ require "rspec"
2
+ require "rspec/mocks"
3
+ require "spec_helper"
4
+ require "sauce/capybara"
5
+
6
+ class MyRackApp
7
+ def self.call(env)
8
+ [200, {}, ["Hello"]]
9
+ end
10
+ end
11
+
12
+ Sauce.config do |c|
13
+ c.browsers = [
14
+ ["Windows 2008", "iexplore", "9"],
15
+ ["Linux", "opera", 12]
16
+ ]
17
+ end
18
+
19
+ Capybara.app = MyRackApp
20
+
21
+ describe "The Selenium Directory with Capybara", :js => true do
22
+
23
+ include Capybara::DSL
24
+ it "should get run on every defined browser", :js => true do
25
+ visit "http://www.google.com"
26
+ end
27
+
28
+ it "should have the same driver as stock webdriver", :js => true do
29
+ Capybara.current_session.driver.browser.should eq @selenium
30
+ end
31
+
32
+ it "should not create a new driver" do
33
+ ::Sauce::Selenium2.should_not_receive(:new)
34
+ visit "http://wwww.google.com"
35
+ end
36
+ end
@@ -0,0 +1,2 @@
1
+ require "rspec"
2
+ require "capybara/rspec"
@@ -103,6 +103,72 @@ describe Sauce::Capybara do
103
103
  end
104
104
  end
105
105
 
106
+ describe '#rspec_browser' do
107
+ let(:driver) { Sauce::Capybara::Driver.new(app) }
108
+
109
+ before :each do
110
+ Sauce::Selenium2.stub(:new).and_return(nil)
111
+ end
112
+
113
+ context "with no rspec driver" do
114
+
115
+ before :each do
116
+ Sauce.stub(:driver_pool).and_return({})
117
+ end
118
+
119
+ it "should return nil" do
120
+ driver.rspec_browser.should be nil
121
+ end
122
+
123
+ it "should set the rspec_driver flag to false" do
124
+ driver.rspec_browser
125
+ driver.instance_variable_get(:@using_rspec_browser).should be_false
126
+ end
127
+
128
+ end
129
+
130
+ context "with an rspec driver" do
131
+ let(:mock_driver) {Object.new}
132
+ before :each do
133
+ Sauce.stub(:driver_pool).and_return({Thread.current.object_id => mock_driver})
134
+ end
135
+
136
+ it "should return the driver" do
137
+ driver.rspec_browser.should be mock_driver
138
+ end
139
+
140
+ it "should set the rspec_driver flag to true" do
141
+ driver.rspec_browser
142
+ driver.instance_variable_get(:@using_rspec_browser).should be_true
143
+ end
144
+ end
145
+
146
+ context "called after a driver_pool change" do
147
+
148
+ context "with no driver present" do
149
+ let(:mock_driver) {Object.new}
150
+
151
+ before (:each) do
152
+ Sauce.stub(:driver_pool).and_return(
153
+ {Thread.current.object_id => mock_driver},
154
+ {Thread.current.object_id => nil}
155
+ )
156
+ end
157
+
158
+ it "should return nil" do
159
+ driver.rspec_browser.should eq mock_driver
160
+ driver.rspec_browser.should be nil
161
+ end
162
+
163
+ it "should set rspec_browser flag false" do
164
+ driver.rspec_browser
165
+ driver.rspec_browser
166
+ driver.instance_variable_get(:@using_rspec_browser).should be_false
167
+ end
168
+ end
169
+ end
170
+ end
171
+
106
172
  describe '#browser' do
107
173
  let(:driver) { Sauce::Capybara::Driver.new(app) }
108
174
 
@@ -110,6 +176,18 @@ describe Sauce::Capybara do
110
176
  # Stub out the selenium driver startup
111
177
  Sauce::Selenium2.stub(:new).and_return(nil)
112
178
  end
179
+
180
+ context "when there is a driver in the driver pool" do
181
+ let(:mock_browser) {Object.new}
182
+ before :each do
183
+ Sauce.driver_pool[Thread.current.object_id] = mock_browser
184
+ end
185
+
186
+ it "should use the driver_pools browser" do
187
+ driver.browser.should eq mock_browser
188
+ end
189
+ end
190
+
113
191
  context 'when tunneling is disabled' do
114
192
  it 'should not call #connect_tunnel' do
115
193
  Sauce::Capybara.should_receive(:connect_tunnel).never
@@ -57,11 +57,11 @@ describe Sauce::Config do
57
57
  describe '#os' do
58
58
  it 'should return the value set in the config block' do
59
59
  Sauce.config do |config|
60
- config.os = 'TEST_OS'
60
+ config[:os] = 'TEST_OS'
61
61
  end
62
62
 
63
63
  c = Sauce::Config.new
64
- c.os.should == 'TEST_OS'
64
+ c[:os].should == 'TEST_OS'
65
65
  end
66
66
  end
67
67
 
@@ -206,7 +206,7 @@ describe Sauce::Config do
206
206
  describe 'browsers=' do
207
207
  it 'should default the config to the first item' do
208
208
  Sauce.config do |config|
209
- config.browsers = [['TEST_OS', 'TEST_BROWSER', 'TEST_BROWSER_VERSION']]
209
+ config[:browsers] = [['TEST_OS', 'TEST_BROWSER', 'TEST_BROWSER_VERSION']]
210
210
  end
211
211
 
212
212
  c = Sauce::Config.new
@@ -228,7 +228,7 @@ describe Sauce::Config do
228
228
 
229
229
  it 'should allow overrides as constructor options' do
230
230
  Sauce.config do |config|
231
- config.browsers = [['OS1', 'BROWSER1', 'BROWSER_VERSION1']]
231
+ config[:browsers] = [['OS1', 'BROWSER1', 'BROWSER_VERSION1']]
232
232
  end
233
233
 
234
234
  c = Sauce::Config.new(:os => 'OS2', :browser => 'BROWSER2',
@@ -0,0 +1,8 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
+
3
+ describe "DriverPool" do
4
+
5
+ it "should be a hash" do
6
+ Sauce.driver_pool.should be_an_instance_of Hash
7
+ end
8
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sauce
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.3.4
4
+ version: 2.3.5
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -14,7 +14,7 @@ authors:
14
14
  autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
- date: 2013-03-26 00:00:00.000000000 Z
17
+ date: 2013-04-02 00:00:00.000000000 Z
18
18
  dependencies:
19
19
  - !ruby/object:Gem::Dependency
20
20
  name: net-http-persistent
@@ -183,9 +183,13 @@ files:
183
183
  - lib/sauce.rb
184
184
  - spec/cucumber_helper.rb
185
185
  - spec/integration/connect_integration_spec.rb
186
+ - spec/integration/rspec/spec/selenium/selenium_directory_spec.rb
187
+ - spec/integration/rspec/spec/selenium/selenium_with_capybara_spec.rb
188
+ - spec/integration/rspec/spec/spec_helper.rb
186
189
  - spec/sauce/capybara_spec.rb
187
190
  - spec/sauce/config_spec.rb
188
191
  - spec/sauce/cucumber_spec.rb
192
+ - spec/sauce/driver_pool_spec.rb
189
193
  - spec/sauce/jasmine_spec.rb
190
194
  - spec/sauce/selenium_spec.rb
191
195
  - spec/spec_helper.rb
@@ -204,7 +208,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
204
208
  version: '0'
205
209
  segments:
206
210
  - 0
207
- hash: -2889318563939788331
211
+ hash: -1836059849841492535
208
212
  required_rubygems_version: !ruby/object:Gem::Requirement
209
213
  none: false
210
214
  requirements:
@@ -213,7 +217,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
213
217
  version: '0'
214
218
  segments:
215
219
  - 0
216
- hash: -2889318563939788331
220
+ hash: -1836059849841492535
217
221
  requirements: []
218
222
  rubyforge_project:
219
223
  rubygems_version: 1.8.25
@@ -223,9 +227,13 @@ summary: A Ruby helper for running tests in Sauce Labs
223
227
  test_files:
224
228
  - spec/cucumber_helper.rb
225
229
  - spec/integration/connect_integration_spec.rb
230
+ - spec/integration/rspec/spec/selenium/selenium_directory_spec.rb
231
+ - spec/integration/rspec/spec/selenium/selenium_with_capybara_spec.rb
232
+ - spec/integration/rspec/spec/spec_helper.rb
226
233
  - spec/sauce/capybara_spec.rb
227
234
  - spec/sauce/config_spec.rb
228
235
  - spec/sauce/cucumber_spec.rb
236
+ - spec/sauce/driver_pool_spec.rb
229
237
  - spec/sauce/jasmine_spec.rb
230
238
  - spec/sauce/selenium_spec.rb
231
239
  - spec/spec_helper.rb