Skip to content

Commit

Permalink
Auto build rspec.js
Browse files Browse the repository at this point in the history
This enable using opal-rspec as a git dependency through bundler.
  • Loading branch information
elia committed Nov 28, 2013
1 parent 4d57cb6 commit 58d10ea
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 31 deletions.
6 changes: 0 additions & 6 deletions Gemfile
Expand Up @@ -5,9 +5,3 @@ gem 'opal', :github => 'opal/opal'
gem 'opal-sprockets', :github => 'opal/opal-sprockets'

gem 'rake'

gem 'rspec', '3.0.0.beta1'
gem 'rspec-support', '3.0.0.beta1'
gem 'rspec-core', '3.0.0.beta1'
gem 'rspec-mocks', '3.0.0.beta1'
gem 'rspec-expectations', '3.0.0.beta1'
26 changes: 3 additions & 23 deletions Rakefile
Expand Up @@ -6,37 +6,17 @@ Opal::RSpec::RakeTask.new(:default)

desc "Build opal/opal/rspec/rspec.js"
task :build do
File.open('opal/opal/rspec/rspec.js', 'w+') do |out|
out << build_rspec
end
Opal::RSpec.build_rspec_js true
end

desc "Show dev/min sizes"
desc 'Show dev/min sizes'
task :sizes do
code = build_rspec
code = Opal::RSpec.build_rspec
min = uglify code

puts "\ndevelopment: #{code.size}, minified: #{min.size}"
end

def build_rspec
Opal::Processor.dynamic_require_severity = :warning
Opal.append_path 'app'

Opal.use_gem 'rspec'
Opal.use_gem 'rspec-expectations'

%w[time fileutils test/unit/assertions coderay optparse shellwords socket uri
drb/drb diff/lcs diff/lcs/hunk].each do |asset|
Opal::Processor.stub_file asset
end

# bug in rspec? this autoload doesnt exist so we must stub it
Opal::Processor.stub_file 'rspec/matchers/built_in/have'

Opal.process('rspec-builder')
end

def uglify(str)
IO.popen('uglifyjs', 'r+') do |i|
i.puts str
Expand Down
40 changes: 39 additions & 1 deletion lib/opal/rspec.rb
@@ -1,6 +1,44 @@
require 'opal'
require 'opal/rspec/version'

module Opal
module RSpec
extend self

def base_dir
File.expand_path('../../..', __FILE__)
end

def build_rspec_js force = false
path = File.expand_path('../../../opal/opal/rspec/rspec.js', __FILE__)
puts "Building: #{path}..."
return if File.exist? path and not(force)
File.open(path, 'w+') { |out| out << rspec_js_code }
end

def rspec_js_code
previous_severity = Opal::Processor.dynamic_require_severity
Opal::Processor.dynamic_require_severity = :warning
Opal.append_path File.join(base_dir, 'app')

Opal.use_gem 'rspec'
Opal.use_gem 'rspec-expectations'

%w[time fileutils test/unit/assertions coderay optparse shellwords socket uri
drb/drb diff/lcs diff/lcs/hunk].each do |asset|
Opal::Processor.stub_file asset
end

# bug in rspec? this autoload doesnt exist so we must stub it
Opal::Processor.stub_file 'rspec/matchers/built_in/have'

Opal.process('rspec-builder').tap do
Opal::Processor.dynamic_require_severity = previous_severity
end
end
end
end

# Just register our opal code path with opal build tools
Opal.append_path File.expand_path('../../../opal', __FILE__)
Opal.append_path File.join(Opal::RSpec.base_dir, 'opal')

10 changes: 9 additions & 1 deletion lib/opal/rspec/rake_task.rb
Expand Up @@ -11,8 +11,10 @@ class RakeTask
URL = "http://localhost:9999/"

def initialize(name = 'opal:rspec', &block)
Opal::RSpec.build_rspec_js

desc "Run opal specs in phantomjs"
task name do
task name => 'opal:rspec:build' do
require 'rack'
require 'webrick'

Expand All @@ -37,6 +39,12 @@ def initialize(name = 'opal:rspec', &block)

exit 1 unless success
end

desc 'Build opal/opal/rspec/rspec.js'
task 'opal:rspec:build' do
Opal::RSpec.build_rspec_js
end

end
end
end
Expand Down
6 changes: 6 additions & 0 deletions opal-rspec.gemspec
Expand Up @@ -18,6 +18,12 @@ Gem::Specification.new do |s|
s.add_dependency 'opal', '~> 0.6.0'
s.add_dependency 'opal-sprockets', '~> 0.4.0'

s.add_dependency 'rspec', '3.0.0.beta1'
s.add_dependency 'rspec-support', '3.0.0.beta1'
s.add_dependency 'rspec-core', '3.0.0.beta1'
s.add_dependency 'rspec-mocks', '3.0.0.beta1'
s.add_dependency 'rspec-expectations', '3.0.0.beta1'

s.add_development_dependency 'rake'
end

0 comments on commit 58d10ea

Please sign in to comment.