Skip to content

Commit 0fc5cee

Browse files
committedMar 13, 2015
Use Builder directly on opal spec controller
1 parent bcee522 commit 0fc5cee

File tree

4 files changed

+40
-17
lines changed

4 files changed

+40
-17
lines changed
 

Diff for: ‎app/controllers/opal_spec_controller.rb

+29-12
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,59 @@
11
class OpalSpecController < ActionController::Base
2-
helper_method :spec_files
2+
helper_method :spec_files, :pattern, :clean_spec_path
33

44
def run
55
end
66

77
def file
8-
spec_file = Dir["#{spec_location}/#{params[:path]}*.{rb,opal}"].first
9-
Opal.paths.concat Rails.application.config.assets.paths
10-
builder = Opal::Builder.new
11-
file = File.new spec_file
12-
builder.build_str file.read, spec_file
8+
sprockets = Rails.application.config.assets
9+
path_finder = Opal::HikePathFinder.new(Opal.paths + sprockets.paths)
10+
11+
builder = Opal::Builder.new(
12+
compiler_options: Opal::Processor.compiler_options,
13+
stubs: Opal::Processor.stubbed_files,
14+
path_reader: Opal::PathReader.new(path_finder),
15+
)
16+
17+
builder.build 'opal'
18+
builder.build 'opal-rspec'
19+
spec_files.each do |spec_file|
20+
file = File.new spec_file
21+
builder.build_str file.read, spec_file
22+
end
23+
builder.build_str 'Opal::RSpec::Runner.autorun', '(exit)'
24+
# builder.build_str 'exit', '(exit)'
1325

1426
render js: builder.to_s
1527
end
1628

29+
30+
31+
1732
private
1833

34+
def clean_spec_path(path)
35+
path.split("#{spec_location}/").flatten.last.gsub(/(\.rb|\.opal)/, '')
36+
end
37+
1938
def spec_files
2039
@spec_files ||= some_spec_files || all_spec_files
2140
end
2241

23-
def specs_param
42+
def pattern
2443
params[:pattern]
2544
end
2645

2746
def some_spec_files
28-
return if specs_param.blank?
29-
specs_param.split(':').map { |path| spec_files_for_glob(path) }.flatten
47+
return if pattern.blank?
48+
pattern.split(':').map { |path| spec_files_for_glob(path) }.flatten
3049
end
3150

3251
def all_spec_files
3352
spec_files_for_glob '**/*_spec{.js,}'
3453
end
3554

3655
def spec_files_for_glob glob = '**'
37-
Dir[Rails.root.join("#{spec_location}/#{glob}.{rb,opal}")].map do |path|
38-
path.split("#{spec_location}/").flatten.last.gsub(/(\.rb|\.opal)/, '')
39-
end.uniq
56+
Dir[Rails.root.join("#{spec_location}/#{glob}.{rb,opal}")]
4057
end
4158

4259
def spec_location

Diff for: ‎app/views/layouts/opal_spec.html.erb

-2
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
<head>
44
<meta charset="utf-8">
55
<title>Opal Spec Runner</title>
6-
<%= javascript_include_tag 'opal-rspec-runner' %>
7-
<%= spec_include_tag *spec_files.map { |f| "#{f}"} %>
86
<style>
97
body { font-family: sans-serif; }
108
</style>

Diff for: ‎app/views/opal_spec/run.html.erb

+9-1
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,17 @@
11
<h2>Running:</h2>
22

33
<ul>
4+
<% if pattern.present? %>
5+
<li><%= link_to 'All specs', opal_spec_path %></li>
6+
<% end %>
7+
48
<% spec_files.each do |spec_file| %>
59
<li>
6-
<%= link_to spec_file, "/opal_spec?pattern=#{URI.escape(spec_file)}" %>
10+
<% spec_file = clean_spec_path(spec_file) %>
11+
<%= link_to spec_file, opal_spec_path(pattern: spec_file) %>
712
</li>
813
<% end %>
914
</ul>
15+
16+
17+
<%= javascript_include_tag opal_spec_files_path(pattern: pattern) %>

Diff for: ‎lib/opal/rails/engine.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ class Engine < ::Rails::Engine
4545
mount maps_app => maps_prefix
4646
end
4747

48-
get '/opal_spec' => 'opal_spec#run'
49-
get '/opal_spec_files/*path' => 'opal_spec#file'
48+
get '/opal_spec' => 'opal_spec#run', as: :opal_spec
49+
get '/opal_spec_files' => 'opal_spec#file', as: :opal_spec_files
5050
end
5151
end
5252

0 commit comments

Comments
 (0)
Please sign in to comment.