Class: Lazylead::Testcase

Inherits:
Requirement show all
Defined in:
lib/lazylead/task/accuracy/testcase.rb

Overview

Check the ‘Description’ field that ticket has mandatory details like

- test case (TC)
- actual result (AR)
- expected result (ER)

Instance Attribute Summary

Attributes inherited from Requirement

#desc, #field, #score

Instance Method Summary collapse

Methods inherited from Requirement

#blank?, #non_blank?

Constructor Details

#initialize(score = 4) ⇒ Testcase

Returns a new instance of Testcase.



33
34
35
# File 'lib/lazylead/task/accuracy/testcase.rb', line 33

def initialize(score = 4)
  super "Test case with AR/ER", score, "Description"
end

Instance Method Details

#detect_ar(index, src, strip) ⇒ Object

Detect index of line with actual result

Parameters:

  • index

    The line number in description

  • src

    The whole line in lower case from description

  • strip

    The escaped line in lower case from description without special symbol(s)



81
82
83
84
85
86
# File 'lib/lazylead/task/accuracy/testcase.rb', line 81

def detect_ar(index, src, strip)
  return unless @ar.negative? && index > @tc
  keywords = %w[ar: actualresult: ar= [ar] actualresult]
  @ar = index if keywords.any? { |k| strip.start_with? k }
  @ar = index if keywords.any? { |k| src.include? k }
end

#detect_er(index, src, strip) ⇒ Object

Detect index of line with expected result

Parameters:

  • index

    The line number in description

  • src

    The whole line in lower case from description

  • strip

    The escaped line in lower case from description without special symbol(s)



92
93
94
95
96
97
# File 'lib/lazylead/task/accuracy/testcase.rb', line 92

def detect_er(index, src, strip)
  return unless @er.negative? && index > @tc
  keywords = %w[er: expectedresult: er= [er] expectedresult]
  @er = index if keywords.any? { |k| strip.start_with? k }
  @er = index if keywords.any? { |k| src.include? k }
end

#detect_tc(index, src, strip) ⇒ Object

Detect index of line with test case

Parameters:

  • index

    The line number in description

  • src

    The whole line in lower case from description

  • strip

    The escaped line in lower case from description without special symbol(s)



69
70
71
72
73
74
75
# File 'lib/lazylead/task/accuracy/testcase.rb', line 69

def detect_tc(index, src, strip)
  return unless @tc.negative?
  keywords = %w[testcase: tc: teststeps: teststeps steps: tcsteps: tc testcases steps usecase
                pre-requisitesandsteps:]
  @tc = index if keywords.any? { |k| strip.eql? k }
  @tc = index if keywords.any? { |k| src.include? k }
end

#escape(line) ⇒ Object



50
51
52
53
54
55
56
57
58
# File 'lib/lazylead/task/accuracy/testcase.rb', line 50

def escape(line)
  if line.include?("{color")
    line.gsub(
      /({color:(#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})|[A-Za-z]+)})|{color}/, ""
    )
  else
    line.gsub(/[^a-zA-Z(:|=)]/, "")
  end
end

#passed(issue) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/lazylead/task/accuracy/testcase.rb', line 37

def passed(issue)
  return false if issue.description.nil?
  @tc = @ar = @er = -1
  issue.description.split("\n").reject(&:blank?).map(&:downcase).each_with_index do |l, i|
    line = escape l.gsub(/(\s+|\*|\+)/, "")
    detect_tc i, l, line
    detect_ar i, l, line
    detect_er i, l, line
    break if with_tc_ar_er?
  end
  with_tc_ar_er?
end

#with_tc_ar_er?Boolean

Returns true if description has test case, AR and ER.

Returns:

  • (Boolean)

    true if description has test case, AR and ER



61
62
63
# File 'lib/lazylead/task/accuracy/testcase.rb', line 61

def with_tc_ar_er?
  (@tc.zero? || @tc.positive?) && @ar.positive? && @er.positive?
end