Class: CucumberMonitor::Step

Inherits:
Object
  • Object
show all
Defined in:
lib/cucumber_monitor/step.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(description, parent, id) ⇒ Step

Returns a new instance of Step.



7
8
9
10
11
12
13
14
# File 'lib/cucumber_monitor/step.rb', line 7

def initialize(description, parent, id)
  @description = description.strip
  code_first_part = parent.name.blank? ? parent.keyword.parameterize : parent.name.parameterize
  code_second_part = @description.parameterize
  @code = "#{code_first_part}-#{code_second_part}"
  @parent = parent
  @id = id
end

Instance Attribute Details

#codeObject

Returns the value of attribute code.



5
6
7
# File 'lib/cucumber_monitor/step.rb', line 5

def code
  @code
end

#descriptionObject

Returns the value of attribute description.



5
6
7
# File 'lib/cucumber_monitor/step.rb', line 5

def description
  @description
end

#idObject

Returns the value of attribute id.



5
6
7
# File 'lib/cucumber_monitor/step.rb', line 5

def id
  @id
end

#parentObject

Returns the value of attribute parent.



5
6
7
# File 'lib/cucumber_monitor/step.rb', line 5

def parent
  @parent
end

Instance Method Details

#definitionObject



58
59
60
# File 'lib/cucumber_monitor/step.rb', line 58

def definition
  Base.new.search_match(description_without_keyword)
end

#description_without_keywordObject



16
17
18
# File 'lib/cucumber_monitor/step.rb', line 16

def description_without_keyword
  description.gsub(/^\S+\s/,'')
end

#formattedObject



84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
# File 'lib/cucumber_monitor/step.rb', line 84

def formatted
  output = ""
  if table_first_line?
    output << "<table>\n"
    output << "  <tr>\n"
    table_content.each do |th|
      output << "    <th>#{th}</th>\n"
    end
    output << "    <th>&nbsp;</th>"
    output << "  </tr>\n"
    output << "</table>\n" if table_last_line?
  elsif table_row?
    output << "  <tr>\n"
    table_content.each do |td|
      output << "    <td>#{td}</td>\n"
    end
    output << "    <td class='td_result'>&nbsp;</td>"
    output << "  </tr>\n"
    output << "</table>\n" if table_last_line?
  else
    output << description
  end
  output
end

#implemented?Boolean

Returns:

  • (Boolean)


80
81
82
# File 'lib/cucumber_monitor/step.rb', line 80

def implemented?
  !definition.nil?
end

#named_paramsObject



74
75
76
77
78
# File 'lib/cucumber_monitor/step.rb', line 74

def named_params
  if implemented? && !table?
    definition.description[/\|(.*)\|/].gsub(/\|/,'').split(",").map{|p| p.strip}
  end
end

#nextObject



28
29
30
# File 'lib/cucumber_monitor/step.rb', line 28

def next
  siblings_and_self.where(id: self.id + 1)
end

#not_a_tableObject



54
55
56
# File 'lib/cucumber_monitor/step.rb', line 54

def not_a_table
  !table?
end

#paramsObject



62
63
64
65
66
67
68
69
70
71
72
# File 'lib/cucumber_monitor/step.rb', line 62

def params
  if implemented? && !table? && !named_params.blank?
    result = description_without_keyword.match(definition.matcher)
    data = {}
    result.size.times do |n|
      next if n == 0
      data.merge!(named_params[n-1].to_sym => result[n])
    end
    data
  end
end

#previousObject



24
25
26
# File 'lib/cucumber_monitor/step.rb', line 24

def previous
  siblings_and_self.where(id: self.id - 1)
end

#siblings_and_selfObject



20
21
22
# File 'lib/cucumber_monitor/step.rb', line 20

def siblings_and_self
  parent.steps
end

#table?Boolean

Returns:

  • (Boolean)


32
33
34
# File 'lib/cucumber_monitor/step.rb', line 32

def table?
  description.scan(/\|/).length >= 2 && description[0] == "|" && description[-1] == "|"
end

#table_contentObject



48
49
50
51
52
# File 'lib/cucumber_monitor/step.rb', line 48

def table_content
  if table?
    description.split("|").map{|l| l.strip}[1..-1]
  end
end

#table_first_line?Boolean

Returns:

  • (Boolean)


36
37
38
# File 'lib/cucumber_monitor/step.rb', line 36

def table_first_line?
  table? && (self.previous.blank? || self.previous.not_a_table)
end

#table_last_line?Boolean

Returns:

  • (Boolean)


40
41
42
# File 'lib/cucumber_monitor/step.rb', line 40

def table_last_line?
  table? && (self.next.blank? || self.next.not_a_table)
end

#table_row?Boolean

Returns:

  • (Boolean)


44
45
46
# File 'lib/cucumber_monitor/step.rb', line 44

def table_row?
  table? && !table_first_line?
end