Module: Kaya::Suites

Defined in:
lib/kaya/suites/suite.rb,
lib/kaya/suites/suites.rb,
lib/kaya/suites/custom/params.rb

Defined Under Namespace

Modules: Custom Classes: Suite

Class Method Summary collapse

Class Method Details

.all_running_suitesArray

Returns the ids for running suites

Returns:

  • (Array)

    of suite ids



114
115
116
117
118
119
# File 'lib/kaya/suites/suites.rb', line 114

def self.all_running_suites
  $K_LOG.debug "Suites: Getting all runnnig suites" if $K_LOG
  Kaya::Database::MongoConnector.all_suites.select do |suite|
    suite["status"] == "RUNNING"
  end.map{|suite| suite["_id"]}
end

.cucumber_ymlObject



4
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
# File 'lib/kaya/suites/suites.rb', line 4

def self.cucumber_yml
  $K_LOG.debug "Getting cucumber.yml content" if $K_LOG
  begin
    # Try to open cucumber.yml file from root folder
    content = YAML.load_file("#{Dir.pwd}/cucumber.yml")
  rescue  # Could not find the file
    # Try to open from /config/
    $K_LOG.warn "cucumber.yml file not found"  if $K_LOG
    begin
      content = YAML.load_file("#{Dir.pwd}/config/cucumber.yml")
    rescue # Could not find the file
      $K_LOG.warn "cucumber.yml file not found"  if $K_LOG
      content ={}
    end
  end

  begin
    unless content.empty?

      content.select do |suite_name, command|
        command.include? "runnable=true"
      end.map do |suite_name, command|

        command.gsub!(' runnable=true','').gsub!(', ',',')

        suite_info = command.scan(/info\=\[(.*)\]/).flatten.first

        suite_info.gsub('<br>','\n') if suite_info.respond_to? :gsub

        command.gsub!(/info\=\[(.*)\]/,"")

        custom_params = command.scan(/custom\=\[(.*)\]/).flatten.first

        custom = Kaya::Suites::Custom::Params.new(custom_params)

        command.gsub!(/custom\=\[(.*)\]/,"")
        $K_LOG.debug "{suite_name => #{suite_name}, command => #{command}, custom => #{custom.params}, info => #{suite_info}}" if $K_LOG

        {"suite_name" => suite_name, "command" => command, "custom" => custom.params, "info" => suite_info}
      end
    else
      []
    end
  rescue => e
    $K_LOG.error "Suites: #{e}#{e.backtrace}" if $K_LOG
    []
  end
end

.is_there_suite_with?(name) ⇒ Boolean

Returns:

  • (Boolean)


90
91
92
# File 'lib/kaya/suites/suites.rb', line 90

def self.is_there_suite_with? name
  self.suite_id_for name
end

.reset_statusesObject



121
122
123
124
125
126
127
128
129
130
131
# File 'lib/kaya/suites/suites.rb', line 121

def self.reset_statuses
  $K_LOG.debug "Resetting suites status" if $K_LOG
  self.all_running_suites.each do |suite_id|
    if suite = Kaya::Suites::Suite.get(suite_id)
      if result = Kaya::Results::Result.get(suite.last_result)
        result.update_values! # update_values! true means result got finished status
      end
      suite.set_ready!
    end
  end
end

.suite_id_for(suite_name, active = nil) ⇒ Fixnum

Returns the id for given suite name

Parameters:

  • suite (String)

    name

Returns:

  • (Fixnum)

    suite id



107
108
109
110
# File 'lib/kaya/suites/suites.rb', line 107

def self.suite_id_for(suite_name, active=nil)
  $K_LOG.debug "Suites:Getting suite id for #{suite_name}" if $K_LOG
  Kaya::Database::MongoConnector.suite_id_for(suite_name, active)
end

.suite_ids(active = nil) ⇒ Array

Returns a list of suites id

Parameters:

  • actives (Boolean)

    or not

Returns:

  • (Array)

    a list of suite ids



97
98
99
100
101
102
# File 'lib/kaya/suites/suites.rb', line 97

def self.suite_ids active=nil
  $K_LOG.debug "Suites:Getting all suites ids" if $K_LOG
  Kaya::Database::MongoConnector.suites(active).map do |suite_data|
    suite_data["_id"]
  end
end

.update!Object



57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/kaya/suites/suites.rb', line 57

def self.update!
  $K_LOG.debug "Updating suites" if $K_LOG
  existing_suites_ids = self.suite_ids

  self.cucumber_yml.each do |suite_data|
    # If is there a suite for the given name suite_id will be setted
    # and the id will be deleted from existing_suites_ids
    existing_suites_ids.delete(suite_id = is_there_suite_with?(suite_data["suite_name"]))

    if suite_id # Update
      suite = Kaya::Suites::Suite.get(suite_id)
      suite.name= suite_data["suite_name"]
    else
      suite = Kaya::Suites::Suite.new_suite(suite_data["suite_name"])
    end

    suite.command= suite_data["command"]
    suite.custom = suite_data["custom"]
    suite.info=    suite_data["info"]

    suite.activate! if suite_id
    $K_LOG.debug "[#{suite.id}:#{suite.name}] Suite Updated" if $K_LOG
    suite.save!
  end

  unless existing_suites_ids.empty?
    existing_suites_ids.each do |suite_id|
      suite = Kaya::Suites::Suite.get(suite_id)
      suite.deactivate!
    end
  end
end

.update_suitesObject



53
54
55
# File 'lib/kaya/suites/suites.rb', line 53

def self.update_suites
  self.update! if Kaya::Support::ChangeInspector.is_there_a_change? or Kaya::Database::MongoConnector.active_suites.size.zero?
end