Class: Cucumber::Runtime

Inherits:
Object show all
Includes:
Formatter::Duration, UserInterface
Defined in:
lib/cucumber/runtime.rb,
lib/cucumber/runtime/results.rb,
lib/cucumber/runtime/support_code.rb,
lib/cucumber/runtime/user_interface.rb,
lib/cucumber/runtime/features_loader.rb,
lib/cucumber/runtime/for_programming_languages.rb

Overview

This is the meaty part of Cucumber that ties everything together.

Direct Known Subclasses

StepMother

Defined Under Namespace

Modules: UserInterface Classes: FeaturesLoader, ForProgrammingLanguages, Results, SupportCode

Instance Attribute Summary collapse

Attributes included from UserInterface

#visitor

Instance Method Summary collapse

Methods included from UserInterface

#ask, #embed, #puts

Methods included from Formatter::Duration

#format_duration

Constructor Details

#initialize(configuration = Configuration.default) ⇒ Runtime

Returns a new instance of Runtime.



23
24
25
26
27
28
# File 'lib/cucumber/runtime.rb', line 23

def initialize(configuration = Configuration.default)
  @current_scenario = nil
  @configuration = Configuration.parse(configuration)
  @support_code = SupportCode.new(self, @configuration)
  @results = Results.new(@configuration)
end

Instance Attribute Details

#resultsObject (readonly)

Returns the value of attribute results.



18
19
20
# File 'lib/cucumber/runtime.rb', line 18

def results
  @results
end

Instance Method Details

#after(scenario) ⇒ Object

:nodoc:



110
111
112
113
114
# File 'lib/cucumber/runtime.rb', line 110

def after(scenario) #:nodoc:
  @current_scenario = nil
  return if @configuration.dry_run?
  @support_code.fire_hook(:after, scenario)
end

#after_stepObject

:nodoc:



116
117
118
119
# File 'lib/cucumber/runtime.rb', line 116

def after_step #:nodoc:
  return if @configuration.dry_run?
  @support_code.fire_hook(:execute_after_step, @current_scenario)
end

#around(scenario, skip_hooks = false, &block) ⇒ Object

:nodoc:



88
89
90
91
92
93
94
95
# File 'lib/cucumber/runtime.rb', line 88

def around(scenario, skip_hooks=false, &block) #:nodoc:
  if skip_hooks
    yield
    return
  end

  @support_code.around(scenario, block)
end

#before(scenario) ⇒ Object

:nodoc:



104
105
106
107
108
# File 'lib/cucumber/runtime.rb', line 104

def before(scenario) #:nodoc:
  return if @configuration.dry_run? || @current_scenario
  @current_scenario = scenario
  @support_code.fire_hook(:before, scenario)
end

#before_and_after(scenario, skip_hooks = false) {|scenario| ... } ⇒ Object

:nodoc:

Yields:

  • (scenario)


97
98
99
100
101
102
# File 'lib/cucumber/runtime.rb', line 97

def before_and_after(scenario, skip_hooks=false) #:nodoc:
  before(scenario) unless skip_hooks
  yield scenario
  after(scenario) unless skip_hooks
  @results.scenario_visited(scenario)
end

#configure(new_configuration) ⇒ Object

Allows you to take an existing runtime and change it’s configuration



31
32
33
34
35
# File 'lib/cucumber/runtime.rb', line 31

def configure(new_configuration)
  @configuration = Configuration.parse(new_configuration)
  @support_code.configure(@configuration)
  @results.configure(@configuration)
end

#doc_string(string_without_triple_quotes, content_type = '', line_offset = 0) ⇒ Object

Returns Ast::DocString for string_without_triple_quotes.



164
165
166
# File 'lib/cucumber/runtime.rb', line 164

def doc_string(string_without_triple_quotes, content_type='', line_offset=0)
  Ast::DocString.new(string_without_triple_quotes,content_type)
end

#features_pathsObject



52
53
54
# File 'lib/cucumber/runtime.rb', line 52

def features_paths
  @configuration.paths
end

#load_programming_language(language) ⇒ Object



37
38
39
# File 'lib/cucumber/runtime.rb', line 37

def load_programming_language(language)
  @support_code.load_programming_language(language)
end

#run!Object



41
42
43
44
45
46
47
48
49
50
# File 'lib/cucumber/runtime.rb', line 41

def run!
  load_step_definitions
  disable_minitest_test_unit_autorun
  fire_after_configuration_hook

  tree_walker = @configuration.build_tree_walker(self)
  self.visitor = tree_walker # Ugly circular dependency, but needed to support World#puts

  tree_walker.visit_features(features)
end

#scenarios(status = nil) ⇒ Object



60
61
62
# File 'lib/cucumber/runtime.rb', line 60

def scenarios(status = nil)
  @results.scenarios(status)
end

#snippet_text(step_keyword, step_name, multiline_arg_class) ⇒ Object

:nodoc:



76
77
78
# File 'lib/cucumber/runtime.rb', line 76

def snippet_text(step_keyword, step_name, multiline_arg_class) #:nodoc:
  @support_code.snippet_text(Gherkin::I18n.code_keyword_for(step_keyword), step_name, multiline_arg_class)
end

#step_match(step_name, name_to_report = nil) ⇒ Object

:nodoc:



68
69
70
# File 'lib/cucumber/runtime.rb', line 68

def step_match(step_name, name_to_report=nil) #:nodoc:
  @support_code.step_match(step_name, name_to_report)
end

#step_visited(step) ⇒ Object

:nodoc:



56
57
58
# File 'lib/cucumber/runtime.rb', line 56

def step_visited(step) #:nodoc:
  @results.step_visited(step)
end

#steps(status = nil) ⇒ Object



64
65
66
# File 'lib/cucumber/runtime.rb', line 64

def steps(status = nil)
  @results.steps(status)
end

#unknown_programming_language?Boolean

Returns:

  • (Boolean)


121
122
123
# File 'lib/cucumber/runtime.rb', line 121

def unknown_programming_language?
  @support_code.unknown_programming_language?
end

#unmatched_step_definitionsObject



72
73
74
# File 'lib/cucumber/runtime.rb', line 72

def unmatched_step_definitions
  @support_code.unmatched_step_definitions
end

#with_hooks(scenario, skip_hooks = false) ⇒ Object



80
81
82
83
84
85
86
# File 'lib/cucumber/runtime.rb', line 80

def with_hooks(scenario, skip_hooks=false)
  around(scenario, skip_hooks) do
    before_and_after(scenario, skip_hooks) do
      yield scenario
    end
  end
end

#write_stepdefs_jsonObject



125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
# File 'lib/cucumber/runtime.rb', line 125

def write_stepdefs_json
  if(@configuration.dotcucumber)
    stepdefs = []
    @support_code.step_definitions.sort{|a,b| a.to_hash['source'] <=> a.to_hash['source']}.each do |stepdef|
      stepdef_hash = stepdef.to_hash
      steps = []
      features.each do |feature|
        feature.feature_elements.each do |feature_element|
          feature_element.raw_steps.each do |step|
            args = stepdef.arguments_from(step.name)
            if(args)
              steps << {
                'name' => step.name,
                'args' => args.map do |arg|
                  {
                    'offset' => arg.offset,
                    'val' => arg.val
                  }
                end
              }
            end
          end
        end
      end
      stepdef_hash['file_colon_line'] = stepdef.file_colon_line
      stepdef_hash['steps'] = steps.uniq.sort {|a,b| a['name'] <=> b['name']}
      stepdefs << stepdef_hash
    end
    if !File.directory?(@configuration.dotcucumber)
      FileUtils.mkdir_p(@configuration.dotcucumber)
    end
    File.open(File.join(@configuration.dotcucumber, 'stepdefs.json'), 'w') do |io|
      io.write(MultiJson.dump(stepdefs, :pretty => true))
    end
  end
end