Class: Specwrk::CLI::Seed

Inherits:
Dry::CLI::Command
  • Object
show all
Includes:
Clientable
Defined in:
lib/specwrk/cli.rb

Instance Method Summary collapse

Methods included from Hookable

extended, #included, #included_hooks, #on_included, #on_setup, #setup_hooks

Instance Method Details

#call(max_retries:, dir:, **args) ⇒ Object



138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
# File 'lib/specwrk/cli.rb', line 138

def call(max_retries:, dir:, **args)
  dir = ["spec"] if dir.length.zero?

  self.class.setup(**args)

  require "specwrk/list_examples"
  require "specwrk/client"

  ENV["SPECWRK_SEED"] = "1"
  examples = ListExamples.new(dir).examples

  Client.wait_for_server!
  Client.new.seed(examples, max_retries)
  file_count = examples.group_by { |e| e[:file_path] }.keys.size
  puts "🌱 Seeded #{examples.size} examples across #{file_count} files"
rescue Errno::ECONNREFUSED
  puts "Server at #{ENV.fetch("SPECWRK_SRV_URI", "http://localhost:5138")} is refusing connections, exiting...#{ENV["SPECWRK_FLUSH_DELIMINATOR"]}"
  exit 1
rescue Errno::ECONNRESET
  puts "Server at #{ENV.fetch("SPECWRK_SRV_URI", "http://localhost:5138")} stopped responding to connections, exiting...#{ENV["SPECWRK_FLUSH_DELIMINATOR"]}"
  exit 1
end