ビルド サーバーでヘッドレス ジャスミン テストを実行し、結果を junit 形式で出力するように rake タスクをセットアップしました。タスクは次のとおりです。
namespace :jasmine do
desc "Runs Jasmine tests headlessly and writes out junit xml."
task :headless_junit do |t, args|
run_jasmine_tests(Dir.pwd)
end
end
def run_jasmine_tests(output_dir)
require 'headless'
require 'jasmine'
require 'rspec'
require 'rspec/core/rake_task'
output_file = "#{output_dir}/jasmine_results.xml"
Headless.ly do
RSpec::Core::RakeTask.new(:jasmine_continuous_integration_runner) do |t|
t.rspec_opts = ['--format', 'RspecJunitFormatter', '--out', output_file ]
t.verbose = true
t.rspec_opts += ["-r #{File.expand_path(File.join(::Rails.root, 'config', 'environment'))}"]
t.pattern = [Jasmine.runner_filepath]
end
Rake::Task['jasmine_continuous_integration_runner'].invoke
end
end
これを実行すると、次のエラーが発生します。
TypeError: jasmine.getEnv(...).currentSpec is null in http://localhost:34002/assets/jquery.js?body=true (line 1129)
expect@http://localhost:34002/assets/jquery.js?body=true:1129
@http://localhost:34002/__spec__/activity_catalog_search_filters_spec.js:15
jasmine.Block.prototype.execute@http://localhost:34002/__jasmine__/jasmine.js:1064
jasmine.Queue.prototype.next_@http://localhost:34002/__jasmine__/jasmine.js:2096
jasmine.Queue.prototype.next_/onComplete/<@http://localhost:34002/__jasmine__/jasmine.js:2086
... LOTS MORE ...
Rails 3.2.13、jasmine 1.3.2、headless 1.0.1、rspec 2.14.1、Jasmine-jQuery 1.5.8 を使用しています。
この男が抱えている問題に似ていると思います: TypeError: jasmine.getEnv().currentSpec is null