Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: opal/opal-rails
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: e519155e6c49
Choose a base ref
...
head repository: opal/opal-rails
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: ec7b38440042
Choose a head ref
  • 3 commits
  • 4 files changed
  • 1 contributor

Commits on Mar 25, 2015

  1. Fix spec_builder spec globbing

    elia committed Mar 25, 2015
    Copy the full SHA
    2c52d06 View commit details
  2. Unverified

    This commit is not signed, but one or more authors requires that any commit attributed to them is signed.
    Copy the full SHA
    63be7b7 View commit details
  3. Copy the full SHA
    ec7b384 View commit details
Showing with 16 additions and 19 deletions.
  1. +5 −4 app/controllers/opal_spec_controller.rb
  2. +1 −1 app/views/opal_spec/run.html.erb
  3. +5 −0 lib/opal/rails/engine.rb
  4. +5 −14 lib/opal/rails/spec_builder.rb
9 changes: 5 additions & 4 deletions app/controllers/opal_spec_controller.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
require 'opal/rails/spec_builder'
require 'fileutils'
require 'pathname'

class OpalSpecController < ActionController::Base
helper_method :spec_files, :pattern, :clean_spec_path

def run
respond_to do |format|
format.html
format.js { render js: builder.to_s }
end
runner = Rails.root.join('tmp/opal_spec/opal_spec_runner.js.rb')
runner.dirname.mkpath
runner.open('w') { |f| f << builder.main_code }
end


2 changes: 1 addition & 1 deletion app/views/opal_spec/run.html.erb
Original file line number Diff line number Diff line change
@@ -13,4 +13,4 @@
</ul>


<%= javascript_include_tag opal_spec_path(pattern: pattern) %>
<%= javascript_include_tag 'opal_spec_runner', debug: true %>
5 changes: 5 additions & 0 deletions lib/opal/rails/engine.rb
Original file line number Diff line number Diff line change
@@ -10,6 +10,7 @@ class Engine < ::Rails::Engine
config.opal = ActiveSupport::OrderedOptions.new
# new default location, override-able in a Rails initializer
config.opal.spec_location = "spec-opal"
config.opal.dynamic_require_severity = :ignore

# Cache eager_load_paths now, otherwise the assets dir is added
# and its .rb files are eagerly loaded.
@@ -20,9 +21,13 @@ class Engine < ::Rails::Engine
end

initializer 'opal.asset_paths', :after => 'sprockets.environment', :group => :all do |app|
app.assets.append_path app.root.join('tmp/opal_spec').to_s
app.assets.append_path app.root.join(app.config.opal.spec_location).to_s
Opal.paths.each do |path|
app.assets.append_path path
end

app.config.assets.precompile += %w[opal_spec_runner.js]
end

config.after_initialize do |app|
19 changes: 5 additions & 14 deletions lib/opal/rails/spec_builder.rb
Original file line number Diff line number Diff line change
@@ -3,7 +3,7 @@ module Rails
class SpecBuilder
def initialize(options)
@root = options.fetch(:root) { ::Rails.root }
@pattern = options.fetch(:pattern, nil)
@pattern = options[:pattern] || '**/*_spec'
@sprockets = options.fetch(:sprockets)
@spec_location = options.fetch(:spec_location)
end
@@ -31,8 +31,8 @@ def paths
[spec_location] + Opal.paths + sprockets.paths
end

def main_code(files = spec_files)
requires(files).map { |file| "require #{file.inspect}\n" }.join + boot_code
def main_code
requires(spec_files).map { |file| "require #{file.inspect}\n" }.join + boot_code
end

def requires(files)
@@ -44,19 +44,10 @@ def boot_code
end

def spec_files
@spec_files ||= some_spec_files || all_spec_files
@spec_files ||= pattern.split(':').map { |path| spec_files_for_glob(path) }.flatten
end

def some_spec_files
return if pattern.blank?
pattern.split(':').map { |path| spec_files_for_glob(path) }.flatten
end

def all_spec_files
spec_files_for_glob '**/*_spec'
end

def spec_files_for_glob glob = '**'
def spec_files_for_glob(glob)
Dir[root.join("#{spec_location}/#{glob}{,.js}.{rb,opal}")]
end