Class: Chinchilla::Runner
- Inherits:
-
Object
- Object
- Chinchilla::Runner
- Defined in:
- lib/chinchilla/runner.rb
Instance Attribute Summary collapse
-
#reporter ⇒ Object
readonly
Returns the value of attribute reporter.
Instance Method Summary collapse
- #driver ⇒ Object
-
#initialize(options = {}) ⇒ Runner
constructor
A new instance of Runner.
- #poltergeist? ⇒ Boolean
- #run ⇒ Object
- #session ⇒ Object
- #timeout ⇒ Object
- #url ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Runner
Returns a new instance of Runner.
5 6 7 8 |
# File 'lib/chinchilla/runner.rb', line 5 def initialize(={}) @options = @reporter = Rocha::Reporter.new(*formatters) end |
Instance Attribute Details
#reporter ⇒ Object (readonly)
Returns the value of attribute reporter.
3 4 5 |
# File 'lib/chinchilla/runner.rb', line 3 def reporter @reporter end |
Instance Method Details
#driver ⇒ Object
14 15 16 |
# File 'lib/chinchilla/runner.rb', line 14 def driver @driver ||= @options[:driver] || :poltergeist end |
#poltergeist? ⇒ Boolean
18 19 20 |
# File 'lib/chinchilla/runner.rb', line 18 def poltergeist? driver == :poltergeist end |
#run ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/chinchilla/runner.rb', line 26 def run session.visit(url) events_consumed = 0 done = false raise_after = Time.now.to_f + timeout begin sleep 0.1 json_events = session.evaluate_script(script_content) events = json_events ? JSON.parse(json_events) : nil if events events[events_consumed..-1].each do |event| done = true if event['event'] == 'end' reporter.process_mocha_event(event) end events_consumed = events.length raise_after = nil elsif raise_after && raise_after < Time.now.to_f raise 'Timeout' end end until done reporter.passed? rescue => e raise e, "Error communicating with browser process: #{e}", e.backtrace end |
#session ⇒ Object
54 55 56 57 58 59 60 61 |
# File 'lib/chinchilla/runner.rb', line 54 def session @session ||= begin if poltergeist? && !defined?(Capybara::Poltergeist) require "capybara/poltergeist" end Capybara::Session.new(driver, application) end end |
#timeout ⇒ Object
22 23 24 |
# File 'lib/chinchilla/runner.rb', line 22 def timeout @timeout ||= @options[:timeout] || 0.5 end |
#url ⇒ Object
10 11 12 |
# File 'lib/chinchilla/runner.rb', line 10 def url @url ||= @options[:url] || '/' end |