Class: Sweet::Format::Cucumber::Scenario

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ Scenario

Returns a new instance of Scenario.



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/sweet/format/cucumber/scenario.rb', line 36

def initialize(opts = {})
  @keyword = opts[:keyword]
  @name = opts[:name]
  @description = opts[:description]
  @line_number = opts[:line_number]
  @tags = opts[:tags] || []
  @file_path = opts[:file_path]

  @steps = opts[:steps] || []
  @steps.map! do |step|
    if step.is_a? Hash
      Step.new step
    else
      step
    end
  end

  @screenshot = opts[:screenshot]

  determine_status
end

Instance Attribute Details

#descriptionObject

Returns the value of attribute description.



32
33
34
# File 'lib/sweet/format/cucumber/scenario.rb', line 32

def description
  @description
end

#durationObject



66
67
68
69
70
# File 'lib/sweet/format/cucumber/scenario.rb', line 66

def duration
  @steps.inject(0.0) do |sum, step|
    sum += step.duration || 0.0
  end
end

#file_pathObject

Returns the value of attribute file_path.



32
33
34
# File 'lib/sweet/format/cucumber/scenario.rb', line 32

def file_path
  @file_path
end

#keywordObject

Returns the value of attribute keyword.



32
33
34
# File 'lib/sweet/format/cucumber/scenario.rb', line 32

def keyword
  @keyword
end

#line_numberObject

Returns the value of attribute line_number.



32
33
34
# File 'lib/sweet/format/cucumber/scenario.rb', line 32

def line_number
  @line_number
end

#nameObject

Returns the value of attribute name.



32
33
34
# File 'lib/sweet/format/cucumber/scenario.rb', line 32

def name
  @name
end

#screenshotObject

Returns the value of attribute screenshot.



32
33
34
# File 'lib/sweet/format/cucumber/scenario.rb', line 32

def screenshot
  @screenshot
end

#statusObject

Returns the value of attribute status.



32
33
34
# File 'lib/sweet/format/cucumber/scenario.rb', line 32

def status
  @status
end

#stepsObject

Returns the value of attribute steps.



32
33
34
# File 'lib/sweet/format/cucumber/scenario.rb', line 32

def steps
  @steps
end

#tagsObject

Returns the value of attribute tags.



32
33
34
# File 'lib/sweet/format/cucumber/scenario.rb', line 32

def tags
  @tags
end

Class Method Details

.from_output(data) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/sweet/format/cucumber/scenario.rb', line 8

def from_output(data)
  data = JSON.parse(data, symbolize_names: true) if data.is_a? String

  tags = if data[:tags]
           data[:tags].map do |tag|
             tag[:name]
           end
  end

  if data[:steps]
    steps = data[:steps].map { |step| Step.from_output step }
  end

  new keyword: data[:keyword],
      name: data[:name],
      description: data[:description],
      line_number: data[:line],
      tags: tags,
      file_path: data[:file_path],
      steps: steps,
      screenshot: data[:screenshot]
end

Instance Method Details

#failed?Boolean

Returns:

  • (Boolean)


62
63
64
# File 'lib/sweet/format/cucumber/scenario.rb', line 62

def failed?
  @status == :failed
end

#is_background?Boolean

Returns:

  • (Boolean)


58
59
60
# File 'lib/sweet/format/cucumber/scenario.rb', line 58

def is_background?
  @keyword == 'Background'
end