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
|
2012-01-18 23:04:36 +00:00
|
|
|
it { should include(target) }
|
2011-12-29 23:37:23 +00:00
|
|
|
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
|
2012-01-11 13:44:28 +00:00
|
|
|
|
|
|
|
context 'quiet' do
|
|
|
|
before do
|
|
|
|
options[:quiet] = true
|
|
|
|
end
|
|
|
|
|
|
|
|
it_should_have_basics
|
|
|
|
it { should include("-q") }
|
|
|
|
end
|
2011-06-16 13:51:49 +00:00
|
|
|
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
|
2012-01-17 18:32:57 +00:00
|
|
|
|
|
|
|
describe '.server_port' do
|
|
|
|
before do
|
|
|
|
described_class.instance_variable_set(:@server_port, nil)
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'port in use' do
|
|
|
|
require 'socket'
|
|
|
|
|
|
|
|
before do
|
|
|
|
described_class.stubs(:select_server_port).returns(5000, 5001)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'should try another port' do
|
|
|
|
server = TCPServer.new(described_class.server_interface, 5000)
|
|
|
|
|
|
|
|
described_class.server_port.should == 5001
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2012-01-18 23:04:36 +00:00
|
|
|
|
|
|
|
describe '#absolute_run_targets' do
|
|
|
|
let(:opts) { {} }
|
|
|
|
|
|
|
|
subject { runner.absolute_run_targets(targets) }
|
|
|
|
|
|
|
|
let(:targets) { [ target ] }
|
|
|
|
let(:target) { 'target' }
|
|
|
|
|
|
|
|
before do
|
|
|
|
runner.stubs(:options).returns(:use_server => use_server)
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'server' do
|
|
|
|
let(:use_server) { true }
|
|
|
|
let(:server_spec_path) { 'server spec path' }
|
|
|
|
|
|
|
|
before do
|
|
|
|
described_class.stubs(:server_spec_path).returns(server_spec_path)
|
|
|
|
end
|
|
|
|
|
|
|
|
it { should == [ server_spec_path + target ] }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'no server' do
|
|
|
|
let(:use_server) { false }
|
|
|
|
|
|
|
|
it { should == [ 'file://' + File.expand_path(target) ] }
|
|
|
|
end
|
|
|
|
end
|
2011-06-16 13:51:49 +00:00
|
|
|
end
|