Class: Jasmine::Headless::Runner

Inherits:
Object
  • Object
show all
Defined in:
lib/jasmine/headless/runner.rb

Constant Summary collapse

JASMINE_DEFAULTS =
{
  'spec_files' => [ '**/*[sS]pec.js' ],
  'helpers' => [ 'helpers/**/*.js' ],
  'spec_dir' => 'spec/javascripts',
  'src_dir' => nil,
  'stylesheets' => [],
  'src_files' => [],
  'backtrace' => []
}
RUNNER_DIR =
File.expand_path('../../../../ext/jasmine-webkit-specrunner', __FILE__)
RUNNER =
File.join(RUNNER_DIR, 'jasmine-webkit-specrunner')

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Runner

Returns a new instance of Runner.



35
36
37
38
39
40
41
42
43
44
45
# File 'lib/jasmine/headless/runner.rb', line 35

def initialize(options)
  if !File.file?(RUNNER)
    $stderr.puts "No runner found, attempting to compile..."
    Dir.chdir RUNNER_DIR do
      system %{ruby extconf.rb}
    end
    raise NoRunnerError if !File.file?(RUNNER)
  end

  @options = options
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



26
27
28
# File 'lib/jasmine/headless/runner.rb', line 26

def options
  @options
end

Class Method Details

.run(options = {}) ⇒ Object



29
30
31
32
# File 'lib/jasmine/headless/runner.rb', line 29

def run(options = {})
  options = Options.new(options) if !options.kind_of?(Options)
  new(options).run
end

Instance Method Details

#jasmine_command(*targets) ⇒ Object



61
62
63
64
65
66
67
68
# File 'lib/jasmine/headless/runner.rb', line 61

def jasmine_command(*targets)
  [
    RUNNER,
    @options[:colors] ? '-c' : nil,
    @options[:report] ? "-r #{@options[:report]}" : nil,
    *targets
  ].compact.join(" ")
end

#jasmine_configObject



51
52
53
54
55
56
57
58
59
# File 'lib/jasmine/headless/runner.rb', line 51

def jasmine_config
  return @jasmine_config if @jasmine_config

  @jasmine_config = JASMINE_DEFAULTS.dup
  jasmine_config_data.each do |key, value|
    @jasmine_config[key] = value if value
  end
  @jasmine_config
end

#runObject



70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
# File 'lib/jasmine/headless/runner.rb', line 70

def run
  Jasmine::Headless::CacheableAction.enabled = @options[:enable_cache]
  FilesList.reset!

  files_list = Jasmine::Headless::FilesList.new(
    :config => jasmine_config,
    :only => @options[:files],
    :seed => @options[:seed]
  )

  @_targets = template_writer.write!(files_list)

  run_targets = @_targets.dup

  if run_targets.length == 2
    if (!@options[:full_run] && files_list.filtered?) || files_list.has_spec_outside_scope?
      run_targets.pop
    end
  end

  system jasmine_command(run_targets)

  puts "\nTest ordering seed: --seed #{@options[:seed]}"

  @_status = $?.exitstatus
ensure
  if @_targets && !runner_filename && (@options[:remove_html_file] || (@_status == 0))
    @_targets.each { |target| FileUtils.rm_f target }
  end
end

#runner_filenameObject



101
102
103
104
105
106
107
108
109
# File 'lib/jasmine/headless/runner.rb', line 101

def runner_filename
  options[:runner_output_filename] || begin
    if (runner_output = jasmine_config['runner_output']) && !runner_output.empty?
      runner_output
    else
      false
    end
  end
end

#template_writerObject



47
48
49
# File 'lib/jasmine/headless/runner.rb', line 47

def template_writer
  @template_writer ||= TemplateWriter.new(self)
end