Class: Sweet::Format::Cucumber::Feature

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ Feature

Returns a new instance of Feature.



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/sweet/format/cucumber/feature.rb', line 43

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

  @passed = []
  @failed = []
  @pending = []
  @skipped = []

  @backgrounds = opts[:backgrounds] || []
  @scenarios = opts[:scenarios] || []

  [@backgrounds, @scenarios].each do |scenarios|
    scenarios.map! do |scenario|
      if scenario.is_a? Hash
        Scenario.new scenario
      else
        scenario
      end
      scenario.file_path = @file_path

      scenario
    end
  end

  organize_scenarios
end

Instance Attribute Details

#backgroundsObject

Returns the value of attribute backgrounds.



39
40
41
# File 'lib/sweet/format/cucumber/feature.rb', line 39

def backgrounds
  @backgrounds
end

#descriptionObject

Returns the value of attribute description.



39
40
41
# File 'lib/sweet/format/cucumber/feature.rb', line 39

def description
  @description
end

#failedObject

Returns the value of attribute failed.



41
42
43
# File 'lib/sweet/format/cucumber/feature.rb', line 41

def failed
  @failed
end

#file_pathObject

Returns the value of attribute file_path.



39
40
41
# File 'lib/sweet/format/cucumber/feature.rb', line 39

def file_path
  @file_path
end

#keywordObject

Returns the value of attribute keyword.



39
40
41
# File 'lib/sweet/format/cucumber/feature.rb', line 39

def keyword
  @keyword
end

#nameObject

Returns the value of attribute name.



39
40
41
# File 'lib/sweet/format/cucumber/feature.rb', line 39

def name
  @name
end

#passedObject

Returns the value of attribute passed.



41
42
43
# File 'lib/sweet/format/cucumber/feature.rb', line 41

def passed
  @passed
end

#pendingObject

Returns the value of attribute pending.



41
42
43
# File 'lib/sweet/format/cucumber/feature.rb', line 41

def pending
  @pending
end

#scenariosObject

Returns the value of attribute scenarios.



39
40
41
# File 'lib/sweet/format/cucumber/feature.rb', line 39

def scenarios
  @scenarios
end

#skippedObject

Returns the value of attribute skipped.



41
42
43
# File 'lib/sweet/format/cucumber/feature.rb', line 41

def skipped
  @skipped
end

#tagsObject

Returns the value of attribute tags.



39
40
41
# File 'lib/sweet/format/cucumber/feature.rb', line 39

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
30
31
32
33
34
35
36
# File 'lib/sweet/format/cucumber/feature.rb', line 8

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

  backgrounds = []
  scenarios = []
  data[:elements].each do |element|
    scenario = Scenario.from_output element
    scenario.file_path = data[:uri]
    if scenario.is_background?
      unless backgrounds.any? do |bg|
        bg.line_number == scenario.line_number
      end
        backgrounds << scenario
      end
    else
      scenarios << scenario
    end
  end

  tags = (data[:tags].map { |tag| tag[:name] } if data[:tags])

  new file_path: data[:uri],
      keyword: data[:keyword],
      name: data[:name],
      description: data[:description],
      tags: tags,
      backgrounds: backgrounds,
      scenarios: scenarios
end

Instance Method Details

#durationObject



74
75
76
77
78
# File 'lib/sweet/format/cucumber/feature.rb', line 74

def duration
  [@scenarios, @backgrounds].flatten.inject(0.0) do |sum, scenario|
    sum += scenario.duration
  end
end

#total_failedObject



88
89
90
# File 'lib/sweet/format/cucumber/feature.rb', line 88

def total_failed
  @failed.count
end

#total_passedObject



84
85
86
# File 'lib/sweet/format/cucumber/feature.rb', line 84

def total_passed
  @passed.count
end

#total_pendingObject



92
93
94
# File 'lib/sweet/format/cucumber/feature.rb', line 92

def total_pending
  @pending.count
end

#total_skippedObject



96
97
98
# File 'lib/sweet/format/cucumber/feature.rb', line 96

def total_skipped
  @skipped.count
end

#total_testsObject



80
81
82
# File 'lib/sweet/format/cucumber/feature.rb', line 80

def total_tests
  @scenarios.count
end