Class: Nitra::Workers::Rspec

Inherits:
Worker
  • Object
show all
Defined in:
lib/nitra/workers/rspec.rb

Instance Attribute Summary

Attributes inherited from Worker

#channel, #configuration, #io, #runner_id, #worker_number

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Worker

#fork_and_run, framework_name, inherited, worker_classes

Constructor Details

#initialize(runner_id, worker_number, configuration) ⇒ Rspec

Returns a new instance of Rspec.



11
12
13
# File 'lib/nitra/workers/rspec.rb', line 11

def initialize(runner_id, worker_number, configuration)
  super(runner_id, worker_number, configuration)
end

Class Method Details

.filename_match?(filename) ⇒ Boolean

Returns:

  • (Boolean)


7
8
9
# File 'lib/nitra/workers/rspec.rb', line 7

def self.filename_match?(filename)
  filename =~ /_spec\.rb/
end

.filesObject



3
4
5
# File 'lib/nitra/workers/rspec.rb', line 3

def self.files
  Dir["spec/**/*_spec.rb"].sort_by {|f| File.size(f)}.reverse
end

Instance Method Details

#clean_upObject



55
56
57
58
59
60
61
62
63
# File 'lib/nitra/workers/rspec.rb', line 55

def clean_up
  # Rspec.reset in 2.6 didn't destroy your rspec_rails fixture loading, we can't use it anymore for it's intended purpose.
  # This means our world object will be slightly polluted by the preload_framework code, but that's a small price to pay
  # to upgrade.
  #
  # RSpec.reset
  #
  RSpec.instance_variable_set(:@world, nil)
end

#load_environmentObject



15
16
17
18
# File 'lib/nitra/workers/rspec.rb', line 15

def load_environment
  require 'rspec'
  RSpec::Core::Runner.disable_autorun!
end

#minimal_fileObject



20
21
22
23
24
25
26
27
28
29
# File 'lib/nitra/workers/rspec.rb', line 20

def minimal_file
  <<-EOS
  require 'spec_helper'
  describe('nitra preloading') do
    it('preloads the fixtures') do
      expect(1).to eq(1)
    end
  end
  EOS
end

#run_file(filename, preloading = false) ⇒ Object

Run an rspec file and write the results back to the runner.

Doesn’t write back to the runner if we mark the run as preloading.



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/nitra/workers/rspec.rb', line 36

def run_file(filename, preloading = false)
  begin
    result = RSpec::Core::CommandLine.new(["-f", "p", filename]).run(io, io)
  rescue LoadError => e
    io << "\nCould not load file #{filename}: #{e.message}\n\n"
    result = 1
  rescue Exception => e
    io << "Exception when running #{filename}: #{e.message}"
    io << e.backtrace[0..7].join("\n")
    result = 1
  end

  if preloading
    puts io.string
  else
    channel.write("command" => "result", "filename" => filename, "return_code" => result.to_i, "text" => io.string, "worker_number" => worker_number)
  end
end