Class: Rambo::CLI

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

Instance Method Summary collapse

Constructor Details

#initialize(raml_file = nil, opts = {}, stdout = STDOUT, stderr = STDERR) ⇒ CLI

Returns a new instance of CLI.



6
7
8
9
10
11
12
13
# File 'lib/cli.rb', line 6

def initialize(raml_file=nil, opts={}, stdout=STDOUT, stderr=STDERR)
  @stdout  = stdout
  @stderr  = stderr
  @file    = raml_file
  @options = opts

  validate!
end

Instance Method Details

#run!Object



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

def run!
  

  begin
    Rambo.generate_contract_tests!(file, options)

    stdout.puts("Generating contract tests...")
    sleep 0.4

    stdout.puts("Done!".green)
  rescue NoMethodError => e
    stderr.puts("Error: #{e.message}".red)
    stderr.puts "\t#{e.backtrace.join("\n\t")}"
  end
end

#validate!Object



31
32
33
34
# File 'lib/cli.rb', line 31

def validate!
  exit_for_missing_file unless file
  exit_for_invalid_file_format unless file.match(/\.raml$/)
end