Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Update to be Compatible with Rails 3.1 #6

Merged
merged 7 commits into from over 2 years ago

2 participants

Chris Marinos Steven Hazel
Chris Marinos

Since Jasmine works differently in Rails 3.1 due to the asset pipeline, I patched jasmine-sauce to use guard-jasmine to run the test server. This allows you to use gems like jasminerice for rails 3.1.

Steven Hazel sah merged commit 1e8bd6c into from
Steven Hazel sah closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
14 README.md
Source Rendered
@@ -12,8 +12,9 @@ Getting Started
12 12 1. Add jasmine-sauce to your Gemfile
13 13 2. bundle install
14 14 3. bundle exec sauce config <YOUR_SAUCE_USENRAME> <YOUR_SAUCE_API_KEY>
15   -4. rails generate sauce:jasmine
16   -5. rake jasmine:ci:sauce
  15 +4. install jasmine for your current rails version as directed in the [guard-jasmine README](https://github.com/netzpirat/guard-jasmine)
  16 +5. rails generate sauce:jasmine
  17 +6. rake jasmine:ci:sauce
17 18
18 19 Rails 2.3
19 20 ---------
@@ -43,3 +44,12 @@ end
43 44
44 45 Modify the browser strings as necessary, look here for details on what to put in there
45 46 https://saucelabs.com/docs/sauce-ondemand/browsers
  47 +
  48 +Changing Settings
  49 +-----------------
  50 +By default, jasmine-sauce will run a server on port 8080 using guard-jasmine's auto server setting.
  51 +You can override these defaults to use a different port or server (such as thin).
  52 +
  53 +```rake jasmine:ci:sauce PORT=<PORT_NUMBER> SERVER=<SERVER_TYPE>```
  54 +
  55 +For details on the available server types, see the [guard-jasmine server types](https://github.com/netzpirat/guard-jasmine#server-options)
4 jasmine-sauce.gemspec
@@ -2,7 +2,7 @@
2 2
3 3 Gem::Specification.new do |s|
4 4 s.name = %q{jasmine-sauce}
5   - s.version = "0.2.2"
  5 + s.version = "0.2.3"
6 6
7 7 s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8 8 s.authors = ["Eric Allen"]
@@ -22,6 +22,6 @@ Gem::Specification.new do |s|
22 22 ]
23 23
24 24 s.add_runtime_dependency("sauce", [">= 0.19.1"])
25   - s.add_runtime_dependency("jasmine", ["~> 1.0.1.1"])
  25 + s.add_runtime_dependency "guard-jasmine"
26 26 end
27 27
2  lib/sauce/jasmine.rb
... ... @@ -1,4 +1,4 @@
1   -require 'jasmine'
  1 +require 'guard/jasmine'
2 2
3 3 require 'sauce/jasmine/config'
4 4 require 'sauce/jasmine/server'
10 lib/sauce/jasmine/config.rb
... ... @@ -1,13 +1,17 @@
1   -require 'jasmine/config'
2 1 require 'sauce/jasmine/selenium_driver'
3 2
4 3 module Sauce
5 4 module Jasmine
6   - class Config < ::Jasmine::Config
  5 + class Config
7 6 attr_accessor :tunnel_domain
  7 + attr_accessor :port
  8 + attr_accessor :server
8 9
9   - def initialize
  10 + def initialize(options)
10 11 sauce_connect = true
  12 + @port = options[:port] ||= 8080
  13 + @server = options[:server] ||= 'auto'
  14 + @server = @server.to_sym
11 15 @tunnel_domain = "#{rand(10000)}.jasmine.test"
12 16 end
13 17
3  lib/sauce/jasmine/jasmine-sauce.rake
@@ -4,7 +4,8 @@ namespace :jasmine do
4 4 namespace :ci do
5 5 desc 'Run Jasmine tests in the cloud'
6 6 task :sauce do
7   - runner = Sauce::Jasmine::Runner.new
  7 + options = {:port => ENV['PORT'], :server => ENV['SERVER']}
  8 + runner = Sauce::Jasmine::Runner.new(options)
8 9 runner.run
9 10 end
10 11 end
6 lib/sauce/jasmine/runner.rb
... ... @@ -1,8 +1,8 @@
1 1 module Sauce
2 2 module Jasmine
3 3 class Runner
4   - def initialize
5   - @config = Config.new
  4 + def initialize(options)
  5 + @config = Config.new(options)
6 6 @server = Server.new(@config)
7 7 end
8 8
@@ -20,7 +20,7 @@ def setup
20 20 puts "Setting up Sauce Connect..."
21 21 @tunnel = Sauce::Connect.new(:domain => @config.tunnel_domain,
22 22 :host => @server.host,
23   - :port => @server.port,
  23 + :port => @config.port,
24 24 :quiet => @config.quiet_tunnel?)
25 25 @tunnel.wait_until_ready
26 26 puts "Sauce Connect ready"
22 lib/sauce/jasmine/selenium_driver.rb
... ... @@ -1,8 +1,7 @@
1 1 require 'sauce'
2   -require 'jasmine/selenium_driver'
3 2 module Sauce
4 3 module Jasmine
5   - class SeleniumDriver < ::Jasmine::SeleniumDriver
  4 + class SeleniumDriver
6 5 def initialize(os, browser, browser_version, domain)
7 6 host = host[7..-1] if host =~ /^http:\/\//
8 7 base_url = "http://#{domain}"
@@ -10,9 +9,28 @@ def initialize(os, browser, browser_version, domain)
10 9 :os => os,
11 10 :browser_version => browser_version,
12 11 :browser_url => base_url,
  12 + :record_video => false,
  13 + :record_screenshots => false,
13 14 :job_name => "Jasmine")
14 15 end
15 16
  17 + def connect
  18 + @driver.start
  19 + @driver.open("/jasmine")
  20 + end
  21 +
  22 + def disconnect
  23 + @driver.stop
  24 + end
  25 +
  26 + def eval_js(script)
  27 + escaped_script = "'" + script.gsub(/(['\\])/) { '\\' + $1 } + "'"
  28 +
  29 + result = @driver.get_eval("try { eval(#{escaped_script}, this.browserbot.getUserWindow()); } catch(err) { this.browserbot.getUserWindow().eval(#{escaped_script}); }")
  30 + JSON.parse("{\"result\":#{result}}")["result"]
  31 + end
  32 +
  33 +
16 34 def tests_have_finished?
17 35 eval_js("jsApiReporter && jsApiReporter.finished")
18 36 end
9 lib/sauce/jasmine/server.rb
... ... @@ -1,3 +1,5 @@
  1 +require 'guard/jasmine/server'
  2 +
1 3 module Sauce
2 4 module Jasmine
3 5 class Server
@@ -9,12 +11,7 @@ def initialize(config)
9 11 end
10 12
11 13 def start
12   - @port = ::Jasmine::find_unused_port
13   - Thread.new do
14   - handler = Rack::Handler.default
15   - handler.run ::Jasmine.app(@config), :Port => @port, :AccessLog => []
16   - end
17   - ::Jasmine::wait_for_listener(@port, "jasmine server")
  14 + ::Guard::Jasmine::Server.start(@config.server, @config.port, 'test', 'spec/javascrips')
18 15 end
19 16
20 17 def stop

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.