jasmine-rails 0.4.5 → 0.4.6

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -37,7 +37,7 @@ mount JasmineRails::Engine => "/specs" if defined?(JasmineRails)
37
37
 
38
38
  ## Configuration
39
39
 
40
- In order to run any specs, you'll need a Jasmine configuration in `spec/javascripts/support/jasmine.yml`. [Here's an example](https://github.com/searls/jasmine-rails/tree/master/spec/dummy/spec/javascripts/support) from this repo's [dummy project](https://github.com/searls/jasmine-rails/tree/master/spec/dummy).
40
+ In order to run any specs, you'll need a Jasmine configuration in `spec/javascripts/support/jasmine.yml`. [Here's an example](https://github.com/searls/jasmine-rails/tree/master/spec/javascripts/support) from this repo's [dummy project](https://github.com/searls/jasmine-rails/tree/master/spec/dummy).
41
41
 
42
42
  ``` yaml
43
43
  # path to parent directory of src_files
@@ -87,11 +87,16 @@ spec_files:
87
87
  - "**/*[Ss]pec.{js,coffee}"
88
88
  ```
89
89
 
90
+ You can write a spec to test Foo in `spec/javascripts/foo_spec.js`:
91
+
90
92
  ```javascript
91
- //= require helpers/spec_helper (includes spec/javascripts/helpers/spec_helper.js)
92
- //= require foo (includes app/assets/javascripts/foo.js)
93
+ // include spec/javascripts/helpers/spec_helper.js and app/assets/javascripts/foo.js
94
+ //= require helpers/spec_helper
95
+ //= require foo
93
96
  describe('Foo', function() {
94
- it('does something');
97
+ it("does something", function() {
98
+ expect(1 + 1).toBe(2);
99
+ });
95
100
  });
96
101
  ```
97
102
 
@@ -99,7 +104,7 @@ describe('Foo', function() {
99
104
 
100
105
  If you were to run:
101
106
 
102
- bundle exec rake spec:javascript
107
+ RAILS_ENV=test bundle exec rake spec:javascript
103
108
 
104
109
  You'd hopefully see something like:
105
110
 
@@ -109,7 +114,7 @@ You'd hopefully see something like:
109
114
 
110
115
  You can filter execution by passing the `SPEC` option as well:
111
116
 
112
- bundle exec rake spec:javascript SPEC=my_test
117
+ RAILS_ENV=test bundle exec rake spec:javascript SPEC=my_test
113
118
 
114
119
  If you experience an error at this point, the most likely cause is JavaScript being loaded out of order, or otherwise conflicting with other existing JavaScript in your project. See "Debugging" below.
115
120
 
@@ -1,5 +1,5 @@
1
1
  module JasmineRails
2
- class SpecRunnerController < ApplicationController
2
+ class SpecRunnerController < JasmineRails::ApplicationController
3
3
  def index
4
4
  JasmineRails.reload_jasmine_config
5
5
  end
@@ -20,6 +20,7 @@ module JasmineRails
20
20
  def jasmine_js_files
21
21
  files = Jasmine::Core.js_files
22
22
  if params[:console]
23
+ files << 'jasmine-console-shims.js'
23
24
  files << 'jasmine-console-reporter.js'
24
25
  end
25
26
  files << 'jasmine-boot.js'
@@ -91,7 +91,7 @@
91
91
  };
92
92
 
93
93
  proto.reportSuiteResults = function(suite) {
94
- if (!suite.parentSuite) { return; }
94
+ if (suite.parentSuite) { return; }
95
95
  var results = suite.results();
96
96
  if (results.totalCount === 0) {
97
97
  return;
@@ -0,0 +1,31 @@
1
+ (function() {
2
+ /**
3
+ * Function.bind Polyfill for ECMAScript 5 Support
4
+ * Kangax's bind with Broofa's arg optimization.
5
+ * http://www.broofa.com/Tools/JSLitmus/tests/PrototypeBind.html
6
+ *
7
+ * Copied from https://gist.github.com/rxgx/1597825
8
+ */
9
+ if (typeof Function.prototype.bind !== "function") {
10
+ Function.prototype.bind = function() {
11
+ var slice = Array.prototype.slice;
12
+ return function(context) {
13
+ var fn = this,
14
+ args = slice.call(arguments, 1);
15
+ if (args.length) {
16
+ return function() {
17
+ return arguments.length
18
+ ? fn.apply(context, args.concat(slice.call(arguments)))
19
+ : fn.apply(context, args);
20
+ };
21
+ }
22
+ return function() {
23
+ return arguments.length
24
+ ? fn.apply(context, arguments)
25
+ : fn.call(context);
26
+ };
27
+ };
28
+ };
29
+ }
30
+ })();
31
+
@@ -36,7 +36,7 @@
36
36
  var fs = require("fs");
37
37
  fs.write(data.filename, data.text, 'w');
38
38
  } else {
39
- console.log('unkown event callback: ' + data);
39
+ console.log('unknown event callback: ' + data);
40
40
  }
41
41
  };
42
42
 
data/lib/jasmine-rails.rb CHANGED
@@ -58,7 +58,8 @@ module JasmineRails
58
58
 
59
59
  def jasmine_config
60
60
  @config ||= begin
61
- path = Rails.root.join('spec', 'javascripts', 'support', 'jasmine.yml')
61
+ path = Rails.root.join('config', 'jasmine.yml')
62
+ path = Rails.root.join('spec', 'javascripts', 'support', 'jasmine.yml') unless File.exists?(path)
62
63
  initialize_jasmine_config_if_absent(path)
63
64
  YAML.load_file(path)
64
65
  end
@@ -0,0 +1,56 @@
1
+ require 'jasmine_rails/offline_asset_paths'
2
+
3
+ module JasmineRails
4
+ module Runner
5
+ class << self
6
+ # Run the Jasmine testsuite via phantomjs CLI
7
+ # raises an exception if any errors are encountered while running the testsuite
8
+ def run(spec_filter = nil)
9
+ override_rails_config do
10
+ include_offline_asset_paths_helper
11
+ html = get_spec_runner(spec_filter)
12
+ runner_path = Rails.root.join('spec/tmp/runner.html')
13
+ File.open(runner_path, 'w') {|f| f << html.gsub('/assets', './assets')}
14
+
15
+ phantomjs_runner_path = File.join(File.dirname(__FILE__), '..', 'assets', 'javascripts', 'jasmine-runner.js')
16
+ run_cmd %{phantomjs "#{phantomjs_runner_path}" "file://#{runner_path.to_s}?spec=#{spec_filter}"}
17
+ end
18
+ end
19
+
20
+ private
21
+ def include_offline_asset_paths_helper
22
+ if Rails::VERSION::MAJOR >= 4
23
+ Sprockets::Rails::Helper.send :include, JasmineRails::OfflineAssetPaths
24
+ else
25
+ ActionView::AssetPaths.send :include, JasmineRails::OfflineAssetPaths
26
+ end
27
+ end
28
+
29
+ def override_rails_config
30
+ config = Rails.application.config
31
+
32
+ original_asssets_debug = config.assets.debug
33
+ config.assets.debug = false
34
+ yield
35
+ config.assets.debug = original_asssets_debug
36
+ end
37
+
38
+ def get_spec_runner(spec_filter)
39
+ app = ActionDispatch::Integration::Session.new(Rails.application)
40
+ path = JasmineRails.route_path
41
+ JasmineRails::OfflineAssetPaths.disabled = false
42
+ app.get path, :console => 'true', :spec => spec_filter
43
+ JasmineRails::OfflineAssetPaths.disabled = true
44
+ raise "Jasmine runner at '#{path}' returned a #{app.response.status} error: #{app.response.message}" unless app.response.success?
45
+ app.response.body
46
+ end
47
+
48
+ def run_cmd(cmd)
49
+ puts "Running `#{cmd}`"
50
+ unless system(cmd)
51
+ raise "Error executing command: #{cmd}"
52
+ end
53
+ end
54
+ end
55
+ end
56
+ end
@@ -1,3 +1,3 @@
1
1
  module JasmineRails
2
- VERSION = "0.4.5"
2
+ VERSION = "0.4.6"
3
3
  end
@@ -1,31 +1,10 @@
1
1
  namespace :spec do
2
- def run_cmd(cmd)
3
- puts "$ #{cmd}"
4
- unless system(cmd)
5
- raise "Error executing command: #{cmd}"
6
- end
7
- end
8
2
 
9
3
  desc "run test with phantomjs"
10
- task :javascript => :environment do
11
- Rails.application.config.assets.debug = false
12
- require 'jasmine_rails/offline_asset_paths'
13
- if Rails::VERSION::MAJOR == 4
14
- Sprockets::Rails::Helper.send :include, JasmineRails::OfflineAssetPaths
15
- else
16
- ActionView::AssetPaths.send :include, JasmineRails::OfflineAssetPaths
17
- end
4
+ task :javascript => [:environment] do
5
+ require 'jasmine_rails/runner'
18
6
  spec_filter = ENV['SPEC']
19
- app = ActionController::Integration::Session.new(Rails.application)
20
- path = JasmineRails.route_path
21
- app.get path, :console => 'true', :spec => spec_filter
22
- JasmineRails::OfflineAssetPaths.disabled = true
23
- raise "Jasmine runner at '#{path}' returned a #{app.response.status} error: #{app.response.message}" unless app.response.success?
24
- html = app.response.body
25
- runner_path = Rails.root.join('spec/tmp/runner.html')
26
- File.open(runner_path, 'w') {|f| f << html.gsub('/assets', './assets')}
27
-
28
- run_cmd %{phantomjs "#{File.join(File.dirname(__FILE__), 'runner.js')}" "file://#{runner_path.to_s}?spec=#{spec_filter}"}
7
+ JasmineRails::Runner.run spec_filter
29
8
  end
30
9
 
31
10
  # alias
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jasmine-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.5
4
+ version: 0.4.6
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -11,7 +11,7 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2013-05-28 00:00:00.000000000 Z
14
+ date: 2013-09-09 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: rails
@@ -95,13 +95,15 @@ files:
95
95
  - config/routes.rb
96
96
  - lib/assets/javascripts/jasmine-boot.js
97
97
  - lib/assets/javascripts/jasmine-console-reporter.js
98
+ - lib/assets/javascripts/jasmine-console-shims.js
99
+ - lib/assets/javascripts/jasmine-runner.js
98
100
  - lib/assets/javascripts/jasmine-specs.js.erb
99
101
  - lib/jasmine-rails.rb
100
102
  - lib/jasmine_rails/engine.rb
101
103
  - lib/jasmine_rails/offline_asset_paths.rb
104
+ - lib/jasmine_rails/runner.rb
102
105
  - lib/jasmine_rails/version.rb
103
106
  - lib/tasks/jasmine-rails_tasks.rake
104
- - lib/tasks/runner.js
105
107
  - MIT-LICENSE
106
108
  - Rakefile
107
109
  - README.md
@@ -119,7 +121,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
119
121
  version: '0'
120
122
  segments:
121
123
  - 0
122
- hash: -657665096791402886
124
+ hash: 384198483
123
125
  required_rubygems_version: !ruby/object:Gem::Requirement
124
126
  none: false
125
127
  requirements:
@@ -128,7 +130,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
128
130
  version: '0'
129
131
  segments:
130
132
  - 0
131
- hash: -657665096791402886
133
+ hash: 384198483
132
134
  requirements: []
133
135
  rubyforge_project:
134
136
  rubygems_version: 1.8.23