Class: Test::Right::CLI

Inherits:
Object
  • Object
show all
Defined in:
lib/test/right/cli.rb

Constant Summary collapse

RUBY_FILE =
/^[^.].+.rb$/

Instance Method Summary collapse

Instance Method Details

#configObject



82
83
84
# File 'lib/test/right/cli.rb', line 82

def config
  @config
end

#featuresObject



100
101
102
# File 'lib/test/right/cli.rb', line 100

def features
  Feature.subclasses || []
end

#load_and_run_testsObject



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/test/right/cli.rb', line 18

def load_and_run_tests
  run_setup

  subdir = false
  if File.directory? "test/right"
    Dir.chdir("test/right")
    subdir = true
  end

  load_config
  load_widgets
  load_features
  
  Dir.chdir("../..") if subdir

  puts "Running #{features.size} features"
  runner = Runner.new(config, widgets, features)
  if runner.run
    puts "Passed!"
  else
    at_exit {
      exit(1)
    }
    puts "Failed:"
    runner.results.each do |feature, feature_result|
      puts "  #{feature}"
      feature_result.each do |method, result|
        if result.is_a? Exception
          if result.is_a? WidgetActionNotImplemented
            puts "    #{method} => #{result}"
          else
            puts "    #{method} => #{result.class} - #{result}"
            result.backtrace.each do |trace|
              puts "      #{trace}"
            end
          end
        else
          puts "    #{method} => #{result}"
        end
      end
    end
  end
end

#load_configObject



74
75
76
77
78
79
80
# File 'lib/test/right/cli.rb', line 74

def load_config
  options = {}
  if File.exists? "config.yml"
    options = YAML.load(open("config.yml"))
  end
  @config = Config.new(options)
end

#load_featuresObject

Raises:



95
96
97
98
# File 'lib/test/right/cli.rb', line 95

def load_features
  raise ConfigurationError, "no features/ directory" unless File.directory? "features"
  load_ruby_in_dir("features")
end

#load_widgetsObject

Raises:



86
87
88
89
# File 'lib/test/right/cli.rb', line 86

def load_widgets
  raise ConfigurationError, "no widgets/ directory" unless File.directory? "widgets"
  load_ruby_in_dir("widgets")
end

#run_setupObject



62
63
64
65
66
67
68
69
70
71
72
# File 'lib/test/right/cli.rb', line 62

def run_setup
  if File.exists? "setup.rb"
    unless system("./setup.rb")
      raise ConfigurationError, "Setup failed"
    end
  elsif File.exists? "test/right/setup.rb"
    unless system("test/right/setup.rb")
      raise ConfigurationError, "Setup failed"
    end
  end
end

#start(argument_list) ⇒ Object



9
10
11
12
13
14
15
16
# File 'lib/test/right/cli.rb', line 9

def start(argument_list)
  if argument_list.first == "install"
    Generator.new(argument_list[1..-1]).generate
    return
  else
    load_and_run_tests
  end
end

#widgetsObject



91
92
93
# File 'lib/test/right/cli.rb', line 91

def widgets
  Widget.subclasses || []
end