jasmine 1.0.1.1 → 1.0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +11 -0
- data/.gitmodules +3 -0
- data/Gemfile +5 -0
- data/HOW_TO_TEST.markdown +11 -0
- data/README.markdown +42 -14
- data/RELEASE.markdown +22 -0
- data/Rakefile +76 -0
- data/generators/jasmine/jasmine_generator.rb +15 -13
- data/generators/jasmine/templates/spec/javascripts/support/jasmine_config.rb +23 -0
- data/install.rb +2 -0
- data/jasmine.gemspec +52 -0
- data/jasmine/Gemfile +6 -0
- data/jasmine/MIT.LICENSE +20 -0
- data/jasmine/README.markdown +28 -0
- data/jasmine/Rakefile +182 -0
- data/jasmine/cruise_config.rb +21 -0
- data/jasmine/example/spec/PlayerSpec.js +58 -0
- data/jasmine/example/spec/SpecHelper.js +9 -0
- data/jasmine/example/src/Player.js +22 -0
- data/jasmine/example/src/Song.js +7 -0
- data/jasmine/images/fail-16.png +0 -0
- data/jasmine/images/fail.png +0 -0
- data/jasmine/images/go-16.png +0 -0
- data/jasmine/images/go.png +0 -0
- data/jasmine/images/pending-16.png +0 -0
- data/jasmine/images/pending.png +0 -0
- data/jasmine/images/question-bk.png +0 -0
- data/jasmine/images/questionbk-16.png +0 -0
- data/jasmine/images/spinner.gif +0 -0
- data/jasmine/jsdoc-template/allclasses.tmpl +17 -0
- data/jasmine/jsdoc-template/allfiles.tmpl +56 -0
- data/jasmine/jsdoc-template/class.tmpl +646 -0
- data/jasmine/jsdoc-template/index.tmpl +39 -0
- data/jasmine/jsdoc-template/publish.js +184 -0
- data/jasmine/jsdoc-template/static/default.css +162 -0
- data/jasmine/jsdoc-template/static/header.html +2 -0
- data/jasmine/jsdoc-template/static/index.html +19 -0
- data/jasmine/jsdoc-template/symbol.tmpl +35 -0
- data/jasmine/spec/runner.html +80 -0
- data/jasmine/spec/suites/BaseSpec.js +27 -0
- data/jasmine/spec/suites/CustomMatchersSpec.js +97 -0
- data/jasmine/spec/suites/EnvSpec.js +158 -0
- data/jasmine/spec/suites/ExceptionsSpec.js +107 -0
- data/jasmine/spec/suites/JsApiReporterSpec.js +103 -0
- data/jasmine/spec/suites/MatchersSpec.js +795 -0
- data/jasmine/spec/suites/MockClockSpec.js +38 -0
- data/jasmine/spec/suites/MultiReporterSpec.js +45 -0
- data/jasmine/spec/suites/NestedResultsSpec.js +54 -0
- data/jasmine/spec/suites/PrettyPrintSpec.js +93 -0
- data/jasmine/spec/suites/QueueSpec.js +23 -0
- data/jasmine/spec/suites/ReporterSpec.js +56 -0
- data/jasmine/spec/suites/RunnerSpec.js +267 -0
- data/jasmine/spec/suites/SpecRunningSpec.js +1253 -0
- data/jasmine/spec/suites/SpecSpec.js +124 -0
- data/jasmine/spec/suites/SpySpec.js +201 -0
- data/jasmine/spec/suites/SuiteSpec.js +120 -0
- data/jasmine/spec/suites/TrivialReporterSpec.js +238 -0
- data/jasmine/spec/suites/UtilSpec.js +40 -0
- data/jasmine/spec/suites/WaitsForBlockSpec.js +87 -0
- data/jasmine/src/Block.js +22 -0
- data/jasmine/src/Env.js +264 -0
- data/jasmine/src/JsApiReporter.js +102 -0
- data/jasmine/src/Matchers.js +354 -0
- data/jasmine/src/MultiReporter.js +35 -0
- data/jasmine/src/NestedResults.js +80 -0
- data/jasmine/src/PrettyPrinter.js +122 -0
- data/jasmine/src/Queue.js +99 -0
- data/jasmine/src/Reporter.js +31 -0
- data/jasmine/src/Runner.js +77 -0
- data/jasmine/src/Spec.js +242 -0
- data/jasmine/src/Suite.js +82 -0
- data/jasmine/src/WaitsBlock.js +13 -0
- data/jasmine/src/WaitsForBlock.js +52 -0
- data/jasmine/src/base.js +589 -0
- data/jasmine/src/html/TrivialReporter.js +188 -0
- data/jasmine/src/html/jasmine.css +166 -0
- data/jasmine/src/mock-timeout.js +183 -0
- data/jasmine/src/util.js +67 -0
- data/jasmine/src/version.json +5 -0
- data/lib/generators/jasmine/examples/USAGE +11 -0
- data/lib/generators/jasmine/examples/examples_generator.rb +19 -0
- data/lib/generators/jasmine/examples/templates/public/javascripts/jasmine_examples/Player.js +22 -0
- data/lib/generators/jasmine/examples/templates/public/javascripts/jasmine_examples/Song.js +7 -0
- data/lib/generators/jasmine/examples/templates/spec/javascripts/helpers/SpecHelper.js +9 -0
- data/lib/generators/jasmine/examples/templates/spec/javascripts/jasmine_examples/PlayerSpec.js +58 -0
- data/lib/generators/jasmine/install/USAGE +11 -0
- data/lib/generators/jasmine/install/install_generator.rb +18 -0
- data/lib/generators/jasmine/install/templates/spec/javascripts/helpers/.gitkeep +0 -0
- data/lib/generators/jasmine/install/templates/spec/javascripts/support/jasmine.yml +81 -0
- data/lib/generators/jasmine/install/templates/spec/javascripts/support/jasmine_config.rb +23 -0
- data/lib/generators/jasmine/install/templates/spec/javascripts/support/jasmine_runner.rb +20 -0
- data/lib/generators/jasmine/jasmine_generator.rb +32 -0
- data/lib/generators/jasmine/templates/INSTALL +9 -0
- data/lib/generators/jasmine/templates/lib/tasks/jasmine.rake +2 -0
- data/lib/generators/jasmine/templates/spec/javascripts/support/jasmine-rails.yml +81 -0
- data/lib/generators/jasmine/templates/spec/javascripts/support/jasmine.yml +73 -0
- data/lib/generators/jasmine/templates/spec/javascripts/support/jasmine_config.rb +23 -0
- data/lib/generators/jasmine/templates/spec/javascripts/support/jasmine_runner.rb +32 -0
- data/lib/jasmine.rb +31 -6
- data/lib/jasmine/command_line_tool.rb +1 -0
- data/lib/jasmine/config.rb +16 -44
- data/lib/jasmine/generator.rb +9 -0
- data/lib/jasmine/selenium_driver.rb +18 -18
- data/lib/jasmine/server.rb +0 -24
- data/lib/jasmine/spec_builder.rb +4 -4
- data/lib/jasmine/tasks/jasmine.rake +2 -2
- data/lib/jasmine/version.rb +3 -0
- data/spec/config_spec.rb +174 -123
- data/spec/fixture/jasmine.erb.yml +4 -0
- data/spec/jasmine_pojs_spec.rb +51 -0
- data/spec/jasmine_rails2_spec.rb +93 -0
- data/spec/jasmine_rails3_spec.rb +71 -0
- data/spec/spec_helper.rb +8 -2
- metadata +215 -65
- data/spec/bug_fixes_spec.rb +0 -32
- data/spec/rails_generator_spec.rb +0 -31
@@ -0,0 +1,73 @@
|
|
1
|
+
# src_files
|
2
|
+
#
|
3
|
+
# Return an array of filepaths relative to src_dir to include before jasmine specs.
|
4
|
+
# Default: []
|
5
|
+
#
|
6
|
+
# EXAMPLE:
|
7
|
+
#
|
8
|
+
# src_files:
|
9
|
+
# - lib/source1.js
|
10
|
+
# - lib/source2.js
|
11
|
+
# - dist/**/*.js
|
12
|
+
#
|
13
|
+
src_files:
|
14
|
+
- public/javascripts/**/*.js
|
15
|
+
|
16
|
+
# stylesheets
|
17
|
+
#
|
18
|
+
# Return an array of stylesheet filepaths relative to src_dir to include before jasmine specs.
|
19
|
+
# Default: []
|
20
|
+
#
|
21
|
+
# EXAMPLE:
|
22
|
+
#
|
23
|
+
# stylesheets:
|
24
|
+
# - css/style.css
|
25
|
+
# - stylesheets/*.css
|
26
|
+
#
|
27
|
+
stylesheets:
|
28
|
+
|
29
|
+
# helpers
|
30
|
+
#
|
31
|
+
# Return an array of filepaths relative to spec_dir to include before jasmine specs.
|
32
|
+
# Default: ["helpers/**/*.js"]
|
33
|
+
#
|
34
|
+
# EXAMPLE:
|
35
|
+
#
|
36
|
+
# helpers:
|
37
|
+
# - helpers/**/*.js
|
38
|
+
#
|
39
|
+
helpers:
|
40
|
+
|
41
|
+
# spec_files
|
42
|
+
#
|
43
|
+
# Return an array of filepaths relative to spec_dir to include.
|
44
|
+
# Default: ["**/*[sS]pec.js"]
|
45
|
+
#
|
46
|
+
# EXAMPLE:
|
47
|
+
#
|
48
|
+
# spec_files:
|
49
|
+
# - **/*[sS]pec.js
|
50
|
+
#
|
51
|
+
spec_files:
|
52
|
+
|
53
|
+
# src_dir
|
54
|
+
#
|
55
|
+
# Source directory path. Your src_files must be returned relative to this path. Will use root if left blank.
|
56
|
+
# Default: project root
|
57
|
+
#
|
58
|
+
# EXAMPLE:
|
59
|
+
#
|
60
|
+
# src_dir: public
|
61
|
+
#
|
62
|
+
src_dir:
|
63
|
+
|
64
|
+
# spec_dir
|
65
|
+
#
|
66
|
+
# Spec directory path. Your spec_files must be returned relative to this path.
|
67
|
+
# Default: spec/javascripts
|
68
|
+
#
|
69
|
+
# EXAMPLE:
|
70
|
+
#
|
71
|
+
# spec_dir: spec/javascripts
|
72
|
+
#
|
73
|
+
spec_dir:
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module Jasmine
|
2
|
+
class Config
|
3
|
+
|
4
|
+
# Add your overrides or custom config code here
|
5
|
+
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
|
10
|
+
# Note - this is necessary for rspec2, which has removed the backtrace
|
11
|
+
module Jasmine
|
12
|
+
class SpecBuilder
|
13
|
+
def declare_spec(parent, spec)
|
14
|
+
me = self
|
15
|
+
example_name = spec["name"]
|
16
|
+
@spec_ids << spec["id"]
|
17
|
+
backtrace = @example_locations[parent.description + " " + example_name]
|
18
|
+
parent.it example_name, {} do
|
19
|
+
me.report_spec(spec["id"])
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
$:.unshift(ENV['JASMINE_GEM_PATH']) if ENV['JASMINE_GEM_PATH'] # for gem testing purposes
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'jasmine'
|
5
|
+
jasmine_config_overrides = File.expand_path(File.join(File.dirname(__FILE__), 'jasmine_config.rb'))
|
6
|
+
require jasmine_config_overrides if File.exist?(jasmine_config_overrides)
|
7
|
+
if Jasmine::rspec2?
|
8
|
+
require 'rspec'
|
9
|
+
else
|
10
|
+
require 'spec'
|
11
|
+
end
|
12
|
+
|
13
|
+
jasmine_config = Jasmine::Config.new
|
14
|
+
spec_builder = Jasmine::SpecBuilder.new(jasmine_config)
|
15
|
+
|
16
|
+
should_stop = false
|
17
|
+
|
18
|
+
if Jasmine::rspec2?
|
19
|
+
RSpec.configuration.after(:suite) do
|
20
|
+
spec_builder.stop if should_stop
|
21
|
+
end
|
22
|
+
else
|
23
|
+
Spec::Runner.configure do |config|
|
24
|
+
config.after(:suite) do
|
25
|
+
spec_builder.stop if should_stop
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
spec_builder.start
|
31
|
+
should_stop = true
|
32
|
+
spec_builder.declare_suites
|
data/lib/jasmine.rb
CHANGED
@@ -1,8 +1,33 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
1
|
+
jasmine_files = ['base',
|
2
|
+
'config',
|
3
|
+
'server',
|
4
|
+
'selenium_driver',
|
5
|
+
'spec_builder',
|
6
|
+
'command_line_tool']
|
5
7
|
|
6
|
-
|
8
|
+
jasmine_files << 'generator' if Gem.available? "rails", ">= 3.0"
|
7
9
|
|
8
|
-
|
10
|
+
jasmine_files.each do |file|
|
11
|
+
require File.join('jasmine', file)
|
12
|
+
end
|
13
|
+
|
14
|
+
if Jasmine.rails3?
|
15
|
+
module Jasmine
|
16
|
+
class Railtie < Rails::Railtie
|
17
|
+
|
18
|
+
config.before_configuration do
|
19
|
+
old_jasmine_rakefile = ::Rails.root.join('lib', 'tasks', 'jasmine.rake')
|
20
|
+
if old_jasmine_rakefile.exist?
|
21
|
+
raise RuntimeError.new(
|
22
|
+
"You no longer need to have jasmine.rake in your project, as it is now automatically loaded " +
|
23
|
+
"from the Jasmine gem. Please delete '#{old_jasmine_rakefile}' before continuing."
|
24
|
+
)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
rake_tasks do
|
29
|
+
load "jasmine/tasks/jasmine.rake"
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -36,6 +36,7 @@ module Jasmine
|
|
36
36
|
copy_unless_exists('jasmine-example/spec/PlayerSpec.js', 'spec/javascripts/PlayerSpec.js')
|
37
37
|
copy_unless_exists('jasmine-example/spec/SpecHelper.js', 'spec/javascripts/helpers/SpecHelper.js')
|
38
38
|
copy_unless_exists('spec/javascripts/support/jasmine_runner.rb')
|
39
|
+
copy_unless_exists('spec/javascripts/support/jasmine_config.rb')
|
39
40
|
|
40
41
|
rails_tasks_dir = dest_path('lib/tasks')
|
41
42
|
if File.exist?(rails_tasks_dir)
|
data/lib/jasmine/config.rb
CHANGED
@@ -11,18 +11,19 @@ module Jasmine
|
|
11
11
|
ENV["JASMINE_HOST"] || 'http://localhost'
|
12
12
|
end
|
13
13
|
|
14
|
-
def
|
15
|
-
ENV[
|
14
|
+
def jasmine_port
|
15
|
+
ENV["JASMINE_PORT"] || Jasmine::find_unused_port
|
16
16
|
end
|
17
17
|
|
18
18
|
def start_server(port = 8888)
|
19
|
-
|
20
|
-
|
19
|
+
server = Rack::Server.new(:Port => port, :AccessLog => [])
|
20
|
+
server.instance_variable_set(:@app, Jasmine.app(self)) # workaround for Rack bug, when Rack > 1.2.1 is released Rack::Server.start(:app => Jasmine.app(self)) will work
|
21
|
+
server.start
|
21
22
|
end
|
22
23
|
|
23
24
|
def start
|
24
|
-
|
25
|
-
@client = Jasmine::SeleniumDriver.new(
|
25
|
+
start_jasmine_server
|
26
|
+
@client = Jasmine::SeleniumDriver.new(browser, "#{jasmine_host}:#{@jasmine_server_port}/")
|
26
27
|
@client.connect
|
27
28
|
end
|
28
29
|
|
@@ -31,7 +32,7 @@ module Jasmine
|
|
31
32
|
end
|
32
33
|
|
33
34
|
def start_jasmine_server
|
34
|
-
@jasmine_server_port =
|
35
|
+
@jasmine_server_port = jasmine_port
|
35
36
|
Thread.new do
|
36
37
|
start_server(@jasmine_server_port)
|
37
38
|
end
|
@@ -44,23 +45,6 @@ module Jasmine
|
|
44
45
|
::RbConfig::CONFIG['host_os'] =~ /mswin|mingw/
|
45
46
|
end
|
46
47
|
|
47
|
-
def start_selenium_server
|
48
|
-
@selenium_server_port = external_selenium_server_port
|
49
|
-
if @selenium_server_port.nil?
|
50
|
-
@selenium_server_port = Jasmine::find_unused_port
|
51
|
-
require 'selenium_rc'
|
52
|
-
SeleniumRC::Server.send(:include, SeleniumServerForkHackForRSpec)
|
53
|
-
SeleniumRC::Server.boot("localhost", @selenium_server_port, :args => [windows? ? ">NUL" : "> /dev/null"])
|
54
|
-
else
|
55
|
-
Jasmine::wait_for_listener(@selenium_server_port, "selenium server")
|
56
|
-
end
|
57
|
-
end
|
58
|
-
|
59
|
-
def start_servers
|
60
|
-
start_jasmine_server
|
61
|
-
start_selenium_server
|
62
|
-
end
|
63
|
-
|
64
48
|
def run
|
65
49
|
begin
|
66
50
|
start
|
@@ -82,10 +66,14 @@ module Jasmine
|
|
82
66
|
|
83
67
|
def match_files(dir, patterns)
|
84
68
|
dir = File.expand_path(dir)
|
85
|
-
patterns.
|
86
|
-
|
87
|
-
|
88
|
-
|
69
|
+
negative, positive = patterns.partition {|pattern| /^!/ =~ pattern}
|
70
|
+
chosen, negated = [positive, negative].collect do |patterns|
|
71
|
+
patterns.collect do |pattern|
|
72
|
+
matches = Dir.glob(File.join(dir, pattern.gsub(/^!/,'')))
|
73
|
+
matches.collect {|f| f.sub("#{dir}/", "")}.sort
|
74
|
+
end.flatten.uniq
|
75
|
+
end
|
76
|
+
chosen - negated
|
89
77
|
end
|
90
78
|
|
91
79
|
def simple_config
|
@@ -170,21 +158,5 @@ module Jasmine
|
|
170
158
|
[]
|
171
159
|
end
|
172
160
|
end
|
173
|
-
|
174
|
-
module SeleniumServerForkHackForRSpec
|
175
|
-
# without this, Selenium's forked process will attempt to run specs a second time at exit;
|
176
|
-
# see http://www.ruby-forum.com/topic/212722
|
177
|
-
def self.included(base)
|
178
|
-
alias_method :fork_without_fix_for_rspec, :fork
|
179
|
-
alias_method :fork, :fork_with_fix_for_rspec
|
180
|
-
end
|
181
|
-
|
182
|
-
def fork_with_fix_for_rspec
|
183
|
-
fork_without_fix_for_rspec do
|
184
|
-
yield
|
185
|
-
at_exit { exit! }
|
186
|
-
end
|
187
|
-
end
|
188
|
-
end
|
189
161
|
end
|
190
162
|
end
|
@@ -1,28 +1,30 @@
|
|
1
1
|
module Jasmine
|
2
2
|
class SeleniumDriver
|
3
|
-
def initialize(
|
4
|
-
require '
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
3
|
+
def initialize(browser, http_address)
|
4
|
+
require 'selenium-webdriver'
|
5
|
+
selenium_server = if ENV['SELENIUM_SERVER']
|
6
|
+
ENV['SELENIUM_SERVER']
|
7
|
+
elsif ENV['SELENIUM_SERVER_PORT']
|
8
|
+
"http://localhost:#{ENV['SELENIUM_SERVER_PORT']}/wd/hub"
|
9
|
+
end
|
10
|
+
@driver = if selenium_server
|
11
|
+
Selenium::WebDriver.for :remote, :url => selenium_server, :desired_capabilities => browser.to_sym
|
12
|
+
else
|
13
|
+
Selenium::WebDriver.for browser.to_sym
|
14
|
+
end
|
12
15
|
@http_address = http_address
|
13
16
|
end
|
14
17
|
|
15
18
|
def tests_have_finished?
|
16
|
-
@driver.
|
19
|
+
@driver.execute_script("return window.jasmine.getEnv().currentRunner.finished") == "true"
|
17
20
|
end
|
18
21
|
|
19
22
|
def connect
|
20
|
-
@driver.
|
21
|
-
@driver.open("/")
|
23
|
+
@driver.navigate.to @http_address
|
22
24
|
end
|
23
25
|
|
24
26
|
def disconnect
|
25
|
-
@driver.
|
27
|
+
@driver.quit
|
26
28
|
end
|
27
29
|
|
28
30
|
def run
|
@@ -30,15 +32,13 @@ module Jasmine
|
|
30
32
|
sleep 0.1
|
31
33
|
end
|
32
34
|
|
33
|
-
puts @driver.
|
34
|
-
failed_count = @driver.
|
35
|
+
puts @driver.execute_script("return window.results()")
|
36
|
+
failed_count = @driver.execute_script("return window.jasmine.getEnv().currentRunner.results().failedCount").to_i
|
35
37
|
failed_count == 0
|
36
38
|
end
|
37
39
|
|
38
40
|
def eval_js(script)
|
39
|
-
|
40
|
-
|
41
|
-
result = @driver.get_eval("try { eval(#{escaped_script}, window); } catch(err) { window.eval(#{escaped_script}); }")
|
41
|
+
result = @driver.execute_script(script)
|
42
42
|
JSON.parse("{\"result\":#{result}}")["result"]
|
43
43
|
end
|
44
44
|
|
data/lib/jasmine/server.rb
CHANGED
@@ -1,29 +1,5 @@
|
|
1
1
|
require 'rack'
|
2
2
|
|
3
|
-
# Backport Rack::Handler.default from Rack 1.1.0 for Rails 2.3.x compatibility.
|
4
|
-
unless Rack::Handler.respond_to?(:default)
|
5
|
-
module Rack::Handler
|
6
|
-
def self.default(options = {})
|
7
|
-
# Guess.
|
8
|
-
if ENV.include?("PHP_FCGI_CHILDREN")
|
9
|
-
# We already speak FastCGI
|
10
|
-
options.delete :File
|
11
|
-
options.delete :Port
|
12
|
-
|
13
|
-
Rack::Handler::FastCGI
|
14
|
-
elsif ENV.include?("REQUEST_METHOD")
|
15
|
-
Rack::Handler::CGI
|
16
|
-
else
|
17
|
-
begin
|
18
|
-
Rack::Handler::Mongrel
|
19
|
-
rescue LoadError => e
|
20
|
-
Rack::Handler::WEBrick
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
3
|
module Jasmine
|
28
4
|
class RunAdapter
|
29
5
|
def initialize(config)
|
data/lib/jasmine/spec_builder.rb
CHANGED
@@ -53,12 +53,12 @@ module Jasmine
|
|
53
53
|
|
54
54
|
def load_suite_info
|
55
55
|
started = Time.now
|
56
|
-
while !eval_js('jsApiReporter && jsApiReporter.started') do
|
56
|
+
while !eval_js('return jsApiReporter && jsApiReporter.started') do
|
57
57
|
raise "couldn't connect to Jasmine after 60 seconds" if (started + 60 < Time.now)
|
58
58
|
sleep 0.1
|
59
59
|
end
|
60
60
|
|
61
|
-
@suites = eval_js("var result = jsApiReporter.suites(); if (window.Prototype && Object.toJSON) { Object.toJSON(result) } else { JSON.stringify(result) }")
|
61
|
+
@suites = eval_js("var result = jsApiReporter.suites(); if (window.Prototype && Object.toJSON) { return Object.toJSON(result) } else { return JSON.stringify(result) }")
|
62
62
|
end
|
63
63
|
|
64
64
|
def results_for(spec_id)
|
@@ -69,14 +69,14 @@ module Jasmine
|
|
69
69
|
def load_results
|
70
70
|
@spec_results = {}
|
71
71
|
@spec_ids.each_slice(50) do |slice|
|
72
|
-
@spec_results.merge!(eval_js("var result = jsApiReporter.resultsForSpecs(#{json_generate(slice)}); if (window.Prototype && Object.toJSON) { Object.toJSON(result) } else { JSON.stringify(result) }"))
|
72
|
+
@spec_results.merge!(eval_js("var result = jsApiReporter.resultsForSpecs(#{json_generate(slice)}); if (window.Prototype && Object.toJSON) { return Object.toJSON(result) } else { return JSON.stringify(result) }"))
|
73
73
|
end
|
74
74
|
@spec_results
|
75
75
|
end
|
76
76
|
|
77
77
|
def wait_for_suites_to_finish_running
|
78
78
|
puts "Waiting for suite to finish in browser ..."
|
79
|
-
while !eval_js('jsApiReporter.finished') do
|
79
|
+
while !eval_js('return jsApiReporter.finished') do
|
80
80
|
sleep 0.1
|
81
81
|
end
|
82
82
|
end
|
@@ -15,7 +15,7 @@ namespace :jasmine do
|
|
15
15
|
|
16
16
|
if Jasmine::rspec2?
|
17
17
|
RSpec::Core::RakeTask.new(:jasmine_continuous_integration_runner) do |t|
|
18
|
-
t.rspec_opts = ["--
|
18
|
+
t.rspec_opts = ["--colour", "--format", "progress"]
|
19
19
|
t.verbose = true
|
20
20
|
t.pattern = ['spec/javascripts/support/jasmine_runner.rb']
|
21
21
|
end
|
@@ -30,7 +30,7 @@ namespace :jasmine do
|
|
30
30
|
end
|
31
31
|
|
32
32
|
task :server => "jasmine:require" do
|
33
|
-
jasmine_config_overrides = 'spec/javascripts/support/jasmine_config.rb'
|
33
|
+
jasmine_config_overrides = './spec/javascripts/support/jasmine_config.rb'
|
34
34
|
require jasmine_config_overrides if File.exist?(jasmine_config_overrides)
|
35
35
|
|
36
36
|
puts "your tests are here:"
|
data/spec/config_spec.rb
CHANGED
@@ -1,40 +1,28 @@
|
|
1
1
|
require File.expand_path(File.join(File.dirname(__FILE__), "spec_helper"))
|
2
|
+
require 'selenium-webdriver'
|
2
3
|
|
3
4
|
describe Jasmine::Config do
|
4
|
-
|
5
5
|
describe "configuration" do
|
6
|
-
|
7
|
-
before(:all) do
|
6
|
+
before :each do
|
8
7
|
temp_dir_before
|
9
8
|
|
10
9
|
Dir::chdir @tmp
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
if rails3?
|
17
|
-
raise Exception.new('rails 3 generators not yet implemented!')
|
18
|
-
else
|
19
|
-
`./script/generate jasmine`
|
20
|
-
end
|
10
|
+
dir_name = "test_js_project"
|
11
|
+
`mkdir -p #{dir_name}`
|
12
|
+
Dir::chdir dir_name
|
13
|
+
`#{@root}/bin/jasmine init .`
|
21
14
|
|
22
|
-
Dir
|
15
|
+
@project_dir = Dir.pwd
|
23
16
|
|
24
|
-
@
|
17
|
+
@template_dir = File.expand_path(File.join(@root, "generators/jasmine/templates"))
|
18
|
+
@config = Jasmine::Config.new
|
25
19
|
end
|
26
20
|
|
27
|
-
after(:
|
21
|
+
after(:each) do
|
28
22
|
temp_dir_after
|
29
23
|
end
|
30
24
|
|
31
|
-
before(:each) do
|
32
|
-
@template_dir = File.expand_path(File.join(File.dirname(__FILE__), "../generators/jasmine/templates"))
|
33
|
-
@config = Jasmine::Config.new
|
34
|
-
end
|
35
|
-
|
36
25
|
describe "defaults" do
|
37
|
-
|
38
26
|
it "src_dir uses root when src dir is blank" do
|
39
27
|
@config.stub!(:project_root).and_return('some_project_root')
|
40
28
|
@config.stub!(:simple_config_file).and_return(File.join(@template_dir, 'spec/javascripts/support/jasmine.yml'))
|
@@ -46,51 +34,77 @@ describe Jasmine::Config do
|
|
46
34
|
@config.stub!(:project_root).and_return('some_project_root')
|
47
35
|
@config.simple_config_file.should == (File.join('some_project_root', 'spec/javascripts/support/jasmine.yml'))
|
48
36
|
end
|
49
|
-
|
50
37
|
end
|
51
38
|
|
52
|
-
|
53
39
|
describe "simple_config" do
|
54
40
|
before(:each) do
|
55
|
-
@config.stub!(:src_dir).and_return(File.join(@
|
56
|
-
@config.stub!(:spec_dir).and_return(File.join(@
|
41
|
+
@config.stub!(:src_dir).and_return(File.join(@project_dir, "."))
|
42
|
+
@config.stub!(:spec_dir).and_return(File.join(@project_dir, "spec/javascripts"))
|
57
43
|
end
|
58
44
|
|
59
|
-
|
60
|
-
|
61
|
-
@config.
|
45
|
+
describe "using default jasmine.yml" do
|
46
|
+
before(:each) do
|
47
|
+
@config.stub!(:simple_config_file).and_return(File.join(@template_dir, 'spec/javascripts/support/jasmine.yml'))
|
48
|
+
end
|
49
|
+
|
50
|
+
it "should find the source files" do
|
51
|
+
@config.src_files.should =~ ['public/javascripts/Player.js', 'public/javascripts/Song.js']
|
52
|
+
end
|
53
|
+
|
54
|
+
it "should find the stylesheet files" do
|
62
55
|
@config.stylesheets.should == []
|
56
|
+
end
|
57
|
+
|
58
|
+
it "should find the spec files" do
|
63
59
|
@config.spec_files.should == ['PlayerSpec.js']
|
60
|
+
end
|
61
|
+
|
62
|
+
it "should find any helpers" do
|
64
63
|
@config.helpers.should == ['helpers/SpecHelper.js']
|
64
|
+
end
|
65
|
+
|
66
|
+
it "should build an array of all the JavaScript files to include, source files then spec files" do
|
65
67
|
@config.js_files.should == [
|
66
|
-
|
67
|
-
|
68
|
+
'/public/javascripts/Player.js',
|
69
|
+
'/public/javascripts/Song.js',
|
70
|
+
'/__spec__/helpers/SpecHelper.js',
|
71
|
+
'/__spec__/PlayerSpec.js'
|
68
72
|
]
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
@config.
|
73
|
-
|
73
|
+
end
|
74
|
+
|
75
|
+
it "should allow the js_files to be filtered" do
|
76
|
+
@config.js_files("PlayerSpec.js").should == [
|
77
|
+
'/public/javascripts/Player.js',
|
78
|
+
'/public/javascripts/Song.js',
|
79
|
+
'/__spec__/helpers/SpecHelper.js',
|
80
|
+
'/__spec__/PlayerSpec.js'
|
74
81
|
]
|
75
82
|
end
|
83
|
+
|
84
|
+
it "should report the full paths of the spec files" do
|
85
|
+
@config.spec_files_full_paths.should == [File.join(@project_dir, 'spec/javascripts/PlayerSpec.js')]
|
86
|
+
end
|
76
87
|
end
|
77
88
|
|
78
89
|
it "should parse ERB" do
|
79
|
-
@config.stub!(:simple_config_file).and_return(File.expand_path(File.join(
|
90
|
+
@config.stub!(:simple_config_file).and_return(File.expand_path(File.join(@root, 'spec', 'fixture','jasmine.erb.yml')))
|
80
91
|
Dir.stub!(:glob).and_return { |glob_string| [glob_string] }
|
81
|
-
@config.src_files.should == [
|
82
|
-
'file0.js',
|
83
|
-
'file1.js',
|
84
|
-
'file2.js',
|
85
|
-
]
|
92
|
+
@config.src_files.should == ['file0.js', 'file1.js', 'file2.js',]
|
86
93
|
end
|
87
94
|
|
88
|
-
|
89
|
-
describe "if sources.yaml not found" do
|
95
|
+
describe "if jasmine.yml not found" do
|
90
96
|
before(:each) do
|
91
97
|
File.stub!(:exist?).and_return(false)
|
92
98
|
end
|
93
|
-
|
99
|
+
|
100
|
+
it "should default to loading no source files" do
|
101
|
+
@config.src_files.should be_empty
|
102
|
+
end
|
103
|
+
|
104
|
+
it "should default to loading no stylesheet files" do
|
105
|
+
@config.stylesheets.should be_empty
|
106
|
+
end
|
107
|
+
|
94
108
|
end
|
95
109
|
|
96
110
|
describe "if jasmine.yml is empty" do
|
@@ -98,22 +112,20 @@ describe Jasmine::Config do
|
|
98
112
|
@config.stub!(:simple_config_file).and_return(File.join(@template_dir, 'spec/javascripts/support/jasmine.yml'))
|
99
113
|
YAML.stub!(:load).and_return(false)
|
100
114
|
end
|
101
|
-
it_should_behave_like "simple_config defaults"
|
102
115
|
|
103
|
-
|
116
|
+
it "should default to loading no source files" do
|
117
|
+
@config.src_files.should be_empty
|
118
|
+
end
|
104
119
|
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
# it_should_behave_like "simple_config defaults"
|
110
|
-
#
|
111
|
-
# end
|
120
|
+
it "should default to loading no stylesheet files" do
|
121
|
+
@config.stylesheets.should be_empty
|
122
|
+
end
|
123
|
+
end
|
112
124
|
|
113
125
|
describe "should use the first appearance of duplicate filenames" do
|
114
126
|
before(:each) do
|
115
127
|
Dir.stub!(:glob).and_return { |glob_string| [glob_string] }
|
116
|
-
fake_config = Hash.new.stub!(:[]).and_return {|x| ["file1.ext", "file2.ext", "file1.ext"]}
|
128
|
+
fake_config = Hash.new.stub!(:[]).and_return { |x| ["file1.ext", "file2.ext", "file1.ext"] }
|
117
129
|
@config.stub!(:simple_config).and_return(fake_config)
|
118
130
|
end
|
119
131
|
|
@@ -144,23 +156,42 @@ describe Jasmine::Config do
|
|
144
156
|
|
145
157
|
it "spec_files_full_paths" do
|
146
158
|
@config.spec_files_full_paths.should == [
|
147
|
-
|
148
|
-
|
159
|
+
File.expand_path("spec/javascripts/file1.ext", @project_dir),
|
160
|
+
File.expand_path("spec/javascripts/file2.ext", @project_dir)
|
149
161
|
]
|
150
162
|
end
|
163
|
+
end
|
164
|
+
|
165
|
+
describe "should allow .gitignore style negation (!pattern)" do
|
166
|
+
before(:each) do
|
167
|
+
Dir.stub!(:glob).and_return { |glob_string| [glob_string] }
|
168
|
+
fake_config = Hash.new.stub!(:[]).and_return { |x| ["file1.ext", "!file1.ext", "file2.ext"] }
|
169
|
+
@config.stub!(:simple_config).and_return(fake_config)
|
170
|
+
end
|
151
171
|
|
172
|
+
it "should not contain negated files" do
|
173
|
+
@config.src_files.should == ["file2.ext"]
|
174
|
+
end
|
152
175
|
end
|
153
176
|
|
154
177
|
it "simple_config stylesheets" do
|
155
178
|
@config.stub!(:simple_config_file).and_return(File.join(@template_dir, 'spec/javascripts/support/jasmine.yml'))
|
179
|
+
|
156
180
|
YAML.stub!(:load).and_return({'stylesheets' => ['foo.css', 'bar.css']})
|
157
181
|
Dir.stub!(:glob).and_return { |glob_string| [glob_string] }
|
182
|
+
|
158
183
|
@config.stylesheets.should == ['foo.css', 'bar.css']
|
159
184
|
end
|
160
185
|
|
161
|
-
|
162
186
|
it "using rails jasmine.yml" do
|
187
|
+
['public/javascripts/prototype.js',
|
188
|
+
'public/javascripts/effects.js',
|
189
|
+
'public/javascripts/controls.js',
|
190
|
+
'public/javascripts/dragdrop.js',
|
191
|
+
'public/javascripts/application.js'].each { |f| `touch #{f}` }
|
192
|
+
|
163
193
|
@config.stub!(:simple_config_file).and_return(File.join(@template_dir, 'spec/javascripts/support/jasmine-rails.yml'))
|
194
|
+
|
164
195
|
@config.spec_files.should == ['PlayerSpec.js']
|
165
196
|
@config.helpers.should == ['helpers/SpecHelper.js']
|
166
197
|
@config.src_files.should == ['public/javascripts/prototype.js',
|
@@ -171,87 +202,107 @@ describe Jasmine::Config do
|
|
171
202
|
'public/javascripts/Player.js',
|
172
203
|
'public/javascripts/Song.js']
|
173
204
|
@config.js_files.should == [
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
205
|
+
'/public/javascripts/prototype.js',
|
206
|
+
'/public/javascripts/effects.js',
|
207
|
+
'/public/javascripts/controls.js',
|
208
|
+
'/public/javascripts/dragdrop.js',
|
209
|
+
'/public/javascripts/application.js',
|
210
|
+
'/public/javascripts/Player.js',
|
211
|
+
'/public/javascripts/Song.js',
|
212
|
+
'/__spec__/helpers/SpecHelper.js',
|
213
|
+
'/__spec__/PlayerSpec.js',
|
183
214
|
]
|
184
215
|
@config.js_files("PlayerSpec.js").should == [
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
216
|
+
'/public/javascripts/prototype.js',
|
217
|
+
'/public/javascripts/effects.js',
|
218
|
+
'/public/javascripts/controls.js',
|
219
|
+
'/public/javascripts/dragdrop.js',
|
220
|
+
'/public/javascripts/application.js',
|
221
|
+
'/public/javascripts/Player.js',
|
222
|
+
'/public/javascripts/Song.js',
|
223
|
+
'/__spec__/helpers/SpecHelper.js',
|
224
|
+
'/__spec__/PlayerSpec.js'
|
194
225
|
]
|
195
|
-
|
196
226
|
end
|
197
|
-
|
198
227
|
end
|
199
|
-
|
200
228
|
end
|
201
229
|
|
202
|
-
describe "
|
203
|
-
|
204
|
-
ENV.stub!(:[]
|
205
|
-
|
206
|
-
|
207
|
-
Jasmine::SeleniumDriver.should_receive(:new).
|
208
|
-
with(anything(), anything(), "*firefox", anything()).
|
209
|
-
and_return(mock(Jasmine::SeleniumDriver, :connect => true))
|
210
|
-
config.start
|
230
|
+
describe "environment variables" do
|
231
|
+
def stub_env_hash(hash)
|
232
|
+
ENV.stub!(:[]) do |arg|
|
233
|
+
hash[arg]
|
234
|
+
end
|
211
235
|
end
|
236
|
+
describe "browser configuration" do
|
237
|
+
it "should use firefox by default" do
|
238
|
+
stub_env_hash({"JASMINE_BROWSER" => nil})
|
239
|
+
config = Jasmine::Config.new
|
240
|
+
config.stub!(:start_jasmine_server)
|
241
|
+
Jasmine::SeleniumDriver.should_receive(:new).
|
242
|
+
with("firefox", anything).
|
243
|
+
and_return(mock(Jasmine::SeleniumDriver, :connect => true))
|
244
|
+
config.start
|
245
|
+
end
|
212
246
|
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
247
|
+
it "should use ENV['JASMINE_BROWSER'] if set" do
|
248
|
+
stub_env_hash({"JASMINE_BROWSER" => "mosaic"})
|
249
|
+
config = Jasmine::Config.new
|
250
|
+
config.stub!(:start_jasmine_server)
|
251
|
+
Jasmine::SeleniumDriver.should_receive(:new).
|
252
|
+
with("mosaic", anything).
|
253
|
+
and_return(mock(Jasmine::SeleniumDriver, :connect => true))
|
254
|
+
config.start
|
255
|
+
end
|
221
256
|
end
|
222
|
-
end
|
223
257
|
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
258
|
+
describe "jasmine host" do
|
259
|
+
it "should use http://localhost by default" do
|
260
|
+
stub_env_hash({})
|
261
|
+
config = Jasmine::Config.new
|
262
|
+
config.instance_variable_set(:@jasmine_server_port, '1234')
|
263
|
+
config.stub!(:start_jasmine_server)
|
264
|
+
|
265
|
+
Jasmine::SeleniumDriver.should_receive(:new).
|
266
|
+
with(anything, "http://localhost:1234/").
|
267
|
+
and_return(mock(Jasmine::SeleniumDriver, :connect => true))
|
268
|
+
config.start
|
269
|
+
end
|
229
270
|
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
271
|
+
it "should use ENV['JASMINE_HOST'] if set" do
|
272
|
+
stub_env_hash({"JASMINE_HOST" => "http://some_host"})
|
273
|
+
config = Jasmine::Config.new
|
274
|
+
config.instance_variable_set(:@jasmine_server_port, '1234')
|
275
|
+
config.stub!(:start_jasmine_server)
|
235
276
|
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
277
|
+
Jasmine::SeleniumDriver.should_receive(:new).
|
278
|
+
with(anything, "http://some_host:1234/").
|
279
|
+
and_return(mock(Jasmine::SeleniumDriver, :connect => true))
|
280
|
+
config.start
|
281
|
+
end
|
241
282
|
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
283
|
+
it "should use ENV['JASMINE_PORT'] if set" do
|
284
|
+
stub_env_hash({"JASMINE_PORT" => "4321"})
|
285
|
+
config = Jasmine::Config.new
|
286
|
+
Jasmine.stub!(:wait_for_listener)
|
287
|
+
config.stub!(:start_server)
|
288
|
+
Jasmine::SeleniumDriver.should_receive(:new).
|
289
|
+
with(anything, "http://localhost:4321/").
|
290
|
+
and_return(mock(Jasmine::SeleniumDriver, :connect => true))
|
291
|
+
config.start
|
292
|
+
end
|
246
293
|
end
|
247
|
-
end
|
248
294
|
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
295
|
+
describe "external selenium server" do
|
296
|
+
it "should use an external selenium server if SELENIUM_SERVER is set" do
|
297
|
+
stub_env_hash({"SELENIUM_SERVER" => "http://myseleniumserver.com:4441"})
|
298
|
+
Selenium::WebDriver.should_receive(:for).with(:remote, :url => "http://myseleniumserver.com:4441", :desired_capabilities => :firefox)
|
299
|
+
Jasmine::SeleniumDriver.new('firefox', 'http://localhost:8888')
|
300
|
+
end
|
301
|
+
it "should use an local selenium server with a specific port if SELENIUM_SERVER_PORT is set" do
|
302
|
+
stub_env_hash({"SELENIUM_SERVER_PORT" => "4441"})
|
303
|
+
Selenium::WebDriver.should_receive(:for).with(:remote, :url => "http://localhost:4441/wd/hub", :desired_capabilities => :firefox)
|
304
|
+
Jasmine::SeleniumDriver.new('firefox', 'http://localhost:8888')
|
305
|
+
end
|
255
306
|
end
|
256
307
|
end
|
257
308
|
end
|