Permalink
Browse files

Schweet RSpec integration

  • Loading branch information...
1 parent 80df8c0 commit e1f05af05c206365607f583e1121794463615392 @epall epall committed Oct 25, 2010
Showing with 80 additions and 11 deletions.
  1. +1 −1 VERSION
  2. +28 −4 lib/sauce/config.rb
  3. +8 −4 lib/sauce/integrations.rb
  4. +3 −1 test/helper.rb
  5. +9 −1 test/saucelabs_spec.rb
  6. +31 −0 test/test_config.rb
View
@@ -1 +1 @@
-0.6.3
+0.7.0
View
@@ -2,6 +2,15 @@
require 'yaml'
module Sauce
+ def self.config
+ @cfg = Sauce::Config.new(false)
+ yield @cfg
+ end
+
+ def self.get_config
+ @cfg
+ end
+
class Config
attr_reader :opts
DEFAULT_OPTIONS = {
@@ -15,13 +24,23 @@ class Config
}
def initialize(opts={})
- @opts = DEFAULT_OPTIONS.merge(load_options_from_yaml)
- @opts.merge! load_options_from_environment
- @opts.merge! opts
+ @opts = {}
+ if opts != false
+ @opts.merge! DEFAULT_OPTIONS
+ @opts.merge! load_options_from_yaml
+ @opts.merge! load_options_from_environment
+ @opts.merge! Sauce.get_config.opts rescue {}
+ @opts.merge! opts
+ end
end
def method_missing(meth, *args)
- return @opts[meth]
+ if meth.to_s =~ /(.*)=$/
+ @opts[$1.to_sym] = args[0]
+ return args[0]
+ else
+ return @opts[meth]
+ end
end
def to_browser_string
@@ -35,6 +54,11 @@ def to_browser_string
return browser_options.to_json
end
+ def browsers
+ return @opts[:browsers] if @opts.include? :browsers
+ return [[os, browser, browser_version]]
+ end
+
private
def load_options_from_environment
View
@@ -5,10 +5,6 @@ module RSpec
class SeleniumExampleGroup < Spec::Example::ExampleGroup
attr_reader :selenium
- before(:all) do
- @selenium = Sauce::Selenium.new
- end
-
before(:each) do
@selenium.start
end
@@ -17,6 +13,14 @@ class SeleniumExampleGroup < Spec::Example::ExampleGroup
@selenium.stop
end
+ def execute(*args)
+ config = Sauce::Config.new
+ config.browsers.each do |os, browser, version|
+ @selenium = Sauce::Selenium.new({:os => os, :browser => browser, :browser_version => version})
+ super(*args)
+ end
+ end
+
alias_method :page, :selenium
alias_method :s, :selenium
View
@@ -7,5 +7,7 @@
$LOAD_PATH.unshift(File.dirname(__FILE__))
require 'sauce'
-class Test::Unit::TestCase
+Sauce.config do |config|
+ config.browsers = [['Windows 2003', 'firefox', '3.6.']]
+ config.root_url = "http://saucelabs.com"
end
View
@@ -1,6 +1,14 @@
require 'helper'
-describe "saucelabs.com", :type => :selenium do
+# This should go in a test helper
+Sauce.config do |config|
+ config.browsers = [
+ ["Windows 2003", "firefox", "3.6."],
+ ["Windows 2003", "safariproxy", "5."]
+ ]
+end
+
+describe "The Sauce website", :type => :selenium do
it "works" do
page.open "/"
page.is_text_present("Sauce Labs").should be_true
View
@@ -23,5 +23,36 @@ class TestConfig < Test::Unit::TestCase
config = Sauce::Config.new
assert_equal "saucelabs.com", config.host
end
+
+ should "gracefully degrade the browsers field" do
+ Sauce.config {|c|}
+ config = Sauce::Config.new
+ config.os = "A"
+ config.browser = "B"
+ config.browser_version = "C"
+
+ assert_equal [["A", "B", "C"]], config.browsers
+ end
+ end
+
+ context "The Sauce.config method" do
+ should "Allow you to set a default OS" do
+ Sauce.config {|c| c.os = "TEST_OS" }
+
+ config = Sauce::Config.new
+ assert_equal "TEST_OS", config.os
+ end
+
+ should "Be callable twice" do
+ Sauce.config {|c| c.os = "A"}
+ assert_equal "A", Sauce::Config.new.os
+ Sauce.config {|c|}
+ assert_not_equal "A", Sauce::Config.new.os
+ end
+
+ should "not retain config after being called again" do
+ Sauce.config {|c|}
+ assert_not_equal [["Windows 2003", "firefox", "3.6."]], Sauce::Config.new.browsers
+ end
end
end

0 comments on commit e1f05af

Please sign in to comment.