Class: Cucumber::Runtime

Inherits:
Object show all
Includes:
Core, Formatter::Duration, UserInterface
Defined in:
lib/cucumber/runtime.rb,
lib/cucumber/runtime/results.rb,
lib/cucumber/runtime/tag_limits.rb,
lib/cucumber/runtime/support_code.rb,
lib/cucumber/runtime/gated_receiver.rb,
lib/cucumber/runtime/user_interface.rb,
lib/cucumber/runtime/features_loader.rb,
lib/cucumber/runtime/tag_limits/filter.rb,
lib/cucumber/runtime/tag_limits/verifier.rb,
lib/cucumber/runtime/for_programming_languages.rb,
lib/cucumber/runtime/tag_limits/test_case_index.rb

Defined Under Namespace

Modules: TagLimits, UserInterface Classes: FeaturesLoader, ForProgrammingLanguages, GatedReceiver, NormalisedEncodingFile, Quit, Randomizer, 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

- (Runtime) initialize(configuration = Configuration.default)



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

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

- (Object) configuration (readonly)

Returns the value of attribute configuration



43
44
45
# File 'lib/cucumber/runtime.rb', line 43

def configuration
  @configuration
end

- (Object) results (readonly)

Returns the value of attribute results



43
44
45
# File 'lib/cucumber/runtime.rb', line 43

def results
  @results
end

- (Object) support_code (readonly)

Returns the value of attribute support_code



43
44
45
# File 'lib/cucumber/runtime.rb', line 43

def support_code
  @support_code
end

Instance Method Details

- (Object) after(scenario)

:nodoc:



141
142
143
144
145
# File 'lib/cucumber/runtime.rb', line 141

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

- (Object) after_step

:nodoc:



147
148
149
150
# File 'lib/cucumber/runtime.rb', line 147

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

- (Object) around(scenario, skip_hooks = false, &block)

:nodoc:



115
116
117
118
119
120
121
122
# File 'lib/cucumber/runtime.rb', line 115

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

  @support_code.around(scenario, block)
end

- (Object) before(scenario)

:nodoc:



135
136
137
138
139
# File 'lib/cucumber/runtime.rb', line 135

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

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

:nodoc:

Yields:

  • (scenario)


124
125
126
127
128
129
# File 'lib/cucumber/runtime.rb', line 124

def before_and_after(scenario, skip_hooks=false) #:nodoc:
  before(scenario) unless skip_hooks
  yield scenario
  after(scenario) unless skip_hooks
  record_result scenario
end

- (Object) configure(new_configuration)

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



57
58
59
60
61
# File 'lib/cucumber/runtime.rb', line 57

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

- (Object) doc_string(string_without_triple_quotes, content_type = '', line_offset = 0)

Returns Ast::DocString for string_without_triple_quotes.



196
197
198
199
200
# File 'lib/cucumber/runtime.rb', line 196

def doc_string(string_without_triple_quotes, content_type='', line_offset=0)
  file, line = *caller[0].split(':')[0..1]
  location = Core::Ast::Location.new(file, line)
  Core::Ast::DocString.new(string_without_triple_quotes, content_type, location)
end

- (Boolean) dry_run?



79
80
81
# File 'lib/cucumber/runtime.rb', line 79

def dry_run?
  @configuration.dry_run?
end

- (Object) features_paths



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

def features_paths
  @configuration.paths
end

- (Object) load_programming_language(language)



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

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

- (Object) record_result(scenario)



131
132
133
# File 'lib/cucumber/runtime.rb', line 131

def record_result(scenario)
  @results.scenario_visited(scenario)
end

- (Object) run!



67
68
69
70
71
72
73
# File 'lib/cucumber/runtime.rb', line 67

def run!
  load_step_definitions
  fire_after_configuration_hook
  self.visitor = report

  execute features, mappings, report, filters
end

- (Object) scenarios(status = nil)



87
88
89
# File 'lib/cucumber/runtime.rb', line 87

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

- (Object) snippet_text(step_keyword, step_name, multiline_arg)

:nodoc:



103
104
105
# File 'lib/cucumber/runtime.rb', line 103

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

- (Object) step_match(step_name, name_to_report = nil)

:nodoc:



95
96
97
# File 'lib/cucumber/runtime.rb', line 95

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

- (Object) step_visited(step)

:nodoc:



83
84
85
# File 'lib/cucumber/runtime.rb', line 83

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

- (Object) steps(status = nil)



91
92
93
# File 'lib/cucumber/runtime.rb', line 91

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

- (Boolean) unknown_programming_language?



152
153
154
# File 'lib/cucumber/runtime.rb', line 152

def unknown_programming_language?
  @support_code.unknown_programming_language?
end

- (Object) unmatched_step_definitions



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

def unmatched_step_definitions
  @support_code.unmatched_step_definitions
end

- (Object) with_hooks(scenario, skip_hooks = false)



107
108
109
110
111
112
113
# File 'lib/cucumber/runtime.rb', line 107

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

- (Object) write_stepdefs_json

 TODO: this code is untested



157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
# File 'lib/cucumber/runtime.rb', line 157

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