Class: Moto::Parser

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

Class Method Summary collapse

Class Method Details

.evaluate_name(tests, tags, filters) ⇒ Object

Generate default name based on input parameters



76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/parser.rb', line 76

def self.evaluate_name(tests, tags, filters)
  name = ''

  if tests
    name << "Tests: #{tests.join(',')}  "
  end

  if tags
    name << "Tags: #{tags.join(',')}  "
  end

  if filters
    name << "Filters: #{filters.join(',')}  "
  end

  return name
end

.generate_parse(argv) ⇒ Object

Parses attributes passed to the application when run by ‘moto generate’



95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
# File 'lib/parser.rb', line 95

def self.generate_parse(argv)
  options = {}

  OptionParser.new do |opts|
    opts.on('-t', '--test Test') { |v| options[:dir ] = v }
    opts.on('-a', '--appname AppName') { |v| options[:app_name ] = v }
    opts.on('-b', '--baseclass BaseClass') { |v| options[:base_class] = v }
    opts.on('-f', '--force') { options[:force ] = true }
  end.parse!

  options[:dir] = options[:dir].underscore

  if options[:app_name].nil?
    options[:app_name] = 'MotoApp'
  end

  return options
end

.run(argv) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/parser.rb', line 11

def self.run(argv)
  begin

    if argv[0] == '--version'
      puts Moto::VERSION
    elsif argv[0] == 'run' && argv.length > 1
      Moto::Cli.run(run_parse(argv))
    elsif argv[0] == 'generate' && argv.length > 1
      Moto::AppGenerator.run(generate_parse(argv))
    else
      show_help
    end
  rescue SystemExit => e
    Kernel.exit(e.status)
  rescue Exception => e
    puts e.message + "\n\n"
    puts e.backtrace.join("\n")
  end
end

.run_parse(argv) ⇒ Object



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
# File 'lib/parser.rb', line 31

def self.run_parse(argv)
  require 'bundler/setup'
  Bundler.require

  # Default options
  options = {}
  options[:listeners]   = []
  options[:run_name]    = nil
  options[:suite_name]  = nil
  options[:assignee]    = nil
  options[:stop_on]     = {error: false, fail: false, skip: false}

  # Parse arguments
  OptionParser.new do |opts|
    opts.on('-t', '--tests Tests', Array)              { |v| options[:tests]        = v }
    opts.on('-g', '--tags Tags', Array)                { |v| options[:tags]         = v }
    opts.on('-f', '--filters Filters', Array)          { |v| options[:filters]      = v }
    opts.on('-l', '--listeners Listeners', Array)      { |v| options[:listeners]    = v }
    opts.on('-e', '--environment Environment')         { |v| options[:environment]  = v }
    opts.on('-r', '--runname RunName')                 { |v| options[:run_name]     = v }
    opts.on('-s', '--suitename SuiteName')             { |v| options[:suite_name]   = v }
    opts.on('-a', '--assignee Assignee')               { |v| options[:assignee]     = v }
    opts.on('-c', '--config Config')                   { |v| options[:config_name]  = v }
    opts.on('--stop-on-error')                         { options[:stop_on][:error] = true }
    opts.on('--stop-on-fail')                          { options[:stop_on][:fail]  = true }
    opts.on('--stop-on-skip')                          { options[:stop_on][:skip]  = true }
  end.parse!

  if options[:run_name].nil?
    options[:run_name] = evaluate_name(options[:tests], options[:tags], options[:filters])
  end


  if options[:environment]
    Moto::Lib::Config.environment = options[:environment]
    Moto::Lib::Config.load_configuration(options[:config_name] ? options[:config_name] : 'moto')
  else
    puts 'ERROR: Environment is mandatory.'
    Kernel.exit(-1)
  end

  return options
end

.show_helpObject



114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
# File 'lib/parser.rb', line 114

def self.show_help
  puts """
  Moto (#{Moto::VERSION}) CLI Help:
  moto --version Display current version

  MOTO RUN:
   -t, --tests       Tests to be executed.
   -g, --tags        Tags of tests to be executed.
                     Use # MOTO_TAGS: TAGNAME in test to assign tag.
   -f, --filters     Tags that filter tests passed via -t parameter.
                     Only tests in appropriate directory, having all of the specified tags will be executed.
                     Use # MOTO_TAGS: TAGNAME1 in test to assign tag.


   -e, --environment Mandatory environment. Environment constants and tests parametrized in certain way depend on this.
   -c, --config      Name of the config, without extension, to be loaded from MotoApp/config/CONFIG_NAME.rb
                     Default: moto (which loads: MotoApp/config/moto.rb)


   -l, --listeners   Reporters to be used.
                     Defaults are Moto::Reporting::Listeners::ConsoleDots, Moto::Reporting::Listeners::JunitXml
                     One reporter that is always used: Moto::Reporting::Listeners::KernelCode
   -s, --suitename   Name of the test suite to which should aggregate the results of current test run.
                     Required when specifying MotoWebUI as one of the listeners.
   -r, --runname     Name of the test run to which everything will be reported when using MotoWebUI.
                     Default: Value of -g or -t depending on which one was specified.
   -a, --assignee    ID of a person responsible for current test run.
                     Can have a default value set in config/webui section.

   --stop-on-error   Moto will stop test execution when an error is encountered in test results
   --stop-on-fail    Moto will stop test execution when a failure is encountered in test results
   --stop-on-skip    Moto will stop test execution when a skip is encountered in test results


  MOTO GENERATE:
   -t, --test        Path and name of the test to be created.
                     Examples:
                     -ttest_name          will create MotoApp/tests/test_name/test_name.rb
                     -tdir/test_name      will create MotoApp/tests/dir/test_name/test_name.rb
   -a, --appname     Name of the application. Will be also used as topmost module in test file.
                     Default: MotoApp
   -b, --baseclass   File, without extension, with base class from which test will derive. Assumes one class per file.
                     Examples:
                     -btest_base          will use the file in MotoApp/lib/test/test_base.rb
                     -bsubdir/test_base   will use the file in MotoApp/lib/test/subdir/test_base.rb
                     By default class will derive from Moto::Test
   -f, --force       Forces generator to overwrite previously existing class file in specified location.
                     You have been warned.
  """
end