Skip to content

Commit

Permalink
Don't rely on local static files
Browse files Browse the repository at this point in the history
I had a local build/specs.js that gave me false positives.
  • Loading branch information
elia committed Nov 21, 2013
1 parent f38e66b commit 68cd470
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 11 deletions.
5 changes: 5 additions & 0 deletions Rakefile
Expand Up @@ -50,3 +50,8 @@ desc 'Rebuild grammar.rb for opal parser'
task :racc do
%x(racc -l lib/opal/parser/grammar.y -o lib/opal/parser/grammar.rb)
end

desc 'Remove any generated file.'
task :clobber do
rm_r './build'
end
23 changes: 12 additions & 11 deletions lib/mspec/opal/rake_task.rb
Expand Up @@ -36,6 +36,7 @@ def initialize(name, &task_block)
namespace name do
desc 'Run MSpec::Opal code examples' unless ::Rake.application.last_comment
task :default do
puts 'Starting MSpec Runner...'
runner = Runner.new(&task_block)
runner.run
end
Expand All @@ -56,7 +57,7 @@ def initialize(name, &task_block)

class Runner
def initialize &block
@app = RackApp.new(&block).app
@app = RackApp.new(&block).to_app
@port = 9999
end

Expand Down Expand Up @@ -116,6 +117,8 @@ def initialize(basedir = nil, pattern = nil)
stubs.each do |asset|
::Opal::Processor.stub_file asset
end

ENV['OPAL_SPEC'] = files_to_run(pattern).join(',')
end

def stubs
Expand All @@ -136,7 +139,7 @@ def specs
end

def build_min file = "#{basedir}/build/specs.min.js"
build uglify(specs.to_s), file
build ::Opal::Builder::Util.uglify(specs.to_s), file
end

def files
Expand Down Expand Up @@ -171,29 +174,27 @@ def files_to_run(pattern=nil)
end

def build_specs file = "#{basedir}/build/specs.js"
ENV['OPAL_SPEC'] = files_to_run(pattern).join(',')
code = specs.to_s
FileUtils.mkdir_p File.dirname(file)
puts "Building #{file}..."
File.open(file, 'w+') { |o| o << code }
end
end

class RackApp
class RackApp < Rack::Builder
attr_accessor :pattern, :basedir
attr_reader :app

def initialize
self.pattern = DEFAULT_PATTERN
self.basedir = DEFAULT_BASEDIR

yield(self) if block_given?
super()

@app = Rack::Builder.app environment do
use Rack::ShowExceptions
use Rack::ShowStatus
use Index
end
use Rack::ShowExceptions
use Rack::ShowStatus
use Index
run environment
end

def environment
Expand All @@ -209,7 +210,7 @@ class Index
<title>Opal Specs</title>
</head>
<body>
<script src="/build/specs.js"></script>
<script src="/mspec/opal/main.js"></script>
</body>
</html>
HTML
Expand Down

0 comments on commit 68cd470

Please sign in to comment.