Class: Mutx::Cucumber::Scenario

Inherits:
Object
  • Object
show all
Defined in:
lib/mutx/cucumber/scenario.rb

Class Method Summary collapse

Class Method Details

.ensure_db_connectionObject

Conntects to database if not connected



64
65
66
67
# File 'lib/mutx/cucumber/scenario.rb', line 64

def self.ensure_db_connection
  Mutx::Support::Configuration.get
  Mutx::Database::MongoConnector.new(Mutx::Support::Configuration.db_connection_data) unless Mutx::Database::MongoConnector.connected?
end

.get_dataObject

Returns result execution data if exist. Else returns an empty hash



59
60
61
# File 'lib/mutx/cucumber/scenario.rb', line 59

def self.get_data
  self.is_there_result? ? self.get_result.execution_data : {}
end

.get_resultObject



54
55
56
# File 'lib/mutx/cucumber/scenario.rb', line 54

def self.get_result
  Mutx::Results::Result.get(self.id)
end

.get_status(scenario) ⇒ Object



44
45
46
47
48
49
50
51
52
# File 'lib/mutx/cucumber/scenario.rb', line 44

def self.get_status scenario
  result = scenario.instance_variable_get(:@result)
  return "passed" if result.passed?
  return "failed" if result.failed?
  return "undefined" if result.undefined?
  return "unknown" if result.unknown?
  return "skipped" if result.skipped?
  return "pending" if result.pending?
end

.idObject

Returns execution id



7
8
9
# File 'lib/mutx/cucumber/scenario.rb', line 7

def self.id
  ENV["_id"]
end

.is_there_result?Boolean

Returns:

  • (Boolean)


11
12
13
# File 'lib/mutx/cucumber/scenario.rb', line 11

def self.is_there_result?
  Mutx::Database::MongoConnector.result_data_for_id(self.id)
end

.send_to_mutx(scenario) ⇒ Boolean

This is only on Cucumber execution Used on Before hooks as follow

Before do |scenario|
  Mutx::Cucumber::Scenario.send_to_mutx(scenario)
  # your code
end

Parameters:

  • (Cucumber::RunningTestCase::Scenario)

Returns:

  • (Boolean)

    true if added. Added means that result id exists and operation could be performed



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/mutx/cucumber/scenario.rb', line 26

def self.send_to_mutx scenario
  # =>  [:duration, :duration=, :describe_to, :to_s, :passed?, :failed?, :undefined?, :unknown?, :skipped?, :pending?....]
  self.ensure_db_connection
  if self.is_there_result?
    result = self.get_result
    if result and result.running?
      details = {
        "name" => scenario.name,
        "status" => self.get_status(scenario),
        "location" => "#{scenario.location.file}:#{scenario.location.line}"
        }
      result.add_test_result details
    else
      false
    end
  end
end