cucumber-compatibility-kit 12.0.0 → 13.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (50) hide show
  1. checksums.yaml +4 -4
  2. data/features/attachments/attachments.feature +2 -2
  3. data/features/attachments/attachments.feature.ndjson +7 -7
  4. data/features/attachments/attachments.feature.rb +18 -23
  5. data/features/attachments/cucumber.jpeg +0 -0
  6. data/features/cdata/cdata.feature.ndjson +1 -1
  7. data/features/data-tables/data-tables.feature.ndjson +1 -1
  8. data/features/data-tables/data-tables.feature.rb +2 -0
  9. data/features/examples-tables/examples-tables.feature.ndjson +1 -1
  10. data/features/examples-tables/examples-tables.feature.rb +2 -0
  11. data/features/hooks/hooks.feature.ndjson +1 -1
  12. data/features/hooks/hooks.feature.rb +2 -5
  13. data/features/markdown/markdown.feature.md.ndjson +1 -1
  14. data/features/minimal/minimal.feature.ndjson +1 -1
  15. data/features/minimal/minimal.feature.rb +3 -1
  16. data/features/parameter-types/parameter-types.feature.ndjson +1 -1
  17. data/features/parameter-types/parameter-types.feature.rb +2 -1
  18. data/features/pending/pending.feature.ndjson +1 -1
  19. data/features/pending/pending.feature.rb +3 -1
  20. data/features/retry/retry.feature.ndjson +1 -1
  21. data/features/retry/retry.feature.rb +2 -0
  22. data/features/rules/rules.feature.ndjson +1 -1
  23. data/features/rules/rules.feature.rb +2 -0
  24. data/features/skipped/skipped.feature +8 -8
  25. data/features/skipped/skipped.feature.ndjson +9 -9
  26. data/features/skipped/skipped.feature.rb +8 -6
  27. data/features/stack-traces/stack-traces.feature +4 -6
  28. data/features/stack-traces/stack-traces.feature.ndjson +4 -4
  29. data/features/stack-traces/stack-traces.feature.rb +3 -1
  30. data/features/undefined/undefined.feature +7 -8
  31. data/features/undefined/undefined.feature.ndjson +7 -7
  32. data/features/undefined/undefined.feature.rb +4 -2
  33. data/features/unknown-parameter-type/unknown-parameter-type.feature +1 -1
  34. data/features/unknown-parameter-type/unknown-parameter-type.feature.ndjson +2 -2
  35. data/features/unknown-parameter-type/unknown-parameter-type.feature.rb +5 -3
  36. data/lib/cck/helpers.rb +11 -0
  37. data/lib/cck/keys_checker.rb +64 -0
  38. data/lib/cck/messages_comparator.rb +97 -0
  39. data/lib/cucumber/cucumber-compatibility-kit.rb +57 -0
  40. data/lib/cucumber-compatibility-kit.rb +1 -55
  41. data/lib/keys_checker.rb +1 -28
  42. data/lib/messages_comparator.rb +1 -86
  43. data/lib/shared_examples.rb +12 -30
  44. data/spec/cck/keys_checker_spec.rb +67 -0
  45. data/spec/cck/messages_comparator_spec.rb +29 -0
  46. data/spec/{cucumber-compatibility-kit_spec.rb → cucumber/cucumber-compatibility-kit_spec.rb} +14 -21
  47. metadata +73 -20
  48. data/spec/capture_warnings.rb +0 -74
  49. data/spec/keys_checker_spec.rb +0 -106
  50. data/spec/messages_comparator_spec.rb +0 -26
@@ -1,86 +1 @@
1
- require_relative 'keys_checker'
2
-
3
- module CCK
4
- class MessagesComparator
5
- def initialize(validator, found, expected)
6
- @all_errors = []
7
- @compared = []
8
- @validator = validator
9
-
10
- compare(found, expected)
11
- end
12
-
13
- def errors
14
- @all_errors.flatten
15
- end
16
-
17
- def debug
18
- # puts 'Compared the following type of message:'
19
- # puts @compared.uniq.map { |m| " - #{m}" }.join("\n")
20
- # puts ''
21
- puts errors.uniq.join("\n")
22
- end
23
-
24
- private
25
-
26
- def compare(found, expected)
27
- found_by_type = messages_by_type(found)
28
- expected_by_type = messages_by_type(expected)
29
-
30
- found_by_type.keys.each do |type|
31
- compare_list(found_by_type[type], expected_by_type[type])
32
- rescue StandardError => e
33
- @all_errors << "Error whild comparing #{type}: #{e.message}"
34
- end
35
- end
36
-
37
- def messages_by_type(messages)
38
- by_type = Hash.new { |h, k| h[k] = [] }
39
- messages.each do |msg|
40
- by_type[message_type(msg)] << remove_envelope(msg)
41
- end
42
- by_type
43
- end
44
-
45
- def message_type(message)
46
- message.to_h.each do |key, value|
47
- return key unless value.nil?
48
- end
49
- end
50
-
51
- def remove_envelope(message)
52
- message.send(message_type(message))
53
- end
54
-
55
- def compare_list(found, expected)
56
- found.each_with_index do |message, index|
57
- compare_message(message, expected[index])
58
- end
59
- end
60
-
61
- def compare_message(found, expected)
62
- return unless found.is_a?(Cucumber::Messages::Message)
63
- return if found.is_a?(Cucumber::Messages::GherkinDocument)
64
- return if found.is_a?(Cucumber::Messages::Pickle)
65
- return if found.is_a?(Cucumber::Messages::Timestamp) && expected.is_a?(Cucumber::Messages::Timestamp)
66
- return if found.is_a?(Cucumber::Messages::Duration) && expected.is_a?(Cucumber::Messages::Duration)
67
- return if ENV['CI'] && found.is_a?(Cucumber::Messages::Ci) && expected.nil?
68
-
69
- @compared << found.class.name
70
- @all_errors << @validator.compare(found, expected)
71
- compare_sub_messages(found, expected)
72
- end
73
-
74
- def compare_sub_messages(found, expected)
75
- return unless expected.respond_to? :to_h
76
- expected.to_h.keys.each do |key|
77
- value = expected.send(key)
78
- if value.is_a?(Array)
79
- compare_list(found.send(key), value)
80
- else
81
- compare_message(found.send(key), value)
82
- end
83
- end
84
- end
85
- end
86
- end
1
+ require_relative 'cck/messages_comparator'
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'json'
2
4
  require 'rspec'
3
5
  require 'cucumber/messages'
@@ -6,12 +8,14 @@ require 'messages_comparator'
6
8
  require 'keys_checker'
7
9
 
8
10
  RSpec.shared_examples 'cucumber compatibility kit' do
11
+ include CCK::Helpers
12
+
9
13
  # Note: to use those examples, you need to define:
10
14
  # let(:example) { } # the name of the example to test
11
15
  # let(:messages) { } # the messages to validate
12
16
 
13
- let(:example) { raise "`example` missing: add `let(:example) { example_name }` to your spec" }
14
- let(:messages) { raise "`messages` missing: add `let(:messages) { ndjson }` to your spec" }
17
+ let(:example) { raise '`example` missing: add `let(:example) { example_name }` to your spec' }
18
+ let(:messages) { raise '`messages` missing: add `let(:messages) { ndjson }` to your spec' }
15
19
 
16
20
  let(:example_path) { Cucumber::CompatibilityKit.example_path(example) }
17
21
 
@@ -22,42 +26,20 @@ RSpec.shared_examples 'cucumber compatibility kit' do
22
26
  let(:generated_messages_types) { parsed_generated.map { |msg| message_type(msg) } }
23
27
 
24
28
  it 'generates valid message types' do
25
- debug_lists(original_messages_types, generated_messages_types)
26
29
  expect(generated_messages_types).to contain_exactly(*original_messages_types)
27
30
  end
28
31
 
29
32
  it 'generates valid message structure' do
30
33
  comparator = CCK::MessagesComparator.new(CCK::KeysChecker, parsed_generated, parsed_original)
31
- comparator.debug if ENV['VERBOSE']
32
34
 
33
- if comparator.errors.any?
34
- fail "There were comparison errors: #{comparator.errors}"
35
- end
35
+ expect(comparator.errors).to be_empty, "There were comparison errors: #{comparator.errors}"
36
36
  end
37
- end
38
37
 
39
- def parse_ndjson_file(path)
40
- parse_ndjson(File.read(path))
41
- end
42
-
43
- def parse_ndjson(ndjson)
44
- Cucumber::Messages::NdjsonToMessageEnumerator.new(ndjson)
45
- end
46
-
47
- def message_type(message)
48
- message.to_h.keys.first
49
- end
50
-
51
- def debug_lists(expected, obtained)
52
- return unless ENV['VERBOSE']
53
- return if expected.sort == obtained.sort
54
-
55
- to_read = expected.count > obtained.count ? expected : obtained
56
- columnize = "\t\t\t\t | \t\t\t\t"
38
+ def parse_ndjson_file(path)
39
+ parse_ndjson(File.read(path))
40
+ end
57
41
 
58
- puts " | Expected #{columnize} GOT"
59
- to_read.each_with_index do |_, index|
60
- ok = expected[index] == obtained[index] ? 'v' : 'x'
61
- puts "[#{ok}] | #{expected[index]} #{columnize} #{obtained[index]}"
42
+ def parse_ndjson(ndjson)
43
+ Cucumber::Messages::NdjsonToMessageEnumerator.new(ndjson)
62
44
  end
63
45
  end
@@ -0,0 +1,67 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'rspec'
4
+ require 'cucumber/messages'
5
+ require_relative '../../lib/keys_checker'
6
+
7
+ describe CCK::KeysChecker do
8
+ describe '#compare' do
9
+ let(:expected_values) { Cucumber::Messages::Attachment.new(url: 'https://foo.com', file_name: 'file.extension') }
10
+ let(:erroneous_values) { Cucumber::Messages::Attachment.new(source: '1', test_step_id: '123') }
11
+ let(:wrong_values) { Cucumber::Messages::Attachment.new(url: 'https://otherfoo.com', file_name: 'file.other') }
12
+
13
+ it 'finds missing keys' do
14
+ expect(described_class.compare(erroneous_values, expected_values)).to include(
15
+ 'Missing keys in message Cucumber::Messages::Attachment: [:file_name, :url]'
16
+ )
17
+ end
18
+
19
+ it 'finds extra keys' do
20
+ expect(described_class.compare(erroneous_values, expected_values)).to include(
21
+ 'Detected extra keys in message Cucumber::Messages::Attachment: [:source, :test_step_id]'
22
+ )
23
+ end
24
+
25
+ it 'finds extra and missing keys' do
26
+ expect(described_class.compare(erroneous_values, expected_values)).to contain_exactly(
27
+ 'Missing keys in message Cucumber::Messages::Attachment: [:file_name, :url]',
28
+ 'Detected extra keys in message Cucumber::Messages::Attachment: [:source, :test_step_id]'
29
+ )
30
+ end
31
+
32
+ it 'does not care about the values' do
33
+ expect(described_class.compare(expected_values, wrong_values)).to be_empty
34
+ end
35
+
36
+ context 'when default values are omitted' do
37
+ let(:default_set) { Cucumber::Messages::Duration.new(seconds: 0, nanos: 12) }
38
+ let(:default_not_set) { Cucumber::Messages::Duration.new(nanos: 12) }
39
+
40
+ it 'does not raise an exception' do
41
+ expect(described_class.compare(default_set, default_not_set)).to be_empty
42
+ end
43
+ end
44
+
45
+ context 'when executed as part of a CI' do
46
+ before { allow(ENV).to receive(:[]).with('CI').and_return(true) }
47
+
48
+ it 'ignores actual CI related messages' do
49
+ detected = Cucumber::Messages::Meta.new(ci: Cucumber::Messages::Ci.new(name: 'Some CI'))
50
+ expected = Cucumber::Messages::Meta.new
51
+
52
+ expect(described_class.compare(detected, expected)).to be_empty
53
+ end
54
+ end
55
+
56
+ context 'when an unexpected error occurs' do
57
+ it 'does not raise error' do
58
+ expect { described_class.compare(nil, nil) }.not_to raise_error
59
+ end
60
+
61
+ it 'returns the error' do
62
+ expect(described_class.compare(nil, nil))
63
+ .to eq(['Unexpected error: wrong number of arguments (given 1, expected 0)'])
64
+ end
65
+ end
66
+ end
67
+ end
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'rspec'
4
+ require 'cucumber/messages'
5
+ require_relative '../../lib/messages_comparator'
6
+
7
+ describe CCK::MessagesComparator do
8
+ context 'when executed as part of a CI' do
9
+ before { allow(ENV).to receive(:[]).with('CI').and_return(true) }
10
+
11
+ let(:ci_message) { Cucumber::Messages::Ci.new(name: 'Some CI') }
12
+ let(:blank_meta_message) { Cucumber::Messages::Meta.new }
13
+ let(:filled_meta_message) { Cucumber::Messages::Meta.new(ci: ci_message) }
14
+ let(:ci_message_envelope) { Cucumber::Messages::Envelope.new(meta: filled_meta_message) }
15
+ let(:meta_message_envelope) { Cucumber::Messages::Envelope.new(meta: blank_meta_message) }
16
+
17
+ it 'ignores any detected CI messages' do
18
+ comparator = described_class.new(CCK::KeysChecker, [ci_message_envelope], [meta_message_envelope])
19
+
20
+ expect(comparator.errors).to be_empty
21
+ end
22
+
23
+ it 'ignores any expected CI messages' do
24
+ comparator = described_class.new(CCK::KeysChecker, [meta_message_envelope], [ci_message_envelope])
25
+
26
+ expect(comparator.errors).to be_empty
27
+ end
28
+ end
29
+ end
@@ -1,8 +1,10 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'cucumber-compatibility-kit'
2
4
 
3
5
  describe Cucumber::CompatibilityKit do
4
- let(:features_path) { File.expand_path("#{File.dirname(__FILE__)}/../features") }
5
- let(:gherkin_examples) {
6
+ let(:features_path) { File.expand_path("#{File.dirname(__FILE__)}/../../features") }
7
+ let(:gherkin_examples) do
6
8
  [
7
9
  'attachments',
8
10
  'cdata',
@@ -19,54 +21,45 @@ describe Cucumber::CompatibilityKit do
19
21
  'undefined',
20
22
  'unknown-parameter-type'
21
23
  ]
22
- }
23
- let(:markdown_examples) {
24
- [
25
- 'markdown'
26
- ]
27
- }
24
+ end
25
+ let(:markdown_examples) { ['markdown'] }
28
26
 
29
27
  describe '#examples_path' do
30
28
  it 'returns the path of the features folder' do
31
- expect(Cucumber::CompatibilityKit.examples_path)
32
- .to eq(features_path)
29
+ expect(described_class.examples_path).to eq(features_path)
33
30
  end
34
31
  end
35
32
 
36
33
  describe '#example_path' do
37
34
  context 'with an existing example' do
38
35
  it 'returns the path of the folder of the example' do
39
- expect(Cucumber::CompatibilityKit.example_path('hooks'))
40
- .to eq("#{features_path}/hooks")
36
+ expect(described_class.example_path('hooks')).to eq("#{features_path}/hooks")
41
37
  end
42
38
  end
43
39
 
44
- context 'with an unexisting example' do
40
+ context 'with an non-existent example' do
45
41
  it 'raises ArgumentError' do
46
- expect { Cucumber::CompatibilityKit.example_path('should-not-exists') }
47
- .to raise_error(ArgumentError)
42
+ expect { described_class.example_path('should-not-exists') }.to raise_error(ArgumentError)
48
43
  end
49
44
  end
50
45
  end
51
46
 
52
47
  describe '#gherkin_examples' do
53
48
  it 'returns the list of gherkin examples' do
54
- expect(Cucumber::CompatibilityKit.gherkin_examples)
55
- .to match_array(gherkin_examples)
49
+ expect(described_class.gherkin_examples).to match_array(gherkin_examples)
56
50
  end
57
51
  end
58
52
 
59
53
  describe '#markdown_examples' do
60
54
  it 'returns the list of markdown examples' do
61
- expect(Cucumber::CompatibilityKit.markdown_examples)
62
- .to match_array(markdown_examples)
55
+ expect(described_class.markdown_examples).to match_array(markdown_examples)
63
56
  end
64
57
  end
65
58
 
66
59
  describe '#all_examples' do
67
60
  it 'returns the list of all available examples' do
68
- expect(Cucumber::CompatibilityKit.all_examples)
61
+ expect(described_class.all_examples)
69
62
  .to match_array(gherkin_examples + markdown_examples)
70
63
  end
71
64
  end
72
- end
65
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cucumber-compatibility-kit
3
3
  version: !ruby/object:Gem::Version
4
- version: 12.0.0
4
+ version: 13.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Aurélien Reeves
@@ -11,7 +11,7 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2023-07-08 00:00:00.000000000 Z
14
+ date: 2023-10-11 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: cucumber-messages
@@ -59,20 +59,70 @@ dependencies:
59
59
  requirements:
60
60
  - - "~>"
61
61
  - !ruby/object:Gem::Version
62
- version: '3.11'
63
- - - ">="
64
- - !ruby/object:Gem::Version
65
- version: 3.11.0
62
+ version: '3.12'
66
63
  type: :runtime
67
64
  prerelease: false
68
65
  version_requirements: !ruby/object:Gem::Requirement
69
66
  requirements:
70
67
  - - "~>"
71
68
  - !ruby/object:Gem::Version
72
- version: '3.11'
73
- - - ">="
69
+ version: '3.12'
70
+ - !ruby/object:Gem::Dependency
71
+ name: rubocop
72
+ requirement: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - "~>"
75
+ - !ruby/object:Gem::Version
76
+ version: 1.17.0
77
+ type: :development
78
+ prerelease: false
79
+ version_requirements: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - "~>"
82
+ - !ruby/object:Gem::Version
83
+ version: 1.17.0
84
+ - !ruby/object:Gem::Dependency
85
+ name: rubocop-performance
86
+ requirement: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - "~>"
89
+ - !ruby/object:Gem::Version
90
+ version: 1.7.0
91
+ type: :development
92
+ prerelease: false
93
+ version_requirements: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - "~>"
96
+ - !ruby/object:Gem::Version
97
+ version: 1.7.0
98
+ - !ruby/object:Gem::Dependency
99
+ name: rubocop-rake
100
+ requirement: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - "~>"
103
+ - !ruby/object:Gem::Version
104
+ version: 0.5.0
105
+ type: :development
106
+ prerelease: false
107
+ version_requirements: !ruby/object:Gem::Requirement
108
+ requirements:
109
+ - - "~>"
110
+ - !ruby/object:Gem::Version
111
+ version: 0.5.0
112
+ - !ruby/object:Gem::Dependency
113
+ name: rubocop-rspec
114
+ requirement: !ruby/object:Gem::Requirement
115
+ requirements:
116
+ - - "~>"
117
+ - !ruby/object:Gem::Version
118
+ version: 2.0.0
119
+ type: :development
120
+ prerelease: false
121
+ version_requirements: !ruby/object:Gem::Requirement
122
+ requirements:
123
+ - - "~>"
74
124
  - !ruby/object:Gem::Version
75
- version: 3.11.0
125
+ version: 2.0.0
76
126
  description: Kit to check compatibility with official cucumber implementation
77
127
  email: cukebot@cucumber.io
78
128
  executables: []
@@ -83,6 +133,7 @@ files:
83
133
  - features/attachments/attachments.feature
84
134
  - features/attachments/attachments.feature.ndjson
85
135
  - features/attachments/attachments.feature.rb
136
+ - features/attachments/cucumber.jpeg
86
137
  - features/attachments/cucumber.png
87
138
  - features/attachments/document.pdf
88
139
  - features/cdata/cdata.feature
@@ -127,14 +178,17 @@ files:
127
178
  - features/unknown-parameter-type/unknown-parameter-type.feature
128
179
  - features/unknown-parameter-type/unknown-parameter-type.feature.ndjson
129
180
  - features/unknown-parameter-type/unknown-parameter-type.feature.rb
181
+ - lib/cck/helpers.rb
182
+ - lib/cck/keys_checker.rb
183
+ - lib/cck/messages_comparator.rb
130
184
  - lib/cucumber-compatibility-kit.rb
185
+ - lib/cucumber/cucumber-compatibility-kit.rb
131
186
  - lib/keys_checker.rb
132
187
  - lib/messages_comparator.rb
133
188
  - lib/shared_examples.rb
134
- - spec/capture_warnings.rb
135
- - spec/cucumber-compatibility-kit_spec.rb
136
- - spec/keys_checker_spec.rb
137
- - spec/messages_comparator_spec.rb
189
+ - spec/cck/keys_checker_spec.rb
190
+ - spec/cck/messages_comparator_spec.rb
191
+ - spec/cucumber/cucumber-compatibility-kit_spec.rb
138
192
  homepage: https://github.com/cucumber/compatibility-kit
139
193
  licenses:
140
194
  - MIT
@@ -153,19 +207,18 @@ required_ruby_version: !ruby/object:Gem::Requirement
153
207
  requirements:
154
208
  - - ">="
155
209
  - !ruby/object:Gem::Version
156
- version: '2.3'
210
+ version: '2.5'
157
211
  required_rubygems_version: !ruby/object:Gem::Requirement
158
212
  requirements:
159
213
  - - ">="
160
214
  - !ruby/object:Gem::Version
161
215
  version: '0'
162
216
  requirements: []
163
- rubygems_version: 3.2.33
217
+ rubygems_version: 3.4.10
164
218
  signing_key:
165
219
  specification_version: 4
166
- summary: cucumber-compatibility-kit-12.0.0
220
+ summary: cucumber-compatibility-kit-13.0.1
167
221
  test_files:
168
- - spec/capture_warnings.rb
169
- - spec/cucumber-compatibility-kit_spec.rb
170
- - spec/keys_checker_spec.rb
171
- - spec/messages_comparator_spec.rb
222
+ - spec/cck/keys_checker_spec.rb
223
+ - spec/cck/messages_comparator_spec.rb
224
+ - spec/cucumber/cucumber-compatibility-kit_spec.rb
@@ -1,74 +0,0 @@
1
- # frozen_string_literal: true
2
- # With thanks to @myronmarston
3
- # https://github.com/vcr/vcr/blob/master/spec/capture_warnings.rb
4
-
5
- module CaptureWarnings
6
- def report_warnings(&block)
7
- current_dir = Dir.pwd
8
- warnings, errors = capture_error(&block).partition { |line| line.include?('warning') }
9
- project_warnings, other_warnings = warnings.uniq.partition { |line| line.include?(current_dir) }
10
-
11
- if errors.any?
12
- puts errors.join("\n")
13
- end
14
-
15
- if other_warnings.any?
16
- puts "#{ other_warnings.count } warnings detected, set VIEW_OTHER_WARNINGS=true to see them."
17
- print_warnings('other', other_warnings) if ENV['VIEW_OTHER_WARNINGS']
18
- end
19
-
20
- # Until they fix https://bugs.ruby-lang.org/issues/10661
21
- if RUBY_VERSION == "2.2.0"
22
- project_warnings = project_warnings.reject { |w| w =~ /warning: possible reference to past scope/ }
23
- end
24
-
25
- if project_warnings.any?
26
- puts "#{ project_warnings.count } warnings detected"
27
- print_warnings('cucumber-expressions', project_warnings)
28
- fail "Please remove all cucumber-expressions warnings."
29
- end
30
-
31
- ensure_system_exit_if_required
32
- end
33
-
34
- def capture_error(&block)
35
- old_stderr = STDERR.clone
36
- pipe_r, pipe_w = IO.pipe
37
- pipe_r.sync = true
38
- error = String.new
39
- reader = Thread.new do
40
- begin
41
- loop do
42
- error << pipe_r.readpartial(1024)
43
- end
44
- rescue EOFError
45
- end
46
- end
47
- STDERR.reopen(pipe_w)
48
- block.call
49
- ensure
50
- capture_system_exit
51
- STDERR.reopen(old_stderr)
52
- pipe_w.close
53
- reader.join
54
- return error.split("\n")
55
- end
56
-
57
- def print_warnings(type, warnings)
58
- puts
59
- puts "-" * 30 + " #{type} warnings: " + "-" * 30
60
- puts
61
- puts warnings.join("\n")
62
- puts
63
- puts "-" * 75
64
- puts
65
- end
66
-
67
- def ensure_system_exit_if_required
68
- raise @system_exit if @system_exit
69
- end
70
-
71
- def capture_system_exit
72
- @system_exit = $!
73
- end
74
- end
@@ -1,106 +0,0 @@
1
- require 'rspec'
2
- require 'cucumber/messages'
3
- require_relative '../lib/keys_checker'
4
-
5
- describe CCK::KeysChecker do
6
- let(:subject) { CCK::KeysChecker }
7
-
8
- describe '#compare' do
9
- let(:complete) do
10
- Cucumber::Messages::PickleStepArgument.new(
11
- doc_string: '1',
12
- data_table: '12'
13
- )
14
- end
15
-
16
- let(:missing_data_table) do
17
- Cucumber::Messages::PickleStepArgument.new(
18
- doc_string: '1'
19
- )
20
- end
21
-
22
- let(:missing_doc_string) do
23
- Cucumber::Messages::PickleStepArgument.new(
24
- data_table: '12'
25
- )
26
- end
27
-
28
- let(:wrong_values) do
29
- Cucumber::Messages::PickleStepArgument.new(
30
- doc_string: '123',
31
- data_table: '456'
32
- )
33
- end
34
-
35
- it 'finds missing key' do
36
- expect(subject.compare(missing_data_table, complete)).to eq(
37
- ['Missing keys in message Cucumber::Messages::PickleStepArgument: [:data_table]']
38
- )
39
- end
40
-
41
- it 'finds extra keys' do
42
- expect(subject.compare(complete, missing_doc_string)).to eq(
43
- ['Found extra keys in message Cucumber::Messages::PickleStepArgument: [:doc_string]']
44
- )
45
- end
46
-
47
- it 'finds extra and missing' do
48
- expect(subject.compare(missing_doc_string, missing_data_table)).to contain_exactly(
49
- 'Missing keys in message Cucumber::Messages::PickleStepArgument: [:doc_string]',
50
- 'Found extra keys in message Cucumber::Messages::PickleStepArgument: [:data_table]'
51
- )
52
- end
53
-
54
- it 'does not care about the values' do
55
- expect(subject.compare(complete, wrong_values)).to be_empty
56
- end
57
-
58
- context 'when default values are omitted' do
59
- let(:default_set) do
60
- Cucumber::Messages::Duration.new(
61
- seconds: 0,
62
- nanos: 12
63
- )
64
- end
65
-
66
- let(:default_not_set) do
67
- Cucumber::Messages::Duration.new(
68
- nanos: 12
69
- )
70
- end
71
-
72
- it 'does not raise an exception' do
73
- expect(subject.compare(default_set, default_not_set)).to be_empty
74
- end
75
- end
76
-
77
- context 'when executed as part of a CI' do
78
- before do
79
- allow(ENV).to receive(:[]).with('CI').and_return(true)
80
- end
81
-
82
- it 'ignores actual CI related messages' do
83
- found = Cucumber::Messages::Meta.new(
84
- ci: Cucumber::Messages::Ci.new(name: 'Some CI')
85
- )
86
-
87
- expected = Cucumber::Messages::Meta.new
88
-
89
- expect(subject.compare(found, expected)).to be_empty
90
- end
91
- end
92
-
93
- context 'when an unexcpected error occurs' do
94
- it 'does not raise error' do
95
- expect {
96
- subject.compare(nil, nil)
97
- }.not_to raise_error
98
- end
99
-
100
- it 'returns the error' do
101
- expect(subject.compare(nil, nil))
102
- .to eq(['Unexpected error: wrong number of arguments (given 1, expected 0)'])
103
- end
104
- end
105
- end
106
- end
@@ -1,26 +0,0 @@
1
- require 'rspec'
2
- require 'cucumber/messages'
3
- require_relative '../lib/messages_comparator'
4
-
5
- describe CCK::MessagesComparator do
6
- subject() { CCK::MessagesComparator }
7
-
8
- context 'when executed as part of a CI' do
9
- before do
10
- allow(ENV).to receive(:[]).with('CI').and_return(true)
11
- end
12
-
13
- it 'ignores actual CI related messages' do
14
- found_message_ci = Cucumber::Messages::Ci.new(name: 'Some CI')
15
- found_message_meta = Cucumber::Messages::Meta.new(ci: found_message_ci)
16
- found_message_envelope = Cucumber::Messages::Envelope.new(meta: found_message_meta)
17
-
18
- expected_message_meta = Cucumber::Messages::Meta.new()
19
- expected_message_envelope = Cucumber::Messages::Envelope.new(meta: expected_message_meta)
20
-
21
- comparator = subject.new(CCK::KeysChecker, [found_message_envelope], [expected_message_envelope])
22
-
23
- expect(comparator.errors).to be_empty
24
- end
25
- end
26
- end