jasmine 2.0.0 → 2.99.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.
Files changed (79) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +27 -13
  3. data/Gemfile +9 -9
  4. data/HOW_TO_TEST.markdown +1 -0
  5. data/README.markdown +18 -11
  6. data/jasmine.gemspec +14 -6
  7. data/lib/generators/jasmine/examples/templates/spec/javascripts/helpers/jasmine_examples/SpecHelper.js +1 -1
  8. data/lib/generators/jasmine/install/templates/spec/javascripts/support/jasmine.yml +38 -5
  9. data/lib/generators/jasmine/install/templates/spec/javascripts/support/jasmine_helper.rb +14 -9
  10. data/lib/jasmine/application.rb +2 -2
  11. data/lib/jasmine/asset_expander.rb +56 -8
  12. data/lib/jasmine/base.rb +5 -5
  13. data/lib/jasmine/ci_runner.rb +50 -0
  14. data/lib/jasmine/command_line_tool.rb +4 -4
  15. data/lib/jasmine/config.rb +34 -5
  16. data/lib/jasmine/configuration.rb +31 -11
  17. data/lib/jasmine/dependencies.rb +8 -37
  18. data/lib/jasmine/formatters/console.rb +69 -4
  19. data/lib/jasmine/formatters/exit_code.rb +4 -6
  20. data/lib/jasmine/formatters/multi.rb +3 -11
  21. data/lib/jasmine/path_expander.rb +5 -1
  22. data/lib/jasmine/path_mapper.rb +11 -2
  23. data/lib/jasmine/railtie.rb +1 -1
  24. data/lib/jasmine/result.rb +21 -9
  25. data/lib/jasmine/ruby_versions.rb +11 -0
  26. data/lib/jasmine/run.html.erb +1 -1
  27. data/lib/jasmine/runners/phantom_boot.js +15 -0
  28. data/lib/jasmine/runners/phantom_jasmine_run.js +39 -43
  29. data/lib/jasmine/runners/phantom_js.rb +53 -8
  30. data/lib/jasmine/server.rb +7 -10
  31. data/lib/jasmine/tasks/jasmine.rake +29 -25
  32. data/lib/jasmine/version.rb +1 -1
  33. data/lib/jasmine/yaml_config_parser.rb +28 -0
  34. data/lib/jasmine.rb +1 -1
  35. data/release_notes/v2.0.1.md +31 -0
  36. data/release_notes/v2.0.2.md +17 -0
  37. data/release_notes/v2.0.3.md +31 -0
  38. data/release_notes/v2.1.0.md +11 -0
  39. data/release_notes/v2.2.0.md +31 -0
  40. data/release_notes/v2.3.0.md +27 -0
  41. data/release_notes/v2.3.1.md +14 -0
  42. data/release_notes/v2.4.0.md +20 -0
  43. data/release_notes/v2.5.0.md +35 -0
  44. data/release_notes/v2.5.1.md +12 -0
  45. data/release_notes/v2.5.2.md +22 -0
  46. data/release_notes/v2.6.0.md +17 -0
  47. data/release_notes/v2.6.1.md +11 -0
  48. data/release_notes/v2.7.0.md +28 -0
  49. data/release_notes/v2.8.0.md +21 -0
  50. data/release_notes/v2.9.0.md +22 -0
  51. data/release_notes/v2.99.md +13 -0
  52. data/spec/application_integration_spec.rb +3 -3
  53. data/spec/application_spec.rb +27 -11
  54. data/spec/base_spec.rb +27 -6
  55. data/spec/ci_runner_spec.rb +137 -0
  56. data/spec/configuration_spec.rb +57 -23
  57. data/spec/fixture/afterall_spec.js +8 -0
  58. data/spec/fixture/console_log_spec.js +5 -0
  59. data/spec/fixture/exception_test.js +1 -0
  60. data/spec/fixture/phantomConfig.js +6 -0
  61. data/spec/fixture/viewport_spec.js +6 -0
  62. data/spec/jasmine_command_line_tool_spec.rb +46 -27
  63. data/spec/jasmine_pojs_spec.rb +73 -12
  64. data/spec/jasmine_rails_spec.rb +107 -41
  65. data/spec/lib/jasmine/formatters/console_spec.rb +124 -26
  66. data/spec/lib/jasmine/formatters/exit_code_spec.rb +34 -0
  67. data/spec/lib/jasmine/formatters/multi_spec.rb +16 -6
  68. data/spec/page_spec.rb +2 -2
  69. data/spec/path_expander_spec.rb +22 -5
  70. data/spec/path_mapper_spec.rb +14 -9
  71. data/spec/performance/phantom_js_runner_performance_spec.rb +1 -1
  72. data/spec/phantom_js_spec.rb +14 -0
  73. data/spec/rack/jasmine/runner_spec.rb +2 -2
  74. data/spec/result_spec.rb +17 -7
  75. data/spec/server_spec.rb +13 -39
  76. data/spec/spec_helper.rb +54 -6
  77. data/spec/yaml_config_parser_spec.rb +21 -21
  78. metadata +75 -36
  79. data/lib/jasmine/asset_bundle.rb +0 -68
@@ -1,25 +1,44 @@
1
1
  module Jasmine
2
2
  class Configuration
3
3
  attr_writer :jasmine_css_files, :css_files
4
- attr_writer :jasmine_files, :boot_files, :src_files, :spec_files
5
- attr_accessor :jasmine_path, :spec_path, :boot_path, :src_path, :image_path
6
- attr_accessor :jasmine_dir, :spec_dir, :boot_dir, :src_dir, :images_dir
4
+ attr_writer :jasmine_files, :boot_files, :src_files, :runner_boot_files
5
+ attr_accessor :helper_files, :spec_files
6
+ attr_accessor :jasmine_path, :spec_path, :boot_path, :src_path, :image_path, :runner_boot_path
7
+ attr_accessor :jasmine_dir, :spec_dir, :boot_dir, :src_dir, :images_dir, :runner_boot_dir
7
8
  attr_accessor :formatters
8
9
  attr_accessor :host
9
10
  attr_accessor :spec_format
10
11
  attr_accessor :runner
12
+ attr_accessor :rack_options
13
+ attr_accessor :prevent_phantom_js_auto_install
14
+ attr_accessor :show_console_log
15
+ attr_accessor :stop_spec_on_expectation_failure
16
+ attr_accessor :random
17
+ attr_accessor :phantom_config_script
18
+ attr_accessor :phantom_cli_options
19
+ attr_accessor :show_full_stack_trace
20
+ attr_reader :rack_apps
11
21
 
12
22
  def initialize()
13
23
  @rack_paths = {}
14
- @apps = []
24
+ @rack_apps = []
15
25
  @path_mappers = []
16
26
  @jasmine_css_files = lambda { [] }
17
27
  @css_files = lambda { [] }
18
28
  @jasmine_files = lambda { [] }
19
29
  @boot_files = lambda { [] }
30
+ @runner_boot_files = lambda { [] }
20
31
  @src_files = lambda { [] }
32
+ @helper_files = lambda { [] }
21
33
  @spec_files = lambda { [] }
34
+ @testing_files = lambda { helper_files.call + spec_files.call}
22
35
  @runner = lambda { |config| }
36
+ @rack_options = {}
37
+ @show_console_log = false
38
+ @stop_spec_on_expectation_failure = false
39
+ @random = false
40
+ @phantom_config_script = nil
41
+ @phantom_cli_options = {}
23
42
 
24
43
  @formatters = [Jasmine::Formatters::Console]
25
44
 
@@ -34,8 +53,9 @@ module Jasmine
34
53
  def js_files
35
54
  map(@jasmine_files, :jasmine) +
36
55
  map(@boot_files, :boot) +
56
+ map(@runner_boot_files, :runner_boot) +
37
57
  map(@src_files, :src) +
38
- map(@spec_files, :spec)
58
+ map(@testing_files, :spec)
39
59
  end
40
60
 
41
61
  def rack_path_map
@@ -46,12 +66,12 @@ module Jasmine
46
66
  @rack_paths[path] = rack_app_lambda
47
67
  end
48
68
 
49
- def rack_apps
50
- [] + @apps
51
- end
52
-
53
- def add_rack_app(app, &block)
54
- @apps << [app, block]
69
+ def add_rack_app(app, *args, &block)
70
+ @rack_apps << {
71
+ :app => app,
72
+ :args => args,
73
+ :block => block
74
+ }
55
75
  end
56
76
 
57
77
  def add_path_mapper(mapper)
@@ -3,55 +3,26 @@ module Jasmine
3
3
 
4
4
  class << self
5
5
  def rails3?
6
- safe_gem_check("rails", "~> 3") && running_rails3?
6
+ rails? && Rails.version.to_i == 3
7
7
  end
8
8
 
9
9
  def rails4?
10
- safe_gem_check("rails", "~> 4.0.0.rc1") && running_rails4?
10
+ rails? && Rails.version.to_i == 4
11
11
  end
12
12
 
13
- def rails?
14
- rails_available? && running_rails?
15
- end
16
-
17
- def rails_available?
18
- safe_gem_check("rails", '>= 3')
13
+ def rails5?
14
+ rails? && Rails.version.to_i == 5
19
15
  end
20
16
 
21
- def legacy_rack?
22
- !defined?(Rack::Server)
17
+ def rails?
18
+ defined?(Rails) && Rails.respond_to?(:version)
23
19
  end
24
20
 
25
21
  def use_asset_pipeline?
26
- assets_pipeline_available = (rails3? || rails4?) && Rails.respond_to?(:application) && Rails.application.respond_to?(:assets)
22
+ assets_pipeline_available = (rails3? || rails4? || rails5?) && Rails.respond_to?(:application) && Rails.application.respond_to?(:assets) && !Rails.application.assets.nil?
27
23
  rails3_assets_enabled = rails3? && assets_pipeline_available && Rails.application.config.assets.enabled != false
28
- assets_pipeline_available && (rails4? || rails3_assets_enabled)
29
- end
30
-
31
- private
32
-
33
- def running_rails3?
34
- running_rails? && Rails.version.to_i == 3
24
+ assets_pipeline_available && (rails4? || rails5? || rails3_assets_enabled)
35
25
  end
36
-
37
- def running_rails4?
38
- running_rails? && Rails.version.to_i == 4
39
- end
40
-
41
- def running_rails?
42
- defined?(Rails) && Rails.respond_to?(:version)
43
- end
44
-
45
- def safe_gem_check(gem_name, version_string)
46
- if Gem::Specification.respond_to?(:find_by_name)
47
- Gem::Specification.find_by_name(gem_name, version_string)
48
- elsif Gem.respond_to?(:available?)
49
- Gem.available?(gem_name, version_string)
50
- end
51
- rescue Gem::LoadError
52
- false
53
- end
54
-
55
26
  end
56
27
  end
57
28
  end
@@ -1,25 +1,52 @@
1
1
  module Jasmine
2
2
  module Formatters
3
3
  class Console
4
- def initialize(outputter = Kernel.method(:puts))
4
+ def initialize(outputter = Kernel)
5
5
  @results = []
6
6
  @outputter = outputter
7
7
  end
8
8
 
9
9
  def format(results_batch)
10
- outputter.call(failures(results_batch))
10
+ outputter.print(chars(results_batch))
11
11
  @results += results_batch
12
12
  end
13
13
 
14
- def done
14
+ def done(run_details)
15
+ outputter.puts
16
+
17
+ run_result = global_failure_details(run_details)
18
+
15
19
  failure_count = results.count(&:failed?)
20
+ if failure_count > 0
21
+ outputter.puts('Failures:')
22
+ outputter.puts(failures(@results))
23
+ outputter.puts
24
+ end
25
+
16
26
  pending_count = results.count(&:pending?)
27
+ if pending_count > 0
28
+ outputter.puts('Pending:')
29
+ outputter.puts(pending(@results))
30
+ outputter.puts
31
+ end
32
+
33
+ deprecationWarnings = (@results + [run_result]).map(&:deprecation_warnings).flatten
34
+ if deprecationWarnings.size > 0
35
+ outputter.puts('Deprecations:')
36
+ outputter.puts(deprecations(deprecationWarnings))
37
+ outputter.puts
38
+ end
39
+
17
40
  summary = "#{pluralize(results.size, 'spec')}, " +
18
41
  "#{pluralize(failure_count, 'failure')}"
19
42
 
20
43
  summary += ", #{pluralize(pending_count, 'pending spec')}" if pending_count > 0
21
44
 
22
- outputter.call(summary)
45
+ outputter.puts(summary)
46
+
47
+ if run_details['order'] && run_details['order']['random']
48
+ outputter.puts("Randomized with seed #{run_details['order']['seed']}")
49
+ end
23
50
  end
24
51
 
25
52
  private
@@ -29,11 +56,49 @@ module Jasmine
29
56
  results.select(&:failed?).map { |f| failure_message(f) }.join("\n\n")
30
57
  end
31
58
 
59
+ def pending(results)
60
+ results.select(&:pending?).map { |spec| pending_message(spec) }.join("\n\n")
61
+ end
62
+
63
+ def deprecations(warnings)
64
+ warnings.map { |w| expectation_message(w) }.join("\n\n")
65
+ end
66
+
67
+ def global_failure_details(run_details)
68
+ result = Jasmine::Result.new(run_details.merge('fullName' => 'Error occurred in afterAll', 'description' => ''))
69
+ if (result.failed_expectations.size > 0)
70
+ outputter.puts(failure_message(result))
71
+ outputter.puts
72
+ end
73
+ result
74
+ end
75
+
76
+ def chars(results)
77
+ results.map do |result|
78
+ if result.succeeded?
79
+ "\e[32m.\e[0m"
80
+ elsif result.pending?
81
+ "\e[33m*\e[0m"
82
+ elsif result.disabled?
83
+ ""
84
+ else
85
+ "\e[31mF\e[0m"
86
+ end
87
+ end.join('')
88
+ end
89
+
32
90
  def pluralize(count, str)
33
91
  word = (count == 1) ? str : str + 's'
34
92
  "#{count} #{word}"
35
93
  end
36
94
 
95
+ def pending_message(spec)
96
+ reason = 'No reason given'
97
+ reason = spec.pending_reason if spec.pending_reason && spec.pending_reason != ''
98
+
99
+ "\t#{spec.full_name}\n\t \e[33m#{reason}\e[0m"
100
+ end
101
+
37
102
  def failure_message(failure)
38
103
  template = <<-FM
39
104
  #{failure.full_name}\n
@@ -3,21 +3,19 @@ module Jasmine
3
3
  class ExitCode
4
4
  def initialize
5
5
  @results = []
6
+ @global_failure = false
6
7
  end
7
8
 
8
9
  def format(results)
9
10
  @results += results
10
11
  end
11
12
 
12
- def done
13
- end
14
-
15
- def exit_code
16
- @results.detect(&:failed?) ? 1 : 0
13
+ def done(details)
14
+ @global_failure = details.fetch('failedExpectations', []).size > 0
17
15
  end
18
16
 
19
17
  def succeeded?
20
- !@results.detect(&:failed?)
18
+ !@results.detect(&:failed?) && !@global_failure
21
19
  end
22
20
  end
23
21
  end
@@ -6,19 +6,11 @@ module Jasmine
6
6
  end
7
7
 
8
8
  def format(results)
9
- go(:format, results)
9
+ @formatters.each { |formatter| formatter.format(results) }
10
10
  end
11
11
 
12
- def done
13
- go(:done)
14
- end
15
-
16
- private
17
-
18
- def go(method, *args)
19
- (@formatters || []).each do |formatter|
20
- formatter.public_send(method, *args)
21
- end
12
+ def done(details = {})
13
+ @formatters.each { |formatter| formatter.done(details) }
22
14
  end
23
15
  end
24
16
  end
@@ -7,7 +7,11 @@ module Jasmine
7
7
  patterns.map do |path|
8
8
  files = globber.call(File.join(base_directory, path.gsub(/^!/, '')))
9
9
  if files.empty? && !(path =~ /\*|^\!/)
10
- files = [File.join(base_directory, path)]
10
+ if path[0..3] == 'http'
11
+ files << path
12
+ else
13
+ files = [File.join(base_directory, path)]
14
+ end
11
15
  end
12
16
  files.sort
13
17
  end.flatten.uniq
@@ -16,14 +16,23 @@ module Jasmine
16
16
  map(paths, @config.boot_dir, @config.boot_path)
17
17
  end
18
18
 
19
+ def map_runner_boot_paths(paths)
20
+ map(paths, @config.runner_boot_dir, @config.runner_boot_path)
21
+ end
22
+
19
23
  def map_jasmine_paths(paths)
20
24
  map(paths, @config.jasmine_dir, @config.jasmine_path)
21
25
  end
22
26
 
23
27
  private
24
28
  def map(paths, remove_path, add_path)
25
- paths.map { |path| File.join(add_path, (path.gsub(remove_path, ''))) }
29
+ paths.map do |path|
30
+ if path[0..3] == 'http'
31
+ path
32
+ else
33
+ File.join(add_path, (path.sub(remove_path, '')))
34
+ end
35
+ end
26
36
  end
27
-
28
37
  end
29
38
  end
@@ -3,7 +3,7 @@ require 'rails/railtie'
3
3
  module Jasmine
4
4
  class Railtie < Rails::Railtie
5
5
 
6
- config.before_configuration do
6
+ initializer "jasmine.initializer", :before => :load_environment_hook do
7
7
  old_jasmine_rakefile = ::Rails.root.join('lib', 'tasks', 'jasmine.rake')
8
8
  if old_jasmine_rakefile.exist? && !ENV['USE_JASMINE_RAKE']
9
9
  puts '
@@ -6,11 +6,14 @@ module Jasmine
6
6
  end
7
7
 
8
8
  def initialize(attrs)
9
+ @show_full_stack_trace = attrs["show_full_stack_trace"]
9
10
  @status = attrs["status"]
10
11
  @full_name = attrs["fullName"]
11
12
  @description = attrs["description"]
12
- @failed_expectations = map_failures(attrs["failedExpectations"])
13
+ @failed_expectations = map_failures(attrs.fetch("failedExpectations", []))
14
+ @deprecation_warnings = map_failures(attrs.fetch("deprecationWarnings", []))
13
15
  @suite_name = full_name.slice(0, full_name.size - description.size - 1)
16
+ @pending_reason = attrs["pendingReason"]
14
17
  end
15
18
 
16
19
  def succeeded?
@@ -25,19 +28,28 @@ module Jasmine
25
28
  status == 'pending'
26
29
  end
27
30
 
28
- attr_reader :full_name, :description, :failed_expectations, :suite_name
31
+ def disabled?
32
+ status == 'disabled'
33
+ end
34
+
35
+ attr_reader :full_name, :description, :failed_expectations, :deprecation_warnings, :suite_name, :pending_reason
29
36
 
30
37
  private
31
- attr_reader :status
38
+ attr_reader :status, :show_full_stack_trace
32
39
 
33
40
  def map_failures(failures)
34
41
  failures.map do |e|
35
- short_stack = if e["stack"]
36
- e["stack"].split("\n").slice(0, 7).join("\n")
37
- else
38
- "No stack trace present."
39
- end
40
- Failure.new(e["message"], short_stack)
42
+ if e["stack"]
43
+ if show_full_stack_trace
44
+ stack = e["stack"]
45
+ else
46
+ stack = e["stack"].split("\n").slice(0, 7).join("\n")
47
+ end
48
+ else
49
+ stack = "No stack trace present."
50
+ end
51
+
52
+ Failure.new(e["message"], stack)
41
53
  end
42
54
  end
43
55
 
@@ -0,0 +1,11 @@
1
+ def ruby_version_less_than(target_version)
2
+ version_parts = RUBY_VERSION.split('.').map(&:to_i).zip(target_version)
3
+
4
+ version_parts.each do |(current_part, target_part)|
5
+ if current_part < target_part
6
+ return true
7
+ end
8
+ end
9
+ false
10
+ end
11
+
@@ -14,7 +14,7 @@
14
14
 
15
15
  </head>
16
16
  <!-- TODO: turbolinks breaks spec filter links -->
17
- <body data-no-turbolink>
17
+ <body data-no-turbolink data-turbolinks="false">
18
18
  <div id="jasmine_content"></div>
19
19
  </body>
20
20
  </html>
@@ -0,0 +1,15 @@
1
+ function PhantomReporter() {
2
+ this.jasmineDone = function(details) {
3
+ window.callPhantom({ state: 'jasmineDone', details: details });
4
+ };
5
+
6
+ this.specDone = function(results) {
7
+ window.callPhantom({ state: 'specDone', results: results });
8
+ };
9
+
10
+ this.suiteDone = function(results) {
11
+ window.callPhantom({ state: 'suiteDone', results: results });
12
+ };
13
+ }
14
+
15
+ jasmine.getEnv().addReporter(new PhantomReporter());
@@ -1,54 +1,50 @@
1
1
  (function() {
2
- /**
3
- * Wait until the test condition is true or a timeout occurs. Useful for waiting
4
- * on a server response or for a ui change (fadeIn, etc.) to occur.
5
- *
6
- * @param testFx javascript condition that evaluates to a boolean,
7
- * it can be passed in as a string (e.g.: "1 == 1" or "$('#bar').is(':visible')" or
8
- * as a callback function.
9
- * @param onReady what to do when testFx condition is fulfilled,
10
- * it can be passed in as a string (e.g.: "1 == 1" or "$('#bar').is(':visible')" or
11
- * as a callback function.
12
- */
13
- function waitFor(testFx, onReady) {
14
- var condition = false,
15
- interval = setInterval(function() {
16
- if (!condition) {
17
- condition = (typeof(testFx) === 'string' ? eval(testFx) : testFx());
18
- } else {
19
- if (typeof(onReady) === 'string') {
20
- eval(onReady);
21
- } else {
22
- onReady();
23
- }
24
- clearInterval(interval);
25
- }
26
- }, 100);
2
+
3
+ if (phantom.version.major >= 2) {
4
+ var system = require('system');
5
+ var url = system.args[1];
6
+ var showConsoleLog = system.args[2] === 'true';
7
+ var configScript = system.args[3];
8
+ }
9
+ else {
10
+ var url = phantom.args[0];
11
+ var showConsoleLog = phantom.args[1] === 'true';
12
+ var configScript = phantom.args[2];
27
13
  }
28
14
 
29
- var url = phantom.args[0];
30
- var batchSize = parseInt(phantom.args[1], 10);
31
15
  var page = require('webpage').create();
16
+ configScript = configScript.replace(/['"]{2}/,"");
17
+
18
+ if (configScript !== '') {
19
+ try {
20
+ require(configScript).configure(page);
21
+ } catch(e) {
22
+ console.error('Failed to configure phantom');
23
+ console.error(e.stack);
24
+ phantom.exit(1);
25
+ }
26
+ }
27
+
28
+ page.onCallback = function(data) {
29
+ if(data.state === 'specDone') {
30
+ console.log('jasmine_spec_result' + JSON.stringify([].concat(data.results)));
31
+ } else if (data.state === 'suiteDone') {
32
+ console.log('jasmine_suite_result' + JSON.stringify([].concat(data.results)));
33
+ } else {
34
+ console.log('jasmine_done' + JSON.stringify(data.details));
35
+ phantom.exit(0);
36
+ }
37
+ };
38
+
39
+ if (showConsoleLog) {
40
+ page.onConsoleMessage = function(message) {
41
+ console.log(message);
42
+ };
43
+ }
32
44
 
33
45
  page.open(url, function(status) {
34
46
  if (status !== "success") {
35
47
  phantom.exit(1);
36
- } else {
37
- waitFor(function() {
38
- return page.evaluate(function() {
39
- return jsApiReporter && jsApiReporter.finished
40
- });
41
- }, function() {
42
- var index = 0, results;
43
- do {
44
- results = page.evaluate(function(index, batchSize) {
45
- return jsApiReporter.specResults(index, batchSize)
46
- }, index, batchSize);
47
- console.log(JSON.stringify(results));
48
- index += batchSize;
49
- } while (results && results.length == batchSize)
50
- phantom.exit(0);
51
- });
52
48
  }
53
49
  });
54
50
  }).call(this);
@@ -3,26 +3,71 @@ require 'phantomjs'
3
3
  module Jasmine
4
4
  module Runners
5
5
  class PhantomJs
6
- def initialize(formatter, jasmine_server_url, result_batch_size)
6
+ def initialize(formatter, jasmine_server_url, prevent_phantom_js_auto_install, show_console_log, phantom_config_script, show_full_stack_trace, cli_options = nil)
7
7
  @formatter = formatter
8
8
  @jasmine_server_url = jasmine_server_url
9
- @result_batch_size = result_batch_size
9
+ @prevent_phantom_js_auto_install = prevent_phantom_js_auto_install
10
+ @show_console_log = show_console_log
11
+ @phantom_config_script = phantom_config_script
12
+ @show_full_stack_trace = show_full_stack_trace
13
+ @cli_options = cli_options || {}
10
14
  end
11
15
 
12
16
  def run
13
- command = "#{Phantomjs.path} '#{File.join(File.dirname(__FILE__), 'phantom_jasmine_run.js')}' #{jasmine_server_url} #{result_batch_size}"
17
+ phantom_script = File.join(File.dirname(__FILE__), 'phantom_jasmine_run.js')
18
+ command = "\"#{phantom_js_path}\" \"#{cli_options_string}\" \"#{phantom_script}\" \"#{jasmine_server_url}\" \"#{show_console_log}\" \"#{@phantom_config_script}\""
19
+ run_details = { 'random' => false }
14
20
  IO.popen(command) do |output|
15
21
  output.each do |line|
16
- raw_results = JSON.parse(line, :max_nesting => false)
17
- results = raw_results.map { |r| Result.new(r) }
18
- formatter.format(results)
22
+ if line =~ /^jasmine_spec_result/
23
+ line = line.sub(/^jasmine_spec_result/, '')
24
+ raw_results = JSON.parse(line, :max_nesting => false)
25
+ results = raw_results.map { |r| Result.new(r.merge!("show_full_stack_trace" => @show_full_stack_trace)) }
26
+ formatter.format(results)
27
+ elsif line =~ /^jasmine_suite_result/
28
+ line = line.sub(/^jasmine_suite_result/, '')
29
+ raw_results = JSON.parse(line, :max_nesting => false)
30
+ results = raw_results.map { |r| Result.new(r.merge!("show_full_stack_trace" => @show_full_stack_trace)) }
31
+ failures = results.select(&:failed?)
32
+ if failures.any?
33
+ formatter.format(failures)
34
+ end
35
+ elsif line =~ /^jasmine_done/
36
+ line = line.sub(/^jasmine_done/, '')
37
+ run_details = JSON.parse(line, :max_nesting => false)
38
+ elsif line =~ /^Failed to configure phantom$/
39
+ config_failure = Result.new('fullName' => line,
40
+ 'failedExpectations' => [],
41
+ 'description' => '',
42
+ 'status' => 'failed',
43
+ 'show_full_stack_trace' => @show_full_stack_trace)
44
+ formatter.format([config_failure])
45
+ @show_console_log = true
46
+ puts line
47
+ elsif show_console_log
48
+ puts line
49
+ end
19
50
  end
20
51
  end
21
- formatter.done
52
+ formatter.done(run_details)
53
+ end
54
+
55
+ def phantom_js_path
56
+ prevent_phantom_js_auto_install ? 'phantomjs' : Phantomjs.path
57
+ end
58
+
59
+ def boot_js
60
+ File.expand_path('phantom_boot.js', File.dirname(__FILE__))
61
+ end
62
+
63
+ def cli_options_string
64
+ @cli_options.
65
+ map {|(k, v)| "--#{k}=#{v}"}.
66
+ join(' ')
22
67
  end
23
68
 
24
69
  private
25
- attr_reader :formatter, :jasmine_server_url, :result_batch_size
70
+ attr_reader :formatter, :jasmine_server_url, :prevent_phantom_js_auto_install, :show_console_log
26
71
  end
27
72
  end
28
73
  end
@@ -1,20 +1,17 @@
1
1
  module Jasmine
2
2
  class Server
3
- def initialize(port = 8888, application = nil)
3
+ def initialize(port = 8888, application = nil, rack_options = nil, env = ENV)
4
4
  @port = port
5
5
  @application = application
6
+ @rack_options = rack_options || {}
7
+ @env = env
6
8
  end
7
9
 
8
10
  def start
9
- if Jasmine::Dependencies.legacy_rack?
10
- handler = Rack::Handler.get('webrick')
11
- handler.run(@application, :Port => @port, :AccessLog => [])
12
- else
13
- server = Rack::Server.new(:Port => @port, :AccessLog => [])
14
- # workaround for Rack bug, when Rack > 1.2.1 is released Rack::Server.start(:app => Jasmine.app(self)) will work
15
- server.instance_variable_set(:@app, @application)
16
- server.start
17
- end
11
+ @env['PORT'] = @port.to_s
12
+ Rack::Server.start(@rack_options.merge(:Port => @port,
13
+ :AccessLog => [],
14
+ :app => @application))
18
15
  end
19
16
  end
20
17
  end