sauce 0.16.2 → 0.17.0

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.
data/Rakefile CHANGED
@@ -51,3 +51,11 @@ Rake::RDocTask.new do |rdoc|
51
51
  rdoc.rdoc_files.include('README*')
52
52
  rdoc.rdoc_files.include('lib/**/*.rb')
53
53
  end
54
+
55
+ task :build do
56
+ system "gem build sauce.gemspec"
57
+ end
58
+
59
+ task :push => :build do
60
+ system "gem push `ls *.gem | sort | tail -n 1`"
61
+ end
data/lib/sauce/client.rb CHANGED
@@ -7,14 +7,12 @@ module Sauce
7
7
  class BadAccessError < StandardError; end #:nodoc
8
8
  class MisconfiguredError < StandardError; end #:nodoc
9
9
 
10
- attr_accessor :username, :access_key, :client
10
+ attr_accessor :client
11
11
  attr_accessor :protocol, :host, :port, :api_path, :api_version, :ip, :api_url
12
12
  attr_accessor :tunnels, :jobs
13
13
 
14
- def initialize(options)
15
- @username = options[:username]
16
- @access_key = options[:access_key]
17
- @ip = options[:ip]
14
+ def initialize(options={})
15
+ config = Sauce::Config.new
18
16
 
19
17
  @protocol = options[:protocol] || "http"
20
18
  @host = options[:host] || "saucelabs.com"
@@ -22,24 +20,28 @@ module Sauce
22
20
  @api_path = options[:api_path] || "rest"
23
21
  @api_version= options[:api_version] || 1
24
22
 
25
- raise MisconfiguredError if @username.nil? or @access_key.nil?
26
- @api_url = "#{@protocol}://#{@username}:#{@access_key}@#{@host}:#{@port}/#{@api_path}/v#{@api_version}/#{@username}/"
23
+ raise MisconfiguredError if config.username.nil? or config.access_key.nil?
24
+ @api_url = "#{@protocol}://#{config.username}:#{config.access_key}@#{@host}:#{@port}/#{@api_path}/v#{@api_version}/#{config.username}/"
27
25
  @client = RestClient::Resource.new @api_url
28
26
 
29
27
  @tunnels = Sauce::Tunnel
30
28
  @tunnels.client = @client
31
29
  @tunnels.account = {
32
- :username => @username,
33
- :access_key => @access_key,
30
+ :username => config.username,
31
+ :access_key => config.access_key,
34
32
  :ip => @ip}
35
33
 
36
34
  @jobs = Sauce::Job
37
35
  @jobs.client = @client
38
36
  @jobs.account = {
39
- :username => @username,
40
- :access_key => @access_key,
37
+ :username => config.username,
38
+ :access_key => config.access_key,
41
39
  :ip => @ip
42
40
  }
43
41
  end
42
+
43
+ def [](url)
44
+ @client[url]
45
+ end
44
46
  end
45
47
  end
data/lib/sauce/config.rb CHANGED
@@ -39,6 +39,10 @@ module Sauce
39
39
  "iexplore" => "internet explorer"
40
40
  }
41
41
 
42
+ SAUCE_OPTIONS = %w{record-video record-screenshots capture-html tags
43
+ sauce-advisor single-window user-extensions-url firefox-profile-url
44
+ max-duration idle-timeout build custom-data}
45
+
42
46
  def initialize(opts={})
43
47
  @opts = {}
44
48
  if opts != false
@@ -69,7 +73,12 @@ module Sauce
69
73
  'os' => os,
70
74
  'browser' => browser,
71
75
  'browser-version' => browser_version,
72
- 'name' => @opts[:job_name]}
76
+ 'name' => @opts[:name] || @opts[:job_name]}
77
+
78
+ SAUCE_OPTIONS.each do |opt|
79
+ opt = opt.to_sym
80
+ browser_options[opt] = @opts[opt] if @opts.include? opt
81
+ end
73
82
  return browser_options.to_json
74
83
  end
75
84
 
@@ -128,7 +137,7 @@ module Sauce
128
137
 
129
138
  def load_options_from_heroku
130
139
  @@herkou_environment ||= begin
131
- buffer = IO.popen("heroku config --shell") { |out| out.read }
140
+ buffer = IO.popen("heroku config --shell 2>/dev/null") { |out| out.read }
132
141
  if $?.exitstatus == 0
133
142
  env = {}
134
143
  buffer.split("\n").each do |line|
data/lib/sauce/connect.rb CHANGED
@@ -63,5 +63,24 @@ module Sauce
63
63
  def self.find_sauce_connect
64
64
  File.join(File.dirname(File.dirname(File.expand_path(File.dirname(__FILE__)))), "support", "sauce_connect")
65
65
  end
66
+
67
+ # Global Sauce Connect-ness
68
+ @connection = nil
69
+
70
+ def self.connect!(*args)
71
+ @connection = self.new(*args)
72
+ @connection.wait_until_ready
73
+ at_exit do
74
+ @connection.disconnect
75
+ end
76
+ end
77
+
78
+ def self.ensure_connected(*args)
79
+ if @connection
80
+ @connection.wait_until_ready
81
+ else
82
+ connect!(*args)
83
+ end
84
+ end
66
85
  end
67
86
  end
@@ -122,160 +122,80 @@ rescue LoadError, TypeError
122
122
  # User doesn't have RSpec 2.x installed
123
123
  end
124
124
 
125
- begin
126
- require 'test/unit/testcase'
127
- module Sauce
128
- class TestCase < Test::Unit::TestCase
129
- attr_reader :selenium
130
-
131
- alias_method :page, :selenium
132
- alias_method :s, :selenium
125
+ module Sauce
126
+ module SeleniumForTestUnit
127
+ attr_reader :browser
128
+
129
+ alias_method :page, :browser
130
+ alias_method :s, :browser
131
+ alias_method :selenium, :browser
132
+
133
+ def run(*args, &blk)
134
+ if self.respond_to? :name
135
+ my_name = self.name
136
+ else
137
+ my_name = self.__name__
138
+ end
139
+ unless my_name =~ /^default_test/
140
+ config = Sauce::Config.new
141
+ if config.application_host && !config.local?
142
+ Sauce::Connect.ensure_connected(:host => config.application_host, :port => config.application_port || 80)
143
+ end
133
144
 
134
- def run(*args, &blk)
135
- if self.respond_to? :name
136
- my_name = self.name
137
- else
138
- my_name = self.__name__
145
+ unless defined?(@@server)
146
+ @@server = Sauce::Utilities::RailsServer.new
147
+ @@server.start
148
+ at_exit do
149
+ @@server.stop
150
+ end
139
151
  end
140
- unless my_name =~ /^default_test/
141
- config = Sauce::Config.new
142
- config.browsers.each do |os, browser, version|
152
+
153
+ config.browsers.each do |os, browser, version|
154
+ if config.single_session?
143
155
  if config.local?
144
- @selenium = ::Selenium::Client::Driver.new(:host => "127.0.0.1",
145
- :port => 4444,
146
- :browser => "*" + browser,
147
- :url => "http://127.0.0.1:#{config.local_application_port}/")
156
+ @browser = Sauce.cached_session(:host => "127.0.0.1", :port => 4444, :browser => "*" +
157
+ browser, :url => "http://127.0.0.1:#{config.local_application_port}/")
148
158
  else
149
- @selenium = Sauce::Selenium.new({:os => os, :browser => browser, :browser_version => version,
150
- :job_name => "#{my_name}"})
159
+ @browser = Sauce.cached_session({:os => os, :browser => browser, :browser_version => version,
160
+ :job_name => "#{Rails.root.split[1].to_s} test suite"})
151
161
  end
152
- @selenium.start
153
162
  super(*args, &blk)
154
- @selenium.stop
163
+ else
164
+ if config.local?
165
+ @browser = ::Selenium::Client::Driver.new(:host => "127.0.0.1",
166
+ :port => 4444,
167
+ :browser => "*" + browser,
168
+ :url => "http://127.0.0.1:#{config.local_application_port}/")
169
+ else
170
+ @browser = Sauce::Selenium.new({:os => os, :browser => browser, :browser_version => version,
171
+ :job_name => "#{my_name}"})
172
+ end
173
+ @browser.start
174
+ super(*args, &blk)
175
+ @browser.stop
155
176
  end
156
177
  end
157
178
  end
158
-
159
- # Placeholder so test/unit ignores test cases without any tests.
160
- def default_test
161
- end
162
179
  end
163
180
  end
164
- rescue LoadError
165
- # User doesn't have Test::Unit installed
166
181
  end
167
182
 
168
- begin
169
- require 'test/unit/autorunner'
170
- if defined?(Test::Unit::AutoRunner)
171
- class Test::Unit::AutoRunner
172
- run_without_tunnel = self.instance_method(:run)
183
+ if defined?(ActiveSupport::TestCase)
184
+ module Sauce
185
+ class RailsTestCase < ::ActiveSupport::TestCase
186
+ include SeleniumForTestUnit
173
187
 
174
- define_method(:run) do |*args|
175
- @suite = @collector[self]
176
- need_tunnel = suite.tests.any? do |test_suite|
177
- test_suite.tests.any? do |test_case|
178
- test_case.class.superclass.to_s =~ /^Sauce::/
179
- end
180
- end
181
- if need_tunnel
182
- config = Sauce::Config.new
183
- if config.application_host && !config.local?
184
- @sauce_tunnel = Sauce::Connect.new(:host => config.application_host, :port => config.application_port || 80)
185
- @sauce_tunnel.wait_until_ready
186
- end
187
- @server = Sauce::Utilities::RailsServer.new
188
- @server.start
189
- end
190
- result = run_without_tunnel.bind(self).call(*args)
191
- @sauce_tunnel.disconnect if defined? @sauce_tunnel
192
- @server.stop if defined? @server
193
- return result
188
+ # Placeholder so test/unit ignores test cases without any tests.
189
+ def default_test
194
190
  end
195
191
  end
196
192
  end
197
- rescue LoadError, NameError
198
- # Ruby 1.8's Test::Unit not found
199
193
  end
200
194
 
201
195
  begin
202
- require 'minitest/unit'
203
- module MiniTest
204
- class Unit
205
- run_without_tunnel = self.instance_method(:run_test_suites)
206
-
207
- define_method(:run_test_suites) do |*args|
208
- need_tunnel = TestCase.test_suites.any? do |suite|
209
- suite.superclass.to_s =~ /^Sauce::/
210
- end
211
- if need_tunnel
212
- config = Sauce::Config.new
213
- if config.application_host && !config.local?
214
- @sauce_tunnel = Sauce::Connect.new(:host => config.application_host, :port => config.application_port || 80)
215
- @sauce_tunnel.wait_until_ready
216
- end
217
-
218
- @server = Sauce::Utilities::RailsServer.new
219
- @server.start
220
- end
221
- result = run_without_tunnel.bind(self).call(*args)
222
- @sauce_tunnel.disconnect if defined? @sauce_tunnel
223
- @server.stop if defined? @server
224
- return result
225
- end
226
- end
227
- end
228
- rescue LoadError
229
- # User is not on Ruby 1.9
230
- end
231
-
232
- if defined?(ActiveSupport::TestCase)
196
+ require 'test/unit/testcase'
233
197
  module Sauce
234
- module SeleniumForTestUnit
235
- attr_reader :browser
236
-
237
- alias_method :page, :browser
238
- alias_method :s, :browser
239
- alias_method :selenium, :browser
240
-
241
- def run(*args, &blk)
242
- if self.respond_to? :name
243
- my_name = self.name
244
- else
245
- my_name = self.__name__
246
- end
247
- unless my_name =~ /^default_test/
248
- config = Sauce::Config.new
249
- config.browsers.each do |os, browser, version|
250
- if config.single_session?
251
- if config.local?
252
- @browser = Sauce.cached_session(:host => "127.0.0.1", :port => 4444, :browser => "*" +
253
- browser, :url => "http://127.0.0.1:#{config.local_application_port}/")
254
- else
255
- @browser = Sauce.cached_session({:os => os, :browser => browser, :browser_version => version,
256
- :job_name => "#{Rails.root.split[1].to_s} test suite"})
257
- end
258
- super(*args, &blk)
259
- else
260
- if config.local?
261
- @browser = ::Selenium::Client::Driver.new(:host => "127.0.0.1",
262
- :port => 4444,
263
- :browser => "*" + browser,
264
- :url => "http://127.0.0.1:#{config.local_application_port}/")
265
- else
266
- @browser = Sauce::Selenium.new({:os => os, :browser => browser, :browser_version => version,
267
- :job_name => "#{my_name}"})
268
- end
269
- @browser.start
270
- super(*args, &blk)
271
- @browser.stop
272
- end
273
- end
274
- end
275
- end
276
- end
277
-
278
- class RailsTestCase < ::ActiveSupport::TestCase
198
+ class TestCase < Test::Unit::TestCase
279
199
  include SeleniumForTestUnit
280
200
 
281
201
  # Placeholder so test/unit ignores test cases without any tests.
@@ -283,4 +203,6 @@ if defined?(ActiveSupport::TestCase)
283
203
  end
284
204
  end
285
205
  end
206
+ rescue LoadError
207
+ # User doesn't have Test::Unit installed
286
208
  end
data/lib/sauce/job.rb CHANGED
@@ -66,6 +66,8 @@ module Sauce
66
66
  elsif options.class == Hash
67
67
  id = options[:id]
68
68
  end
69
+
70
+ @@client ||= Sauce::Client.new
69
71
 
70
72
  #puts "GET-URL: #{@@client.url}jobs/#{id}"
71
73
  response = @@client["jobs/#{id}"].get
@@ -20,6 +20,10 @@ module Sauce
20
20
  @driver.send(meth, *args)
21
21
  end
22
22
 
23
+ def session_id
24
+ @driver.send(:bridge).session_id
25
+ end
26
+
23
27
  def stop
24
28
  @driver.quit
25
29
  end
data/sauce.gemspec CHANGED
@@ -2,21 +2,16 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{sauce}
5
- s.version = "0.16.2"
5
+ s.version = "0.17.0"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["Sean Grove", "Eric Allen", "Steven Hazel"]
9
- s.date = %q{2011-02-04}
9
+ s.date = %q{2011-02-09}
10
10
  s.default_executable = %q{sauce}
11
11
  s.description = %q{A Ruby interface to Sauce Labs' services. Start/stop tunnels, retrieve Selenium logs, access video replays, etc.}
12
12
  s.email = %q{help@saucelabs.com}
13
13
  s.executables = ["sauce"]
14
- s.extra_rdoc_files = [
15
- "LICENSE",
16
- "README.markdown"
17
- ]
18
14
  s.files = [
19
- ".document",
20
15
  "LICENSE",
21
16
  "README.markdown",
22
17
  "Rakefile",
@@ -55,6 +50,7 @@ Gem::Specification.new do |s|
55
50
  "support/simplejson/tool.py",
56
51
  "test/helper.rb",
57
52
  "test/test_config.rb",
53
+ "test/test_job.rb",
58
54
  "test/test_connect.rb",
59
55
  "test/test_selenium.rb",
60
56
  "test/test_selenium2.rb"
@@ -72,7 +68,9 @@ Gem::Specification.new do |s|
72
68
  "test/helper.rb",
73
69
  "test/test_config.rb",
74
70
  "test/test_connect.rb",
75
- "test/test_selenium.rb"
71
+ "test/test_selenium.rb",
72
+ "test/test_job.rb",
73
+ "test/test_selenium2.rb"
76
74
  ]
77
75
 
78
76
  if s.respond_to? :specification_version then
data/test/test_job.rb ADDED
@@ -0,0 +1,13 @@
1
+ require File.expand_path("../helper", __FILE__)
2
+
3
+ class TestJob < Test::Unit::TestCase
4
+ def test_running_a_job_creates_a_reasonable_job_object
5
+ selenium = Sauce::Selenium.new(:name => "test_running_a_job_creates_a_job_object")
6
+ selenium.start
7
+ session_id = selenium.session_id
8
+ selenium.stop
9
+
10
+ job = Sauce::Job.find(session_id)
11
+ assert_equal "test_running_a_job_creates_a_job_object", job.name
12
+ end
13
+ end
metadata CHANGED
@@ -5,9 +5,9 @@ version: !ruby/object:Gem::Version
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
- - 16
9
- - 2
10
- version: 0.16.2
8
+ - 17
9
+ - 0
10
+ version: 0.17.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Sean Grove
@@ -17,7 +17,7 @@ autorequire:
17
17
  bindir: bin
18
18
  cert_chain: []
19
19
 
20
- date: 2011-02-04 00:00:00 -08:00
20
+ date: 2011-02-09 00:00:00 -08:00
21
21
  default_executable: sauce
22
22
  dependencies:
23
23
  - !ruby/object:Gem::Dependency
@@ -148,11 +148,9 @@ executables:
148
148
  - sauce
149
149
  extensions: []
150
150
 
151
- extra_rdoc_files:
152
- - LICENSE
153
- - README.markdown
151
+ extra_rdoc_files: []
152
+
154
153
  files:
155
- - .document
156
154
  - LICENSE
157
155
  - README.markdown
158
156
  - Rakefile
@@ -191,6 +189,7 @@ files:
191
189
  - support/simplejson/tool.py
192
190
  - test/helper.rb
193
191
  - test/test_config.rb
192
+ - test/test_job.rb
194
193
  - test/test_connect.rb
195
194
  - test/test_selenium.rb
196
195
  - test/test_selenium2.rb
@@ -238,3 +237,5 @@ test_files:
238
237
  - test/test_config.rb
239
238
  - test/test_connect.rb
240
239
  - test/test_selenium.rb
240
+ - test/test_job.rb
241
+ - test/test_selenium2.rb
data/.document DELETED
@@ -1,5 +0,0 @@
1
- README.rdoc
2
- lib/**/*.rb
3
- bin/*
4
- features/**/*.feature
5
- LICENSE