Skip to content

Commit af07766

Browse files
committed
pull out some of the task behavior
1 parent 6906994 commit af07766

File tree

1 file changed

+31
-14
lines changed

1 file changed

+31
-14
lines changed

lib/tasks/jasmine-rails_tasks.rake

Lines changed: 31 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,50 @@
11
namespace :spec do
2-
def run_cmd(cmd)
3-
puts "$ #{cmd}"
4-
unless system(cmd)
5-
raise "Error executing command: #{cmd}"
2+
3+
desc "run test with phantomjs"
4+
task :javascript => [:environment] do
5+
override_rails_config do
6+
include_offline_asset_paths_helper
7+
spec_filter = ENV['SPEC']
8+
html = get_spec_runner(spec_filter)
9+
runner_path = Rails.root.join('spec/tmp/runner.html')
10+
File.open(runner_path, 'w') {|f| f << html.gsub('/assets', './assets')}
11+
12+
run_cmd %{phantomjs "#{File.join(File.dirname(__FILE__), 'runner.js')}" "file://#{runner_path.to_s}?spec=#{spec_filter}"}
613
end
714
end
815

9-
desc "run test with phantomjs"
10-
task :javascript => :environment do
11-
original_debug_setting = Rails.application.config.assets.debug
12-
Rails.application.config.assets.debug = false
16+
def include_offline_asset_paths_helper
1317
require 'jasmine_rails/offline_asset_paths'
1418
if Rails::VERSION::MAJOR >= 4
1519
Sprockets::Rails::Helper.send :include, JasmineRails::OfflineAssetPaths
1620
else
1721
ActionView::AssetPaths.send :include, JasmineRails::OfflineAssetPaths
1822
end
19-
spec_filter = ENV['SPEC']
23+
end
24+
25+
def override_rails_config
26+
config = Rails.application.config
27+
28+
original_asssets_debug = config.assets.debug
29+
config.assets.debug = false
30+
yield
31+
config.assets.debug = original_asssets_debug
32+
end
33+
34+
def get_spec_runner(spec_filter)
2035
app = ActionController::Integration::Session.new(Rails.application)
2136
path = JasmineRails.route_path
2237
app.get path, :console => 'true', :spec => spec_filter
2338
JasmineRails::OfflineAssetPaths.disabled = true
2439
raise "Jasmine runner at '#{path}' returned a #{app.response.status} error: #{app.response.message}" unless app.response.success?
25-
html = app.response.body
26-
runner_path = Rails.root.join('spec/tmp/runner.html')
27-
File.open(runner_path, 'w') {|f| f << html.gsub('/assets', './assets')}
40+
app.response.body
41+
end
2842

29-
run_cmd %{phantomjs "#{File.join(File.dirname(__FILE__), 'runner.js')}" "file://#{runner_path.to_s}?spec=#{spec_filter}"}
30-
Rails.application.config.assets.debug = original_debug_setting
43+
def run_cmd(cmd)
44+
puts "Running `#{cmd}`"
45+
unless system(cmd)
46+
raise "Error executing command: #{cmd}"
47+
end
3148
end
3249

3350
# alias

0 commit comments

Comments
 (0)