gurke 3.4.0 → 3.5.0

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b6701a22fdedaffd847fa2cb45077bed6d3bbbf7f6c1faf996a9908bac7ca335
4
- data.tar.gz: 621bf975bcaf87268a5f98e28b7a15830820d4eef866fcccc74766c15ceecbf8
3
+ metadata.gz: f25197fd297ba62d42f9d4895bd3df3bd556882cd5fc66769b0bb717ebe1c16e
4
+ data.tar.gz: fd92245e82302cd497b236ba92bbcb14917dbcee30cbc0923c8ce9c9867de028
5
5
  SHA512:
6
- metadata.gz: 3933d5b317b1da87502c1c171b39e48975184720ae9924196c6e05ddfbf922b26ec75c5ce39df087d4a9e51e5f331ec60c435a3bc81bcb31d0166e2ebe8369d4
7
- data.tar.gz: 4e2d338ef6266709da78fd237906e20cd49839d4e0e55e4005251815b4802924d35436841e15a5b48ea13793dedf1876ce9b9ef157b62c934a0fdb00cb2fe5c5
6
+ metadata.gz: 914606fbd5b71e005980a8dec79d0842093d544299282018a2c0b2cbc4cbdce35dcbf6aa30799417ec1fca855a07bfbf958aa7abaf9f737a698b3f99b887426b
7
+ data.tar.gz: 0cd6bb85c10f9edcea212902844cc6417c857133584b1f852d31b5ae75707c8c9f2cdbec17b227f7303f90ebfe30e13eae41a54ab8b5fc852464e50e584760e8
data/CHANGELOG.md CHANGED
@@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## [3.5.0] - 2025-04-09
11
+
12
+ ### Added
13
+
14
+ - Add `--color=[(auto)|on|off]` command line flag
15
+
10
16
  ## [3.4.0] - 2024-08-28
11
17
 
12
18
  ### Added
@@ -130,7 +136,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
130
136
 
131
137
  ## [1.0.0] - 2013-12-04
132
138
 
133
- [Unreleased]: https://github.com/jgraichen/gurke/compare/v3.4.0...HEAD
139
+ [Unreleased]: https://github.com/jgraichen/gurke/compare/v3.5.0...HEAD
140
+ [3.5.0]: https://github.com/jgraichen/gurke/compare/v3.4.0...v3.5.0
134
141
  [3.4.0]: https://github.com/jgraichen/gurke/compare/v3.3.5...v3.4.0
135
142
  [3.3.5]: https://github.com/jgraichen/gurke/compare/v3.3.4...v3.3.5
136
143
  [3.3.4]: https://github.com/jgraichen/gurke/compare/v3.3.3...v3.3.4
data/gurke.gemspec CHANGED
@@ -28,5 +28,4 @@ Gem::Specification.new do |spec|
28
28
 
29
29
  spec.add_dependency 'colorize'
30
30
  spec.add_dependency 'gherkin', '~> 2.0'
31
- spec.add_dependency 'optimist', '~> 3.0'
32
31
  end
data/lib/gurke/cli.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'optimist'
3
+ require 'optparse'
4
4
 
5
5
  module Gurke
6
6
  class CLI
@@ -10,13 +10,103 @@ module Gurke
10
10
  # @param argv [Array<String>] Tokenized argument list.
11
11
  #
12
12
  def run(argv)
13
- call parser.parse(argv), argv
14
- rescue Optimist::VersionNeeded
15
- print_version && exit
16
- rescue Optimist::HelpNeeded
17
- print_help && exit
18
- rescue Optimist::CommandlineError => e
19
- warn "Error: #{e}"
13
+ options = {
14
+ backtrace: false,
15
+ drb_server: false,
16
+ drb: false,
17
+ force_color: false,
18
+ formatter: 'default',
19
+ pattern: 'features/**/*.feature',
20
+ require: [],
21
+ tags: [],
22
+ }
23
+
24
+ OptionParser.new do |opts| # rubocop:disable Metrics/BlockLength
25
+ opts.banner = 'Usage: gurke [options] [files...]'
26
+
27
+ opts.on('-h', '--help', 'Print this help.') do
28
+ puts opts
29
+ exit
30
+ end
31
+
32
+ opts.on('-v', '--version', 'Show program version information.') do
33
+ puts "gurke v#{Gurke::VERSION}"
34
+ exit
35
+ end
36
+
37
+ opts.on('-b', '--backtrace', 'Show full error backtraces.') do
38
+ options[:backtrace] = true
39
+ end
40
+
41
+ opts.on(
42
+ '-f', '--formatter=<s>',
43
+ 'Select a special formatter as reporter (default: "default")',
44
+ ) do |arg|
45
+ options[:formatter] = arg.to_s
46
+ end
47
+
48
+ opts.on(
49
+ '-r', '--require=<s>',
50
+ 'Files matching this pattern will be required after loading ' \
51
+ 'environment but before running features. ' \
52
+ '(Default: features/steps/**/*.rb, features/support/steps/**/*.rb)',
53
+ ) do |arg|
54
+ options[:require] << arg.to_s
55
+ end
56
+
57
+ opts.on(
58
+ '-t', '--tags=<s>',
59
+ 'Only run features and scenarios matching given tag ' \
60
+ 'filtering expression. (Default: ~wip)',
61
+ ) do |arg|
62
+ options[:tags] << arg.to_s
63
+ end
64
+
65
+ opts.on(
66
+ '-p', '--pattern=<s>',
67
+ 'File pattern matching feature files to be run. (Default: features/**/*.feature)',
68
+ ) do |arg|
69
+ options[:pattern] = arg.to_s
70
+ end
71
+
72
+ opts.on('--drb', 'Run features on already started DRb server. (experimental)') do
73
+ options[:drb] = true
74
+ end
75
+
76
+ opts.on('--drb-server', 'Run features on already started DRb server. (experimental)') do
77
+ options[:drb_server] = true
78
+ end
79
+
80
+ opts.on('-c', '--color=<mode>', 'Colored output (default: "auto")') do |arg|
81
+ value = arg.to_s.downcase
82
+ if value == 'auto'
83
+ options[:color] = :auto
84
+ elsif %w[1 yes on true t force].include?(value)
85
+ options[:color] = true
86
+ elsif %w[0 no off false f].include?(value)
87
+ options[:color] = false
88
+ else
89
+ warn "Invalid value for color: #{value}"
90
+ warn 'Supported values are: 0, 1, yes, no, true, false, t, f, force, auto'
91
+ exit 255
92
+ end
93
+ end
94
+ end.parse!(argv)
95
+
96
+ if options[:require].empty?
97
+ options[:require] << 'features/steps/**/*.rb'
98
+ options[:require] << 'features/support/steps/**/*.rb'
99
+ end
100
+
101
+ if options[:tags].empty?
102
+ options[:tags] << '~wip'
103
+ end
104
+
105
+ pp options
106
+
107
+ call(options, argv)
108
+ rescue OptionParser::InvalidOption => e
109
+ warn e.message
20
110
  warn "Run with `-h' for more information on available arguments."
21
111
  exit 255
22
112
  end
@@ -45,40 +135,6 @@ module Gurke
45
135
  Kernel.exit runner.run files
46
136
  end
47
137
 
48
- def print_version
49
- $stdout.puts <<~VSTR
50
- gurke v#{Gurke::VERSION}
51
- VSTR
52
- end
53
-
54
- def print_help
55
- parser.educate($stdout)
56
- end
57
-
58
- def parser
59
- @parser ||= Optimist::Parser.new do
60
- opt :help, 'Print this help.'
61
- opt :version, 'Show program version information.'
62
- opt :backtrace, 'Show full error backtraces.'
63
- opt :formatter, 'Select a special formatter as reporter', \
64
- default: 'default'
65
- opt :pattern, 'File pattern matching feature files to be run.',
66
- default: 'features/**/*.feature'
67
- opt :require, 'Files matching this pattern will be required after' \
68
- 'loading environment but before running features.',
69
- default: ['features/steps/**/*.rb',
70
- 'features/support/steps/**/*.rb',],
71
- multi: true
72
- opt :tags, 'Only run features and scenarios matching given tag ' \
73
- 'filtering expression. TODO: Description.',
74
- default: ['~wip'],
75
- multi: true
76
- opt :drb_server, 'Run gurke DRb server. (experimental)', short: :none
77
- opt :drb, 'Run features on already started DRb server. (experimental)',
78
- short: :none
79
- end
80
- end
81
-
82
138
  private
83
139
 
84
140
  def expand_files(files, options)
@@ -36,6 +36,8 @@ module Gurke
36
36
  retry_scenario
37
37
  ].freeze
38
38
 
39
+ def initialize(**kwargs); end
40
+
39
41
  # Called before the execution of any feature and before any
40
42
  # before-features hook is invoked.
41
43
  #
@@ -293,7 +295,7 @@ module Gurke
293
295
  end
294
296
  end
295
297
 
296
- if err.respond_to?(:cause) && err.cause && err.cause.respond_to?(:message)
298
+ if err.respond_to?(:cause) && err.cause.respond_to?(:message)
297
299
  s << (' ' * indent) << 'caused by: '
298
300
  s << format_exception(
299
301
  err.cause, backtrace: backtrace, indent: indent,
@@ -0,0 +1,41 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'colorize'
4
+
5
+ # Colors
6
+ # :black, :red, :green, :yellow, :blue,
7
+ # :magenta, :cyan, :white, :default, :light_black,
8
+ # :light_red, :light_green, :light_yellow, :light_blue,
9
+ # :light_magenta, :light_cyan, :light_white
10
+ #
11
+ module Gurke::Reporters
12
+ module Colored
13
+ def initialize(color: nil, **kwargs)
14
+ super(**kwargs)
15
+
16
+ case color
17
+ when :auto, nil
18
+ @colored = io.tty?
19
+ when TrueClass
20
+ @colored = true
21
+ when FalseClass
22
+ @colored = false
23
+ end
24
+ end
25
+
26
+ def color?
27
+ (@color == :auto && io.tty?) || @color
28
+ end
29
+
30
+ protected
31
+
32
+ %i[black red green yellow blue
33
+ magenta cyan white default light_black
34
+ light_red light_green light_yellow light_blue
35
+ light_magenta light_cyan light_white].each do |color|
36
+ define_method(color) do |str|
37
+ @colored ? str.send(color) : str
38
+ end
39
+ end
40
+ end
41
+ end
@@ -1,20 +1,14 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'colorize'
4
-
5
- # Colors
6
- # :black, :red, :green, :yellow, :blue,
7
- # :magenta, :cyan, :white, :default, :light_black,
8
- # :light_red, :light_green, :light_yellow, :light_blue,
9
- # :light_magenta, :light_cyan, :light_white
10
- #
11
3
  module Gurke::Reporters
12
4
  class CompactReporter < NullReporter
5
+ include Colored
6
+
13
7
  attr_reader :io
14
8
 
15
- def initialize(io = $stdout)
16
- super()
9
+ def initialize(io: $stdout, **kwargs)
17
10
  @io = io
11
+ super(**kwargs)
18
12
  end
19
13
 
20
14
  def after_step(result, scenario, *)
@@ -125,12 +119,5 @@ module Gurke::Reporters
125
119
 
126
120
  light_black("# #{path}:#{line}")
127
121
  end
128
-
129
- %i[black red green yellow blue
130
- magenta cyan white default light_black
131
- light_red light_green light_yellow light_blue
132
- light_magenta light_cyan light_white].each do |color|
133
- define_method(color) {|str| io.tty? ? str.send(color) : str }
134
- end
135
122
  end
136
123
  end
@@ -1,11 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Colors
4
- # :black, :red, :green, :yellow, :blue,
5
- # :magenta, :cyan, :white, :default, :light_black,
6
- # :light_red, :light_green, :light_yellow, :light_blue,
7
- # :light_magenta, :light_cyan, :light_white
8
- #
9
3
  module Gurke::Reporters
10
4
  #
11
5
  # The {DefaultReporter} prints features, scenarios and
@@ -14,11 +8,13 @@ module Gurke::Reporters
14
8
  # That includes colorized step results reports etc.
15
9
  #
16
10
  class DefaultReporter < NullReporter
11
+ include Colored
12
+
17
13
  attr_reader :io
18
14
 
19
- def initialize(io = $stdout)
20
- super()
15
+ def initialize(io: $stdout, **kwargs)
21
16
  @io = io
17
+ super(**kwargs)
22
18
  end
23
19
 
24
20
  def before_feature(feature)
@@ -155,12 +151,5 @@ module Gurke::Reporters
155
151
 
156
152
  light_black("# #{path}:#{line}")
157
153
  end
158
-
159
- %i[black red green yellow blue
160
- magenta cyan white default light_black
161
- light_red light_green light_yellow light_blue
162
- light_magenta light_cyan light_white].each do |color|
163
- define_method(color) {|str| io.tty? ? str.send(color) : str }
164
- end
165
154
  end
166
155
  end
data/lib/gurke/runner.rb CHANGED
@@ -16,7 +16,7 @@ module Gurke
16
16
  .map(&:capitalize)
17
17
  .join
18
18
 
19
- Reporters.const_get(r).new
19
+ Reporters.const_get(r).new(color: options[:color])
20
20
  end
21
21
  end
22
22
 
data/lib/gurke/version.rb CHANGED
@@ -3,7 +3,7 @@
3
3
  module Gurke
4
4
  module VERSION
5
5
  MAJOR = 3
6
- MINOR = 4
6
+ MINOR = 5
7
7
  PATCH = 0
8
8
  STAGE = nil
9
9
  STRING = [MAJOR, MINOR, PATCH, STAGE].compact.join('.').freeze
data/lib/gurke.rb CHANGED
@@ -23,6 +23,8 @@ module Gurke
23
23
  require 'gurke/world'
24
24
 
25
25
  module Reporters
26
+ require 'gurke/reporters/colored'
27
+
26
28
  require 'gurke/reporters/null_reporter'
27
29
  require 'gurke/reporters/compact_reporter'
28
30
  require 'gurke/reporters/default_reporter'
@@ -6,7 +6,7 @@ require 'spec_helper'
6
6
 
7
7
  RSpec.describe Gurke::Reporters::CompactReporter do
8
8
  subject(:out) do
9
- reporter = described_class.new(StringIO.new)
9
+ reporter = described_class.new(io: StringIO.new)
10
10
  reporter.send(*action)
11
11
  reporter.io.string
12
12
  end
@@ -6,11 +6,13 @@ require 'spec_helper'
6
6
 
7
7
  RSpec.describe Gurke::Reporters::DefaultReporter do
8
8
  subject(:out) do
9
- reporter = described_class.new(StringIO.new)
9
+ reporter = described_class.new(io: StringIO.new, color: color)
10
10
  reporter.send(*action)
11
11
  reporter.io.string
12
12
  end
13
13
 
14
+ let(:color) { nil }
15
+
14
16
  let(:feature) { instance_double(Gurke::Feature) }
15
17
  let(:scenario) { instance_double(Gurke::Scenario) }
16
18
  let(:step) { instance_double(Gurke::Step) }
@@ -37,6 +39,21 @@ RSpec.describe Gurke::Reporters::DefaultReporter do
37
39
  .
38
40
  TEXT
39
41
  end
42
+
43
+ context 'with colors' do
44
+ let(:color) { true }
45
+
46
+ it 'outputs ASCII color codes' do
47
+ expect(out).to eq unindent <<~TEXT
48
+ \e[0;33;49mFeature\e[0m: Demo feature \e[0;90;49m# features/file.feature:1\e[0m
49
+ \e[0;90;49m As a developer
50
+ I would like have this spec passed
51
+ In order to work on\e[0m
52
+ .
53
+ .
54
+ TEXT
55
+ end
56
+ end
40
57
  end
41
58
 
42
59
  describe '#start_background' do
@@ -6,7 +6,7 @@ require 'spec_helper'
6
6
 
7
7
  RSpec.describe Gurke::Reporters::TeamCityReporter do
8
8
  subject(:statements) do
9
- reporter = described_class.new(StringIO.new)
9
+ reporter = described_class.new(io: StringIO.new)
10
10
  reporter.send(*action)
11
11
  reporter.io.string.scan(/##teamcity\[.*\]/)
12
12
  end
metadata CHANGED
@@ -1,14 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gurke
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.4.0
4
+ version: 3.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jan Graichen
8
- autorequire:
9
8
  bindir: bin
10
9
  cert_chain: []
11
- date: 2024-08-28 00:00:00.000000000 Z
10
+ date: 2025-04-09 00:00:00.000000000 Z
12
11
  dependencies:
13
12
  - !ruby/object:Gem::Dependency
14
13
  name: colorize
@@ -38,21 +37,6 @@ dependencies:
38
37
  - - "~>"
39
38
  - !ruby/object:Gem::Version
40
39
  version: '2.0'
41
- - !ruby/object:Gem::Dependency
42
- name: optimist
43
- requirement: !ruby/object:Gem::Requirement
44
- requirements:
45
- - - "~>"
46
- - !ruby/object:Gem::Version
47
- version: '3.0'
48
- type: :runtime
49
- prerelease: false
50
- version_requirements: !ruby/object:Gem::Requirement
51
- requirements:
52
- - - "~>"
53
- - !ruby/object:Gem::Version
54
- version: '3.0'
55
- description:
56
40
  email:
57
41
  - jgraichen@altimos.de
58
42
  executables:
@@ -90,6 +74,7 @@ files:
90
74
  - lib/gurke/feature.rb
91
75
  - lib/gurke/feature_list.rb
92
76
  - lib/gurke/reporter.rb
77
+ - lib/gurke/reporters/colored.rb
93
78
  - lib/gurke/reporters/compact_reporter.rb
94
79
  - lib/gurke/reporters/default_reporter.rb
95
80
  - lib/gurke/reporters/null_reporter.rb
@@ -118,7 +103,6 @@ licenses:
118
103
  - MIT
119
104
  metadata:
120
105
  rubygems_mfa_required: 'true'
121
- post_install_message:
122
106
  rdoc_options: []
123
107
  require_paths:
124
108
  - lib
@@ -133,8 +117,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
133
117
  - !ruby/object:Gem::Version
134
118
  version: '0'
135
119
  requirements: []
136
- rubygems_version: 3.5.17
137
- signing_key:
120
+ rubygems_version: 3.6.2
138
121
  specification_version: 4
139
122
  summary: An alternative gherkin feature runner inspired by rspec and turnip.
140
123
  test_files: []