opal-rails 0.7.0 → 0.8.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 96adc4465b9418b685005f5de7dbdcd90e399070
4
- data.tar.gz: f439b5a2e40f788d9e7847330cfc6a28a6de7ba6
3
+ metadata.gz: 073a982ba5fda2d923d8e79db68596f63ab125e6
4
+ data.tar.gz: 72b8f6b7e70f2b942919b03ae7bbde7bb9f147c8
5
5
  SHA512:
6
- metadata.gz: ae94e6c55571998bf7eba402edd0b4766f3595bff84041e62107a3ac6eb83fe52f6a733d17307006abe55e963202ad7bcaaf378aa959121cb8a924fa1770fbb8
7
- data.tar.gz: 45bec77e78344a544b6508d1b9a1e0c84e5c58fadb839c80893a9a1b0adca9ebe7e1b7e0d2ddd29e75cd987907f9ea827f547131f041cc5caa11de462b05a068
6
+ metadata.gz: 305c56f69497766454b69586b9a1fbb9b555d78924a9b2a8b5bbf9b46306070ed67e01cf2f2ea1b4d97660783b215a77802e29457a0208f0169eb91d07e2e727
7
+ data.tar.gz: 29a02ff388e6b40a6e1d3e6f474da7c5d2d1cb6760dd5414bdb91bdce4dac5ef0443af63739bd5cf03148c73c009a28b3b7b500a4232c5cf0e3ffbfe810ef236
data/.spectator.rb ADDED
@@ -0,0 +1 @@
1
+ ENV['RSPEC_COMMAND'] = 'rspec'
data/.travis.yml CHANGED
@@ -1,10 +1,15 @@
1
1
  language: ruby
2
- cache: bundler
2
+
3
+ sudo: false
4
+
5
+ cache:
6
+ bundler: true
3
7
 
4
8
  rvm:
5
- - 1.9.3
9
+ - 2.2
10
+ - 2.1
6
11
  - 2.0.0
7
- - 2.1.1
12
+ - 1.9.3
8
13
 
9
14
  before_script:
10
15
  - "export DISPLAY=:99.0"
data/CHANGELOG.md CHANGED
@@ -1,5 +1,8 @@
1
1
  # edge
2
2
 
3
+ * All specs now need to require "opal" and "opal-rspec" explicitly
4
+
5
+
3
6
  # 0.6.1 2013-11-05
4
7
 
5
8
  * Fix the rake task, now uses `opal-rspec` too
data/Gemfile CHANGED
@@ -2,10 +2,14 @@ source 'https://rubygems.org'
2
2
  gemspec
3
3
 
4
4
  gem 'capybara-webkit'
5
- gem 'opal-jquery', github: 'opal/opal-jquery'
6
- # gem 'opal', github: 'opal'
7
- # gem 'opal-jquery', path: '../opal-jquery'
5
+
8
6
  # gem 'opal', path: '../opal'
7
+ # gem 'opal-rspec', path: '../opal-rspec'
8
+ # gem 'opal-jquery', path: '../opal-jquery'
9
+
10
+ gem 'opal', github: 'opal'
11
+ gem 'opal-rspec', github: 'opal/opal-rspec'
12
+ gem 'opal-jquery', github: 'opal/opal-jquery'
9
13
 
10
14
  if RUBY_VERSION.to_f < 1.9
11
15
  gem 'nokogiri', '< 1.6'
data/README.md CHANGED
@@ -1,7 +1,7 @@
1
1
  # Opal Rails
2
2
 
3
- [![Build Status](https://secure.travis-ci.org/elia/opal-rails.svg)](http://travis-ci.org/elia/opal-rails)
4
- [![Code Climate](https://img.shields.io/codeclimate/github/elia/opal-rails.svg)](https://codeclimate.com/github/elia/opal-rails)
3
+ [![Build Status](https://secure.travis-ci.org/opal/opal-rails.svg)](http://travis-ci.org/opal/opal-rails)
4
+ [![Code Climate](https://img.shields.io/codeclimate/github/opal/opal-rails.svg)](https://codeclimate.com/github/opal/opal-rails)
5
5
  [![Gem Version](https://badge.fury.io/rb/opal-rails.svg)](http://badge.fury.io/rb/opal-rails)
6
6
  ![fun guaranteed](https://img.shields.io/badge/fun-guaranteed-brightgreen.svg)
7
7
  ![web scale](http://img.shields.io/badge/webscale-over%209000-green.svg)
@@ -37,6 +37,12 @@ module MyApp
37
37
  config.opal.optimized_operators = true
38
38
  config.opal.arity_check = false
39
39
  config.opal.const_missing = true
40
+ config.opal.dynamic_require_severity = :ignore
41
+
42
+ # Enable/disable /opal_specs route
43
+ config.opal.enable_specs = true
44
+
45
+ config.opal.spec_location = 'spec-opal'
40
46
  end
41
47
  end
42
48
  ```
@@ -55,15 +61,33 @@ Now ships with a patch to sprockets cache key to include processor version that
55
61
 
56
62
  ### Asset Pipeline
57
63
 
58
- ```js
59
- // app/assets/application.js.rb
64
+ You can rename `app/assets/javascripts/application.js` to `application.js.rb`. Even if not necessary, it is recommended to change Sprockets' `//= require` statements to Ruby' `require` methods.
65
+ Sprockets' `//= require` statements won't be known by the opal builder and therefore you can end up adding something twice.
66
+
67
+ For Opal 0.7 and below, the following example should work:
68
+
69
+ ```ruby
70
+ # app/assets/javascripts/application.js.rb
71
+
72
+ #= require opal
73
+ #= require opal_ujs
74
+ #= require turbolinks
75
+ #= require_tree .
76
+ ```
77
+
78
+ For Opal 0.8 and above, you should be able to use the following syntax:
79
+
80
+ ```ruby
81
+ # app/assets/javascripts/application.js.rb
60
82
 
61
- //= require opal
62
- //= require opal_ujs
63
- //= require turbolinks
64
- //= require_tree .
83
+ require 'opal'
84
+ require 'opal_ujs'
85
+ require 'turbolinks'
86
+ require_tree '.'
65
87
  ```
66
88
 
89
+ As you see in the example above, Opal also gives you a Ruby equivalent of `//= require_tree`.
90
+
67
91
  Opal requires are forwarded to the Asset Pipeline at compile time (similarly to what happens for RubyMotion). You can use either the `.rb` or `.opal` extension:
68
92
 
69
93
  ```ruby
@@ -138,12 +162,12 @@ Of course you need to require `haml-rails` separately since its presence is not
138
162
 
139
163
  ### Spec!
140
164
 
141
- Add specs into `app/assets/javascripts/spec`:
165
+ Add specs into `/spec-opal`:
142
166
 
143
167
  and then a spec folder with you specs!
144
168
 
145
169
  ```ruby
146
- # app/assets/javascripts/spec/example_spec.js.rb
170
+ # spec-opal/example_spec.js.rb
147
171
 
148
172
  describe 'a spec' do
149
173
  it 'has successful examples' do
@@ -154,6 +178,23 @@ end
154
178
 
155
179
  Then visit `/opal_spec` from your app and **reload at will** or use the command line with `rake opal:spec`.
156
180
 
181
+ #### CHANGE from versions pre 0.7.1
182
+
183
+ Specs used to run out of app/assets/javascripts/spec which was problematic because require_tree . would cause opal/sprockets to compile the specs for non spec running. This could result in bad specs that prevent your application Opal code from compiling, and even if it compiles you'll get exceptions about the test framework methods not being defined. To address this, specs have been moved out of the app/assets/javascripts to Rails.root/spec-opal. The name spec-opal was chosen to put it close to the spec directory. We don't want to put specs in spec directory because we don't want the "backend" rspec to run those.
184
+
185
+ The location of specs is configurable. To restore the old location of app/assets/javascripts/spec add an initializer file like the below.
186
+
187
+ ```ruby
188
+ # config/initializers/opal.rb
189
+ Rails.application.config.opal.spec_location = "app/assets/javascripts/spec"
190
+
191
+ ```
192
+
193
+ Similarly, you can put the opal specs in another location via a similar initializer call.
194
+
195
+
196
+
197
+
157
198
  ![1 examples, 0 failures](http://f.cl.ly/items/001n0V0g0u0v14160W2G/Schermata%2007-2456110%20alle%201.06.29%20am.png)
158
199
 
159
200
 
data/Rakefile CHANGED
@@ -10,5 +10,10 @@ Bundler::GemHelper.install_tasks
10
10
  # TEST
11
11
 
12
12
  require 'rspec/core/rake_task'
13
- RSpec::Core::RakeTask.new :default
13
+ RSpec::Core::RakeTask.new :rspec
14
14
 
15
+
16
+ require File.expand_path('../test_app/config/application', __FILE__)
17
+ TestApp::Application.load_tasks
18
+
19
+ task :default => [:rspec, 'opal:spec']
@@ -1,5 +1,10 @@
1
+ require 'opal/rails/spec_builder'
2
+ require 'fileutils'
3
+ require 'pathname'
4
+
1
5
  class OpalSpecController < ActionController::Base
2
- helper_method :spec_files
6
+ helper_method :spec_files, :pattern, :clean_spec_path, :runner_name
7
+ helper_method :check_errors_for, :builder
3
8
 
4
9
  def run
5
10
  end
@@ -7,26 +12,27 @@ class OpalSpecController < ActionController::Base
7
12
 
8
13
  private
9
14
 
10
- def spec_files
11
- @spec_files ||= some_spec_files || all_spec_files
15
+ # This will deactivate the requirement to precompile assets in this controller
16
+ # as specs shouldn't go to production anyway.
17
+ def check_errors_for(*)
18
+ #noop
12
19
  end
13
20
 
14
- def specs_param
21
+ def pattern
15
22
  params[:pattern]
16
23
  end
17
24
 
18
- def some_spec_files
19
- return if specs_param.blank?
20
- specs_param.split(':').map { |path| spec_files_for_glob(path) }.flatten
25
+ def builder
26
+ @builder ||= Opal::Rails::SpecBuilder.new(
27
+ spec_location: Rails.application.config.opal.spec_location,
28
+ sprockets: Rails.application.config.assets,
29
+ pattern: pattern,
30
+ )
21
31
  end
22
32
 
23
- def all_spec_files
24
- spec_files_for_glob '**/*_spec{.js,}'
33
+ def runner_name
34
+ builder.runner_pathname.basename.to_s.gsub(/(\.js)?\.rb$/, '')
25
35
  end
26
36
 
27
- def spec_files_for_glob glob = '**'
28
- Dir[Rails.root.join("{app,lib}/assets/javascripts/spec/#{glob}.{rb,opal}")].map do |path|
29
- path.split('assets/javascripts/spec/').flatten.last.gsub(/(\.rb|\.opal)/, '')
30
- end.uniq
31
- end
37
+ delegate :spec_files, :clean_spec_path, to: :builder
32
38
  end
@@ -1,7 +1,25 @@
1
1
  module OpalHelper
2
- def opal_tag(&block)
3
- opal_code = capture(&block)
4
- js_code = Opal.compile(opal_code)
2
+ def opal_tag(opal_code = nil, &block)
3
+ opal_code ||= capture(&block)
4
+ compiler_options = Opal::Processor.compiler_options.merge(requirable: false)
5
+ compiler = Opal::Compiler.new(opal_code, compiler_options)
6
+ js_code = compiler.compile
5
7
  javascript_tag js_code
6
8
  end
9
+
10
+ def javascript_include_tag(*sources)
11
+ options = sources.extract_options!
12
+ sprockets = Rails.application.assets
13
+ skip_loader = options.delete(:skip_opal_loader)
14
+ script_tags = super(*sources, options)
15
+
16
+ return script_tags if skip_loader
17
+
18
+ sources.each do |source|
19
+ loading_code = Opal::Processor.load_asset_code(sprockets, source)
20
+ script_tags << javascript_tag(loading_code) if loading_code.present?
21
+ end
22
+
23
+ script_tags
24
+ end
7
25
  end
@@ -3,8 +3,6 @@
3
3
  <head>
4
4
  <meta charset="utf-8">
5
5
  <title>Opal Spec Runner</title>
6
- <%= javascript_include_tag 'opal-rspec-runner' %>
7
- <%= javascript_include_tag *spec_files.map { |f| "spec/#{f}"} %>
8
6
  <style>
9
7
  body { font-family: sans-serif; }
10
8
  </style>
@@ -1,9 +1,40 @@
1
- <h2>Running:</h2>
1
+ <% if pattern.present? %>
2
+ <%= link_to 'All specs', opal_spec_path %>
3
+ <% end %>
2
4
 
5
+ <h2>Running:</h2>
3
6
  <ul>
4
7
  <% spec_files.each do |spec_file| %>
5
8
  <li>
6
- <%= link_to spec_file, "/opal_spec?pattern=#{URI.escape(spec_file)}" %>
9
+ <% spec_file = clean_spec_path(spec_file) %>
10
+ <%= link_to spec_file, opal_spec_path(pattern: spec_file) %>
7
11
  </li>
8
12
  <% end %>
9
13
  </ul>
14
+
15
+ <%# The list of all asset dependency %>
16
+ <% all_specs = [] %>
17
+
18
+ <%# Track root assets that will need to be bootstrapped %>
19
+ <% root_assets = {} %>
20
+
21
+ <%# Collect all assets with their dependencies %>
22
+ <% builder.clean_spec_files.each do |require_path| %>
23
+ <% asset = lookup_asset_for_path(require_path, type: :javascript) %>
24
+ <% dependency_paths = asset.to_a.map { |a| a.logical_path } %>
25
+ <% all_specs += dependency_paths %>
26
+ <% root_assets[dependency_paths.last] = require_path %>
27
+ <% end %>
28
+
29
+ <%# We'll ececute the boot code all at once in the end %>
30
+ <% load_code = [] %>
31
+
32
+ <%# Add include tags and boot code, we use #uniq as we don't want to source the same asset twice %>
33
+ <% all_specs.uniq.each do |asset_path| %>
34
+ <%- root_asset = root_assets[asset_path] -%>
35
+ <%= javascript_include_tag asset_path, skip_opal_loader: true %>
36
+ <%- load_code << javascript_tag(Opal::Processor.load_asset_code(Rails.application.assets, root_asset)) if root_asset -%>
37
+ <% end %>
38
+
39
+ <%# Boot! %>
40
+ <%= load_code.join.html_safe %>
@@ -0,0 +1,4 @@
1
+ require 'jquery'
2
+ require 'jquery_ujs'
3
+ require 'opal'
4
+ require 'opal-jquery'
@@ -1,6 +1,7 @@
1
1
  require 'rails'
2
2
  require 'opal/sprockets/server'
3
3
  require 'opal/sprockets/processor'
4
+ require 'opal/rails/spec_builder'
4
5
 
5
6
  module Opal
6
7
  module Rails
@@ -9,6 +10,12 @@ module Opal
9
10
 
10
11
  config.opal = ActiveSupport::OrderedOptions.new
11
12
 
13
+ config.opal.enable_specs = ::Rails.env.development? || ::Rails.env.test?
14
+
15
+ # new default location, override-able in a Rails initializer
16
+ config.opal.spec_location = 'spec-opal'
17
+
18
+ config.opal.dynamic_require_severity = :ignore
12
19
 
13
20
  # Cache eager_load_paths now, otherwise the assets dir is added
14
21
  # and its .rb files are eagerly loaded.
@@ -19,6 +26,15 @@ module Opal
19
26
  end
20
27
 
21
28
  initializer 'opal.asset_paths', :after => 'sprockets.environment', :group => :all do |app|
29
+ if app.config.opal.enable_specs
30
+ spec_location = app.root.join(app.config.opal.spec_location).to_s
31
+ runner_dir = ::Opal::Rails::SpecBuilder.runner_dir(app.root)
32
+ runner_dir.mkpath
33
+
34
+ app.assets.append_path runner_dir.to_s
35
+ app.assets.append_path spec_location
36
+ end
37
+
22
38
  Opal.paths.each do |path|
23
39
  app.assets.append_path path
24
40
  end
@@ -35,13 +51,18 @@ module Opal
35
51
  end
36
52
 
37
53
  app.routes.prepend do
38
- if Opal::Processor.source_map_enabled
39
- prefix = app.config.assets.prefix
40
- maps_app = Opal::SourceMapServer.new(app.assets, prefix)
41
- mount Rack::Cascade.new([maps_app, app.assets]) => prefix
54
+ if Opal::Processor.source_map_enabled && config.assets.compile && config.assets.debug
55
+ maps_prefix = '/__OPAL_SOURCE_MAPS__'
56
+ maps_app = Opal::SourceMapServer.new(app.assets, maps_prefix)
57
+
58
+ ::Opal::Sprockets::SourceMapHeaderPatch.inject!(maps_prefix)
59
+
60
+ mount maps_app => maps_prefix
42
61
  end
43
62
 
44
- get '/opal_spec' => 'opal_spec#run'
63
+ if app.config.opal.enable_specs
64
+ get '/opal_spec' => 'opal_spec#run', as: :opal_spec
65
+ end
45
66
  end
46
67
  end
47
68
 
@@ -0,0 +1,92 @@
1
+ require 'digest'
2
+
3
+ module Opal
4
+ module Rails
5
+ class SpecBuilder
6
+ def initialize(options)
7
+ @root = options.fetch(:root) { ::Rails.root }
8
+ @pattern = options[:pattern] || '**/*_spec'
9
+ @sprockets = options.fetch(:sprockets)
10
+ @spec_location = options.fetch(:spec_location)
11
+ end
12
+
13
+ attr_reader :sprockets, :pattern, :spec_location, :root
14
+
15
+ def to_s
16
+ builder.build_str main_code, 'opal_spec'
17
+ builder.to_s + 'Opal.load("opal_spec");'
18
+ end
19
+
20
+ def builder
21
+ @builder ||= begin
22
+ path_finder = Opal::HikePathFinder.new(paths)
23
+
24
+ Opal::Builder.new(
25
+ compiler_options: Opal::Processor.compiler_options,
26
+ stubs: Opal::Processor.stubbed_files,
27
+ path_reader: Opal::PathReader.new(path_finder),
28
+ )
29
+ end
30
+ end
31
+
32
+ def paths
33
+ [
34
+ root.join(spec_location).to_s,
35
+ runner_dir.to_s,
36
+ *Opal.paths,
37
+ *sprockets.paths,
38
+ ]
39
+ end
40
+
41
+ def self.runner_dir(root)
42
+ root.join('tmp/opal_spec')
43
+ end
44
+
45
+ def runner_dir
46
+ self.class.runner_dir(root)
47
+ end
48
+
49
+ def main_code
50
+ requires.map { |file| "require #{file.inspect}\n" }.join + boot_code
51
+ end
52
+
53
+ def runner_pathname
54
+ runner_dir.join("#{runner_logical_path}.js.rb")
55
+ end
56
+
57
+ def runner_logical_path
58
+ "opal_spec_runner_#{digest}"
59
+ end
60
+
61
+ def digest
62
+ # The digest is cached as it shouldn't change
63
+ # for a given builder instance
64
+ @digest ||= Digest::SHA1.new.update(requires.join).to_s
65
+ end
66
+
67
+ def requires
68
+ ['opal', 'opal-rspec', *clean_spec_files]
69
+ end
70
+
71
+ def clean_spec_files
72
+ spec_files.map{|f| clean_spec_path(f)}
73
+ end
74
+
75
+ def boot_code
76
+ 'Opal::RSpec::Runner.autorun'
77
+ end
78
+
79
+ def spec_files
80
+ @spec_files ||= pattern.split(':').map { |path| spec_files_for_glob(path) }.flatten
81
+ end
82
+
83
+ def spec_files_for_glob(glob)
84
+ Dir[root.join("#{spec_location}/#{glob}{,.js}.{rb,opal}").to_s]
85
+ end
86
+
87
+ def clean_spec_path(path)
88
+ path.split("#{spec_location}/").flatten.last.gsub(/(\.js)?\.(rb|opal)$/, '')
89
+ end
90
+ end
91
+ end
92
+ end
@@ -1,5 +1,5 @@
1
1
  module Opal
2
2
  module Rails
3
- VERSION = '0.7.0'
3
+ VERSION = '0.8.0.rc1'
4
4
  end
5
5
  end
@@ -15,7 +15,7 @@ module Opal
15
15
  end
16
16
 
17
17
  def copy_opal
18
- template 'javascript.js.rb', File.join('app/assets/javascripts', class_path, "#{controller_name}_view.js.rb")
18
+ template 'javascript.js.rb', File.join('app/assets/javascripts', "#{controller_name.underscore}_view.js.rb")
19
19
  end
20
20
  end
21
21
  end
@@ -1,27 +1,26 @@
1
1
  require 'opal/rspec/rake_task'
2
2
 
3
3
  Opal::RSpec::RakeTask.new('opal:spec' => :environment) do |server|
4
- require 'tempfile'
4
+ require 'opal/rails/spec_builder'
5
+ pattern = ENV['PATTERN'] || nil
5
6
 
6
- asset_paths = Opal.paths + Rails.configuration.assets.paths.to_a
7
- tempfile = Tempfile.new(['opal-rspec', '.js.rb'])
7
+ builder = Opal::Rails::SpecBuilder.new(
8
+ spec_location: Rails.application.config.opal.spec_location,
9
+ sprockets: Rails.application.config.assets,
10
+ pattern: pattern,
11
+ )
8
12
 
9
- server.sprockets.clear_paths
10
- asset_paths << File.dirname(tempfile.path)
11
- server.main = File.basename(tempfile.path, '.js.rb')
13
+ runner = builder.runner_pathname
14
+ runner.dirname.mkpath
15
+ runner.open('w') { |f| f << builder.main_code }
12
16
 
13
- asset_paths.each { |path| server.append_path path }
17
+ server.sprockets.clear_paths
18
+ builder.paths.each { |path| server.append_path path }
14
19
 
15
- required_assets = ['opal']
16
- required_assets << 'opal-rspec-runner'
20
+ main_name = builder.runner_logical_path
17
21
 
18
- asset_paths.each do |path|
19
- Dir["#{path}/spec/**_spec.js.{opal,rb}"].each do |spec|
20
- spec = spec[path.size+1..-1] # +1 is for the trailing slash
21
- required_assets << spec
22
- end
23
- end
22
+ # Sometimes seems that sprockets will need a moment to pickup the new file
23
+ sleep 0.1 unless server.sprockets[main_name]
24
24
 
25
- required_assets.each { |a| tempfile.puts "require #{a.inspect}" }
26
- tempfile.close
25
+ server.main = main_name
27
26
  end
data/opal-rails.gemspec CHANGED
@@ -22,9 +22,9 @@ Gem::Specification.new do |s|
22
22
  required_ruby_version = '>= 1.9.3'
23
23
 
24
24
  s.add_dependency 'rails', '>= 3.2', '< 5.0'
25
- s.add_dependency 'opal', '~> 0.7.0'
26
- s.add_dependency 'opal-jquery', '~> 0.3.0.beta1'
27
- s.add_dependency 'opal-rspec', '~> 0.4.0'
25
+ s.add_dependency 'opal', '~> 0.8.0.rc'
26
+ s.add_dependency 'opal-jquery', '~> 0.3.0'
27
+ s.add_dependency 'opal-rspec', '~> 0.4.2'
28
28
  s.add_dependency 'jquery-rails'
29
29
  s.add_dependency 'opal-activesupport', '>= 0.0.5'
30
30
 
@@ -0,0 +1,18 @@
1
+ require 'spec_helper'
2
+
3
+ describe OpalHelper do
4
+ subject(:helper) { double.extend described_class }
5
+
6
+ describe '#opal_tag' do
7
+ it 'compiles to js' do
8
+ allow(helper).to receive(:javascript_tag) { |code| code }
9
+ ruby_code = 'puts 5'
10
+
11
+ expect(Opal::Compiler).to receive(:new)
12
+ .with(ruby_code, hash_including(requirable: false))
13
+ .and_call_original
14
+
15
+ expect(helper.opal_tag(ruby_code)).to include('.$puts(')
16
+ end
17
+ end
18
+ end
@@ -26,13 +26,14 @@ describe 'controller assignments' do
26
26
  end
27
27
 
28
28
  def opal_eval source
29
- opal_source = get_source_of '/assets/opal.js'
29
+ builder = Opal::Builder.new
30
+ builder.build 'opal'
30
31
 
31
32
  # Any lib should be already required in the page,
32
33
  # require won't work in this kind of templates.
33
- opal_source << get_source_of('/assets/native.js')
34
+ builder.build 'native'
34
35
 
35
- context = ExecJS.compile opal_source
36
+ context = ExecJS.compile builder.to_s
36
37
  context.eval source
37
38
  rescue
38
39
  $!.message << "\n\n#{source}"
@@ -3,17 +3,19 @@ require 'spec_helper'
3
3
  feature 'In-browser specs runner' do
4
4
  scenario 'runs all specs', :js do
5
5
  visit '/opal_spec'
6
-
7
- page.should have_content('subdirectory/other_spec.js')
8
- page.should have_content('example_spec.js ')
9
- page.should have_content('2 examples, 0 failures')
6
+ page.should have_content('example_spec ')
7
+ page.should have_content('requires_opal_spec ')
8
+ page.should have_content('subdirectory/other_spec ')
9
+ page.should have_content('3 examples, 0 failures')
10
10
  end
11
11
 
12
12
  scenario "runs single spec file", :js do
13
13
  visit '/opal_spec'
14
- click_link 'subdirectory/other_spec.js'
14
+ click_link 'subdirectory/other_spec'
15
15
 
16
- page.should have_content('Running: subdirectory/other_spec.js')
16
+ page.should_not have_content('example_spec ')
17
+ page.should_not have_content('requires_opal_spec ')
18
+ page.should have_content('subdirectory/other_spec ')
17
19
  page.should have_content('1 examples, 0 failures')
18
20
  end
19
21
  end
@@ -2,10 +2,12 @@ require 'spec_helper'
2
2
  require 'opal/source_map'
3
3
 
4
4
  describe Opal::SourceMap do
5
- let(:js_asset_path) { '/assets/source_map_example.js' }
5
+ let(:js_asset_path) { '/assets/source_map_example.self.js' }
6
6
 
7
7
  before do
8
8
  expect(Rails.application.config.opal.source_map_enabled).to be_truthy
9
+ expect(Rails.application.config.assets.compile).to be_truthy
10
+ expect(Rails.application.config.assets.debug).to be_truthy
9
11
  get js_asset_path
10
12
  end
11
13
 
@@ -32,10 +34,9 @@ describe Opal::SourceMap do
32
34
 
33
35
  def extract_map_path response
34
36
  source_map_regexp = %r{^//[@#] sourceMappingURL=([^\n]+)}
35
- map_path = (response.headers['X-SourceMap'] ||
36
- response.body.scan(source_map_regexp).
37
- flatten.first.to_s.strip)
38
- File.join(File.dirname(js_asset_path), map_path) if map_path
39
- end
37
+ header_map_path = response.headers['X-SourceMap'].presence
38
+ comment_map_path = response.body.scan(source_map_regexp).flatten.first.to_s.strip.presence
40
39
 
40
+ header_map_path or comment_map_path
41
+ end
41
42
  end
@@ -9,7 +9,7 @@ TestApp::Application.configure do
9
9
  config.action_controller.perform_caching = true
10
10
 
11
11
  # Disable Rails's static asset server (Apache or nginx will already do this)
12
- config.serve_static_assets = false
12
+ config.serve_static_files = false
13
13
 
14
14
  # Compress JavaScripts and CSS
15
15
  config.assets.compress = true
@@ -8,7 +8,7 @@ TestApp::Application.configure do
8
8
  config.cache_classes = true
9
9
 
10
10
  # Configure static asset server for tests with Cache-Control for performance
11
- config.serve_static_assets = true
11
+ config.serve_static_files = true
12
12
  config.static_cache_control = "public, max-age=3600"
13
13
 
14
14
  # Log error messages when you accidentally call methods on nil
@@ -34,4 +34,9 @@ TestApp::Application.configure do
34
34
  config.active_support.deprecation = :stderr
35
35
 
36
36
  config.eager_load = false if Rails.version.to_i == 4
37
+
38
+
39
+ # Allow sourcemaps to be compiled in test mode
40
+ config.assets.debug = true
41
+ config.assets.compile = true
37
42
  end
@@ -1,3 +1,5 @@
1
+ require 'spec_helper'
2
+
1
3
  describe 'a running spec' do
2
4
  it 'runs successfully' do
3
5
  'I run'.should =~ /run/
@@ -0,0 +1,8 @@
1
+ require 'opal'
2
+ require 'spec_helper'
3
+
4
+ describe 'a running spec' do
5
+ it 'runs successfully' do
6
+ 'I run'.should =~ /run/
7
+ end
8
+ end
@@ -0,0 +1,3 @@
1
+ require 'opal'
2
+ require 'opal-rspec'
3
+ Opal::RSpec::Runner.autorun
@@ -1,3 +1,5 @@
1
+ require 'spec_helper'
2
+
1
3
  describe "spec inside subdirectory" do
2
4
  it "runs fine" do
3
5
  1.should == 1
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: opal-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.0
4
+ version: 0.8.0.rc1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Elia Schito
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-02-02 00:00:00.000000000 Z
11
+ date: 2015-06-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -36,42 +36,42 @@ dependencies:
36
36
  requirements:
37
37
  - - "~>"
38
38
  - !ruby/object:Gem::Version
39
- version: 0.7.0
39
+ version: 0.8.0.rc
40
40
  type: :runtime
41
41
  prerelease: false
42
42
  version_requirements: !ruby/object:Gem::Requirement
43
43
  requirements:
44
44
  - - "~>"
45
45
  - !ruby/object:Gem::Version
46
- version: 0.7.0
46
+ version: 0.8.0.rc
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: opal-jquery
49
49
  requirement: !ruby/object:Gem::Requirement
50
50
  requirements:
51
51
  - - "~>"
52
52
  - !ruby/object:Gem::Version
53
- version: 0.3.0.beta1
53
+ version: 0.3.0
54
54
  type: :runtime
55
55
  prerelease: false
56
56
  version_requirements: !ruby/object:Gem::Requirement
57
57
  requirements:
58
58
  - - "~>"
59
59
  - !ruby/object:Gem::Version
60
- version: 0.3.0.beta1
60
+ version: 0.3.0
61
61
  - !ruby/object:Gem::Dependency
62
62
  name: opal-rspec
63
63
  requirement: !ruby/object:Gem::Requirement
64
64
  requirements:
65
65
  - - "~>"
66
66
  - !ruby/object:Gem::Version
67
- version: 0.4.0
67
+ version: 0.4.2
68
68
  type: :runtime
69
69
  prerelease: false
70
70
  version_requirements: !ruby/object:Gem::Requirement
71
71
  requirements:
72
72
  - - "~>"
73
73
  - !ruby/object:Gem::Version
74
- version: 0.4.0
74
+ version: 0.4.2
75
75
  - !ruby/object:Gem::Dependency
76
76
  name: jquery-rails
77
77
  requirement: !ruby/object:Gem::Requirement
@@ -165,6 +165,7 @@ extra_rdoc_files: []
165
165
  files:
166
166
  - ".gitignore"
167
167
  - ".rspec"
168
+ - ".spectator.rb"
168
169
  - ".travis.yml"
169
170
  - CHANGELOG.md
170
171
  - Gemfile
@@ -174,13 +175,13 @@ files:
174
175
  - app/helpers/opal_helper.rb
175
176
  - app/views/layouts/opal_spec.html.erb
176
177
  - app/views/opal_spec/run.html.erb
177
- - lib/assets/javascripts/opal-rspec-runner.js.rb
178
- - lib/assets/javascripts/opal_ujs.js
178
+ - lib/assets/javascripts/opal_ujs.js.rb
179
179
  - lib/opal-rails.rb
180
180
  - lib/opal/rails.rb
181
181
  - lib/opal/rails/engine.rb
182
182
  - lib/opal/rails/haml_filter.rb
183
183
  - lib/opal/rails/slim_filter.rb
184
+ - lib/opal/rails/spec_builder.rb
184
185
  - lib/opal/rails/sprockets_cache_key_fix.rb
185
186
  - lib/opal/rails/template_handler.rb
186
187
  - lib/opal/rails/version.rb
@@ -189,6 +190,7 @@ files:
189
190
  - lib/tasks/opal-rails_tasks.rake
190
191
  - opal-rails.gemspec
191
192
  - script/rails
193
+ - spec/helpers/opal_helper_spec.rb
192
194
  - spec/integration/assigns_spec.rb
193
195
  - spec/integration/in_browser_specs_spec.rb
194
196
  - spec/integration/source_map_spec.rb
@@ -200,9 +202,6 @@ files:
200
202
  - test_app/app/assets/images/rails.png
201
203
  - test_app/app/assets/javascripts/application.js
202
204
  - test_app/app/assets/javascripts/source_map_example.js.rb
203
- - test_app/app/assets/javascripts/spec.js
204
- - test_app/app/assets/javascripts/spec/example_spec.js.rb
205
- - test_app/app/assets/javascripts/spec/subdirectory/other_spec.js.rb
206
205
  - test_app/app/assets/stylesheets/application.css
207
206
  - test_app/app/controllers/application_controller.rb
208
207
  - test_app/app/views/application/index.html.erb
@@ -232,6 +231,10 @@ files:
232
231
  - test_app/public/favicon.ico
233
232
  - test_app/public/robots.txt
234
233
  - test_app/script/rails
234
+ - test_app/spec-opal/example_spec.js.rb
235
+ - test_app/spec-opal/requires_opal_spec.js.rb
236
+ - test_app/spec-opal/spec_helper.rb
237
+ - test_app/spec-opal/subdirectory/other_spec.js.rb
235
238
  homepage: http://elia.github.com/opal-rails
236
239
  licenses:
237
240
  - MIT-LICENSE
@@ -247,16 +250,17 @@ required_ruby_version: !ruby/object:Gem::Requirement
247
250
  version: '0'
248
251
  required_rubygems_version: !ruby/object:Gem::Requirement
249
252
  requirements:
250
- - - ">="
253
+ - - ">"
251
254
  - !ruby/object:Gem::Version
252
- version: '0'
255
+ version: 1.3.1
253
256
  requirements: []
254
257
  rubyforge_project: opal-rails
255
- rubygems_version: 2.4.3
258
+ rubygems_version: 2.4.5
256
259
  signing_key:
257
260
  specification_version: 4
258
261
  summary: Rails bindings for opal JS engine
259
262
  test_files:
263
+ - spec/helpers/opal_helper_spec.rb
260
264
  - spec/integration/assigns_spec.rb
261
265
  - spec/integration/in_browser_specs_spec.rb
262
266
  - spec/integration/source_map_spec.rb
@@ -1,6 +0,0 @@
1
- #= require opal_ujs
2
- require 'opal-rspec'
3
-
4
- Document.ready? do
5
- Opal::RSpec::Runner.new.run
6
- end
@@ -1,4 +0,0 @@
1
- //= require jquery
2
- //= require jquery_ujs
3
- //= require opal
4
- //= require opal-jquery
@@ -1 +0,0 @@
1
- // = require_tree ./spec