Class: Guard::Jasmine::CLI

Inherits:
Thor
  • Object
show all
Extended by:
Util
Defined in:
lib/guard/jasmine/cli.rb

Overview

Small helper class to run the Jasmine runner_options once from the command line. This can be useful to integrate guard-jasmine into a continuous integration server.

This outputs the specdoc and disables any notifications.

Instance Method Summary (collapse)

Methods included from Util

find_free_server_port, phantomjs_bin_valid?, runner_available?, which

Instance Method Details

- (Object) spec(*paths)

Run the Guard::Jasmine::Runner with options from the command line.

Parameters:

  • paths (Array<String>)

    the name of the specs to run



140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
# File 'lib/guard/jasmine/cli.rb', line 140

def spec(*paths)
  paths = [options.spec_dir] if paths.empty?

  runner_options                        = { }
  runner_options[:port]                 = options.port || CLI.find_free_server_port
  runner_options[:jasmine_url]          = options.url || "http://localhost:#{ runner_options[:port] }#{ options.server.to_sym == :jasmine_gem ? '/' : '/jasmine' }"
  runner_options[:phantomjs_bin]        = options.bin || CLI.which('phantomjs')
  runner_options[:timeout]              = options.timeout
  runner_options[:verbose]              = options.verbose
  runner_options[:server]               = options.server.to_sym
  runner_options[:server_env]           = options.server_env
  runner_options[:server_timeout]       = options.server_timeout
  runner_options[:rackup_config]        = options.rackup_config
  runner_options[:spec_dir]             = options.spec_dir
  runner_options[:console]              = [:always, :never, :failure].include?(options.console.to_sym) ? options.console.to_sym : :failure
  runner_options[:errors]               = [:always, :never, :failure].include?(options.errors.to_sym) ? options.errors.to_sym : :failure
  runner_options[:specdoc]              = [:always, :never, :failure].include?(options.specdoc.to_sym) ? options.specdoc.to_sym : :always
  runner_options[:focus]                = options.focus
  runner_options[:coverage]             = options.coverage || options.coverage_html || options.coverage_summary
  runner_options[:coverage_html]        = options.coverage_html
  runner_options[:coverage_summary]     = options.coverage_summary
  runner_options[:statements_threshold] = options.statements_threshold
  runner_options[:functions_threshold]  = options.functions_threshold
  runner_options[:branches_threshold]   = options.branches_threshold
  runner_options[:lines_threshold]      = options.lines_threshold
  runner_options[:notification]         = false
  runner_options[:hide_success]         = true
  runner_options[:max_error_notify]     = 0

  if CLI.phantomjs_bin_valid?(runner_options[:phantomjs_bin])
    catch(:task_has_failed) do
      ::Guard::Jasmine::Server.start(runner_options) unless runner_options[:server] == :none
    end

    if CLI.runner_available?(runner_options)
      result = ::Guard::Jasmine::Runner.run(paths, runner_options)
      ::Guard::Jasmine::Server.stop

      Process.exit result.first ? 0 : 1
    else
      ::Guard::Jasmine::Server.stop
      Process.exit 2
    end

  else
    Process.exit 2
  end

rescue => e
  ::Guard::UI.error e.message
  Process.exit 2
end

- (Object) version

Shows the current version of Guard::Jasmine.

See Also:

  • VERSION


200
201
202
# File 'lib/guard/jasmine/cli.rb', line 200

def version
  ::Guard::UI.info "Guard::Jasmine version #{ ::Guard::JasmineVersion::VERSION }"
end