Module: Cyperful

Defined in:
lib/cyperful.rb,
lib/cyperful/commands.rb

Defined Under Namespace

Modules: FrameworkHelper, Minitest Classes: AbstractCommand, Config, Driver, ExitCommand, Logger, Railtie, ResetCommand, TestParser, UiServer

Constant Summary collapse

ROOT_DIR =
File.expand_path("..", __dir__)
DEV_MODE =

Add ‘CYPERFUL_DEV=1` to use the Vite dev hot-reloading server instead of the pre-built files in `public/`

!!ENV["CYPERFUL_DEV"]

Class Method Summary collapse

Class Method Details

.add_step_at_methods(*mods_or_methods) ⇒ Object



84
85
86
# File 'lib/cyperful.rb', line 84

def self.add_step_at_methods(*mods_or_methods)
  Cyperful::TestParser.add_step_at_methods(*mods_or_methods)
end

.configObject



32
33
34
# File 'lib/cyperful.rb', line 32

def self.config
  @config ||= Config.new
end

.currentObject



50
51
52
# File 'lib/cyperful.rb', line 50

def self.current
  @current
end

.loggerObject



36
37
38
# File 'lib/cyperful.rb', line 36

def self.logger
  @logger ||= Cyperful::Logger.new
end

.minitest?Boolean

Returns:

  • (Boolean)


46
47
48
# File 'lib/cyperful.rb', line 46

def self.minitest?
  @test_framework == :minitest
end

.rspec?Boolean

Returns:

  • (Boolean)


43
44
45
# File 'lib/cyperful.rb', line 43

def self.rspec?
  @test_framework == :rspec
end

.setup(test_class, test_name) ⇒ Object



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/cyperful.rb', line 53

def self.setup(test_class, test_name)
  @test_framework =
    if defined?(RSpec::Core::ExampleGroup) &&
         test_class < RSpec::Core::ExampleGroup
      :rspec
    elsif defined?(ActiveSupport::TestCase) &&
          test_class < ActiveSupport::TestCase
      :minitest
    else
      raise "Unsupported test framework for class: #{test_class.name}"
    end

  logger.puts "init test: \"#{rspec? ? test_name : "#{test_class}##{test_name}"}\""

  # must set `Cyperful.current` before calling `async_setup`
  @current ||= Cyperful::Driver.new
  @current.set_current_test(test_class, test_name)

  nil
rescue => err
  unless err.is_a?(Cyperful::AbstractCommand)
    warn "Error setting up Cyperful:\n\n#{err.message}\n#{err.backtrace.slice(0, 4).join("\n")}\n"
  end

  raise err
end

.teardown(error = nil) ⇒ Object



80
81
82
# File 'lib/cyperful.rb', line 80

def self.teardown(error = nil)
  @current&.teardown(error)
end

.test_frameworkObject



40
41
42
# File 'lib/cyperful.rb', line 40

def self.test_framework
  @test_framework || raise("Cyperful not set up yet")
end