Class: Rutema::Step

Inherits:
Object
  • Object
show all
Includes:
Patir::Command, SpecificationElement
Defined in:
lib/rutema/core/objectmodel.rb

Overview

Represents a step in a Scenario.

Each Rutema::Step can have text and a command associated with it.

Step standard attributes are.

attended - the step can only run in attended mode, it requires user input.

step_type - a string identifying the type of the step. It is "step" by default.

ignore - set to true if the step's success or failure is to be ignored. It essentially means that the step is always considered succesfull

continue - set to true if the step's success or failure is to be recognized, but following steps in the same scenario are to be carried out regardless of if indicates test failure, but ensures any further state is carried out as needed

skip_on_error - if the test case has been marked a failure, skip steps marked with this attribute

number - this is set when the step is assigned to a Scenario and is the sequence number

cmd - the command associated with this step. This should quack like Patir::Command.

status - one of :not_executed, :success, :warning, :error. Encapsulates the underlying command's status

==Dynamic behaviour

A Rutema::Step can be queried dynamicaly about the attributes it posesses: step.has_script? - will return true if script is step's attribute. Attribute's are mostly assigned by the parser, i.e. the Rutema::BaseXMLParser from the XML element will create a Step instance with step_type=="test" and script="some_script". In this case

step.has_script? returns true step.script returns "some_script"

Just like an OpenStruct, Step attributes will be created by direct assignment: step.script="some_script" creates the script attribute if it does not exist.

See Rutema::SpecificationElement for the implementation details.

Instance Method Summary collapse

Methods included from SpecificationElement

#attribute, #method_missing, #respond_to?, #respond_to_missing?

Constructor Details

#initialize(txt = "", cmd = nil) ⇒ Step

txt describes the step, cmd is the command to run



184
185
186
187
188
189
190
191
192
193
194
195
196
197
# File 'lib/rutema/core/objectmodel.rb', line 184

def initialize(txt = "", cmd = nil)
  @attributes = {}
  # ignore is off by default
  @attributes[:ignore] = false
  # continue is off by default
  @attributes[:continue] = false
  # skip_on_error is off by default
  @attributes[:skip_on_error] = false
  # assign
  @attributes[:cmd] = cmd if cmd
  @attributes[:text] = txt
  @number = 0
  @attributes[:step_type] = "step"
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Rutema::SpecificationElement

Instance Method Details

#backtraceObject



215
216
217
218
219
220
# File 'lib/rutema/core/objectmodel.rb', line 215

def backtrace
  return "no backtrace associated" unless @attributes[:cmd]
  return @attributes[:cmd].backtrace if @attributes[:cmd].respond_to?(:backtrace)

  return ""
end

#continue?Boolean

Returns:

  • (Boolean)


234
235
236
237
238
# File 'lib/rutema/core/objectmodel.rb', line 234

def continue?
  return false unless @attributes[:continue]

  return @attributes[:continue]
end

#errorObject



209
210
211
212
213
# File 'lib/rutema/core/objectmodel.rb', line 209

def error
  return "no command associated" unless @attributes[:cmd]

  return @attributes[:cmd].error
end

#exec_timeObject



240
241
242
243
244
# File 'lib/rutema/core/objectmodel.rb', line 240

def exec_time
  return 0 unless @attributes[:cmd]

  return @attributes[:cmd].exec_time
end

#ignore?Boolean

Returns:

  • (Boolean)


228
229
230
231
232
# File 'lib/rutema/core/objectmodel.rb', line 228

def ignore?
  return false unless @attributes[:ignore]

  return @attributes[:ignore]
end

#nameObject



199
200
201
# File 'lib/rutema/core/objectmodel.rb', line 199

def name
  return name_with_parameters
end

#name_with_parametersObject



266
267
268
269
# File 'lib/rutema/core/objectmodel.rb', line 266

def name_with_parameters
  param = " - #{cmd}" if has_cmd?
  return "#{@attributes[:step_type]}#{param}"
end

#outputObject



203
204
205
206
207
# File 'lib/rutema/core/objectmodel.rb', line 203

def output
  return "" unless @attributes[:cmd]

  return @attributes[:cmd].output
end

#resetObject



262
263
264
# File 'lib/rutema/core/objectmodel.rb', line 262

def reset
  @attributes[:cmd]&.reset
end

#run(context = nil) ⇒ Object



256
257
258
259
260
# File 'lib/rutema/core/objectmodel.rb', line 256

def run(context = nil)
  return not_executed unless @attributes[:cmd]

  return @attributes[:cmd].run(context)
end

#skip_on_error?Boolean

Returns:

  • (Boolean)


222
223
224
225
226
# File 'lib/rutema/core/objectmodel.rb', line 222

def skip_on_error?
  return false unless @attributes[:skip_on_error]

  return @attributes[:skip_on_error]
end

#statusObject



246
247
248
249
250
# File 'lib/rutema/core/objectmodel.rb', line 246

def status
  return :warning unless @attributes[:cmd]

  return @attributes[:cmd].status
end

#status=(stts) ⇒ Object



252
253
254
# File 'lib/rutema/core/objectmodel.rb', line 252

def status=(stts)
  @attributes[:cmd].status = stts if @attributes[:cmd]
end

#to_sObject

:nodoc:



271
272
273
274
275
276
277
278
279
# File 'lib/rutema/core/objectmodel.rb', line 271

def to_s # :nodoc:
  if has_cmd?
    msg = "#{number} - #{cmd}"
  else
    msg = "#{number} - #{name}"
  end
  msg << " in #{included_in}" if has_included_in?
  return msg
end