Class: Brut::CLI::Apps::Test::Run

Inherits:
Command
  • Object
show all
Defined in:
lib/brut/cli/apps/test.rb

Direct Known Subclasses

E2e

Instance Method Summary collapse

Methods inherited from Command

#after_bootstrap, args, #args, #before_execute, command_name, default_env, #delegate_to_commands, description, detailed_description, env_var, #err, #global_options, #handle_bootstrap_exception, #initialize, name_matches?, option_parser, #options, opts, #out, requires_project_env, requires_project_env?, #system!

Methods included from Framework::Errors

#abstract_method!, #bug!

Methods included from I18n::ForCLI

#capture, #html_escape, #safe

Methods included from I18n::BaseMethods

#l, #t, #t_direct, #this_field_value

Methods included from ExecutionResults

#abort_execution, #as_execution_result, #cli_usage_error, #continue_execution, #show_cli_usage, #stop_execution

Constructor Details

This class inherits a constructor from Brut::CLI::Command

Instance Method Details

#executeObject



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/brut/cli/apps/test.rb', line 43

def execute
  Brut.container.sequel_db_handle.disconnect
  if options.rebuild?(default: rebuild_by_default?)
    Brut.container.instrumentation.span("schema.rebuild.before") do
      out.puts "Rebuilding test database schema"
      system! "bin/db rebuild --env=test"
    end
  end
  Brut.container.instrumentation.span("tests.run") do |span|
    if args.empty?
      span.add_prefixed_attributes("brut.cli.test", tests: :all)
      out.puts "Running all tests"
      system! "#{rspec_command} #{Brut.container.app_specs_dir}/"
    else
      span.add_prefixed_attributes("brut.cli.test", tests: args.length)
      test_args = args.map { |_|
        '"' + Shellwords.escape(_) + '"'
      }.join(" ")
      system! "#{rspec_command} #{test_args}"
    end
  end
  if options.rebuild_after?(default: rebuild_after_by_default?)
    Brut.container.instrumentation.span("schema.rebuild.after") do
      out.puts "Re-Rebuilding test database schema"
      system! "bin/db rebuild --env=test"
    end
  end
  0
end

#rebuild_after_by_default?Boolean

Returns:

  • (Boolean)


41
# File 'lib/brut/cli/apps/test.rb', line 41

def rebuild_after_by_default? = false

#rebuild_by_default?Boolean

Returns:

  • (Boolean)


40
# File 'lib/brut/cli/apps/test.rb', line 40

def rebuild_by_default?       = false

#rspec_cli_argsObject



38
# File 'lib/brut/cli/apps/test.rb', line 38

def rspec_cli_args = "--tag ~e2e"

#rspec_commandObject



23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/brut/cli/apps/test.rb', line 23

def rspec_command
  parts = [
    "bin/rspec",
    "-I", Brut.container.app_specs_dir,
    "-I", Brut.container.app_src_dir,
    "-I lib/", # not needed when Brut is gemified
    rspec_cli_args,
    "-P \"**/*.spec.rb\"",
  ]
  if options.seed
    parts << "--seed #{options.seed}"
  end
  parts.join(" ")
end