flakie 1.0.0 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 75a64b188fc68b39cab7b3aabff3dfbd63300475f2d0d185a0577b251c91160e
4
- data.tar.gz: 2d1df7b06d7bf31d67b97008cf0439de8bf69ef98735d922973430e4a064126f
3
+ metadata.gz: 8fb34ac8ca43a45eed4f1f0d44c6c2e7bb42165dcb88b62b7493bdd63baf9b9e
4
+ data.tar.gz: 6c847cdcbe2c5456446179ca25254333f9f24e78fd777a5d8ee8841786d9248a
5
5
  SHA512:
6
- metadata.gz: 77220c649e9b013180760cee5306b0abd1db9cf047f1c684e92cd85127e06f11dc77f60c52f76b4f6ecd7ea7f54c285e3876b614f2c374e85fe4924d42ca231f
7
- data.tar.gz: 5e2314d28ae93bfb3123cd0c49491801756178280bb001caef0f4d96691127b2fc1b7c21552a751fd7750030723e670a48eae766b6f7a94f6f8e52179477a25d
6
+ metadata.gz: 52c5846a7221fe468ebd6edcddda83166f6d97b95174101057de62869b40450a67c022da65eeeb5d02c4947f74159c76bdaa65ef19c73adb31be3e33007557b3
7
+ data.tar.gz: a5d9e8418b723cfd717e5f5eaf5dd2012c70335ce371466bcfb8c473207784538575fe1517348219cc919f771936e809bc519ed9bfcb03dcad6bce66be2857ab
data/.rubocop.yml CHANGED
@@ -25,6 +25,9 @@ Metrics/AbcSize:
25
25
  Metrics/MethodLength:
26
26
  Enabled: false
27
27
 
28
+ RSpec/MultipleExpectations:
29
+ Enabled: false
30
+
28
31
  Style/Documentation:
29
32
  Enabled: false
30
33
 
data/lefthook.yml CHANGED
@@ -10,8 +10,10 @@ pre-commit:
10
10
  rspec:
11
11
  run: bundle exec rspec
12
12
  rubocop:
13
- files: git ls-files **/*.rb
14
- run: bundle exec rubocop --fail-fast {files}
13
+ files: "git diff --name-only --staged"
14
+ glob: "{Gemfile,Rakefile,*.gemspec,*.rb}"
15
+ run: bundle exec rubocop --parallel {files}
15
16
  stree:
16
- files: git ls-files **/*.rb
17
+ files: "git diff --name-only --staged"
18
+ glob: "{Rakefile,*.gemspec,*.rb}"
17
19
  run: bundle exec stree check {files}
@@ -3,26 +3,11 @@
3
3
  module Flakie
4
4
  module CLI
5
5
  Options =
6
- Struct.new(:count, :env, :format, :output, :help, :version) do
7
- def self.default = new(count: 5, env: {}, format: :tictactoe, output: $stdout, help: false, version: false)
6
+ Struct.new(:count, :format, :output, :help, :version) do
7
+ def self.default = new(count: 5, format: :tictactoe, output: $stdout, help: false, version: false)
8
8
  def self.from(args) = default.tap { |options| Parser.parse!(args, into: options) }
9
9
 
10
- def []=(key, value)
11
- if key == :env
12
- add_env(value)
13
- else
14
- super
15
- end
16
- end
17
-
18
- def add_env(raw)
19
- name, value = raw.split("=")
20
- CLI.exit_with_error("Bad env variable format: #{raw}") if name.nil? || value.nil?
21
-
22
- env[name] = value
23
- end
24
-
25
- def formatter = Formatters::ALL.fetch(format)
10
+ def reporter = Reporters::ALL.fetch(format)
26
11
 
27
12
  def help? = help
28
13
  def version? = version
@@ -4,22 +4,20 @@ module Flakie
4
4
  module CLI
5
5
  Parser =
6
6
  OptionParser.new do |opts|
7
- opts.banner = "USAGE: #{PROGRAM_NAME} [OPTIONS] COMMAND"
7
+ opts.banner = "USAGE: #{NAME} [OPTIONS] COMMAND"
8
8
  opts.separator ""
9
9
 
10
- opts.version = "#{PROGRAM_NAME} #{VERSION}"
10
+ opts.version = "#{NAME} #{VERSION}"
11
11
 
12
12
  opts.separator "OPTIONS:"
13
13
  opts.on("-n", "--count COUNT", Integer, "Number of tries (default: #{Options.default.count})")
14
14
 
15
15
  opts.on("-f", "--format FORMATTER", "Output format. See FORMATTERS section below.") do |choice|
16
- Formatters::ALL.include?(choice.to_sym) ? choice.to_sym : CLI.exit_with_error("Invalid format: #{choice}")
16
+ Reporters::ALL.include?(choice.to_sym) ? choice.to_sym : CLI.fail("Invalid format: #{choice}")
17
17
  end
18
18
 
19
19
  opts.on("-o", "--output FILE", "File to output result. Defaults to STDOUT.") { |path| File.open(path, "w") }
20
20
 
21
- opts.on("-e", "--env KEY_VALUE", "Additional environment variables to set. Can be called multiple times.")
22
-
23
21
  opts.on("-v", "--version", "Show the version")
24
22
  opts.on("-h", "--help", "Show this help message")
25
23
  opts.separator ""
@@ -29,9 +27,11 @@ module Flakie
29
27
  opts.separator ""
30
28
 
31
29
  opts.separator "EXAMPLES:"
32
- opts.separator " #{PROGRAM_NAME} rails t test/foo_test.rb"
33
- opts.separator " #{PROGRAM_NAME} -n10 rails t test/foo_test.rb"
34
- opts.separator " #{PROGRAM_NAME} -count=10 rails t test/foo_test.rb"
30
+ opts.separator " #{NAME} rails t test/foo_test.rb"
31
+ opts.separator " #{NAME} -n10 rails t test/foo_test.rb"
32
+ opts.separator " #{NAME} --count=10 rails t test/foo_test.rb"
33
+ opts.separator " #{NAME} --format=tictactoe rails t test/foo_test.rb"
34
+ opts.separator " #{NAME} -f tictactoe -o result.txt rails t test/foo_test.rb"
35
35
  end
36
36
  end
37
37
  end
@@ -15,18 +15,19 @@ module Flakie
15
15
  in version: true
16
16
  Parser.version.display
17
17
  else
18
- Engine.new(
19
- args.join(" "),
20
- count: options.count,
21
- env: options.env,
22
- reporter: options.formatter.new(options.output),
23
- ).run
18
+ Engine.new(command, count: options.count, reporter: options.reporter.new(options.output)).run
24
19
  end
25
20
  end
26
21
 
27
22
  private
28
23
 
29
24
  attr_reader :options, :args
25
+
26
+ def command
27
+ CLI.fail("Command is a required argument") if args.empty?
28
+
29
+ args.join(" ")
30
+ end
30
31
  end
31
32
  end
32
33
  end
data/lib/flakie/cli.rb CHANGED
@@ -2,14 +2,20 @@
2
2
 
3
3
  module Flakie
4
4
  module CLI
5
- PROGRAM_NAME = "flakie"
5
+ extend self
6
6
 
7
- def self.run(args)
7
+ def run(args)
8
8
  Runner.new(args).call
9
9
  end
10
10
 
11
- def self.exit_with_error(msg)
12
- warn(msg)
11
+ def fail(msg, show_help: true)
12
+ warn("error: #{msg}")
13
+
14
+ if show_help
15
+ warn("")
16
+ warn(Parser.help)
17
+ end
18
+
13
19
  exit 1
14
20
  end
15
21
  end
data/lib/flakie/engine.rb CHANGED
@@ -10,10 +10,9 @@ module Flakie
10
10
 
11
11
  Report = Data.define(:runs) { def last_run = runs.last }
12
12
 
13
- def initialize(command, count:, env:, reporter:)
13
+ def initialize(command, count:, reporter:)
14
14
  @command = command
15
15
  @count = count
16
- @env = env
17
16
  @reporter = reporter
18
17
  @report = Report.new([])
19
18
  end
@@ -23,7 +22,7 @@ module Flakie
23
22
 
24
23
  count.times do |index|
25
24
  start_time = Process.clock_gettime(Process::CLOCK_MONOTONIC)
26
- system(env, command, out: File::NULL, err: File::NULL)
25
+ system(command, out: File::NULL, err: File::NULL)
27
26
  end_time = Process.clock_gettime(Process::CLOCK_MONOTONIC)
28
27
  duration = (end_time - start_time).round
29
28
  report.runs.append Run.new(status: $?.success?, duration: duration, number: index + 1)
@@ -35,6 +34,6 @@ module Flakie
35
34
 
36
35
  private
37
36
 
38
- attr_reader :command, :count, :env, :reporter, :report
37
+ attr_reader :command, :count, :reporter, :report
39
38
  end
40
39
  end
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Flakie
4
- module Formatters
4
+ module Reporters
5
5
  class Base
6
6
  def initialize(output)
7
7
  @output = output
@@ -16,7 +16,7 @@ module Flakie
16
16
  end
17
17
 
18
18
  def report(_report)
19
- raise NotImplementedError, "Base formatter class must implement this method"
19
+ raise NotImplementedError, "Base class must implement this method"
20
20
  end
21
21
 
22
22
  private
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Flakie
4
- module Formatters
4
+ module Reporters
5
5
  class TicTacToe < Base
6
6
  CHARACTER_SUCCESS = "o"
7
7
  CHARACTER_FAILURE = "x"
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Flakie
4
- module Formatters
4
+ module Reporters
5
5
  ALL = { tictactoe: TicTacToe }.freeze
6
6
  end
7
7
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Flakie
4
- VERSION = "1.0.0"
4
+ VERSION = "2.0.0"
5
5
  end
data/lib/flakie.rb CHANGED
@@ -9,4 +9,5 @@ Zeitwerk::Loader.for_gem.tap do |loader|
9
9
  end
10
10
 
11
11
  module Flakie
12
+ NAME = "flakie"
12
13
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: flakie
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Khurram Raza
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-11-11 00:00:00.000000000 Z
11
+ date: 2023-11-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: zeitwerk
@@ -48,9 +48,9 @@ files:
48
48
  - lib/flakie/cli/parser.rb
49
49
  - lib/flakie/cli/runner.rb
50
50
  - lib/flakie/engine.rb
51
- - lib/flakie/formatters.rb
52
- - lib/flakie/formatters/base.rb
53
- - lib/flakie/formatters/tic_tac_toe.rb
51
+ - lib/flakie/reporters.rb
52
+ - lib/flakie/reporters/base.rb
53
+ - lib/flakie/reporters/tic_tac_toe.rb
54
54
  - lib/flakie/version.rb
55
55
  homepage: https://github.com/ikhurramraza/flakie.git
56
56
  licenses: