Class: Nukumber::Cli

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

Instance Method Summary collapse

Constructor Details

#initialize(args, out_stream = STDOUT) ⇒ Cli

Returns a new instance of Cli.



5
6
7
8
9
10
11
12
13
14
15
16
17
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/nukumber/cli.rb', line 5

def initialize(args, out_stream = STDOUT)

  directories = {
    :features => 'features',
    :definitions => 'test_definitions',
    :support => 'support'
  }

  reporter_type = 'Mono'
  reporter_type = 'Colour' if out_stream.tty?

  filters = []
  filenames = []

  i = 0
  while i < args.size do

    # named arguments
    if %w( -h --help ).include? args[i]
      print_help(out_stream)
      return

    elsif %w( -fd --features ).include? args[i] and (i+1) < args.size
      directories[:features] = args[i+1]
      i += 2
      next

    elsif %w( -sd --support ).include? args[i] and (i+1) < args.size
      directories[:support] = args[i+1]
      i += 2
      next

    elsif %w( -dd --definitions ).include? args[i] and (i+1) < args.size
      directories[:definitions] = args[i+1]
      i += 2
      next

    elsif %w( -t --tag ).include? args[i] and (i+1) < args.size
      filters << args[i+1] if args[i+1][0, 1] == '@'
      i += 2
      next

    elsif %w( -f --format ).include? args[i] and i + 1 < args.size
      if %w( c colour ).include? args[i+1]
        reporter_type = 'Colour'
      elsif %w( m mono ).include? args[i+1]
        reporter_type = 'Mono'
      elsif %w( h html ).include? args[i+1]
        reporter_type = 'Html'
      elsif %w( s silent ).include? args[i+1]
        reporter_type = 'Abstract'
      else
        raise "\"#{args[i+1]}\" is an invalid argument to \"#{args[i]}\""
      end
      i += 2
      next
    end

    # filename patterns
    arr = args[i].split(/:/)
    filenames << arr.shift
    arr.each { |n| filters << n.to_i unless n.to_i == 0 }

    # increment and loop
    i += 1
  end

  reporter = eval("Nukumber::Reporter::#{reporter_type}").new(out_stream)

  @runtime = Nukumber::Runtime.new(
    directories,
    filenames,
    filters,
    reporter
  )

end

Instance Method Details



83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# File 'lib/nukumber/cli.rb', line 83

def print_help(out_stream)
  out_stream.puts <<HERE
Usage: nukumber [options] [FILENAMEPATTERN[:LINE]]
  -fd, --features X    : Specify feature directory name
  -dd, --definitions X : Specify test definitions subdirectory name
  -sd, --support X     : Specify support code subdirectory name
  -t,  --tag X         : Only run tests with this tag
  -f,  --format X      : Specify output format; options are c/colour,
                     m/mono, h/html, s/silent
  FILENAMEPATTERN      : Only run feature files whose names include
                     this string
  LINE                 : Optional addition to FILENAMEPATTERN; filters
                     to a specific line number
HERE
end