Module: Rubee::CLI::Test

Defined in:
lib/rubee/cli/test.rb

Class Method Summary collapse

Class Method Details

.call(command, argv) ⇒ Object



5
6
7
# File 'lib/rubee/cli/test.rb', line 5

def call(command, argv)
  send(command, argv)
end

.test(argv) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/rubee/cli/test.rb', line 9

def test(argv)
  ENV['RACK_ENV'] = 'test'
  file_name = argv[1] # Get the first argument
  line = argv[2]&.start_with?('--line=') ? argv[2].split('=')[1] : nil
  lib = Rubee::PROJECT_NAME == 'rubee' ? '/lib' : ''
  if file_name && !line
    color_puts("Running #{file_name} test ...", color: :yellow)
    exec("ruby -Itest -e \"require '.#{lib}/tests/#{file_name}'\"")
  elsif file_name && line
    color_puts("Running #{file_name} test at line #{line} ...", color: :yellow)
    test_name = find_test_at_line(".#{lib}/tests/#{file_name}", line)
    exec("ruby -Itest .#{lib}/tests/#{file_name} -n #{test_name}")
  else
    color_puts('Running all tests ...', color: :yellow)
    exec("ruby -Itest -e \"Dir.glob('.#{lib}/tests/**/*_test.rb').each { |file| require file }\"")
  end
end