Class: Calasmash::Command

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

Overview

The main point of entry for all commands, Command parses command line arguments and decides what to do about them.

Author:

  • alexfish

Class Method Summary collapse

Class Method Details

.compile(scheme, &compiled) ⇒ Object

Kick off a compile

Parameters:

  • scheme (String)

    The scheme to compile

  • &compiled (Block)

    Completion block



82
83
84
85
86
87
# File 'lib/calasmash/command.rb', line 82

def compile(scheme, &compiled)
  compiler = Calasmash::Compiler.new(scheme)
  compiler.compile do |complete|
    yield
  end
end

.execute(*args) ⇒ type

Execute a command with some arguments then figure out what we’re supposed to be doing with the arguments

Parameters:

  • *args (Array)

    An Array of arguments to play with

Returns:

  • (type)
    description


24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/calasmash/command.rb', line 24

def execute(*args)
  return overview unless args.length > 1

  options = parse(args)
  scheme  = options[:scheme]
  ios     = options[:ios]
  tags    = options[:tags]
  format  = options[:format]
  output  = options[:output]

  # Compile the project
  compile(scheme) do
    # Update the plist
    update_plist(scheme)
    # Run the tests
    run_tests(ios, tags, format, output)
  end
end

.overviewObject

Outputs a nice helpful banner overview to STDOUT



116
117
118
119
120
121
122
123
124
125
# File 'lib/calasmash/command.rb', line 116

def overview
  s = "Usage: calasmash [OPTIONS]"
  s << "\n  --tags -t the tags to pass to cucumber, for multiple tags pass one per tag"
  s << "\n  --scheme -s the Xcode scheme to build"
  s << "\n  --ios -i the iOS version to build with"
  s << "\n  --output -o The output directory for the test report"
  s << "\n  --format -f The format of the test report"

  puts s
end

.parse(args) ⇒ Hash

parse the arguments and act on them

Parameters:

  • args (Array)

    The arguments from execute

Returns:

  • (Hash)

    A hash containing all of our options



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
# File 'lib/calasmash/command.rb', line 48

def parse(args)
  options = {}
  options[:tags] = []

  OptionParser.new do |opt|
   opt.on("-s","--scheme SCHEME","the scheme to build") do |tags|
      options[:scheme] = tags
    end

    opt.on("-t","--tags TAGS","the tags to pass to Cucumber") do |tag_set|
      options[:tags] << tag_set
    end

    opt.on("-i", "--ios OS", "iOS simulator version of the sdk to run e.g. 6.0 or 7.0") do |tags|
      options[:ios] = tags
    end

    opt.on("-f", "--format FORMAT", "the format of the test reports to output") do |format|
      options[:format] = format
    end

    opt.on("-o", "--output OUTPUT", "the output path for the test results") do |output|
      options[:output] = output
    end
  end.parse!

  return options
end

.run_tests(ios, tags, format = nil, output = nil) ⇒ Object

Run the cucumber tests, that’s why we’re here afterall

Parameters:

  • ios (String)

    The iOS version to test with

  • tags (Array)

    The cucumber tags to test with

  • format (String) (defaults to: nil)

    The output format for the cucumber tests, Optional

  • output (String) (defaults to: nil)

    The path to the output directory to output test reports to, Optional



106
107
108
109
110
111
# File 'lib/calasmash/command.rb', line 106

def run_tests(ios, tags, format=nil, output=nil)
  cucumber = Calasmash::Cucumber.new(ios, tags)
  cucumber.format = format if format
  cucumber.output = output if output
  cucumber.test
end

.update_plist(scheme) ⇒ Object

Update the applications plist so that the application connects to sinatra

Parameters:

  • scheme (String)

    The scheme related to the application



94
95
96
97
# File 'lib/calasmash/command.rb', line 94

def update_plist(scheme)
  plist = Calasmash::Plist.new(scheme)
  plist.execute
end