class Nitra::Workers::Rspec

Public Class Methods

filename_match?(filename) click to toggle source
# File lib/nitra/workers/rspec.rb, line 7
def self.filename_match?(filename)
  filename =~ /_spec\.rb/
end
files() click to toggle source
# File lib/nitra/workers/rspec.rb, line 3
def self.files
  Dir["spec/**/*_spec.rb"].sort_by {|f| File.size(f)}.reverse
end
new(runner_id, worker_number, configuration) click to toggle source
Calls superclass method Nitra::Workers::Worker::new
# File lib/nitra/workers/rspec.rb, line 11
def initialize(runner_id, worker_number, configuration)
  super(runner_id, worker_number, configuration)
end

Public Instance Methods

clean_up() click to toggle source
# 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_environment() click to toggle source
# File lib/nitra/workers/rspec.rb, line 15
def load_environment
  require 'rspec'
  RSpec::Core::Runner.disable_autorun!
end
minimal_file() click to toggle source
# 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) click to toggle source

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.

# 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