Method: Opal::RSpec::RakeTask#initialize
- Defined in:
- lib/opal/rspec/rake_task.rb
#initialize(name = 'opal:rspec', &block) ⇒ RakeTask
Returns a new instance of RakeTask.
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 |
# File 'lib/opal/rspec/rake_task.rb', line 81 def initialize(name = 'opal:rspec', &block) desc 'Run opal specs in phantomjs/node' task name do require 'rack' require 'webrick' sprockets_env = Opal::RSpec::SprocketsEnvironment.new app = Opal::Server.new(sprockets: sprockets_env) { |s| s.main = 'opal/rspec/sprockets_runner' s.debug = false block.call s, self if block sprockets_env.spec_pattern = self.pattern if self.pattern sprockets_env.spec_exclude_pattern = self.exclude_pattern sprockets_env.spec_files = self.files sprockets_env.default_path = self.default_path if self.default_path raise 'Cannot supply both a pattern and files!' if self.files and self.pattern sprockets_env.add_spec_paths_to_sprockets } # TODO: Once Opal 0.9 compatibility is established, if we're running node, add in the node stdlib requires in so RSpec can use them, also add NODE_PATH to the runner command above server = Thread.new do Thread.current.abort_on_exception = true Rack::Server.start( :app => app, :Port => PORT, :AccessLog => [], :Logger => WEBrick::Log.new("/dev/null"), ) end wait_for_server is_phantom = runner == :phantom if is_phantom if `phantomjs -v`.nil? warn "Could not find phantomjs command" exit 1 end end begin is_phantom ? launch_phantom(timeout) : launch_node(app) ensure server.kill end end end |