lib/mspec/opal/rake_task.rb in opal-0.6.1 vs lib/mspec/opal/rake_task.rb in opal-0.6.2
- old
+ new
@@ -22,11 +22,11 @@
require 'rack'
require 'webrick'
module MSpec
module Opal
- DEFAULT_PATTERN = 'spec/opal/{parser,core,compiler,stdlib}/**/*_spec.rb'
+ DEFAULT_PATTERN = 'spec/{corelib,opal,stdlib}/**/*_spec.rb'
DEFAULT_BASEDIR = 'spec'
require 'rake'
require 'rake/tasklib'
class RakeTask < ::Rake::TaskLib
@@ -82,17 +82,30 @@
def stop_server
server.kill
end
- def start_phantomjs
+ require 'opal/util'
+ class PhantomJS < ::Opal::Util::Command
require 'shellwords'
+
+ def initialize(runner, url)
+ runner = runner.shellescape
+ url = url.shellescape
+ super 'phantomjs', "#{runner} #{url}", '. Please install PhantomJS'
+ end
+
+ def run
+ system "#{command} #{options}"
+ end
+ end
+
+ def start_phantomjs
runner = File.expand_path('../sprockets.js', __FILE__).shellescape
url = "http://localhost:#{port}/".shellescape
- command = %Q{phantomjs #{runner} #{url}}
-
- @passed = system command
+ command = PhantomJS.new(runner, url)
+ @passed = command.run
end
def start_server
@server = Thread.new do
Rack::Server.start(:app => app, :Port => port, :AccessLog => [],
@@ -106,20 +119,20 @@
def initialize(basedir = nil, pattern = nil)
::Opal::Processor.arity_check_enabled = true
::Opal::Processor.dynamic_require_severity = :ignore
super()
- @pattern = pattern || DEFAULT_PATTERN
+ @pattern = pattern
@basedir = basedir = File.expand_path(basedir || DEFAULT_BASEDIR)
append_path basedir
use_gem 'mspec'
stubs.each do |asset|
::Opal::Processor.stub_file asset
end
- ENV['OPAL_SPEC'] = files_to_run(pattern).join(',')
+ ENV['OPAL_SPEC'] ||= files_to_run(pattern).join(',')
end
def stubs
# missing stdlib
stubs = %w[fileutils iconv yaml]
@@ -145,10 +158,11 @@
def files
@files ||= []
end
def add_files specs
+ puts "Adding #{specs.size} spec files..."
files.concat specs.flatten
end
def paths_from_glob pattern
Dir.glob(File.expand_path(pattern)).map do |s|
@@ -174,24 +188,30 @@
File.join path, spec
end
end
def rubyspec_white_list
- File.read("#{basedir}/rubyspecs").split("\n").map do |line|
- line.sub(/#.*/, '').strip
- end.reject(&:empty?)
+ File.read("#{basedir}/rubyspecs").split("\n").reject do |line|
+ line.sub(/#.*/, '').strip.empty?
+ end
end
def files_to_run(pattern=nil)
# add any filters in spec/filters of specs we dont want to run
add_files paths_from_glob("#{basedir}/filters/**/*.rb")
- # add custom opal specs from spec/
- add_files paths_from_glob(pattern) if pattern
+ if pattern
+ # add custom opal specs from spec/
+ add_files paths_from_glob(pattern) & rubyspec_paths
- # add any rubyspecs we want to run (defined in spec/rubyspecs)
- add_files rubyspec_paths
+ else
+ # add opal specific specs
+ add_files paths_from_glob("#{basedir}/{opal}/**/*_spec.rb")
+
+ # add any rubyspecs we want to run (defined in spec/rubyspecs)
+ add_files rubyspec_paths
+ end
end
def build_specs file = "#{basedir}/build/specs.js"
code = specs.to_s
FileUtils.mkdir_p File.dirname(file)
@@ -202,10 +222,10 @@
class RackApp < Rack::Builder
attr_accessor :pattern, :basedir
def initialize
- self.pattern = DEFAULT_PATTERN
+ self.pattern = nil
self.basedir = DEFAULT_BASEDIR
yield(self) if block_given?
super()