Class: Cucumber::Messages::Feature

Inherits:
Message
  • Object
show all
Defined in:
lib/cucumber/messages/feature.rb

Overview

Represents the Feature message in Cucumber’s message protocol.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Message

camelize, from_json, #to_h, #to_json

Constructor Details

#initialize(location: Location.new, tags: [], language: '', keyword: '', name: '', description: '', children: []) ⇒ Feature

Returns a new instance of Feature.



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/cucumber/messages/feature.rb', line 46

def initialize(
  location: Location.new,
  tags: [],
  language: '',
  keyword: '',
  name: '',
  description: '',
  children: []
)
  @location = location
  @tags = tags
  @language = language
  @keyword = keyword
  @name = name
  @description = description
  @children = children
  super()
end

Instance Attribute Details

#childrenObject (readonly)

Zero or more children



44
45
46
# File 'lib/cucumber/messages/feature.rb', line 44

def children
  @children
end

#descriptionObject (readonly)

The line(s) underneath the line with the ‘keyword` that are used as description



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

def description
  @description
end

#keywordObject (readonly)

The text of the ‘Feature` keyword (in the language specified by `language`)



29
30
31
# File 'lib/cucumber/messages/feature.rb', line 29

def keyword
  @keyword
end

#languageObject (readonly)

The [ISO 639-1](en.wikipedia.org/wiki/ISO_639-1) language code of the Gherkin document



24
25
26
# File 'lib/cucumber/messages/feature.rb', line 24

def language
  @language
end

#locationObject (readonly)

The location of the ‘Feature` keyword



14
15
16
# File 'lib/cucumber/messages/feature.rb', line 14

def location
  @location
end

#nameObject (readonly)

The name of the feature (the text following the ‘keyword`)



34
35
36
# File 'lib/cucumber/messages/feature.rb', line 34

def name
  @name
end

#tagsObject (readonly)

All the tags placed above the ‘Feature` keyword



19
20
21
# File 'lib/cucumber/messages/feature.rb', line 19

def tags
  @tags
end

Class Method Details

.from_h(hash) ⇒ Object

Returns a new Feature from the given hash. If the hash keys are camelCased, they are properly assigned to the corresponding snake_cased attributes.

Cucumber::Messages::Feature.from_h(some_hash) # => #<Cucumber::Messages::Feature:0x... ...>


72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/cucumber/messages/feature.rb', line 72

def self.from_h(hash)
  return nil if hash.nil?

  new(
    location: Location.from_h(hash[:location]),
    tags: hash[:tags]&.map { |item| Tag.from_h(item) },
    language: hash[:language],
    keyword: hash[:keyword],
    name: hash[:name],
    description: hash[:description],
    children: hash[:children]&.map { |item| FeatureChild.from_h(item) }
  )
end