Skip to content

Commit fc6f854

Browse files
committed
[snapshot]
1 parent f6da4a9 commit fc6f854

File tree

10 files changed

+42
-8
lines changed

10 files changed

+42
-8
lines changed

app/controllers/opal_spec_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
class OpalSpecController < ActionController::Base
66
helper_method :spec_files, :pattern, :clean_spec_path, :runner_name
7-
helper_method :check_errors_for
7+
helper_method :check_errors_for, :builder
88

99
def run
1010
logical_path = builder.runner_logical_path

app/helpers/opal_helper.rb

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,18 @@ def opal_tag(opal_code = nil, &block)
88
end
99

1010
def javascript_include_tag(*sources)
11-
sources_copy = sources.dup.tap(&:extract_options!)
11+
options = sources.extract_options!
1212
sprockets = Rails.application.assets
13+
skip_loader = options.delete(:skip_opal_loader)
14+
script_tags = super(*sources, options)
1315

14-
script_tags = super
16+
return script_tags if skip_loader
1517

16-
sources_copy.map do |source|
18+
sources.each do |source|
1719
loading_code = Opal::Processor.load_asset_code(sprockets, source)
1820
script_tags << javascript_tag(loading_code) if loading_code.present?
1921
end
22+
2023
script_tags
2124
end
2225
end

app/views/opal_spec/run.html.erb

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,23 @@
1212
<% end %>
1313
</ul>
1414

15-
<%= javascript_include_tag runner_name, debug: true %>
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+
<%# Add include tags and boot code, we use #uniq as we don't want to source the same asset twice %>
30+
<% all_specs.uniq.each do |asset_path| %>
31+
<% root_asset = root_assets[asset_path] %>
32+
<%= javascript_include_tag asset_path, skip_opal_loader: true %>
33+
<%= javascript_tag Opal::Processor.load_asset_code(Rails.application.assets, root_asset) if root_asset %>
34+
<% end %>

lib/opal/rails/engine.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ class Engine < ::Rails::Engine
1010

1111
config.opal = ActiveSupport::OrderedOptions.new
1212

13-
config.opal.enable_specs = true
13+
config.opal.enable_specs = ::Rails.env.development? || ::Rails.env.test?
1414

1515
# new default location, override-able in a Rails initializer
1616
config.opal.spec_location = 'spec-opal'

lib/opal/rails/spec_builder.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,11 @@ def digest
6565
end
6666

6767
def requires
68-
['opal', 'opal-rspec', *spec_files.map{|f| clean_spec_path(f)}]
68+
['opal', 'opal-rspec', *clean_spec_files]
69+
end
70+
71+
def clean_spec_files
72+
spec_files.map{|f| clean_spec_path(f)}
6973
end
7074

7175
def boot_code

opal-rails.gemspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ Gem::Specification.new do |s|
2222
required_ruby_version = '>= 1.9.3'
2323

2424
s.add_dependency 'rails', '>= 3.2', '< 5.0'
25-
s.add_dependency 'opal', '~> 0.8.0.beta'
25+
s.add_dependency 'opal', '~> 0.8.0.rc'
2626
s.add_dependency 'opal-jquery', '~> 0.3.0'
2727
s.add_dependency 'opal-rspec', '~> 0.4.2'
2828
s.add_dependency 'jquery-rails'

test_app/spec-opal/example_spec.js.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
require 'spec_helper'
2+
13
describe 'a running spec' do
24
it 'runs successfully' do
35
'I run'.should =~ /run/

test_app/spec-opal/requires_opal_spec.js.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
require 'opal'
2+
require 'spec_helper'
23

34
describe 'a running spec' do
45
it 'runs successfully' do

test_app/spec-opal/spec_helper.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
require 'opal'
2+
require 'opal-rspec'
3+
Opal::RSpec::Runner.autorun

test_app/spec-opal/subdirectory/other_spec.js.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
require 'spec_helper'
2+
13
describe "spec inside subdirectory" do
24
it "runs fine" do
35
1.should == 1

0 commit comments

Comments
 (0)