Module: LapisLazuli::WorldModule::Hooks
- Included in:
- LapisLazuli
- Defined in:
- lib/lapis_lazuli/world/hooks.rb
Overview
Module with cucumber hooks
The module is special in that it does not include other modules. Instead it always tests whether World responds to a function before calling it.
Constant Summary collapse
- HOOK_QUEUES =
Add hooks to one of the four queues :before, :after, :start or :end.
[ :before, :after, :start, # :end # FIXME hard to implement. See issue #13 ]
Class Method Summary collapse
Instance Method Summary collapse
-
#after_scenario_hook(cuke_scenario) ⇒ Object
Hook invoked in AfterScenario.
-
#before_scenario_hook(cuke_scenario) ⇒ Object
Hook invoked in BeforeScenario.
Class Method Details
.add_hook(queue, hook) ⇒ Object
26 27 28 29 30 31 32 33 34 |
# File 'lib/lapis_lazuli/world/hooks.rb', line 26 def self.add_hook(queue, hook) if not HOOK_QUEUES.include?(queue) raise "Invalid hook queue #{queue}" end @@hooks ||= {} @@hooks[queue] ||= [] @@hooks[queue] << hook end |
Instance Method Details
#after_scenario_hook(cuke_scenario) ⇒ Object
Hook invoked in AfterScenario
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 |
# File 'lib/lapis_lazuli/world/hooks.rb', line 63 def after_scenario_hook(cuke_scenario) # Run 'after' queue run_queue(:after, cuke_scenario) # Run 'end' queue # FIXME hard to implement; see issue #13 # The current scenario has finished if respond_to? :scenario scenario.running = false end # Sleep if needed if respond_to? :config and has_env_or_config?("step_pause_time") sleep env_or_config("step_pause_time") end # Did we fail? if respond_to? :scenario and respond_to? :has_browser? and respond_to? :browser and respond_to? :config if has_browser? and (cuke_scenario.failed? or (scenario.check_browser_errors and browser.has_error?)) # Take a screenshot if needed if has_env_or_config?('screenshot_on_failure') if env_or_config("screenshot_scheme") == "new" # Take screenshots on all active browsers LapisLazuli::Browser.browsers.each do |b| fileloc = b.take_screenshot() end else browser.take_screenshot() end end end end # Close browser if needed if respond_to? :has_browser? and respond_to? :browser if has_browser? browser.close_after_scenario(cuke_scenario) end end end |
#before_scenario_hook(cuke_scenario) ⇒ Object
Hook invoked in BeforeScenario
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/lapis_lazuli/world/hooks.rb', line 38 def before_scenario_hook(cuke_scenario) # Update the scenario informaton if respond_to? :scenario scenario.running = true scenario.update(cuke_scenario) end # Show the name if respond_to? :log log.info("Starting Scenario: #{scenario.id}") end # Run 'start' queue once. @@started ||= false if not @@started @@started = true run_queue(:start, cuke_scenario) end # Run 'before' queue run_queue(:before, cuke_scenario) end |