Module: Guard::Jasmine::Server

Defined in:
lib/guard/jasmine/server.rb

Overview

Start and stop a Jasmine test server for requesting the specs from PhantomJS.

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.cmdObject

Returns the value of attribute cmd.



17
18
19
# File 'lib/guard/jasmine/server.rb', line 17

def cmd
  @cmd
end

.processObject

Returns the value of attribute process.



17
18
19
# File 'lib/guard/jasmine/server.rb', line 17

def process
  @process
end

Class Method Details

.choose_server_port(options) ⇒ Integer

A port was not specified, therefore we attempt to detect the best port to use

Parameters:

  • options (Hash)

    the server options

Options Hash (options):

  • server (Symbol)

    the rack server to use

Returns:

  • (Integer)

    port number



58
59
60
61
62
63
64
# File 'lib/guard/jasmine/server.rb', line 58

def choose_server_port(options)
  if options[:server] == :jasmine_gem
    ::Jasmine.config.port(:server)
  else
    ::Guard::Jasmine.find_free_server_port
  end
end

.detect_server(spec_dir) ⇒ Symbol

Detect the server to use

Parameters:

  • spec_dir (String)

    the spec directory

Returns:

  • (Symbol)

    the server strategy



71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/guard/jasmine/server.rb', line 71

def detect_server(spec_dir)
  if spec_dir && File.exist?(File.join(spec_dir, 'support', 'jasmine.yml'))
    :jasmine_gem
  elsif File.exist?('config.ru')
    %w(unicorn thin mongrel puma).each do |server|
      begin
        require server
        return server.to_sym
      rescue LoadError
        # Ignore missing server and try next
      end
    end
    :webrick
  else
    :none
  end
end

.start(options) ⇒ Object

Start the internal test server for getting the Jasmine runner.

Parameters:

  • options (Hash)

    the server options

Options Hash (options):

  • server (String)

    the server to use

  • port (Number)

    the server port

  • server_env (String)

    the Rails environment

  • server_timeout (Number)

    the server start timeout

  • spec_dir (String)

    the spec directory

  • rackup_config (String)

    custom rackup config to use (i.e. spec/dummy/config.ru for mountable engines)



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/guard/jasmine/server.rb', line 28

def start(options)
  port = options[:port]

  case options[:server]
  when :webrick, :mongrel, :thin, :puma
    start_rack_server(options[:server], port, options)
  when :unicorn
    start_unicorn_server(port, options)
  when :jasmine_gem
    start_rake_server(port, 'jasmine', options)
  when :none # noop
  else
    start_rake_server(port, options[:server], options)
  end

  wait_for_server(port, options[:server_timeout]) unless options[:server] == :none
end

.stopObject

Stop the server thread.



48
49
50
51
52
# File 'lib/guard/jasmine/server.rb', line 48

def stop
  return unless process
  Compat::UI.info 'Guard::Jasmine stops server.'
  process.stop(5)
end