Module: Seaweed
- Defined in:
- lib/seaweed.rb,
lib/seaweed/runner.rb,
lib/seaweed/server.rb,
lib/seaweed/version.rb
Defined Under Namespace
Constant Summary collapse
- ROOT =
File. File.join(File.dirname(__FILE__), '..')
- PROJECT_ROOT =
File. "."
- CONFIG_PATHS =
[ File.join(PROJECT_ROOT, 'seaweed.yml'), File.join(PROJECT_ROOT, 'config', 'seaweed.yml') ]
- VERSION =
"0.1.4"
Class Method Summary collapse
- .all_paths ⇒ Object
- .close_browser ⇒ Object
- .libs ⇒ Object
- .load_configuration ⇒ Object
- .port ⇒ Object
- .port=(value) ⇒ Object
- .root_url ⇒ Object
- .run_suite ⇒ Object
- .spawn_server ⇒ Object
- .specs ⇒ Object
-
.sprockets_environment ⇒ Object
Prepares a Sprockets::Environment object to serve coffeescript assets.
- .start_server ⇒ Object
- .watch_for_changes ⇒ Object
Class Method Details
.all_paths ⇒ Object
57 58 59 |
# File 'lib/seaweed.rb', line 57 def self.all_paths libs + specs end |
.close_browser ⇒ Object
109 110 111 112 |
# File 'lib/seaweed.rb', line 109 def self.close_browser @browser.close @browser = nil end |
.libs ⇒ Object
49 50 51 |
# File 'lib/seaweed.rb', line 49 def self.libs @configuration['libs'] end |
.load_configuration ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/seaweed.rb', line 22 def self.load_configuration # Set configuration defaults @configuration['port'] = 4567 @configuration['libs'] = ['lib'] @configuration['specs'] = ['spec'] # Load custom configuration file CONFIG_PATHS.each do |path| if File.exists? path @configuration.merge! YAML.load(File.read(path)) puts "Loaded configuration from “#{path}”" end end end |
.port ⇒ Object
37 38 39 |
# File 'lib/seaweed.rb', line 37 def self.port @configuration['port'] end |
.port=(value) ⇒ Object
41 42 43 |
# File 'lib/seaweed.rb', line 41 def self.port= value @configuration['port'] = value end |
.root_url ⇒ Object
45 46 47 |
# File 'lib/seaweed.rb', line 45 def self.root_url "http://localhost:#{port}/" end |
.run_suite ⇒ Object
97 98 99 100 101 102 103 104 105 106 107 |
# File 'lib/seaweed.rb', line 97 def self.run_suite if @browser @browser.navigate.refresh else @browser = Selenium::WebDriver.for :firefox, profile: Selenium::WebDriver::Firefox::Profile.new @browser.get "#{root_url}#terminal" end result = @browser[css: '.results'].text puts result !!result.match('passed, 0 failed') end |
.spawn_server ⇒ Object
84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/seaweed.rb', line 84 def self.spawn_server # Start server in its own thread server = Thread.new &method(:start_server) # Keep trying to connect to server until we succeed begin page = Net::HTTP.get URI.parse(root_url) rescue Errno::ECONNREFUSED sleep 1 retry end end |
.specs ⇒ Object
53 54 55 |
# File 'lib/seaweed.rb', line 53 def self.specs @configuration['specs'] end |
.sprockets_environment ⇒ Object
Prepares a Sprockets::Environment object to serve coffeescript assets
62 63 64 65 66 67 68 69 |
# File 'lib/seaweed.rb', line 62 def self.sprockets_environment @environment ||= Sprockets::Environment.new.tap do |environment| environment.append_path File.join(Seaweed::ROOT, 'lib') all_paths.each do |path| environment.append_path path end end end |
.start_server ⇒ Object
71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/seaweed.rb', line 71 def self.start_server app = Rack::Builder.app do map '/assets' do run Seaweed.sprockets_environment end map '/' do run Seaweed::Server end end Rack::Handler.default.run app, :Port => port end |
.watch_for_changes ⇒ Object
114 115 116 117 118 119 120 121 122 123 124 |
# File 'lib/seaweed.rb', line 114 def self.watch_for_changes require 'watchr' # Build a regexp to match .coffee files in any project paths path_matcher = Regexp.new('^(' + all_paths.map{ |s| Regexp.escape s}.join('|') + ')\/.*\.coffee$') script = Watchr::Script.new script.watch(path_matcher) { run_suite } controller = Watchr::Controller.new(script, Watchr.handler.new) controller.run end |