jasmine 1.3.2 → 2.0.0.rc2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (63) hide show
  1. checksums.yaml +7 -0
  2. data/.travis.yml +3 -37
  3. data/Gemfile +11 -2
  4. data/HOW_TO_TEST.markdown +1 -1
  5. data/README.markdown +10 -10
  6. data/Rakefile +18 -29
  7. data/generators/jasmine/templates/jasmine-example/spec/PlayerSpec.js +2 -2
  8. data/generators/jasmine/templates/jasmine-example/spec/SpecHelper.js +14 -8
  9. data/generators/jasmine/templates/spec/javascripts/support/jasmine.yml +3 -3
  10. data/generators/jasmine/templates/spec/javascripts/support/jasmine_helper.rb +1 -0
  11. data/jasmine.gemspec +11 -41
  12. data/lib/generators/jasmine/examples/templates/spec/javascripts/helpers/SpecHelper.js +15 -9
  13. data/lib/generators/jasmine/examples/templates/spec/javascripts/jasmine_examples/PlayerSpec.js +1 -1
  14. data/lib/jasmine.rb +10 -7
  15. data/lib/jasmine/asset_bundle.rb +69 -0
  16. data/lib/jasmine/asset_expander.rb +7 -7
  17. data/lib/jasmine/command_line_tool.rb +18 -0
  18. data/lib/jasmine/config.rb +23 -15
  19. data/lib/jasmine/configuration.rb +14 -8
  20. data/lib/jasmine/core_configuration.rb +7 -4
  21. data/lib/jasmine/dependencies.rb +14 -18
  22. data/lib/jasmine/formatters/base.rb +9 -0
  23. data/lib/jasmine/formatters/console.rb +45 -0
  24. data/lib/jasmine/formatters/junit_xml.rb +47 -0
  25. data/lib/jasmine/path_expander.rb +1 -1
  26. data/lib/jasmine/railtie.rb +7 -6
  27. data/lib/jasmine/reporters/api_reporter.rb +38 -0
  28. data/lib/jasmine/results.rb +28 -9
  29. data/lib/jasmine/results_processor.rb +1 -1
  30. data/lib/jasmine/run.html.erb +1 -1
  31. data/lib/jasmine/run_specs.rb +12 -15
  32. data/lib/jasmine/runners/http.rb +11 -49
  33. data/lib/jasmine/selenium_driver.rb +17 -14
  34. data/lib/jasmine/tasks/jasmine.rake +21 -30
  35. data/lib/jasmine/tasks/{jasmine_rails3.rake → jasmine_rails.rake} +0 -0
  36. data/lib/jasmine/version.rb +1 -1
  37. data/lib/jasmine/yaml_config_parser.rb +9 -0
  38. data/release_notes/v2.0.0.rc2.md +44 -0
  39. data/spec/application_spec.rb +33 -38
  40. data/spec/asset_expander_spec.rb +4 -32
  41. data/spec/configuration_spec.rb +95 -35
  42. data/spec/jasmine_command_line_tool_spec.rb +63 -11
  43. data/spec/jasmine_rails_spec.rb +94 -0
  44. data/spec/lib/jasmine/formatters/base_spec.rb +9 -0
  45. data/spec/lib/jasmine/formatters/console_spec.rb +92 -0
  46. data/spec/lib/jasmine/formatters/junit_xml_spec.rb +55 -0
  47. data/spec/lib/jasmine/reporters/api_reporter_spec.rb +53 -0
  48. data/spec/lib/jasmine/runners/http_spec.rb +21 -0
  49. data/spec/path_expander_spec.rb +25 -0
  50. data/spec/results_spec.rb +59 -17
  51. data/spec/spec_helper.rb +36 -18
  52. data/spec/support/fake_selenium_driver.rb +35 -0
  53. data/spec/yaml_config_parser_spec.rb +37 -0
  54. metadata +65 -103
  55. data/generators/jasmine/templates/jasmine-example/SpecRunner.html +0 -54
  56. data/lib/jasmine/asset_pipeline_utility.rb +0 -19
  57. data/lib/jasmine/javascripts/boot.js +0 -28
  58. data/lib/jasmine/rspec_formatter.rb +0 -92
  59. data/spec/dependencies_spec.rb +0 -315
  60. data/spec/jasmine_rails2_spec.rb +0 -89
  61. data/spec/jasmine_rails3_spec.rb +0 -69
  62. data/spec/jasmine_self_test_spec.rb +0 -29
  63. data/spec/rspec_formatter_spec.rb +0 -88
@@ -1,18 +1,18 @@
1
1
  module Jasmine
2
2
  class AssetExpander
3
- def initialize(bundled_asset_factory, asset_path_for)
3
+ def initialize(bundled_asset_factory)
4
4
  @bundled_asset_factory = bundled_asset_factory
5
- @asset_path_for = asset_path_for
6
5
  end
7
6
 
8
7
  def expand(src_dir, src_path)
9
8
  pathname = src_path.gsub(/^\/?assets\//, '').gsub(/\.js$/, '')
10
- bundled_asset = @bundled_asset_factory.call(pathname, 'js')
11
- return nil unless bundled_asset
12
-
13
- bundled_asset.to_a.map do |asset|
14
- "/#{@asset_path_for.call(asset).gsub(/^\//, '')}?body=true"
9
+ bundled_asset = bundled_asset_factory.new(pathname)
10
+ bundled_asset.assets.map do |asset|
11
+ "/#{asset.gsub(/^\//, '')}?body=true"
15
12
  end.flatten
16
13
  end
14
+
15
+ private
16
+ attr_reader :bundled_asset_factory
17
17
  end
18
18
  end
@@ -26,6 +26,24 @@ module Jasmine
26
26
  if argv[0] == 'init'
27
27
  require 'fileutils'
28
28
 
29
+ force = false
30
+
31
+ if argv.size > 1 && argv[1] == "--force"
32
+ force = true
33
+ end
34
+
35
+ if File.exist?("Gemfile") && open("Gemfile", 'r').read.include?('rails') && !force
36
+ puts <<-EOF
37
+
38
+ You're attempting to run jasmine init in a Rails project. You probably want to use the Rails generator like so:
39
+ rails g jasmine:init
40
+
41
+ If you're not actually in a Rails application, just run this command again with --force
42
+ jasmine init --force
43
+ EOF
44
+ exit 1
45
+ end
46
+
29
47
  FileUtils.makedirs('public/javascripts')
30
48
  FileUtils.makedirs('spec/javascripts')
31
49
  FileUtils.makedirs('spec/javascripts/support')
@@ -12,19 +12,21 @@ module Jasmine
12
12
 
13
13
  @config.add_path_mapper(Jasmine::PathMapper.method(:new))
14
14
 
15
- @config.jasmine_path = jasmine_path = "/__jasmine__"
16
- @config.src_path = src_path = "/"
17
- @config.spec_path = spec_path = "/__spec__"
18
- @config.boot_path = boot_path = "/__boot__"
15
+ @config.jasmine_path = jasmine_path = '/__jasmine__'
16
+ @config.src_path = src_path = '/'
17
+ @config.spec_path = spec_path = '/__spec__'
18
+ @config.boot_path = boot_path = '/__boot__'
19
+ @config.image_path = image_path = '/__images__'
19
20
 
20
21
  @config.jasmine_dir = core_config.path
21
- @config.boot_dir = core_config.boot_path
22
+ @config.boot_dir = core_config.boot_dir
22
23
  @config.boot_files = lambda { core_config.boot_files }
23
24
  @config.jasmine_files = lambda { core_config.js_files }
24
25
  @config.jasmine_css_files = lambda { core_config.css_files }
25
26
  @config.add_rack_path(jasmine_path, lambda { Rack::File.new(config.jasmine_dir) })
26
27
  @config.add_rack_path(boot_path, lambda { Rack::File.new(config.boot_dir) })
27
28
  @config.add_rack_path(spec_path, lambda { Rack::File.new(config.spec_dir) })
29
+ @config.add_rack_path(image_path, lambda { Rack::File.new(core_config.images_dir) })
28
30
  @config.add_rack_path(src_path, lambda {
29
31
  Rack::Cascade.new([
30
32
  Rack::URLMap.new('/' => Rack::File.new(config.src_dir)),
@@ -35,21 +37,23 @@ module Jasmine
35
37
  @config.add_rack_app(Rack::Head)
36
38
  @config.add_rack_app(Rack::Jasmine::CacheControl)
37
39
 
38
- if Jasmine::Dependencies.rails_3_asset_pipeline?
40
+ if Jasmine::Dependencies.use_asset_pipeline?
39
41
  @config.add_path_mapper(lambda { |config|
40
- asset_expander = Jasmine::AssetExpander.new(
41
- Jasmine::AssetPipelineUtility.method(:bundled_asset_factory),
42
- Jasmine::AssetPipelineUtility.method(:asset_path_for)
43
- )
42
+ asset_expander = Jasmine::AssetExpander.new(Jasmine::AssetBundle.factory)
44
43
  Jasmine::AssetPipelineMapper.new(config, asset_expander.method(:expand))
45
44
  })
46
- @config.add_rack_path('/assets', lambda {
45
+ @config.add_rack_path(Rails.application.config.assets.prefix, lambda {
47
46
  # In order to have asset helpers like asset_path and image_path, we need to require 'action_view/base'. This
48
47
  # triggers run_load_hooks on action_view which, in turn, causes sprockets/railtie to load the Sprockets asset
49
48
  # helpers. Alternatively, you can include the helpers yourself without loading action_view/base:
50
49
  Rails.application.assets.context_class.instance_eval do
51
- include ::Sprockets::Helpers::IsolatedHelper
52
- include ::Sprockets::Helpers::RailsHelper
50
+ if Jasmine::Dependencies.rails3?
51
+ include ::Sprockets::Helpers::IsolatedHelper
52
+ include ::Sprockets::Helpers::RailsHelper
53
+ end
54
+ if Jasmine::Dependencies.rails4?
55
+ include ::Sprockets::Rails::Helper
56
+ end
53
57
  end
54
58
  Rails.application.assets
55
59
  })
@@ -73,11 +77,15 @@ module Jasmine
73
77
  config.jasmine_dir = yaml_config.jasmine_dir if yaml_config.jasmine_dir
74
78
  config.jasmine_files = lambda { yaml_config.jasmine_files } if yaml_config.jasmine_files.any?
75
79
  config.jasmine_css_files = lambda { yaml_config.jasmine_css_files } if yaml_config.jasmine_css_files.any?
80
+ config.boot_dir = yaml_config.boot_dir if yaml_config.boot_dir
81
+ config.boot_files = lambda { yaml_config.boot_files } if yaml_config.boot_files.any?
82
+
83
+ config.src_dir = yaml_config.src_dir
76
84
  config.src_files = lambda { yaml_config.src_files }
77
- config.spec_files = lambda { yaml_config.helpers + yaml_config.spec_files }
78
85
  config.css_files = lambda { yaml_config.css_files }
79
- config.src_dir = yaml_config.src_dir
86
+
80
87
  config.spec_dir = yaml_config.spec_dir
88
+ config.spec_files = lambda { yaml_config.helpers + yaml_config.spec_files }
81
89
  end
82
90
  require yaml_config.spec_helper if File.exist?(yaml_config.spec_helper)
83
91
  end
@@ -2,10 +2,14 @@ module Jasmine
2
2
  class Configuration
3
3
  attr_writer :jasmine_css_files, :css_files
4
4
  attr_writer :jasmine_files, :boot_files, :src_files, :spec_files
5
- attr_accessor :jasmine_path, :spec_path, :boot_path, :src_path
6
- attr_accessor :jasmine_dir, :spec_dir, :boot_dir, :src_dir
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
7
+ attr_accessor :formatters
7
8
  #TODO: these are largely client concerns, move them.
8
9
  attr_accessor :port, :browser, :host, :result_batch_size
10
+ attr_accessor :selenium_server, :selenium_server_port, :webdriver
11
+ attr_accessor :junit_xml_path
12
+ attr_accessor :spec_format, :jasmine_port
9
13
 
10
14
  def initialize()
11
15
  @rack_paths = {}
@@ -17,6 +21,12 @@ module Jasmine
17
21
  @boot_files = lambda { [] }
18
22
  @src_files = lambda { [] }
19
23
  @spec_files = lambda { [] }
24
+
25
+ @formatters = [Jasmine::Formatters::Console]
26
+
27
+ @browser = 'firefox'
28
+ @junit_xml_path = Dir.getwd
29
+ @jasmine_port = 8888
20
30
  end
21
31
 
22
32
  def css_files
@@ -26,9 +36,9 @@ module Jasmine
26
36
 
27
37
  def js_files
28
38
  map(@jasmine_files, :jasmine) +
39
+ map(@boot_files, :boot) +
29
40
  map(@src_files, :src) +
30
- map(@spec_files, :spec) +
31
- map(@boot_files, :boot)
41
+ map(@spec_files, :spec)
32
42
  end
33
43
 
34
44
  def rack_path_map
@@ -55,10 +65,6 @@ module Jasmine
55
65
  @port ||= Jasmine.find_unused_port
56
66
  end
57
67
 
58
- def browser
59
- @browser || 'firefox'
60
- end
61
-
62
68
  def host
63
69
  @host || 'http://localhost'
64
70
  end
@@ -8,13 +8,12 @@ module Jasmine
8
8
  @core.path
9
9
  end
10
10
 
11
- #TODO: maybe this doesn't belong in CoreConfig
12
- def boot_path
13
- Jasmine.root('javascripts')
11
+ def boot_dir
12
+ @core.boot_dir
14
13
  end
15
14
 
16
15
  def boot_files
17
- Dir.glob(File.join(boot_path, "**"))
16
+ @core.boot_files
18
17
  end
19
18
 
20
19
  def js_files
@@ -24,5 +23,9 @@ module Jasmine
24
23
  def css_files
25
24
  @core.css_files
26
25
  end
26
+
27
+ def images_dir
28
+ @core.images_dir
29
+ end
27
30
  end
28
31
  end
@@ -2,44 +2,40 @@ module Jasmine
2
2
  module Dependencies
3
3
 
4
4
  class << self
5
- def rspec2?
6
- safe_gem_check("rspec", ">= 2.0")
5
+ def rails3?
6
+ safe_gem_check("rails", "~> 3") && running_rails3?
7
7
  end
8
8
 
9
- def rails2?
10
- safe_gem_check("rails", "~> 2.3") && running_rails2?
9
+ def rails4?
10
+ safe_gem_check("rails", "~> 4.0.0.rc1") && running_rails4?
11
11
  end
12
12
 
13
- def legacy_rails?
14
- safe_gem_check("rails", "< 2.3.11") && running_legacy_rails?
13
+ def rails?
14
+ rails_available? && running_rails?
15
15
  end
16
16
 
17
- def rails3?
18
- safe_gem_check("rails", ">= 3.0") && running_rails3?
17
+ def rails_available?
18
+ safe_gem_check("rails", '>= 3')
19
19
  end
20
20
 
21
21
  def legacy_rack?
22
22
  !defined?(Rack::Server)
23
23
  end
24
24
 
25
- def rails_3_asset_pipeline?
26
- rails3? && Rails.respond_to?(:application) && Rails.application.respond_to?(:assets) && Rails.application.assets
25
+ def use_asset_pipeline?
26
+ (rails3? || rails4?) && Rails.respond_to?(:application) && Rails.application.respond_to?(:assets) && Rails.application.assets
27
27
  end
28
28
 
29
29
  private
30
30
 
31
- def running_legacy_rails?
32
- running_rails? && (Gem::Version.new(Rails.version) < Gem::Version.new("2.3.11"))
33
- end
34
-
35
- def running_rails2?
36
- running_rails? && Rails.version.to_i == 2
37
- end
38
-
39
31
  def running_rails3?
40
32
  running_rails? && Rails.version.to_i == 3
41
33
  end
42
34
 
35
+ def running_rails4?
36
+ running_rails? && Rails.version.to_i == 4
37
+ end
38
+
43
39
  def running_rails?
44
40
  defined?(Rails) && Rails.respond_to?(:version)
45
41
  end
@@ -0,0 +1,9 @@
1
+ module Jasmine
2
+ module Formatters
3
+ class BaseFormatter < Struct.new(:results)
4
+ def format
5
+ raise NotImplementedError.new('You must override the summary method on any custom formatters.')
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,45 @@
1
+ module Jasmine
2
+ module Formatters
3
+ class Console < BaseFormatter
4
+ def format
5
+ puts failures
6
+ puts summary
7
+ end
8
+
9
+ def summary
10
+ summary = "#{pluralize(results.size, 'spec')}, " +
11
+ "#{pluralize(results.failures.size, 'failure')}"
12
+
13
+ summary += ", #{pluralize(results.pending_specs.size, 'pending spec')}" unless results.pending_specs.empty?
14
+
15
+ summary
16
+ end
17
+
18
+ def failures
19
+ results.failures.map { |f| failure_message(f) }.join("\n\n")
20
+ end
21
+
22
+ private
23
+
24
+ def pluralize(count, str)
25
+ word = (count == 1) ? str : str + 's'
26
+ "#{count} #{word}"
27
+ end
28
+
29
+ def failure_message(failure)
30
+ template = <<-FM
31
+ #{failure.full_name}\n
32
+ FM
33
+
34
+ template += failure.failed_expectations.map { |fe| expectation_message(fe) }.join("\n")
35
+ end
36
+
37
+ def expectation_message(expectation)
38
+ <<-FE
39
+ #{expectation.message}
40
+ #{expectation.stack}
41
+ FE
42
+ end
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,47 @@
1
+ require 'nokogiri'
2
+
3
+ module Jasmine
4
+ module Formatters
5
+ class JUnitXml < BaseFormatter
6
+ def format
7
+ f = open(File.join(Jasmine.config.junit_xml_location, 'junit_results.xml'), 'w')
8
+ f.puts summary
9
+ f.close()
10
+ end
11
+
12
+ def summary
13
+ doc = Nokogiri::XML '<testsuites></testsuites>', nil, 'UTF-8'
14
+
15
+ testsuites = doc.at_css('testsuites')
16
+
17
+ results.results.each do |result|
18
+ suite_name = result.full_name.slice(0, result.full_name.size - result.description.size - 1)
19
+
20
+ testsuite = Nokogiri::XML::Node.new 'testsuite', doc
21
+ testsuite['tests'] = 1
22
+ testsuite['failures'] = result.status == 'failed' ? 1 : 0
23
+ testsuite['errors'] = 0
24
+ testsuite['name'] = suite_name
25
+ testsuite.parent = testsuites
26
+
27
+ testcase = Nokogiri::XML::Node.new 'testcase', doc
28
+ testcase['name'] = result.description
29
+
30
+ if result.status == 'failed'
31
+ result.failed_expectations.each do |failed_exp|
32
+ failure = Nokogiri::XML::Node.new 'failure', doc
33
+ failure['message'] = failed_exp.message
34
+ failure['type'] = 'Failure'
35
+ failure.content = failed_exp.stack
36
+ failure.parent = testcase
37
+ end
38
+ end
39
+
40
+ testcase.parent = testsuite
41
+ end
42
+
43
+ doc.to_xml(indent: 2)
44
+ end
45
+ end
46
+ end
47
+ end
@@ -9,7 +9,7 @@ module Jasmine
9
9
  if files.empty? && !(path =~ /\*|^\!/)
10
10
  files = [File.join(base_directory, path)]
11
11
  end
12
- files
12
+ files.sort
13
13
  end.flatten.uniq
14
14
  end
15
15
  chosen - negated
@@ -1,21 +1,22 @@
1
- require "rails/railtie"
1
+ require 'rails/railtie'
2
+
2
3
  module Jasmine
3
4
  class Railtie < Rails::Railtie
4
5
 
5
6
  config.before_configuration do
6
7
  old_jasmine_rakefile = ::Rails.root.join('lib', 'tasks', 'jasmine.rake')
7
- if old_jasmine_rakefile.exist? && !ENV["USE_JASMINE_RAKE"]
8
- puts %Q{
8
+ if old_jasmine_rakefile.exist? && !ENV['USE_JASMINE_RAKE']
9
+ puts '
9
10
  You no longer need to have jasmine.rake in your project, as it is now automatically loaded
10
11
  from the Jasmine gem. To silence this warning, set "USE_JASMINE_RAKE=true" in your environment
11
12
  or remove jasmine.rake.
12
- }
13
+ '
13
14
  end
14
15
  end
15
16
 
16
17
  rake_tasks do
17
- load "jasmine/tasks/jasmine.rake"
18
- load "jasmine/tasks/jasmine_rails3.rake"
18
+ load 'jasmine/tasks/jasmine.rake'
19
+ load 'jasmine/tasks/jasmine_rails.rake'
19
20
  end
20
21
  end
21
22
  end
@@ -0,0 +1,38 @@
1
+ module Jasmine
2
+ module Reporters
3
+ #TODO: where does this live?
4
+ class ApiReporter < Struct.new(:driver, :batch_size)
5
+ STARTED_JS = "return jsApiReporter && jsApiReporter.started"
6
+ FINISHED_JS = "return jsApiReporter && jsApiReporter.finished"
7
+
8
+ def started?
9
+ driver.eval_js STARTED_JS
10
+ end
11
+
12
+ def finished?
13
+ driver.eval_js FINISHED_JS
14
+ end
15
+
16
+ def results
17
+ index = 0
18
+ spec_results = []
19
+
20
+ loop do
21
+ slice = get_results_slice(index)
22
+ spec_results << slice
23
+ index += batch_size
24
+
25
+ break if slice.size < batch_size
26
+ end
27
+
28
+ spec_results.flatten
29
+ end
30
+
31
+ private
32
+
33
+ def get_results_slice(index)
34
+ driver.eval_js("return jsApiReporter.specResults(#{index}, #{batch_size})")
35
+ end
36
+ end
37
+ end
38
+ end