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,19 +1,38 @@
1
1
  module Jasmine
2
2
  class Results
3
+ attr_reader :results
3
4
 
4
- attr_reader :suites
5
- def initialize(result_hash, suite_hash, example_locations)
6
- @suites = suite_hash
7
- @results = result_hash
8
- @example_locations = example_locations
5
+ def initialize(raw_results)
6
+ @results = raw_results.map {|raw| Result.new(raw) }
9
7
  end
10
8
 
11
- def for_spec_id(id)
12
- @results[id]
9
+ def failures
10
+ @results.select { |result|
11
+ result.status == "failed"
12
+ }
13
13
  end
14
14
 
15
- def example_location_for(spec_description)
16
- @example_locations[spec_description]
15
+ def pending_specs
16
+ @results.select { |result|
17
+ result.status == "pending"
18
+ }
19
+ end
20
+
21
+ def size
22
+ @results.size
23
+ end
24
+
25
+ class Result < OpenStruct
26
+ def full_name
27
+ fullName
28
+ end
29
+
30
+ def failed_expectations
31
+ failedExpectations.map { |e|
32
+ short_stack = e["stack"].split("\n").slice(0, 7).join("\n")
33
+ OpenStruct.new(:message => e["message"], :stack => short_stack)
34
+ }
35
+ end
17
36
  end
18
37
  end
19
38
  end
@@ -6,7 +6,7 @@ module Jasmine
6
6
  end
7
7
 
8
8
  def process(results_hash, suites_hash)
9
- return Jasmine::Results.new(results_hash, suites_hash, example_locations)
9
+ Jasmine::Results.new(results_hash, suites_hash, example_locations)
10
10
  end
11
11
 
12
12
  def example_locations
@@ -3,7 +3,7 @@
3
3
  <head>
4
4
  <meta content="text/html;charset=UTF-8" http-equiv="Content-Type"/>
5
5
  <title>Jasmine suite</title>
6
- <link rel="shortcut icon" type="image/png" href="/__JASMINE_ROOT__/images/jasmine_favicon.png">
6
+ <link rel="shortcut icon" type="image/png" href="/__images__/jasmine_favicon.png">
7
7
  <% css_files.each do |css_file| %>
8
8
  <link rel="stylesheet" href="<%= css_file %>" type="text/css" media="screen"/>
9
9
  <% end %>
@@ -2,15 +2,7 @@ $:.unshift(ENV['JASMINE_GEM_PATH']) if ENV['JASMINE_GEM_PATH'] # for gem testing
2
2
 
3
3
  require 'rubygems'
4
4
  require 'jasmine'
5
- if Jasmine::Dependencies.rspec2?
6
- require 'rspec'
7
- else
8
- require 'spec'
9
- end
10
-
11
- jasmine_yml = File.join(Dir.pwd, 'spec', 'javascripts', 'support', 'jasmine.yml')
12
- if File.exist?(jasmine_yml)
13
- end
5
+ require 'rspec'
14
6
 
15
7
  Jasmine.load_configuration_from_yaml
16
8
 
@@ -26,11 +18,16 @@ t = Thread.new do
26
18
  # # ignore bad exits
27
19
  end
28
20
  t.abort_on_exception = true
29
- Jasmine::wait_for_listener(config.port, "jasmine server")
30
- puts "jasmine server started."
21
+ Jasmine::wait_for_listener(config.port, 'jasmine server')
22
+ puts 'jasmine server started.'
31
23
 
32
- results_processor = Jasmine::ResultsProcessor.new(config)
33
- results = Jasmine::Runners::HTTP.new(driver, results_processor, config.result_batch_size).run
34
- formatter = Jasmine::RspecFormatter.new
35
- formatter.format_results(results)
24
+ reporter = Jasmine::Reporters::ApiReporter.new(driver, config.result_batch_size)
25
+ raw_results = Jasmine::Runners::HTTP.new(driver, reporter).run
26
+ results = Jasmine::Results.new(raw_results)
27
+
28
+ config.formatters.each do |formatter_class|
29
+ formatter = formatter_class.new(results)
30
+ formatter.format()
31
+ end
36
32
 
33
+ exit results.failures.size
@@ -1,71 +1,33 @@
1
1
  module Jasmine
2
2
  module Runners
3
- class HTTP
4
- attr_accessor :suites
5
-
6
- def initialize(client, results_processor, result_batch_size)
7
- @client = client
8
- @results_processor = results_processor
9
- @result_batch_size = result_batch_size
10
- end
11
-
3
+ class HTTP < Struct.new(:driver, :reporter)
12
4
  def run
13
- @client.connect
14
- load_suite_info
5
+ driver.connect
6
+ ensure_connection_established
15
7
  wait_for_suites_to_finish_running
16
- results = @results_processor.process(results_hash, suites)
17
- @client.disconnect
8
+
9
+ results = reporter.results
10
+
11
+ driver.disconnect
18
12
  results
19
13
  end
20
14
 
21
15
  private
22
-
23
- def load_suite_info
16
+
17
+ def ensure_connection_established
24
18
  started = Time.now
25
- while !eval_js('return jsApiReporter && jsApiReporter.started') do
19
+ until reporter.started? do
26
20
  raise "couldn't connect to Jasmine after 60 seconds" if (started + 60 < Time.now)
27
21
  sleep 0.1
28
22
  end
29
-
30
- @suites = eval_js("var result = jsApiReporter.suites(); if (window.Prototype && Object.toJSON) { return Object.toJSON(result) } else { return JSON.stringify(result) }")
31
- end
32
-
33
- def results_hash
34
- spec_results = {}
35
- spec_ids.each_slice(@result_batch_size) do |slice|
36
- 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) }"))
37
- end
38
- spec_results
39
- end
40
-
41
- def spec_ids
42
- map_spec_ids = lambda do |suites|
43
- suites.map do |suite_or_spec|
44
- if suite_or_spec['type'] == 'spec'
45
- suite_or_spec['id']
46
- else
47
- map_spec_ids.call(suite_or_spec['children'])
48
- end
49
- end
50
- end
51
- map_spec_ids.call(@suites).compact.flatten
52
23
  end
53
24
 
54
25
  def wait_for_suites_to_finish_running
55
26
  puts "Waiting for suite to finish in browser ..."
56
- while !eval_js('return jsApiReporter.finished') do
27
+ until reporter.finished? do
57
28
  sleep 0.1
58
29
  end
59
30
  end
60
-
61
- def eval_js(script)
62
- @client.eval_js(script)
63
- end
64
-
65
- def json_generate(obj)
66
- @client.json_generate(obj)
67
- end
68
-
69
31
  end
70
32
  end
71
33
  end
@@ -3,22 +3,25 @@ module Jasmine
3
3
  class SeleniumDriver
4
4
  def initialize(browser, http_address)
5
5
  require 'selenium-webdriver'
6
- selenium_server = if ENV['SELENIUM_SERVER']
7
- ENV['SELENIUM_SERVER']
8
- elsif ENV['SELENIUM_SERVER_PORT']
9
- "http://localhost:#{ENV['SELENIUM_SERVER_PORT']}/wd/hub"
10
- end
11
- options = if browser == "firefox" && ENV["JASMINE_FIREBUG"]
12
- require File.join(File.dirname(__FILE__), "firebug/firebug")
13
- profile = Selenium::WebDriver::Firefox::Profile.new
6
+
7
+ selenium_server = if Jasmine.config.selenium_server
8
+ Jasmine.config.selenium_server
9
+ elsif Jasmine.config.selenium_server_port
10
+ "http://localhost:#{Jasmine.config.selenium_server_port}/wd/hub"
11
+ end
12
+ options = if browser == 'firefox-firebug'
13
+ require File.join(File.dirname(__FILE__), 'firebug/firebug')
14
+ (profile = Selenium::WebDriver::Firefox::Profile.new)
14
15
  profile.enable_firebug
15
16
  {:profile => profile}
16
17
  end || {}
17
- @driver = if selenium_server
18
- Selenium::WebDriver.for :remote, :url => selenium_server, :desired_capabilities => browser.to_sym
19
- else
20
- Selenium::WebDriver.for browser.to_sym, options
21
- end
18
+ @driver = if Jasmine.config.webdriver
19
+ Jasmine.config.webdriver
20
+ elsif selenium_server
21
+ Selenium::WebDriver.for :remote, :url => selenium_server, :desired_capabilities => browser.to_sym
22
+ else
23
+ Selenium::WebDriver.for browser.to_sym, options
24
+ end
22
25
  @http_address = http_address
23
26
  end
24
27
 
@@ -32,7 +35,7 @@ module Jasmine
32
35
 
33
36
  def eval_js(script)
34
37
  result = @driver.execute_script(script)
35
- JSON.parse("{\"result\":#{result}}", :max_nesting => false)["result"]
38
+ JSON.parse("{\"result\":#{result.to_json}}", :max_nesting => false)['result']
36
39
  end
37
40
 
38
41
  def json_generate(obj)
@@ -1,4 +1,8 @@
1
1
  namespace :jasmine do
2
+ require 'jasmine/config'
3
+
4
+ Jasmine.load_configuration_from_yaml
5
+
2
6
  task :require do
3
7
  require 'jasmine'
4
8
  end
@@ -12,44 +16,31 @@ namespace :jasmine do
12
16
  end
13
17
  end
14
18
 
15
- desc "Run continuous integration tests"
16
- task :ci => ["jasmine:require_json", "jasmine:require"] do
17
- if Jasmine::Dependencies.rspec2?
18
- require "rspec"
19
- require "rspec/core/rake_task"
20
- else
21
- require "spec"
22
- require 'spec/rake/spectask'
23
- end
19
+ desc 'Run continuous integration tests'
20
+ task :ci => %w(jasmine:require_json jasmine:require) do
21
+ require 'rspec'
22
+ require 'rspec/core/rake_task'
24
23
 
25
- if Jasmine::Dependencies.rspec2?
26
- RSpec::Core::RakeTask.new(:jasmine_continuous_integration_runner) do |t|
27
- t.rspec_opts = ["--colour", "--format", ENV['JASMINE_SPEC_FORMAT'] || "progress"]
28
- t.verbose = true
29
- if Jasmine::Dependencies.rails_3_asset_pipeline?
30
- t.rspec_opts += ["-r #{File.expand_path(File.join(::Rails.root, 'config', 'environment'))}"]
31
- end
32
- t.pattern = [Jasmine.runner_filepath]
33
- end
34
- else
35
- Spec::Rake::SpecTask.new(:jasmine_continuous_integration_runner) do |t|
36
- t.spec_opts = ["--color", "--format", ENV['JASMINE_SPEC_FORMAT'] || "specdoc"]
37
- t.verbose = true
38
- t.spec_files = [Jasmine.runner_filepath]
24
+ RSpec::Core::RakeTask.new(:jasmine_continuous_integration_runner) do |t|
25
+ t.rspec_opts = ['--colour', '--format', Jasmine.config.spec_format || 'progress']
26
+ t.verbose = true
27
+ if Jasmine::Dependencies.use_asset_pipeline?
28
+ t.rspec_opts += ["-r #{File.expand_path(File.join(::Rails.root, 'config', 'environment'))}"]
39
29
  end
30
+ t.pattern = [Jasmine.runner_filepath]
40
31
  end
41
- Rake::Task["jasmine_continuous_integration_runner"].invoke
32
+
33
+ Rake::Task['jasmine_continuous_integration_runner'].invoke
42
34
  end
43
35
 
44
- task :server => "jasmine:require" do
45
- port = ENV['JASMINE_PORT'] || 8888
46
- puts "your tests are here:"
36
+ task :server => 'jasmine:require' do
37
+ port = Jasmine.config.jasmine_port || 8888
38
+ puts 'your tests are here:'
47
39
  puts " http://localhost:#{port}/"
48
- Jasmine.load_configuration_from_yaml
49
40
  app = Jasmine::Application.app(Jasmine.config)
50
41
  Jasmine::Server.new(port, app).start
51
42
  end
52
43
  end
53
44
 
54
- desc "Run specs via server"
55
- task :jasmine => ['jasmine:server']
45
+ desc 'Run specs via server'
46
+ task :jasmine => %w(jasmine:server)
@@ -1,3 +1,3 @@
1
1
  module Jasmine
2
- VERSION = "1.3.2"
2
+ VERSION = "2.0.0.rc2"
3
3
  end
@@ -22,6 +22,11 @@ module Jasmine
22
22
  File.join(@pwd, loaded_yaml['jasmine_dir'])
23
23
  end
24
24
 
25
+ def boot_dir
26
+ return nil unless loaded_yaml['boot_dir']
27
+ File.join(@pwd, loaded_yaml['boot_dir'])
28
+ end
29
+
25
30
  def src_files
26
31
  @path_expander.call(src_dir, loaded_yaml['src_files'] || [])
27
32
  end
@@ -30,6 +35,10 @@ module Jasmine
30
35
  @path_expander.call(jasmine_dir, loaded_yaml['jasmine_files'] || [])
31
36
  end
32
37
 
38
+ def boot_files
39
+ @path_expander.call(boot_dir, loaded_yaml['boot_files'] || [])
40
+ end
41
+
33
42
  def jasmine_css_files
34
43
  @path_expander.call(jasmine_dir, loaded_yaml['jasmine_css_files'] || [])
35
44
  end
@@ -0,0 +1,44 @@
1
+ # Jasmine Gem 2.0 Release Notes
2
+
3
+ ## Summary
4
+
5
+ These notes cover v2.0.0.rc2.
6
+
7
+ ## Changes
8
+
9
+ * Support for changes in Jasmine 2.0
10
+ * hooks for `boot_dir` and `boot_files`
11
+ * New resutls interface in reporters
12
+ * Results Formatters
13
+ * New console results formatter for CI tasks - no longer depend on RSpec for console output
14
+ * Optional JUnit XML results formatter for CI tasks
15
+ * Projects can provide custom formatters
16
+ * Rails 4 support
17
+ * Better support for non-Rails Ruby projects
18
+ * Loosely pinning to jasmine-core, allowing for jasmine-core's build to work on release for jasmine build to work.
19
+ * SHA: 42021e3a86e57f6b7b23dfbe921867d7560f4e4f
20
+ * Add warning to jasmine init
21
+ * SHA: e071474b014e7d6909d69f86988b84eacb801201
22
+ * Globbing should now return files in a consistent, predictable order across systems
23
+ * Reactivated the Rails integration tests; fix resulting issues
24
+ * Added the configuration option to specify your own webdriver instance
25
+ * Brought back the Jasmine Favicon
26
+
27
+ ## Dropped Support
28
+
29
+ * ENV variables removed - use Jasmine.configure to set browser, ports, etc.
30
+ * Dropped support for 1.8.x Rubies, Rails 2, RSpec 1 - please continue to use Jasmine gem 1.3.2
31
+ * "self-test" is gone as [Jasmine core now tests itself](http://travis-ci.org/pivotal/jasmine)
32
+
33
+ ## Pull Requests
34
+
35
+ * Fix README.markdown and add config example #[144](http://github.com/pivotal/jasmine-gem/pull/144) from enrapt-mochizuki
36
+ * Use a relative path to jasmine repo in Gemfile #[161](http://github.com/pivotal/jasmine-gem/pull/161) from zephyr-dev
37
+ * Problem when using a asset prefix other than '/assets' #[155](http://github.com/pivotal/jasmine-gem/pull/155) from janv
38
+ * Remove unused code - #[154]((http://github.com/pivotal/jasmine-gem/pull/154) from daytonn
39
+ * Fix default path for :spec_helper in template #[147]((http://github.com/pivotal/jasmine-gem/pull/147) from kmayer
40
+ * Improve Gemfile installation instructions #[141]((http://github.com/pivotal/jasmine-gem/pull/141)
41
+
42
+ ------
43
+
44
+ _Release Notes generated with [Anchorman](http://github.com/infews/anchorman)_
@@ -1,44 +1,39 @@
1
1
  require 'spec_helper'
2
2
 
3
- #Rspec 1 doesn't correctly pass blocks to stubs, so skip (covered by integration tests)
4
- #https://groups.google.com/forum/?fromgroups=#!topic/rspec/XT7paH2asCo
3
+ describe 'Jasmine::Application' do
4
+ it 'should map paths provided by the config' do
5
+ handler1 = double(:handler1)
6
+ handler2 = double(:handler2)
7
+ app1 = double(:app1)
8
+ app2 = double(:app2)
9
+ rack_path_map = {'/foo' => lambda { handler1 }, '/bar' => lambda { handler2 }}
10
+ config = double(:config, :rack_path_map => rack_path_map, :rack_apps => [])
11
+ builder = double('Rack::Builder.new')
12
+ #Rack::Builder instance evals, so builder.run is invalid syntax,
13
+ #this is the only way to stub out the 'run' dsl it gives to the block.
14
+ Jasmine::Application.stub(:run).with(handler1).and_return(app1)
15
+ Jasmine::Application.stub(:run).with(handler2).and_return(app2)
5
16
 
6
- if Jasmine::Dependencies.rspec2?
7
- describe "Jasmine::Application" do
8
- it "should map paths provided by the config" do
9
- handler1 = double(:handler1)
10
- handler2 = double(:handler2)
11
- app1 = double(:app1)
12
- app2 = double(:app2)
13
- rack_path_map = {"/foo" => lambda { handler1 }, "/bar" => lambda { handler2 }}
14
- config = double(:config, :rack_path_map => rack_path_map, :rack_apps => [])
15
- builder = double("Rack::Builder.new")
16
- #Rack::Builder instance evals, so builder.run is invalid syntax,
17
- #this is the only way to stub out the 'run' dsl it gives to the block.
18
- Jasmine::Application.stub(:run).with(handler1).and_return(app1)
19
- Jasmine::Application.stub(:run).with(handler2).and_return(app2)
20
-
21
- builder.should_receive(:map).twice do |path, &app|
22
- if path == '/foo'
23
- app.call.should == app1
24
- elsif path == '/bar'
25
- app.call.should == app2
26
- else
27
- raise "Unexpected path passed"
28
- end
17
+ builder.should_receive(:map).twice do |path, &app|
18
+ if path == '/foo'
19
+ app.call.should == app1
20
+ elsif path == '/bar'
21
+ app.call.should == app2
22
+ else
23
+ raise 'Unexpected path passed'
29
24
  end
30
-
31
- Jasmine::Application.app(config, builder).should == builder
32
- end
33
- it "should run rack apps provided by the config" do
34
- app1 = double(:app1)
35
- app2 = double(:app2)
36
- block = lambda { "foo" }
37
- config = double(:config, :rack_path_map => [], :rack_apps => [[app1, nil], [app2, block]])
38
- builder = double("Rack::Builder.new")
39
- builder.should_receive(:use).with(app1)
40
- builder.should_receive(:use).with(app2, &block)
41
- Jasmine::Application.app(config, builder).should == builder
42
25
  end
26
+
27
+ Jasmine::Application.app(config, builder).should == builder
28
+ end
29
+ it 'should run rack apps provided by the config' do
30
+ app1 = double(:app1)
31
+ app2 = double(:app2)
32
+ block = lambda { 'foo' }
33
+ config = double(:config, :rack_path_map => [], :rack_apps => [[app1, nil], [app2, block]])
34
+ builder = double('Rack::Builder.new')
35
+ builder.should_receive(:use).with(app1)
36
+ builder.should_receive(:use).with(app2, &block)
37
+ Jasmine::Application.app(config, builder).should == builder
43
38
  end
44
- end
39
+ end