Class: Jasmine::Config

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

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Config

Returns a new instance of Config.



3
4
5
6
7
8
9
10
11
# File 'lib/jasmine/config.rb', line 3

def initialize(options = {})
  require 'selenium_rc'
  @selenium_jar_path = SeleniumRC::Server.allocate.jar_path
  @options = options

  @browser = options[:browser] ? options.delete(:browser) : 'firefox'
  @selenium_pid = nil
  @jasmine_server_pid = nil
end

Instance Method Details

#eval_js(script) ⇒ Object



68
69
70
# File 'lib/jasmine/config.rb', line 68

def eval_js(script)
  @client.eval_js(script)
end

#js_filesObject



116
117
118
# File 'lib/jasmine/config.rb', line 116

def js_files
  src_files.collect {|f| File.join(src_path, f) } + spec_files.collect {|f| File.join(spec_path, f) }
end

#mappingsObject



72
73
74
# File 'lib/jasmine/config.rb', line 72

def mappings
  raise "You need to declare a mappings method in #{self.class}!"
end

#match_files(dir, pattern) ⇒ Object



88
89
90
91
# File 'lib/jasmine/config.rb', line 88

def match_files(dir, pattern)
  dir = File.expand_path(dir)
  Dir.glob(File.join(dir, pattern)).collect {|f| f.sub("#{dir}/", "")}.sort
end

#runObject



57
58
59
60
61
62
63
64
65
66
# File 'lib/jasmine/config.rb', line 57

def run
  begin
    start
    puts "servers are listening on their ports -- running the test script..."
    tests_passed = @client.run
  ensure
    stop
  end
  return tests_passed
end

#spec_filesObject



84
85
86
# File 'lib/jasmine/config.rb', line 84

def spec_files
  raise "You need to declare a spec_files method in #{self.class}!"
end

#spec_files_full_pathsObject



120
121
122
# File 'lib/jasmine/config.rb', line 120

def spec_files_full_paths
  spec_files.collect {|spec_file| File.join(spec_dir, spec_file) }
end

#spec_pathObject



101
102
103
# File 'lib/jasmine/config.rb', line 101

def spec_path
  "spec"
end

#src_filesObject



80
81
82
# File 'lib/jasmine/config.rb', line 80

def src_files
  []
end

#src_pathObject



97
98
99
# File 'lib/jasmine/config.rb', line 97

def src_path
  "src"
end

#startObject



17
18
19
20
21
# File 'lib/jasmine/config.rb', line 17

def start
  start_servers
  @client = Jasmine::SeleniumDriver.new("localhost", @selenium_server_port, "*#{@browser}", "http://localhost:#{@jasmine_server_port}/")
  @client.connect
end

#start_server(port = 8888) ⇒ Object



13
14
15
# File 'lib/jasmine/config.rb', line 13

def start_server(port = 8888)
  Jasmine::Server.new(port, self).start
end

#start_serversObject



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/jasmine/config.rb', line 28

def start_servers
  @jasmine_server_port = Jasmine::find_unused_port
  @selenium_server_port = Jasmine::find_unused_port

  server = Jasmine::Server.new(@jasmine_server_port, self)

  @selenium_pid = fork do
    Process.setpgrp
    exec "java -jar #{@selenium_jar_path} -port #{@selenium_server_port} > /dev/null 2>&1"
  end
  puts "selenium started.  pid is #{@selenium_pid}"

  @jasmine_server_pid = fork do
    Process.setpgrp
    server.start
    exit! 0
  end
  puts "jasmine server started.  pid is #{@jasmine_server_pid}"

  Jasmine::wait_for_listener(@selenium_server_port, "selenium server")
  Jasmine::wait_for_listener(@jasmine_server_port, "jasmine server")
end

#stopObject



23
24
25
26
# File 'lib/jasmine/config.rb', line 23

def stop
  @client.disconnect
  stop_servers
end

#stop_serversObject



51
52
53
54
55
# File 'lib/jasmine/config.rb', line 51

def stop_servers
  puts "shutting down the servers..."
  Jasmine::kill_process_group(@selenium_pid) if @selenium_pid
  Jasmine::kill_process_group(@jasmine_server_pid) if @jasmine_server_pid
end

#stylesheetsObject



76
77
78
# File 'lib/jasmine/config.rb', line 76

def stylesheets
  []
end