Class: Aspec::CLI

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(working_dir, args) ⇒ CLI

Returns a new instance of CLI


7
8
9
10
# File 'lib/aspec/cli.rb', line 7

def initialize(working_dir, args)
  @working_dir = Pathname.new(working_dir)
  @args = args
end

Instance Attribute Details

#argsObject (readonly)

Returns the value of attribute args


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

def args
  @args
end

#working_dirObject (readonly)

Returns the value of attribute working_dir


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

def working_dir
  @working_dir
end

Instance Method Details

#aspec_filesObject


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

def aspec_files
  files = []
  @args.each do |arg|
    arg = File.expand_path(arg, working_dir)
    if File.exist?(arg)
      if File.directory?(arg)
        files += Dir[arg + "**/*.aspec"]
      elsif arg =~ /.*\.aspec/
        files << arg
      end
    end
  end
  files
end

#aspec_helper_pathObject


27
28
29
# File 'lib/aspec/cli.rb', line 27

def aspec_helper_path
  working_dir.join("aspec/aspec_helper.rb")
end

#runObject


31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/aspec/cli.rb', line 31

def run
  bits = args[0].split(":")

  load aspec_helper_path if File.exist?(aspec_helper_path)

  @lines = bits[1..-1].map(&:to_i)
  is_verbose = args.include?("-v")
  Aspec.configure do |c|
    c.verbose   = is_verbose
    c.slow      = args.include?("--slow")
    c.formatter = args.include?("--junit") ? Formatter::JUnit.new(@file) : Formatter::Terminal.new(is_verbose)
  end
  TestRunner.new(Aspec.configuration, aspec_files).run(@lines)
end