2011-06-16 13:51:49 +00:00
|
|
|
require 'spec_helper'
|
|
|
|
require 'fakefs/spec_helpers'
|
|
|
|
require 'jasmine/headless/runner'
|
|
|
|
|
|
|
|
describe Jasmine::Headless::Runner do
|
|
|
|
let(:runner) { Jasmine::Headless::Runner.new(options) }
|
|
|
|
let(:options) { Jasmine::Headless::Options.new(opts) }
|
|
|
|
|
2011-06-16 14:11:37 +00:00
|
|
|
describe '#initialize' do
|
2011-06-16 23:38:45 +00:00
|
|
|
let(:opts) { { :test => 'test', :jasmine_config => nil } }
|
2011-06-16 14:11:37 +00:00
|
|
|
|
|
|
|
it 'should have default options' do
|
|
|
|
runner.options[:test].should == 'test'
|
|
|
|
runner.options[:jasmine_config].should == 'spec/javascripts/support/jasmine.yml'
|
|
|
|
end
|
2011-10-10 18:11:13 +00:00
|
|
|
|
|
|
|
it 'should have a template writer' do
|
|
|
|
runner.template_writer.should be_a_kind_of(Jasmine::Headless::TemplateWriter)
|
|
|
|
runner.template_writer.runner.should == runner
|
|
|
|
end
|
2011-06-16 14:11:37 +00:00
|
|
|
end
|
|
|
|
|
2011-06-16 13:51:49 +00:00
|
|
|
describe '#load_config' do
|
|
|
|
include FakeFS::SpecHelpers
|
|
|
|
|
2011-09-09 15:49:17 +00:00
|
|
|
let(:runner_filename) { 'ext/jasmine-webkit-specrunner/jasmine-webkit-specrunner' }
|
|
|
|
|
2011-06-16 13:51:49 +00:00
|
|
|
before do
|
2011-09-09 15:49:17 +00:00
|
|
|
FileUtils.mkdir_p File.split(runner_filename).first
|
|
|
|
|
|
|
|
File.open(runner_filename, 'w')
|
2011-08-10 17:11:05 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
let(:config_filename) { 'test.yml' }
|
|
|
|
let(:opts) { { :jasmine_config => config_filename } }
|
|
|
|
|
|
|
|
context 'file exists' do
|
|
|
|
before do
|
2011-12-16 12:21:06 +00:00
|
|
|
File.open(config_filename, 'w') { |fh| fh.print YAML.dump('test' => 'hello', 'erb' => '<%= "erb" %>') }
|
2011-08-10 17:11:05 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'should load the jasmine config' do
|
|
|
|
runner.jasmine_config['test'].should == 'hello'
|
|
|
|
runner.jasmine_config['spec_dir'].should == 'spec/javascripts'
|
|
|
|
end
|
2011-12-16 12:21:06 +00:00
|
|
|
|
|
|
|
it 'should execute ERB in the config file' do
|
|
|
|
runner.jasmine_config['erb'].should == 'erb'
|
|
|
|
end
|
2011-06-16 13:51:49 +00:00
|
|
|
end
|
|
|
|
|
2011-08-10 17:11:05 +00:00
|
|
|
context 'file does not exist' do
|
|
|
|
it 'should raise an exception' do
|
|
|
|
expect { runner.jasmine_config }.to raise_error(Jasmine::Headless::JasmineConfigNotFound, /#{config_filename}/)
|
|
|
|
end
|
2011-06-16 13:51:49 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#jasmine_command' do
|
2011-12-29 23:37:23 +00:00
|
|
|
subject { runner.jasmine_command(target) }
|
2011-06-16 13:51:49 +00:00
|
|
|
|
2011-12-29 23:37:23 +00:00
|
|
|
let(:target) { 'target' }
|
|
|
|
|
|
|
|
let(:options) { {} }
|
|
|
|
let(:reporters) { [] }
|
|
|
|
|
|
|
|
before do
|
|
|
|
runner.stubs(:options).returns(options)
|
|
|
|
options.stubs(:file_reporters).returns(reporters)
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.it_should_have_basics
|
|
|
|
it { should include(target) }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'colors' do
|
|
|
|
before do
|
|
|
|
options[:colors] = true
|
|
|
|
end
|
|
|
|
|
|
|
|
it_should_have_basics
|
|
|
|
it { should include('-c') }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'reporters' do
|
|
|
|
let(:reporter) { [ 'Reporter', 'identifier', file ] }
|
|
|
|
let(:reporters) { [ reporter ] }
|
|
|
|
|
|
|
|
let(:file) { 'file' }
|
|
|
|
|
|
|
|
it_should_have_basics
|
|
|
|
it { should include("-r #{file}") }
|
2011-06-16 13:51:49 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2011-10-10 18:11:13 +00:00
|
|
|
describe '#runner_filename' do
|
2011-10-11 12:55:43 +00:00
|
|
|
let(:runner_filename) { runner.runner_filename }
|
|
|
|
let(:yaml_output) { 'yaml output' }
|
|
|
|
|
|
|
|
context 'not in options' do
|
2011-10-10 18:11:13 +00:00
|
|
|
let(:opts) { { :runner_output_filename => false } }
|
|
|
|
|
2011-10-11 12:55:43 +00:00
|
|
|
context 'not in yaml file' do
|
|
|
|
before do
|
|
|
|
runner.stubs(:jasmine_config).returns('runner_output' => '')
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'should reverse the remove_html_file option' do
|
|
|
|
runner_filename.should == false
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'in yaml file' do
|
|
|
|
before do
|
|
|
|
runner.stubs(:jasmine_config).returns('runner_output' => yaml_output)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'should use the yaml file definition' do
|
|
|
|
runner_filename.should == yaml_output
|
|
|
|
end
|
2011-10-10 18:11:13 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2011-10-11 12:55:43 +00:00
|
|
|
context 'in options' do
|
2011-10-10 18:11:13 +00:00
|
|
|
let(:filename) { 'filename.html' }
|
|
|
|
let(:opts) { { :runner_output_filename => filename } }
|
|
|
|
|
2011-10-11 12:55:43 +00:00
|
|
|
context 'not in yaml file' do
|
|
|
|
before do
|
|
|
|
runner.stubs(:jasmine_config).returns('runner_output' => '')
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'should reverse the remove_html_file option' do
|
|
|
|
runner.runner_filename.should == filename
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'in yaml file' do
|
|
|
|
before do
|
|
|
|
runner.stubs(:jasmine_config).returns('runner_output' => yaml_output)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'shoulduse the command line filename' do
|
|
|
|
runner.runner_filename.should == filename
|
|
|
|
end
|
2011-10-10 18:11:13 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2011-10-24 15:48:41 +00:00
|
|
|
|
|
|
|
describe '#jasmine_config' do
|
|
|
|
let(:opts) { {} }
|
|
|
|
|
|
|
|
before do
|
|
|
|
runner.stubs(:jasmine_config_data).returns('spec_files' => nil)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'should not merge in things with nil values' do
|
|
|
|
runner.jasmine_config['spec_files'].should == described_class::JASMINE_DEFAULTS['spec_files']
|
|
|
|
end
|
|
|
|
end
|
2011-12-29 23:37:23 +00:00
|
|
|
|
|
|
|
describe '#files_list' do
|
|
|
|
subject { runner.files_list }
|
|
|
|
|
|
|
|
let(:options) { { :files => only, :seed => seed } }
|
|
|
|
|
|
|
|
let(:only) { 'only' }
|
|
|
|
let(:seed) { 12345 }
|
|
|
|
let(:jasmine_config) { 'jasmine config' }
|
2011-12-30 16:34:30 +00:00
|
|
|
let(:reporters) { [] }
|
2011-12-29 23:37:23 +00:00
|
|
|
|
|
|
|
before do
|
|
|
|
runner.stubs(:options).returns(options)
|
|
|
|
runner.stubs(:jasmine_config).returns(jasmine_config)
|
2011-12-30 16:34:30 +00:00
|
|
|
|
|
|
|
options.stubs(:reporters).returns(reporters)
|
2011-12-29 23:37:23 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it { should be_a_kind_of(Jasmine::Headless::FilesList) }
|
|
|
|
|
|
|
|
it 'should have settings' do
|
|
|
|
subject.options[:config].should == jasmine_config
|
|
|
|
subject.options[:only].should == only
|
|
|
|
subject.options[:seed].should == seed
|
2011-12-30 16:34:30 +00:00
|
|
|
subject.options[:reporters].should == reporters
|
2011-12-29 23:37:23 +00:00
|
|
|
end
|
|
|
|
end
|
2011-06-16 13:51:49 +00:00
|
|
|
end
|