Class: Nitra::Workers::Cucumber

Inherits:
Worker
  • Object
show all
Defined in:
lib/nitra/workers/cucumber.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) ⇒ Cucumber

Returns a new instance of Cucumber.



11
12
13
# File 'lib/nitra/workers/cucumber.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/cucumber.rb', line 7

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

.filesObject



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

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

Instance Method Details

#clean_upObject



58
59
60
# File 'lib/nitra/workers/cucumber.rb', line 58

def clean_up
  @cuke_runtime.reset
end

#load_environmentObject



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

def load_environment
  require 'cucumber'
  require 'nitra/ext/cucumber'
end

#minimal_fileObject



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

def minimal_file
  <<-EOS
  Feature: cucumber preloading
    Scenario: a fake scenario
      Given every step is unimplemented
      When we run this file
      Then Cucumber will load it's environment
  EOS
end

#run_file(filename, preloading = false) ⇒ Object

Run a Cucumber file and write the results back to the runner.

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



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

def run_file(filename, preloading = false)
  @cuke_runtime ||= ::Cucumber::ResetableRuntime.new  # This runtime gets reused, this is important as it's the part that loads the steps...
  begin
    result = 1
    cuke_config = ::Cucumber::Cli::Configuration.new(io, io)
    cuke_config.parse!(["--no-color", "--require", "features", filename])
    @cuke_runtime.configure(cuke_config)
    @cuke_runtime.run!
    result = 0 unless @cuke_runtime.results.failure?
  rescue LoadError => e
    io << "\nCould not load file #{filename}: #{e.message}\n\n"
  rescue Exception => e
    io << "Exception when running #{filename}: #{e.message}"
    io << e.backtrace[0..7].join("\n")
  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