cucumber-messages 24.0.1 → 25.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (79) hide show
  1. checksums.yaml +4 -4
  2. data/VERSION +1 -1
  3. data/lib/cucumber/messages/attachment.rb +126 -0
  4. data/lib/cucumber/messages/attachment_content_encoding.rb +11 -0
  5. data/lib/cucumber/messages/background.rb +64 -0
  6. data/lib/cucumber/messages/ci.rb +62 -0
  7. data/lib/cucumber/messages/comment.rb +50 -0
  8. data/lib/cucumber/messages/data_table.rb +41 -0
  9. data/lib/cucumber/messages/doc_string.rb +51 -0
  10. data/lib/cucumber/messages/duration.rb +50 -0
  11. data/lib/cucumber/messages/envelope.rb +124 -0
  12. data/lib/cucumber/messages/examples.rb +74 -0
  13. data/lib/cucumber/messages/exception.rb +57 -0
  14. data/lib/cucumber/messages/feature.rb +87 -0
  15. data/lib/cucumber/messages/feature_child.rb +49 -0
  16. data/lib/cucumber/messages/gherkin_document.rb +62 -0
  17. data/lib/cucumber/messages/git.rb +54 -0
  18. data/lib/cucumber/messages/group.rb +46 -0
  19. data/lib/cucumber/messages/helpers/id_generator/incrementing.rb +20 -0
  20. data/lib/cucumber/messages/helpers/id_generator/uuid.rb +17 -0
  21. data/lib/cucumber/messages/helpers/id_generator.rb +4 -0
  22. data/lib/cucumber/messages/helpers/ndjson_to_message_enumerator.rb +30 -0
  23. data/lib/cucumber/messages/helpers/time_conversion.rb +31 -0
  24. data/lib/cucumber/messages/hook.rb +51 -0
  25. data/lib/cucumber/messages/java_method.rb +46 -0
  26. data/lib/cucumber/messages/java_stack_trace_element.rb +46 -0
  27. data/lib/cucumber/messages/location.rb +44 -0
  28. data/lib/cucumber/messages/message.rb +92 -4
  29. data/lib/cucumber/messages/meta.rb +81 -0
  30. data/lib/cucumber/messages/parameter_type.rb +64 -0
  31. data/lib/cucumber/messages/parse_error.rb +41 -0
  32. data/lib/cucumber/messages/pickle.rb +107 -0
  33. data/lib/cucumber/messages/pickle_doc_string.rb +41 -0
  34. data/lib/cucumber/messages/pickle_step.rb +71 -0
  35. data/lib/cucumber/messages/pickle_step_argument.rb +43 -0
  36. data/lib/cucumber/messages/pickle_step_type.rb +13 -0
  37. data/lib/cucumber/messages/pickle_table.rb +36 -0
  38. data/lib/cucumber/messages/pickle_table_cell.rb +36 -0
  39. data/lib/cucumber/messages/pickle_table_row.rb +36 -0
  40. data/lib/cucumber/messages/pickle_tag.rb +47 -0
  41. data/lib/cucumber/messages/product.rb +49 -0
  42. data/lib/cucumber/messages/rule.rb +72 -0
  43. data/lib/cucumber/messages/rule_child.rb +44 -0
  44. data/lib/cucumber/messages/scenario.rb +74 -0
  45. data/lib/cucumber/messages/source.rb +63 -0
  46. data/lib/cucumber/messages/source_media_type.rb +11 -0
  47. data/lib/cucumber/messages/source_reference.rb +55 -0
  48. data/lib/cucumber/messages/step.rb +80 -0
  49. data/lib/cucumber/messages/step_definition.rb +46 -0
  50. data/lib/cucumber/messages/step_definition_pattern.rb +41 -0
  51. data/lib/cucumber/messages/step_definition_pattern_type.rb +11 -0
  52. data/lib/cucumber/messages/step_keyword_type.rb +14 -0
  53. data/lib/cucumber/messages/step_match_argument.rb +54 -0
  54. data/lib/cucumber/messages/step_match_arguments_list.rb +36 -0
  55. data/lib/cucumber/messages/table_cell.rb +49 -0
  56. data/lib/cucumber/messages/table_row.rb +54 -0
  57. data/lib/cucumber/messages/tag.rb +58 -0
  58. data/lib/cucumber/messages/test_case.rb +54 -0
  59. data/lib/cucumber/messages/test_case_finished.rb +46 -0
  60. data/lib/cucumber/messages/test_case_started.rb +69 -0
  61. data/lib/cucumber/messages/test_run_finished.rb +63 -0
  62. data/lib/cucumber/messages/test_run_started.rb +36 -0
  63. data/lib/cucumber/messages/test_step.rb +74 -0
  64. data/lib/cucumber/messages/test_step_finished.rb +51 -0
  65. data/lib/cucumber/messages/test_step_result.rb +57 -0
  66. data/lib/cucumber/messages/test_step_result_status.rb +16 -0
  67. data/lib/cucumber/messages/test_step_started.rb +46 -0
  68. data/lib/cucumber/messages/timestamp.rb +52 -0
  69. data/lib/cucumber/messages/undefined_parameter_type.rb +41 -0
  70. data/lib/cucumber/messages.rb +9 -5
  71. metadata +110 -30
  72. data/lib/cucumber/messages/id_generator.rb +0 -24
  73. data/lib/cucumber/messages/message/deserialization.rb +0 -37
  74. data/lib/cucumber/messages/message/serialization.rb +0 -70
  75. data/lib/cucumber/messages/message/utils.rb +0 -45
  76. data/lib/cucumber/messages/ndjson_to_message_enumerator.rb +0 -21
  77. data/lib/cucumber/messages/time_conversion.rb +0 -33
  78. data/lib/cucumber/messages.deserializers.rb +0 -1208
  79. data/lib/cucumber/messages.dtos.rb +0 -1782
@@ -0,0 +1,46 @@
1
+ # frozen_string_literal: true
2
+
3
+ # The code was auto-generated by {this script}[https://github.com/cucumber/messages/blob/main/jsonschema/scripts/codegen.rb]
4
+ module Cucumber
5
+ module Messages
6
+ ##
7
+ # Represents the TestStepStarted message in Cucumber's {message protocol}[https://github.com/cucumber/messages].
8
+ ##
9
+ ##
10
+ class TestStepStarted < Message
11
+ attr_reader :test_case_started_id
12
+
13
+ attr_reader :test_step_id
14
+
15
+ attr_reader :timestamp
16
+
17
+ def initialize(
18
+ test_case_started_id: '',
19
+ test_step_id: '',
20
+ timestamp: Timestamp.new
21
+ )
22
+ @test_case_started_id = test_case_started_id
23
+ @test_step_id = test_step_id
24
+ @timestamp = timestamp
25
+ super()
26
+ end
27
+
28
+ ##
29
+ # Returns a new TestStepStarted from the given hash.
30
+ # If the hash keys are camelCased, they are properly assigned to the
31
+ # corresponding snake_cased attributes.
32
+ #
33
+ # Cucumber::Messages::TestStepStarted.from_h(some_hash) # => #<Cucumber::Messages::TestStepStarted:0x... ...>
34
+ ##
35
+ def self.from_h(hash)
36
+ return nil if hash.nil?
37
+
38
+ new(
39
+ test_case_started_id: hash[:testCaseStartedId],
40
+ test_step_id: hash[:testStepId],
41
+ timestamp: Timestamp.from_h(hash[:timestamp])
42
+ )
43
+ end
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,52 @@
1
+ # frozen_string_literal: true
2
+
3
+ # The code was auto-generated by {this script}[https://github.com/cucumber/messages/blob/main/jsonschema/scripts/codegen.rb]
4
+ module Cucumber
5
+ module Messages
6
+ ##
7
+ # Represents the Timestamp message in Cucumber's {message protocol}[https://github.com/cucumber/messages].
8
+ ##
9
+ ##
10
+ class Timestamp < Message
11
+ ##
12
+ # Represents seconds of UTC time since Unix epoch
13
+ # 1970-01-01T00:00:00Z. Must be from 0001-01-01T00:00:00Z to
14
+ # 9999-12-31T23:59:59Z inclusive.
15
+ ##
16
+ attr_reader :seconds
17
+
18
+ ##
19
+ # Non-negative fractions of a second at nanosecond resolution. Negative
20
+ # second values with fractions must still have non-negative nanos values
21
+ # that count forward in time. Must be from 0 to 999,999,999
22
+ # inclusive.
23
+ ##
24
+ attr_reader :nanos
25
+
26
+ def initialize(
27
+ seconds: 0,
28
+ nanos: 0
29
+ )
30
+ @seconds = seconds
31
+ @nanos = nanos
32
+ super()
33
+ end
34
+
35
+ ##
36
+ # Returns a new Timestamp from the given hash.
37
+ # If the hash keys are camelCased, they are properly assigned to the
38
+ # corresponding snake_cased attributes.
39
+ #
40
+ # Cucumber::Messages::Timestamp.from_h(some_hash) # => #<Cucumber::Messages::Timestamp:0x... ...>
41
+ ##
42
+ def self.from_h(hash)
43
+ return nil if hash.nil?
44
+
45
+ new(
46
+ seconds: hash[:seconds],
47
+ nanos: hash[:nanos]
48
+ )
49
+ end
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,41 @@
1
+ # frozen_string_literal: true
2
+
3
+ # The code was auto-generated by {this script}[https://github.com/cucumber/messages/blob/main/jsonschema/scripts/codegen.rb]
4
+ module Cucumber
5
+ module Messages
6
+ ##
7
+ # Represents the UndefinedParameterType message in Cucumber's {message protocol}[https://github.com/cucumber/messages].
8
+ ##
9
+ ##
10
+ class UndefinedParameterType < Message
11
+ attr_reader :expression
12
+
13
+ attr_reader :name
14
+
15
+ def initialize(
16
+ expression: '',
17
+ name: ''
18
+ )
19
+ @expression = expression
20
+ @name = name
21
+ super()
22
+ end
23
+
24
+ ##
25
+ # Returns a new UndefinedParameterType from the given hash.
26
+ # If the hash keys are camelCased, they are properly assigned to the
27
+ # corresponding snake_cased attributes.
28
+ #
29
+ # Cucumber::Messages::UndefinedParameterType.from_h(some_hash) # => #<Cucumber::Messages::UndefinedParameterType:0x... ...>
30
+ ##
31
+ def self.from_h(hash)
32
+ return nil if hash.nil?
33
+
34
+ new(
35
+ expression: hash[:expression],
36
+ name: hash[:name]
37
+ )
38
+ end
39
+ end
40
+ end
41
+ end
@@ -1,10 +1,14 @@
1
- require 'cucumber/messages/ndjson_to_message_enumerator'
2
- require 'cucumber/messages/time_conversion'
3
- require 'cucumber/messages/id_generator'
4
- require 'cucumber/messages.deserializers'
1
+ # frozen_string_literal: true
2
+
3
+ require 'cucumber/messages/helpers/ndjson_to_message_enumerator'
4
+ require 'cucumber/messages/helpers/time_conversion'
5
+ require 'cucumber/messages/helpers/id_generator'
6
+ require 'cucumber/messages/message'
7
+
8
+ Dir["#{File.dirname(__FILE__)}/messages/*.rb"].each { |file| require file }
5
9
 
6
10
  module Cucumber
7
11
  module Messages
8
- VERSION = File.read(File.expand_path("../../VERSION", __dir__)).strip
12
+ VERSION = File.read(File.expand_path('../../VERSION', __dir__)).strip
9
13
  end
10
14
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cucumber-messages
3
3
  version: !ruby/object:Gem::Version
4
- version: 24.0.1
4
+ version: 25.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Aslak Hellesøy
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-12-21 00:00:00.000000000 Z
11
+ date: 2024-06-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: cucumber-compatibility-kit
@@ -16,76 +16,98 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '12.0'
19
+ version: '15.0'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '12.0'
26
+ version: '15.0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '13.0'
34
- - - ">="
35
- - !ruby/object:Gem::Version
36
- version: 13.0.6
33
+ version: '13.1'
37
34
  type: :development
38
35
  prerelease: false
39
36
  version_requirements: !ruby/object:Gem::Requirement
40
37
  requirements:
41
38
  - - "~>"
42
39
  - !ruby/object:Gem::Version
43
- version: '13.0'
44
- - - ">="
45
- - !ruby/object:Gem::Version
46
- version: 13.0.6
40
+ version: '13.1'
47
41
  - !ruby/object:Gem::Dependency
48
42
  name: rspec
49
43
  requirement: !ruby/object:Gem::Requirement
50
44
  requirements:
51
45
  - - "~>"
52
46
  - !ruby/object:Gem::Version
53
- version: '3.12'
47
+ version: '3.13'
54
48
  type: :development
55
49
  prerelease: false
56
50
  version_requirements: !ruby/object:Gem::Requirement
57
51
  requirements:
58
52
  - - "~>"
59
53
  - !ruby/object:Gem::Version
60
- version: '3.12'
54
+ version: '3.13'
61
55
  - !ruby/object:Gem::Dependency
62
56
  name: rubocop
63
57
  requirement: !ruby/object:Gem::Requirement
64
58
  requirements:
65
59
  - - "~>"
66
60
  - !ruby/object:Gem::Version
67
- version: 1.28.0
61
+ version: 1.50.2
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 1.50.2
69
+ - !ruby/object:Gem::Dependency
70
+ name: rubocop-performance
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: 1.21.0
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: 1.21.0
83
+ - !ruby/object:Gem::Dependency
84
+ name: rubocop-rake
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: 0.6.0
68
90
  type: :development
69
91
  prerelease: false
70
92
  version_requirements: !ruby/object:Gem::Requirement
71
93
  requirements:
72
94
  - - "~>"
73
95
  - !ruby/object:Gem::Version
74
- version: 1.28.0
96
+ version: 0.6.0
75
97
  - !ruby/object:Gem::Dependency
76
98
  name: rubocop-rspec
77
99
  requirement: !ruby/object:Gem::Requirement
78
100
  requirements:
79
101
  - - "~>"
80
102
  - !ruby/object:Gem::Version
81
- version: 2.5.0
103
+ version: 2.25.0
82
104
  type: :development
83
105
  prerelease: false
84
106
  version_requirements: !ruby/object:Gem::Requirement
85
107
  requirements:
86
108
  - - "~>"
87
109
  - !ruby/object:Gem::Version
88
- version: 2.5.0
110
+ version: 2.25.0
89
111
  description: JSON schema-based messages for Cucumber's inter-process communication
90
112
  email: cukes@googlegroups.com
91
113
  executables: []
@@ -94,16 +116,74 @@ extra_rdoc_files: []
94
116
  files:
95
117
  - README.md
96
118
  - VERSION
97
- - lib/cucumber/messages.deserializers.rb
98
- - lib/cucumber/messages.dtos.rb
99
119
  - lib/cucumber/messages.rb
100
- - lib/cucumber/messages/id_generator.rb
120
+ - lib/cucumber/messages/attachment.rb
121
+ - lib/cucumber/messages/attachment_content_encoding.rb
122
+ - lib/cucumber/messages/background.rb
123
+ - lib/cucumber/messages/ci.rb
124
+ - lib/cucumber/messages/comment.rb
125
+ - lib/cucumber/messages/data_table.rb
126
+ - lib/cucumber/messages/doc_string.rb
127
+ - lib/cucumber/messages/duration.rb
128
+ - lib/cucumber/messages/envelope.rb
129
+ - lib/cucumber/messages/examples.rb
130
+ - lib/cucumber/messages/exception.rb
131
+ - lib/cucumber/messages/feature.rb
132
+ - lib/cucumber/messages/feature_child.rb
133
+ - lib/cucumber/messages/gherkin_document.rb
134
+ - lib/cucumber/messages/git.rb
135
+ - lib/cucumber/messages/group.rb
136
+ - lib/cucumber/messages/helpers/id_generator.rb
137
+ - lib/cucumber/messages/helpers/id_generator/incrementing.rb
138
+ - lib/cucumber/messages/helpers/id_generator/uuid.rb
139
+ - lib/cucumber/messages/helpers/ndjson_to_message_enumerator.rb
140
+ - lib/cucumber/messages/helpers/time_conversion.rb
141
+ - lib/cucumber/messages/hook.rb
142
+ - lib/cucumber/messages/java_method.rb
143
+ - lib/cucumber/messages/java_stack_trace_element.rb
144
+ - lib/cucumber/messages/location.rb
101
145
  - lib/cucumber/messages/message.rb
102
- - lib/cucumber/messages/message/deserialization.rb
103
- - lib/cucumber/messages/message/serialization.rb
104
- - lib/cucumber/messages/message/utils.rb
105
- - lib/cucumber/messages/ndjson_to_message_enumerator.rb
106
- - lib/cucumber/messages/time_conversion.rb
146
+ - lib/cucumber/messages/meta.rb
147
+ - lib/cucumber/messages/parameter_type.rb
148
+ - lib/cucumber/messages/parse_error.rb
149
+ - lib/cucumber/messages/pickle.rb
150
+ - lib/cucumber/messages/pickle_doc_string.rb
151
+ - lib/cucumber/messages/pickle_step.rb
152
+ - lib/cucumber/messages/pickle_step_argument.rb
153
+ - lib/cucumber/messages/pickle_step_type.rb
154
+ - lib/cucumber/messages/pickle_table.rb
155
+ - lib/cucumber/messages/pickle_table_cell.rb
156
+ - lib/cucumber/messages/pickle_table_row.rb
157
+ - lib/cucumber/messages/pickle_tag.rb
158
+ - lib/cucumber/messages/product.rb
159
+ - lib/cucumber/messages/rule.rb
160
+ - lib/cucumber/messages/rule_child.rb
161
+ - lib/cucumber/messages/scenario.rb
162
+ - lib/cucumber/messages/source.rb
163
+ - lib/cucumber/messages/source_media_type.rb
164
+ - lib/cucumber/messages/source_reference.rb
165
+ - lib/cucumber/messages/step.rb
166
+ - lib/cucumber/messages/step_definition.rb
167
+ - lib/cucumber/messages/step_definition_pattern.rb
168
+ - lib/cucumber/messages/step_definition_pattern_type.rb
169
+ - lib/cucumber/messages/step_keyword_type.rb
170
+ - lib/cucumber/messages/step_match_argument.rb
171
+ - lib/cucumber/messages/step_match_arguments_list.rb
172
+ - lib/cucumber/messages/table_cell.rb
173
+ - lib/cucumber/messages/table_row.rb
174
+ - lib/cucumber/messages/tag.rb
175
+ - lib/cucumber/messages/test_case.rb
176
+ - lib/cucumber/messages/test_case_finished.rb
177
+ - lib/cucumber/messages/test_case_started.rb
178
+ - lib/cucumber/messages/test_run_finished.rb
179
+ - lib/cucumber/messages/test_run_started.rb
180
+ - lib/cucumber/messages/test_step.rb
181
+ - lib/cucumber/messages/test_step_finished.rb
182
+ - lib/cucumber/messages/test_step_result.rb
183
+ - lib/cucumber/messages/test_step_result_status.rb
184
+ - lib/cucumber/messages/test_step_started.rb
185
+ - lib/cucumber/messages/timestamp.rb
186
+ - lib/cucumber/messages/undefined_parameter_type.rb
107
187
  homepage: https://github.com/cucumber/messages#readme
108
188
  licenses:
109
189
  - MIT
@@ -122,15 +202,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
122
202
  requirements:
123
203
  - - ">="
124
204
  - !ruby/object:Gem::Version
125
- version: '2.5'
205
+ version: '3.0'
126
206
  required_rubygems_version: !ruby/object:Gem::Requirement
127
207
  requirements:
128
208
  - - ">="
129
209
  - !ruby/object:Gem::Version
130
- version: 3.0.0
210
+ version: 3.2.3
131
211
  requirements: []
132
- rubygems_version: 3.4.10
212
+ rubygems_version: 3.5.11
133
213
  signing_key:
134
214
  specification_version: 4
135
- summary: cucumber-messages-24.0.1
215
+ summary: cucumber-messages-25.0.0
136
216
  test_files: []
@@ -1,24 +0,0 @@
1
- require 'securerandom'
2
-
3
- module Cucumber
4
- module Messages
5
- module IdGenerator
6
- class Incrementing
7
- def initialize
8
- @index = -1
9
- end
10
-
11
- def new_id
12
- @index += 1
13
- @index.to_s
14
- end
15
- end
16
-
17
- class UUID
18
- def new_id
19
- SecureRandom.uuid
20
- end
21
- end
22
- end
23
- end
24
- end
@@ -1,37 +0,0 @@
1
- require 'cucumber/messages/message/utils'
2
- require 'json'
3
-
4
- module Cucumber
5
- module Messages
6
- class Message
7
- include Cucumber::Messages::Message::Utils
8
-
9
- module Deserialization
10
- def self.included(other)
11
- other.extend(ClassMethods)
12
- end
13
-
14
- module ClassMethods
15
- ##
16
- # Returns a new Message - or messages into an array - deserialized from the given json document.
17
- # CamelCased keys are properly converted to snake_cased attributes in the process
18
- #
19
- # Cucumber::Messages::Duration.from_json('{"seconds":1,"nanos":42}') # => #<Cucumber::Messages::Duration:0x00007efda134c290 @seconds=1, @nanos=42>
20
- # Cucumber::Messages::PickleTag.from_json('{"name":"foo","astNodeId":"abc-def"}') # => #<Cucumber::Messages::PickleTag:0x00007efda138cdb8 @name="foo", @ast_node_id="abc-def">
21
- #
22
- # It is recursive so embedded messages are also processed.
23
- #
24
- # json_string = { location: { line: 2 }, text: "comment" }.to_json
25
- # Cucumber::Messages::Comment.from_json(json_string) # => #<Cucumber::Messages::Comment:0x00007efda6abf888 @location=#<Cucumber::Messages::Location:0x00007efda6abf978 @line=2, @column=nil>, @text="comment">
26
- #
27
- # json_string = { uri: 'file:///...', comments: [{text: 'text comment'}, {text: 'another comment'}]}.to_json
28
- # Cucumber::Messages::GherkinDocument.from_json(json_string) # => #<Cucumber::Messages::GherkinDocument:0x00007efda11e6a90 ... @comments=[#<Cucumber::Messages::Comment:0x00007efda11e6e50 ..., #<Cucumber::Messages::Comment:0x00007efda11e6b58 ...>]>
29
- ##
30
- def from_json(json_string)
31
- from_h(JSON.parse(json_string, { symbolize_names: true }))
32
- end
33
- end
34
- end
35
- end
36
- end
37
- end
@@ -1,70 +0,0 @@
1
- require 'cucumber/messages/message/utils'
2
- require 'json'
3
-
4
- module Cucumber
5
- module Messages
6
- class Message
7
- include Cucumber::Messages::Message::Utils
8
-
9
- module Serialization
10
- ##
11
- # Returns a new Hash formed from the message attributes
12
- # If +camelize:+ keyword parameter is set to true, then keys will be camelized
13
- # If +reject_nil_values:+ keyword parameter is set to true, resulting hash won't include nil values
14
- #
15
- # Cucumber::Messages::Duration.new(seconds: 1, nanos: 42).to_h # => { seconds: 1, nanos: 42 }
16
- # Cucumber::Messages::PickleTag.new(name: 'foo', ast_node_id: 'abc-def').to_h(camelize: true) # => { name: 'foo', astNodeId: 'abc-def' }
17
- # Cucumber::Messages::PickleTag.new(name: 'foo', ast_node_id: nil).to_h(reject_nil_values: true) # => { name: 'foo' }
18
- #
19
- # It is recursive so embedded messages are also processed
20
- #
21
- # location = Cucumber::Messages::Location.new(line: 2)
22
- # Cucumber::Messages::Comment.new(location: location, text: 'comment').to_h # => { location: { line: 2, :column: nil }, text: "comment" }
23
- ##
24
- def to_h(camelize: false, reject_nil_values: false)
25
- resulting_hash = self.instance_variables.map do |variable_name|
26
- h_key = variable_name[1..-1]
27
- h_key = Cucumber::Messages::Message.camelize(h_key) if camelize
28
-
29
- h_value = prepare_value(
30
- self.instance_variable_get(variable_name),
31
- camelize: camelize,
32
- reject_nil_values: reject_nil_values
33
- )
34
-
35
- [ h_key.to_sym, h_value ]
36
- end.to_h
37
-
38
- resulting_hash.reject! { |_, value| value.nil? } if reject_nil_values
39
- resulting_hash
40
- end
41
-
42
- ##
43
- # Generates a JSON document from the message.
44
- # Keys are camelized during the process. Null values are not part of the json document.
45
- #
46
- # Cucumber::Messages::Duration.new(seconds: 1, nanos: 42).to_json # => '{"seconds":1,"nanos":42}'
47
- # Cucumber::Messages::PickleTag.new(name: 'foo', ast_node_id: 'abc-def').to_json # => '{"name":"foo","astNodeId":"abc-def"}'
48
- # Cucumber::Messages::PickleTag.new(name: 'foo', ast_node_id: nil).to_json # => '{"name":"foo"}'
49
- #
50
- # As #to_h, the method is recursive
51
- #
52
- # location = Cucumber::Messages::Location.new(line: 2)
53
- # Cucumber::Messages::Comment.new(location: location, text: 'comment').to_json # => '{"location":{"line":2,"column":null},"text":"comment"}'
54
- ##
55
- def to_json
56
- to_h(camelize: true, reject_nil_values: true).to_json
57
- end
58
-
59
- private
60
-
61
- def prepare_value(value, camelize:, reject_nil_values:)
62
- return value.to_h(camelize: camelize, reject_nil_values: reject_nil_values) if value.is_a?(Cucumber::Messages::Message)
63
- return value.map { |v| prepare_value(v, camelize: camelize, reject_nil_values: reject_nil_values) } if value.is_a?(Array)
64
-
65
- value
66
- end
67
- end
68
- end
69
- end
70
- end
@@ -1,45 +0,0 @@
1
- module Cucumber
2
- module Messages
3
- class Message
4
- module Utils
5
- def self.included(other)
6
- other.extend(ClassMethods)
7
- end
8
-
9
- module ClassMethods
10
- ##
11
- # Makes an underscored, lowercase form from the expression in the string.
12
- #
13
- # underscore('GherkinDocument') # => "gherkin_document"
14
- #
15
- # This is a simplified version of the Ruby on Rails implementation
16
- # https://github.com/rails/rails/blob/v6.1.3.2/activesupport/lib/active_support/inflector/methods.rb#L92
17
- ##
18
- def underscore(term)
19
- return term unless /[A-Z-]/.match?(term)
20
-
21
- word = term.gsub(/([A-Z\d]+)([A-Z][a-z])/, '\1_\2')
22
- word.gsub!(/([a-z\d])([A-Z])/, '\1_\2')
23
- word.tr!("-", "_")
24
- word.downcase!
25
- word
26
- end
27
-
28
- ##
29
- # Converts strings to UpperCamelCase.
30
- #
31
- # camelize('gherkin_document') # => "GherkinDocument"
32
- #
33
- # This is a simplified version of the Ruby on Rails implementation
34
- # https://github.com/rails/rails/blob/v6.1.3.2/activesupport/lib/active_support/inflector/methods.rb#L69
35
- ##
36
- def camelize(term)
37
- camelized = term.to_s
38
- camelized.gsub!(/(?:_|(\/))([a-z\d]*)/i) { "#{$1}#{$2.capitalize}" }
39
- camelized
40
- end
41
- end
42
- end
43
- end
44
- end
45
- end
@@ -1,21 +0,0 @@
1
- require 'cucumber/messages.deserializers'
2
-
3
- module Cucumber
4
- module Messages
5
- class NdjsonToMessageEnumerator < Enumerator
6
- def initialize(io)
7
- super() do |yielder|
8
- io.each_line do |line|
9
- next if line.strip.empty?
10
- begin
11
- m = Envelope.from_json(line)
12
- rescue => e
13
- raise "Not JSON: #{line.strip}"
14
- end
15
- yielder.yield(m)
16
- end
17
- end
18
- end
19
- end
20
- end
21
- end
@@ -1,33 +0,0 @@
1
- module Cucumber
2
- module Messages
3
- module TimeConversion
4
- NANOSECONDS_PER_SECOND = 1000000000
5
-
6
- def time_to_timestamp(time)
7
- {
8
- 'seconds' => time.to_i,
9
- 'nanos' => time.nsec
10
- }
11
- end
12
-
13
- def timestamp_to_time(timestamp)
14
- Time.at(timestamp['seconds'] + timestamp['nanos'].to_f / NANOSECONDS_PER_SECOND)
15
- end
16
-
17
- def seconds_to_duration(seconds_float)
18
- seconds, second_modulus = seconds_float.divmod(1)
19
- nanos = second_modulus * NANOSECONDS_PER_SECOND
20
- {
21
- 'seconds' => seconds,
22
- 'nanos' => nanos.to_i
23
- }
24
- end
25
-
26
- def duration_to_seconds(duration)
27
- seconds_part = duration['seconds']
28
- nanos_part = duration['nanos'].to_f / NANOSECONDS_PER_SECOND
29
- seconds_part + nanos_part
30
- end
31
- end
32
- end
33
- end