jasmine 2.0.0.rc2 → 2.0.0.rc3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (74) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +9 -11
  3. data/Gemfile +4 -2
  4. data/HOW_TO_TEST.markdown +1 -1
  5. data/README.markdown +23 -14
  6. data/RELEASE.markdown +6 -13
  7. data/Rakefile +21 -23
  8. data/jasmine.gemspec +9 -16
  9. data/{generators/jasmine/templates/jasmine-example/spec → lib/generators/jasmine/examples/templates/spec/javascripts/helpers/jasmine_examples}/SpecHelper.js +0 -0
  10. data/lib/generators/jasmine/examples/templates/spec/javascripts/jasmine_examples/PlayerSpec.js +1 -1
  11. data/lib/generators/jasmine/install/templates/spec/javascripts/support/jasmine.yml +15 -2
  12. data/lib/generators/jasmine/install/templates/spec/javascripts/support/jasmine_helper.rb +2 -2
  13. data/lib/jasmine.rb +5 -7
  14. data/lib/jasmine/asset_bundle.rb +9 -10
  15. data/lib/jasmine/command_line_install.txt +13 -0
  16. data/lib/jasmine/command_line_tool.rb +100 -58
  17. data/lib/jasmine/config.rb +25 -13
  18. data/lib/jasmine/configuration.rb +21 -16
  19. data/lib/jasmine/dependencies.rb +1 -1
  20. data/lib/jasmine/formatters/console.rb +21 -13
  21. data/lib/jasmine/formatters/exit_code.rb +21 -0
  22. data/lib/jasmine/formatters/multi.rb +25 -0
  23. data/lib/jasmine/result.rb +46 -0
  24. data/lib/jasmine/run.html.erb +3 -1
  25. data/lib/jasmine/runners/phantom_jasmine_run.js +54 -0
  26. data/lib/jasmine/runners/phantom_js.rb +29 -0
  27. data/lib/jasmine/tasks/jasmine.rake +42 -21
  28. data/lib/jasmine/version.rb +1 -1
  29. data/spec/configuration_spec.rb +34 -72
  30. data/spec/fixture/coffee_spec.coffee +3 -0
  31. data/spec/fixture/failing_runner.rb +9 -0
  32. data/spec/fixture/failing_test.js +5 -0
  33. data/spec/fixture/large_test_suite_spec.js +20 -0
  34. data/spec/jasmine_command_line_tool_spec.rb +94 -52
  35. data/spec/jasmine_pojs_spec.rb +37 -21
  36. data/spec/jasmine_rails_spec.rb +89 -49
  37. data/spec/lib/jasmine/formatters/console_spec.rb +50 -35
  38. data/spec/lib/jasmine/formatters/multi_spec.rb +17 -0
  39. data/spec/performance/phantom_js_runner_performance_spec.rb +23 -0
  40. data/spec/result_spec.rb +34 -0
  41. data/spec/spec_helper.rb +40 -16
  42. metadata +34 -84
  43. data/generators/jasmine/jasmine_generator.rb +0 -25
  44. data/generators/jasmine/templates/INSTALL +0 -9
  45. data/generators/jasmine/templates/jasmine-example/spec/PlayerSpec.js +0 -58
  46. data/generators/jasmine/templates/jasmine-example/src/Player.js +0 -22
  47. data/generators/jasmine/templates/jasmine-example/src/Song.js +0 -7
  48. data/generators/jasmine/templates/lib/tasks/jasmine.rake +0 -8
  49. data/generators/jasmine/templates/spec/javascripts/support/jasmine-rails.yml +0 -81
  50. data/generators/jasmine/templates/spec/javascripts/support/jasmine.yml +0 -88
  51. data/generators/jasmine/templates/spec/javascripts/support/jasmine_helper.rb +0 -12
  52. data/lib/generators/jasmine/examples/templates/spec/javascripts/helpers/SpecHelper.js +0 -15
  53. data/lib/jasmine/firebug/firebug-1.6.2.xpi +0 -0
  54. data/lib/jasmine/firebug/firebug-1.7.0.xpi +0 -0
  55. data/lib/jasmine/firebug/firebug-license.txt +0 -30
  56. data/lib/jasmine/firebug/firebug.rb +0 -30
  57. data/lib/jasmine/formatters/base.rb +0 -9
  58. data/lib/jasmine/formatters/junit_xml.rb +0 -47
  59. data/lib/jasmine/reporters/api_reporter.rb +0 -38
  60. data/lib/jasmine/results.rb +0 -38
  61. data/lib/jasmine/results_processor.rb +0 -38
  62. data/lib/jasmine/run_specs.rb +0 -33
  63. data/lib/jasmine/runners/http.rb +0 -33
  64. data/lib/jasmine/selenium_driver.rb +0 -45
  65. data/spec/asset_expander_spec.rb +0 -13
  66. data/spec/asset_pipeline_mapper_spec.rb +0 -19
  67. data/spec/jasmine_command_line_tool_rakeless_spec.rb +0 -20
  68. data/spec/lib/jasmine/formatters/base_spec.rb +0 -9
  69. data/spec/lib/jasmine/formatters/junit_xml_spec.rb +0 -55
  70. data/spec/lib/jasmine/reporters/api_reporter_spec.rb +0 -53
  71. data/spec/lib/jasmine/runners/http_spec.rb +0 -21
  72. data/spec/results_processor_spec.rb +0 -3
  73. data/spec/results_spec.rb +0 -69
  74. data/spec/support/fake_selenium_driver.rb +0 -35
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 829cb8b7df0ab6b49277bd1ff57726df9def1ad5
4
- data.tar.gz: 8b35c826f0dce1001cfb2f572139b104f1d0cfa8
3
+ metadata.gz: 5805b801f003eafc553273cb7ee5c5719e390f11
4
+ data.tar.gz: 6b1872c956711198c0c80f6398ed57ab99e99520
5
5
  SHA512:
6
- metadata.gz: c88cd5229bba530394d60d17a6221812e71623b9f44f88ff4d480280a7c0a92ca29942635bbb02b5c89b0eb386bfd79ba01f4a7b053d8f3628be13cab48dd9f1
7
- data.tar.gz: ca5e0e70008293b2c96f142df85aa0d7a014a7dfea1a71c93151d13115c81f746210e6698b1da7dacbdab2d2b72bf400546b33822ce700ea4880c137dbff65cc
6
+ metadata.gz: fe9d0640516dfe16120a9540c6b1e40eb1ba5e2b7955b4173fdb1cba5fa05954e1a881df606dff69f190a01575cc4448ec47eabbfe60e418917f42c33b978576
7
+ data.tar.gz: 5eed88cc462358bd3d8d36eadcb2ca84e1b4e272717969eb244b1a847a473cf89ae1b27341435d9c570ba94281e6e7d9e906021a44ca762cfaca7cdd69cd1d37
data/.travis.yml CHANGED
@@ -1,6 +1,4 @@
1
- before_script:
2
- - "sh -e /etc/init.d/xvfb start"
3
- script: "DISPLAY=:99.0 bundle exec rake"
1
+ script: "if [ $PERFORMANCE_SPECS ];then bundle exec rake performance_specs --trace; else bundle exec rake --trace; fi"
4
2
 
5
3
  rvm:
6
4
  - "1.9.3"
@@ -11,14 +9,14 @@ rvm:
11
9
  env:
12
10
  - "RAILS_VERSION=rails3"
13
11
  - "RAILS_VERSION=rails4"
14
- - "RAILS_VERSION=pojs-rspec2"
12
+ - "RAILS_VERSION=pojs"
15
13
 
16
14
  matrix:
15
+ include:
16
+ - rvm: "2.0.0"
17
+ env: "PERFORMANCE_SPECS=true"
17
18
  exclude:
18
- - rvm: rbx
19
- env: RAILS_VERSION=pojs-rspec2
20
- - rvm: jruby
21
- env: RAILS_VERSION=pojs-rspec2
22
- allow_failures:
23
- - rvm: rbx
24
- - rvm: jruby
19
+ - rvm: "rbx"
20
+ env: "RAILS_VERSION=pojs"
21
+ - rvm: "jruby"
22
+ env: "RAILS_VERSION=pojs"
data/Gemfile CHANGED
@@ -4,14 +4,16 @@ gemspec
4
4
 
5
5
  unless ENV['TRAVIS']
6
6
  group :debug do
7
- gem 'debugger'
7
+ gem 'debugger', :platform => :mri
8
+ gem 'ruby-debug', :platform => :jruby
8
9
  end
9
10
  end
10
11
 
11
-
12
+ gem 'anchorman', :platform => :mri
12
13
  # during development, do not release
13
14
  if ENV['TRAVIS']
14
15
  gem 'jasmine-core', :git => 'http://github.com/pivotal/jasmine.git'
15
16
  else
16
17
  gem 'jasmine-core', :path => '../jasmine'
17
18
  end
19
+
data/HOW_TO_TEST.markdown CHANGED
@@ -1,6 +1,6 @@
1
1
  To test changes to the jasmine-gem:
2
2
 
3
- * Export RAILS_VERSION as either "pojs-rspec2", or "rails3" to test environments other than Rails 4.
3
+ * Export RAILS_VERSION as either "pojs" (Plain Old JavaScript -- IE, no rails bindings), or "rails3" to test environments other than Rails 4.
4
4
  * Delete `Gemfile.lock`
5
5
  * Clear out your current gemset
6
6
  * exec a `bundle install`
data/README.markdown CHANGED
@@ -34,36 +34,45 @@ Start the Jasmine server:
34
34
 
35
35
  `rake jasmine`
36
36
 
37
- Point your browser to `localhost:8888`. The suite will run every time this page is re-loaded.
38
-
39
- Start Jasmine on a different port:
40
-
41
- `rake jasmine JASMINE_PORT=1337`
42
-
43
- Point your browser to `localhost:1337`.
37
+ Point your browser to `localhost:8888`. The suite will run every time this page is re-loaded.
44
38
 
45
39
  For Continuous Integration environments, add this task to the project build steps:
46
40
 
47
41
  `rake jasmine:ci`
48
42
 
49
- This uses Selenium to launch a browser and run the Jasmine suite. Then it uses RSpec to extract the results from the Jasmine reporter and write them to your build log. The browser used by selenium can be changed by configuration in spec_helper file (this might require additional webdriver dependencies).
43
+ This uses PhantomJS to load and run the Jasmine suite.
50
44
 
51
45
  ## Configuration
52
46
 
53
47
  Customize `spec/javascripts/support/jasmine.yml` to enumerate the source files, stylesheets, and spec files you would like the Jasmine runner to include.
54
48
  You may use dir glob strings.
55
49
 
56
- ## Note about the CI task and RSpec
50
+ Alternatively, you may specify the path to your `jasmine.yml` by setting an environment variable:
51
+
52
+ `rake jasmine:ci JASMINE_CONFIG_PATH=relative/path/to/your/jasmine.yml`
53
+
54
+ In addition, the `spec_helper` key in your jasmine.yml specifies the path to a ruby file that can do programmatic configuration.
55
+ After running `jasmine init` or `rails g jasmine:init` it will point to `spec/javascripts/support/jasmine_helper.rb` which you can modify to fit your needs.
56
+
57
+ ### Running Jasmine on a different port
58
+
59
+ The ports that `rake jasmine` (or `rake jasmine:server`) and `rake jasmine:ci` run on are configured independently, so they can both run at the same time.
60
+
61
+ To change the port that `rake jasmine` uses:
57
62
 
58
- This gem requires RSpec for the `jasmine:ci` rake task to work. But this gem does not explicitly *depend* on any version of the RSpec gem.
63
+ In your jasmine_helper.rb:
59
64
 
60
- If you're writing a Rails application then as long as you've installed RSpec before you install Jasmine and attempt a `rake jasmine:ci`, then you will be fine.
65
+ Jasmine.configure do |config|
66
+ config.server_port = 5555
67
+ end
61
68
 
62
- If you're using another Ruby framework, or don't care about Ruby, then run
69
+ By default `rake jasmine:ci` will attempt to find a random open port, to set the port that `rake jasmine:ci` uses:
63
70
 
64
- `gem install rspec`
71
+ In your jasmine_helper.rb:
65
72
 
66
- before you attempt the CI task.
73
+ Jasmine.configure do |config|
74
+ config.ci_port = 1234
75
+ end
67
76
 
68
77
  ## Support
69
78
 
data/RELEASE.markdown CHANGED
@@ -4,19 +4,12 @@ Add release notes to gh-pages branch /release-notes.html.markdown
4
4
 
5
5
  ## Jasmine core
6
6
 
7
- * update version.json with new version
8
- * rake jasmine:dist
9
- * add pages/downloads/*.zip
10
- * commit, tag, and push both jasmine/pages and jasmine
11
- * * git push
12
- * * git tag -a x.x.x-release
13
- * * git push --tags
7
+ See release docs in jasmine-core
14
8
 
15
9
  ## Jasmine Gem
16
10
 
17
- * update version in version.rb
18
- * for release candidates, add "rc" + number to the end of the appropriate version part,
19
- e.g. we should have tagged the 1.0 RC's as 1.0.0rc1, not 1.0.0.rc1. Likewise 1.0.0.1rc1.
20
- * rake jeweler:install and try stuff out
21
- * * (jasmine init and script/generate jasmine)
22
- * rake site
11
+ 1. update version in version.rb
12
+ * for release candidates, add ".rc" + number to the end of the appropriate version part
13
+ 1. commit and push the version update to github
14
+ 1. `rake release` - tags the repo with the version, builds the `jasmine` gem, pushes the gem to Rubygems.org. In order to release you will have to ensure you have rubygems creds locally.
15
+
data/Rakefile CHANGED
@@ -10,42 +10,40 @@ require 'rspec/core/rake_task'
10
10
  desc 'Run all examples'
11
11
  RSpec::Core::RakeTask.new(:spec) do |t|
12
12
  t.pattern = 'spec/**/*_spec.rb'
13
+ t.rspec_opts = '-t ~performance'
14
+ end
15
+
16
+ desc 'Run performance build'
17
+ RSpec::Core::RakeTask.new(:performance_specs) do |t|
18
+ t.pattern = 'spec/**/*_spec.rb'
19
+ t.rspec_opts = '-t performance'
13
20
  end
14
21
 
15
22
  task :spec => %w(jasmine:copy_examples_to_gem)
23
+ task :performance_specs => %w(jasmine:copy_examples_to_gem)
16
24
 
17
25
  task :default => :spec
18
26
 
19
27
  namespace :jasmine do
20
28
  require 'jasmine-core'
21
- task :server do
22
- Jasmine.configure do |config|
23
- root = File.expand_path(File.join(File.dirname(__FILE__), '..'))
24
- config.src_dir = File.join(root, 'src')
25
- config.spec_dir = Jasmine::Core.path
26
- config.spec_files = lambda { (Jasmine::Core.html_spec_files + Jasmine::Core.core_spec_files).map {|f| File.join(config.spec_dir, f) } }
27
- config.jasmine_port = ENV['JASMINE_PORT'] || 8888
28
- end
29
-
30
- config = Jasmine.config
31
-
32
- server = Jasmine::Server.new(config.jasmine_port, Jasmine::Application.app(config))
33
- server.start
34
-
35
- puts 'your tests are here:'
36
- puts " http://localhost:#{config.jasmine_port}/"
37
- end
38
29
 
39
30
  desc 'Copy examples from Jasmine JS to the gem'
40
31
  task :copy_examples_to_gem do
41
32
  require 'fileutils'
42
33
 
43
- # copy jasmine's example tree into our generator templates dir
44
- FileUtils.rm_r('generators/jasmine/templates/jasmine-example', :force => true)
45
- FileUtils.cp_r(File.join(Jasmine::Core.path, 'example'), 'generators/jasmine/templates/jasmine-example', :preserve => true)
34
+ destination_root = File.expand_path(File.join('..', 'lib', 'generators', 'jasmine', 'examples', 'templates'), __FILE__)
35
+ spec_path = File.join(destination_root, 'spec', 'javascripts', 'jasmine_examples')
36
+ helpers_path = File.join(destination_root, 'spec', 'javascripts', 'helpers', 'jasmine_examples')
37
+ source_code_path = File.join(destination_root, 'app', 'assets', 'javascripts', 'jasmine_examples')
38
+
39
+ FileUtils.rm Dir.glob(File.join(spec_path, '*'))
40
+ FileUtils.cp(Dir.glob(File.join(Jasmine::Core.path, 'example', 'spec', '*Spec.js')), spec_path, :preserve => true)
41
+
42
+ FileUtils.rm Dir.glob(File.join(helpers_path, '*'))
43
+ FileUtils.cp(Dir.glob(File.join(Jasmine::Core.path, 'example', 'spec', 'SpecHelper.js')), helpers_path, :preserve => true)
44
+
45
+ FileUtils.rm Dir.glob(File.join(source_code_path, '*'))
46
+ FileUtils.cp(Dir.glob(File.join(Jasmine::Core.path, 'example', 'src', '*')), source_code_path, :preserve => true)
46
47
  end
47
48
  end
48
49
 
49
- desc 'Run specs via server'
50
- task :jasmine => %w(jasmine:server)
51
-
data/jasmine.gemspec CHANGED
@@ -20,27 +20,20 @@ Gem::Specification.new do |s|
20
20
  s.require_paths = ["lib"]
21
21
  s.rdoc_options = ["--charset=UTF-8"]
22
22
 
23
- if ENV['RAILS_VERSION'] == 'pojs-rspec2'
24
- s.add_development_dependency 'rspec', '>= 2.5.0'
25
- s.add_development_dependency 'rake-tasks'
26
- elsif ENV['RAILS_VERSION'] == 'rails3'
27
- # for development & test of Rails 3 Generators
28
- s.add_development_dependency 'rspec', '>= 2.5.0'
23
+ case ENV['RAILS_VERSION']
24
+ when 'rails3'
29
25
  s.add_development_dependency 'rails', '>= 3.0.0', '< 4.0.0'
30
- s.add_development_dependency 'sqlite3'
31
- else
32
- s.add_development_dependency 'rspec', '>= 2.5.0'
26
+ when 'pojs'
27
+ else #default to rails 4
33
28
  s.add_development_dependency 'rails', '>= 4'
34
29
  end
35
30
 
36
31
  s.add_development_dependency 'rack-test'
37
- s.add_development_dependency 'json_pure'
32
+ s.add_development_dependency 'multi_json'
33
+ s.add_development_dependency 'rspec', '>= 2.5.0'
38
34
 
39
- s.add_development_dependency 'anchorman'
40
-
41
- s.add_dependency 'jasmine-core', '~> 2.0.0.alpha'
35
+ s.add_dependency 'jasmine-core', '~> 2.0.0.rc3'
42
36
  s.add_dependency 'rack'
43
- s.add_dependency 'rspec', '>= 1.3.1'
44
- s.add_dependency 'selenium-webdriver', '>= 0.1.3'
45
- s.add_dependency 'nokogiri'
37
+ s.add_dependency 'rake'
38
+ s.add_dependency 'phantomjs'
46
39
  end
@@ -55,4 +55,4 @@ describe("Player", function() {
55
55
  }).toThrowError("song is already playing");
56
56
  });
57
57
  });
58
- });
58
+ });
@@ -38,7 +38,7 @@ stylesheets:
38
38
  # - helpers/**/*.js
39
39
  #
40
40
  helpers:
41
- - helpers/**/*.js
41
+ - 'helpers/**/*.js'
42
42
 
43
43
  # spec_files
44
44
  #
@@ -73,4 +73,17 @@ src_dir:
73
73
  #
74
74
  # spec_dir: spec/javascripts
75
75
  #
76
- spec_dir: spec/javascripts
76
+ spec_dir:
77
+
78
+ # spec_helper
79
+ #
80
+ # Ruby file that Jasmine server will require before starting.
81
+ # Returned relative to your root path
82
+ # Default spec/javascripts/support/jasmine_helper.rb
83
+ #
84
+ # EXAMPLE:
85
+ #
86
+ # spec_helper: spec/javascripts/support/jasmine_helper.rb
87
+ #
88
+ spec_helper: spec/javascripts/support/jasmine_helper.rb
89
+
@@ -4,8 +4,8 @@
4
4
  #
5
5
  #Example: using a different boot file.
6
6
  #Jasmine.configure do |config|
7
- # @config.boot_dir = '/absolute/path/to/boot_dir'
8
- # @config.boot_files = lambda { ['/absolute/path/to/boot_dir/file.js'] }
7
+ # config.boot_dir = '/absolute/path/to/boot_dir'
8
+ # config.boot_files = lambda { ['/absolute/path/to/boot_dir/file.js'] }
9
9
  #end
10
10
  #
11
11
 
data/lib/jasmine.rb CHANGED
@@ -5,22 +5,20 @@ jasmine_files = ['base',
5
5
  'config',
6
6
  'application',
7
7
  'server',
8
- 'selenium_driver',
9
8
  'command_line_tool',
10
9
  'page',
11
10
  'path_mapper',
12
11
  'asset_bundle',
13
12
  'asset_pipeline_mapper',
14
13
  'asset_expander',
15
- 'results_processor',
16
- 'results',
14
+ 'result',
17
15
  'path_expander',
18
16
  'yaml_config_parser',
19
- File.join('formatters', 'base'),
17
+ File.join('formatters', 'exit_code'),
20
18
  File.join('formatters', 'console'),
21
- File.join('formatters', 'junit_xml'),
22
- File.join('runners', 'http'),
23
- File.join('reporters', 'api_reporter')]
19
+ File.join('formatters', 'multi'),
20
+ File.join('runners', 'phantom_js'),
21
+ ]
24
22
 
25
23
 
26
24
  jasmine_files.each do |file|
@@ -24,7 +24,7 @@ module Jasmine
24
24
 
25
25
  def assets
26
26
  context = get_asset_context
27
- context.asset_paths.asset_for(pathname, 'js').to_a.map do |path|
27
+ context.asset_paths.asset_for(pathname, nil).to_a.map do |path|
28
28
  context.asset_path(path)
29
29
  end
30
30
  end
@@ -37,26 +37,25 @@ module Jasmine
37
37
  end
38
38
  end
39
39
 
40
- class Rails4AssetBundle
41
-
42
- def initialize(pathname)
43
- @pathname = pathname
44
- end
40
+ class Rails4AssetBundle < RailsAssetBundle
45
41
 
46
42
  def assets
47
43
  context.get_original_assets(pathname)
48
44
  end
49
45
 
50
46
  private
51
- attr_reader :pathname
52
-
53
47
  def context
54
48
  return @context if @context
55
49
  @context = ActionView::Base.new
56
50
  @context.instance_eval do
57
51
  def get_original_assets(pathname)
58
- lookup_asset_for_path(pathname, :type => :javascript).to_a.map do |processed_asset|
59
- path_to_javascript(processed_asset.logical_path)
52
+ assets_environment.find_asset(pathname).to_a.map do |processed_asset|
53
+ case processed_asset.content_type
54
+ when "text/css"
55
+ path_to_stylesheet(processed_asset.logical_path)
56
+ when "application/javascript"
57
+ path_to_javascript(processed_asset.logical_path)
58
+ end
60
59
  end
61
60
  end
62
61
  end
@@ -0,0 +1,13 @@
1
+ Jasmine has been installed.
2
+
3
+ To run the server:
4
+
5
+ rake jasmine
6
+
7
+ To run the automated CI task with PhantomJS:
8
+
9
+ rake jasmine:ci
10
+
11
+ To install some example javascripts and specs:
12
+
13
+ jasmine examples
@@ -1,82 +1,124 @@
1
+ require 'fileutils'
2
+
1
3
  module Jasmine
2
4
  class CommandLineTool
3
- def cwd
4
- File.expand_path(File.join(File.dirname(__FILE__), '../..'))
5
- end
5
+ def process(argv)
6
+ @argv = argv
6
7
 
7
- def expand(*paths)
8
- File.expand_path(File.join(*paths))
8
+ if respond_to?(@argv[0])
9
+ public_send(@argv[0])
10
+ else
11
+ print_help
12
+ end
9
13
  end
10
14
 
11
- def template_path(filepath)
12
- expand(cwd, File.join("generators", "jasmine" ,"templates", filepath))
15
+ def init
16
+ ensure_not_rails!
17
+
18
+ copy_file_structure('install')
19
+
20
+ update_rakefile
21
+
22
+ install_path = File.join(jasmine_gem_path, "lib", "jasmine", "command_line_install.txt")
23
+ puts File.read(install_path)
13
24
  end
14
25
 
15
- def dest_path(filepath)
16
- expand(Dir.pwd, filepath)
26
+ def examples
27
+ copy_file_structure('examples')
28
+
29
+ puts "Jasmine has installed some examples."
17
30
  end
18
31
 
19
- def copy_unless_exists(relative_path, dest_path = nil)
20
- unless File.exist?(dest_path(relative_path))
21
- FileUtils.copy(template_path(relative_path), dest_path(dest_path || relative_path))
32
+ def copy_boot_js
33
+ destination_path = File.join('spec', 'javascripts', 'support', 'boot.js')
34
+ if File.exists?(destination_path)
35
+ puts "#{destination_path} already exists"
36
+ else
37
+ require 'jasmine-core'
38
+ source = File.join(Jasmine::Core.path, 'boot.js')
39
+ FileUtils.mkdir_p(File.dirname(destination_path))
40
+ FileUtils.cp(source, destination_path)
41
+
42
+ puts 'Jasmine has copied an example boot.js to spec/javascripts/support'
43
+ puts 'To use it set the boot_dir and boot_files keys in jasmine.yml'
44
+ puts ' to point to your custom boot.js'
22
45
  end
23
46
  end
24
47
 
25
- def process(argv)
26
- if argv[0] == 'init'
27
- require 'fileutils'
48
+ def license
49
+ puts File.read(File.join(jasmine_gem_path, "MIT.LICENSE"))
50
+ end
28
51
 
29
- force = false
52
+ def print_help
53
+ puts "unknown command #{@argv.join(' ')}"
54
+ puts "Usage: jasmine init"
55
+ puts " examples"
56
+ puts " copy_boot_js"
57
+ puts " license"
58
+ end
30
59
 
31
- if argv.size > 1 && argv[1] == "--force"
32
- force = true
33
- end
60
+ private
34
61
 
35
- if File.exist?("Gemfile") && open("Gemfile", 'r').read.include?('rails') && !force
36
- puts <<-EOF
62
+ def jasmine_gem_path
63
+ File.expand_path('../../..', __FILE__)
64
+ end
37
65
 
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
66
+ def copy_file_structure(generator)
67
+ source_dir = File.join(jasmine_gem_path, 'lib', 'generators', 'jasmine', generator, 'templates')
68
+ dest_dir = Dir.pwd
40
69
 
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
70
+ globber = File.join(source_dir, '**', '{*,.*}')
71
+ source_files = Dir.glob(globber).reject { |path| File.directory?(path) }
72
+ source_files.each do |source_path|
73
+ relative_path = source_path.sub(source_dir, '')
74
+ dest_path = File.join(dest_dir, relative_path).sub(/app[\/\\]assets/, 'public')
75
+ unless File.exist?(dest_path)
76
+ FileUtils.mkdir_p(File.dirname(dest_path))
77
+ FileUtils.copy(source_path, dest_path)
78
+ if File.basename(dest_path) == 'jasmine.yml'
79
+ replaced = File.read(dest_path).gsub("assets/application.js", "public/javascripts/**/*.js")
80
+ File.open(dest_path, 'w') do |file|
81
+ file.write(replaced)
82
+ end
83
+ end
45
84
  end
85
+ end
86
+ end
46
87
 
47
- FileUtils.makedirs('public/javascripts')
48
- FileUtils.makedirs('spec/javascripts')
49
- FileUtils.makedirs('spec/javascripts/support')
50
- FileUtils.makedirs('spec/javascripts/helpers')
51
-
52
- copy_unless_exists('jasmine-example/src/Player.js', 'public/javascripts/Player.js')
53
- copy_unless_exists('jasmine-example/src/Song.js', 'public/javascripts/Song.js')
54
- copy_unless_exists('jasmine-example/spec/PlayerSpec.js', 'spec/javascripts/PlayerSpec.js')
55
- copy_unless_exists('jasmine-example/spec/SpecHelper.js', 'spec/javascripts/helpers/SpecHelper.js')
56
-
57
- copy_unless_exists('spec/javascripts/support/jasmine.yml')
58
- copy_unless_exists('spec/javascripts/support/jasmine_helper.rb')
59
- require 'rake'
60
- write_mode = 'w'
61
- if File.exist?(dest_path('Rakefile'))
62
- load dest_path('Rakefile')
63
- write_mode = 'a'
64
- end
88
+ def force?
89
+ @argv.size > 1 && @argv[1] == "--force"
90
+ end
65
91
 
66
- unless Rake::Task.task_defined?('jasmine')
67
- File.open(dest_path('Rakefile'), write_mode) do |f|
68
- f.write("\n" + File.read(template_path('lib/tasks/jasmine.rake')))
69
- end
70
- end
71
- File.open(template_path('INSTALL'), 'r').each_line do |line|
72
- puts line
92
+ def ensure_not_rails!
93
+ if File.exist?("Gemfile") && open("Gemfile", 'r').read.include?('rails') && !force?
94
+ puts <<-EOF
95
+
96
+ You're attempting to run jasmine init in a Rails project. You probably want to use the Rails generator like so:
97
+ rails g jasmine:init
98
+
99
+ If you're not actually in a Rails application, just run this command again with --force
100
+ jasmine init --force
101
+ EOF
102
+ exit 1
103
+ end
104
+ end
105
+
106
+ def update_rakefile
107
+ require 'rake'
108
+ write_mode = 'w'
109
+ rakefile_path = File.join(Dir.pwd, 'Rakefile')
110
+ if File.exist?(rakefile_path)
111
+ load rakefile_path
112
+ write_mode = 'a'
113
+ end
114
+
115
+ unless Rake::Task.task_defined?('jasmine')
116
+ File.open(rakefile_path, write_mode) do |f|
117
+ f.write(<<-JASMINE_RAKE)
118
+ require 'jasmine'
119
+ load 'jasmine/tasks/jasmine.rake'
120
+ JASMINE_RAKE
73
121
  end
74
- elsif argv[0] == "license"
75
- puts File.new(expand(cwd, "MIT.LICENSE")).read
76
- else
77
- puts "unknown command #{argv}"
78
- puts "Usage: jasmine init"
79
- puts " license"
80
122
  end
81
123
  end
82
124
  end