Class: Nitra::Workers::Rspec
- 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
- #clean_up ⇒ Object
-
#initialize(runner_id, worker_number, configuration) ⇒ Rspec
constructor
A new instance of Rspec.
- #load_environment ⇒ Object
- #minimal_file ⇒ Object
-
#run_file(filename, preloading = false) ⇒ Object
Run an rspec file and write the results back to the runner.
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
7 8 9 |
# File 'lib/nitra/workers/rspec.rb', line 7 def self.filename_match?(filename) filename =~ /_spec\.rb/ end |
.files ⇒ Object
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_up ⇒ Object
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_environment ⇒ Object
15 16 17 18 |
# File 'lib/nitra/workers/rspec.rb', line 15 def load_environment require 'rspec' RSpec::Core::Runner.disable_autorun! end |
#minimal_file ⇒ Object
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.}\n\n" result = 1 rescue Exception => e io << "Exception when running #{filename}: #{e.}" 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 |