Class: Jasmine::Config
- Inherits:
-
Object
- Object
- Jasmine::Config
- Defined in:
- lib/jasmine/config.rb
Instance Method Summary collapse
- #eval_js(script) ⇒ Object
-
#initialize(options = {}) ⇒ Config
constructor
A new instance of Config.
- #js_files ⇒ Object
- #mappings ⇒ Object
- #match_files(dir, pattern) ⇒ Object
- #run ⇒ Object
- #spec_files ⇒ Object
- #spec_files_full_paths ⇒ Object
- #spec_path ⇒ Object
- #src_files ⇒ Object
- #src_path ⇒ Object
- #start ⇒ Object
- #start_server(port = 8888) ⇒ Object
- #start_servers ⇒ Object
- #stop ⇒ Object
- #stop_servers ⇒ Object
- #stylesheets ⇒ Object
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( = {}) require 'selenium_rc' @selenium_jar_path = SeleniumRC::Server.allocate.jar_path @options = @browser = [:browser] ? .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_files ⇒ Object
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 |
#mappings ⇒ Object
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.(dir) Dir.glob(File.join(dir, pattern)).collect {|f| f.sub("#{dir}/", "")}.sort end |
#run ⇒ Object
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_files ⇒ Object
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_paths ⇒ Object
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_path ⇒ Object
101 102 103 |
# File 'lib/jasmine/config.rb', line 101 def spec_path "spec" end |
#src_files ⇒ Object
80 81 82 |
# File 'lib/jasmine/config.rb', line 80 def src_files [] end |
#src_path ⇒ Object
97 98 99 |
# File 'lib/jasmine/config.rb', line 97 def src_path "src" end |
#start ⇒ Object
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_servers ⇒ Object
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 |
#stop ⇒ Object
23 24 25 26 |
# File 'lib/jasmine/config.rb', line 23 def stop @client.disconnect stop_servers end |
#stop_servers ⇒ Object
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 |
#stylesheets ⇒ Object
76 77 78 |
# File 'lib/jasmine/config.rb', line 76 def stylesheets [] end |