Class: Nukumber::Runtime

Inherits:
Object
  • Object
show all
Defined in:
lib/nukumber/runtime.rb

Instance Method Summary collapse

Constructor Details

#initialize(dirs, filenames, filters, reporter) ⇒ Runtime

Returns a new instance of Runtime.



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/nukumber/runtime.rb', line 5

def initialize(dirs, filenames, filters, reporter)

  @reporter = reporter

  builder = Nukumber::GherkinBuilder.new

  if filters.empty?
    filter_f = builder
  else
    filter_f = Gherkin::Formatter::FilterFormatter.new(builder, filters)
  end
  tag_f = Gherkin::Formatter::TagCountFormatter.new(filter_f, {})
  parser = Gherkin::Parser::Parser.new(tag_f)

  parse_feature_files(parser, dirs, filenames)
  validate_features(builder.features)

  $before_hooks = {}
  $after_hooks  = {}
  old_methods   = Object.private_methods

  # Load all user-space Ruby files
  Dir[Dir.pwd + "/#{dirs[:features]}/#{dirs[:support]}/env.rb"].each   { |f| load f }
  Dir[Dir.pwd + "/#{dirs[:features]}/#{dirs[:support]}/*.rb"].each     { |f| load f }
  Dir[Dir.pwd + "/#{dirs[:features]}/#{dirs[:definitions]}/*.rb"].each { |f| load f }

  user_methods = Object.private_methods - old_methods

  @expected_steps  = []
  @tests_passed    = []
  @tests_failed    = []
  @tests_pending   = []
  @tests_undefined = []

  # Run all relevant features
  builder.features.each { |feature| run_feature feature }

  # Report
  @reporter.final_report(@tests_passed, @tests_failed, @tests_pending, @tests_undefined)

  # Provide code snippets as appropriate
  @reporter.print_skeleton_code @tests_undefined unless @tests_undefined.empty?

  @reporter.terminate

  user_methods.each { |method_sym| Object.send(:remove_method, method_sym) }

end

Instance Method Details

#fail(err_msg = nil) ⇒ Object



70
71
72
73
74
75
76
77
# File 'lib/nukumber/runtime.rb', line 70

def fail (err_msg = nil)
  err_msg = ": #{err_msg}" unless err_msg.nil?
  if @expected_steps.empty?
    raise "Failed after all steps completed#{err_msg}"
  else
    raise "Failed step \"#{@expected_steps.first.name}\"#{err_msg}"
  end
end

#pass(step_name) ⇒ Object



54
55
56
57
58
59
60
61
62
63
64
# File 'lib/nukumber/runtime.rb', line 54

def pass (step_name)
  raise "Tried to pass without a step name" unless step_name.is_a? String
  if @expected_steps.empty?
    raise "Tried to pass unexpected step \"#{step_name}\" (expected test to be finished)"
  elsif @expected_steps.first.name != step_name
    raise "Tried to pass unexpected step \"#{step_name}\" (expected \"#{@expected_steps.first.name}\")"
  else
    @reporter.print_step(@expected_steps.first, :passed) unless @executing_element.is_a? Nukumber::Model::ScenarioOutline
    @expected_steps.shift
  end
end

#pendingObject



66
67
68
# File 'lib/nukumber/runtime.rb', line 66

def pending (*)
  raise Nukumber::PendingTestError
end