Class: CucumberHook
- Inherits:
-
Object
- Object
- CucumberHook
- Includes:
- Singleton
- Defined in:
- lib/pseudo_cleaner/cucumber.rb
Instance Attribute Summary collapse
-
#first_test_run ⇒ Object
Returns the value of attribute first_test_run.
Instance Method Summary collapse
- #end_test(scenario) ⇒ Object
- #init_pseudo ⇒ Object
-
#initialize ⇒ CucumberHook
constructor
A new instance of CucumberHook.
- #peek_data_inline(scenario) ⇒ Object
- #peek_data_new_test(scenario) ⇒ Object
- #report_name(scenario) ⇒ Object
- #run_test(scenario, strategy, block) ⇒ Object
- #start_test(scenario, strategy) ⇒ Object
- #test_location(scenario) ⇒ Object
Constructor Details
#initialize ⇒ CucumberHook
Returns a new instance of CucumberHook.
15 16 17 |
# File 'lib/pseudo_cleaner/cucumber.rb', line 15 def initialize @first_test_run = false end |
Instance Attribute Details
#first_test_run ⇒ Object
Returns the value of attribute first_test_run.
13 14 15 |
# File 'lib/pseudo_cleaner/cucumber.rb', line 13 def first_test_run @first_test_run end |
Instance Method Details
#end_test(scenario) ⇒ Object
42 43 44 45 46 |
# File 'lib/pseudo_cleaner/cucumber.rb', line 42 def end_test(scenario) PseudoCleaner::MasterCleaner.end_example(scenario, description: "PseudoCleaner::end_test - #{report_name (scenario)}", location: test_location(scenario)) end |
#init_pseudo ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/pseudo_cleaner/cucumber.rb', line 19 def init_pseudo unless first_test_run @first_test_run = true # before tests run... # We start suite in case a custom cleaner wants/needs to. if PseudoCleaner::Configuration.current_instance.clean_database_before_tests PseudoCleaner::MasterCleaner.reset_database else PseudoCleaner::MasterCleaner.start_suite end DatabaseCleaner.strategy = :transaction end end |
#peek_data_inline(scenario) ⇒ Object
75 76 77 78 |
# File 'lib/pseudo_cleaner/cucumber.rb', line 75 def peek_data_inline(scenario) PseudoCleaner::MasterCleaner.peek_data_inline(description: "PseudoCleaner::peek_data - #{report_name(scenario)}", location: test_location(scenario)) end |
#peek_data_new_test(scenario) ⇒ Object
80 81 82 83 |
# File 'lib/pseudo_cleaner/cucumber.rb', line 80 def peek_data_new_test(scenario) PseudoCleaner::MasterCleaner.peek_data_new_test(description: "PseudoCleaner::peek_data - #{report_name(scenario)}", location: test_location(scenario)) end |
#report_name(scenario) ⇒ Object
56 57 58 59 60 61 62 63 |
# File 'lib/pseudo_cleaner/cucumber.rb', line 56 def report_name(scenario) report_name = "Unknown" if scenario.respond_to?(:feature) report_name = "#{scenario.feature.title}:#{scenario.title}" elsif scenario.respond_to?(:line) report_name = "Line - #{scenario.line}" end end |
#run_test(scenario, strategy, block) ⇒ Object
65 66 67 68 69 70 71 72 73 |
# File 'lib/pseudo_cleaner/cucumber.rb', line 65 def run_test(scenario, strategy, block) start_test(scenario, strategy) begin block.call ensure end_test(scenario) end end |
#start_test(scenario, strategy) ⇒ Object
35 36 37 38 39 40 |
# File 'lib/pseudo_cleaner/cucumber.rb', line 35 def start_test(scenario, strategy) PseudoCleaner::MasterCleaner.start_example(scenario, strategy, description: "PseudoCleaner::start_test - #{report_name(scenario)}", location: test_location(scenario)) end |
#test_location(scenario) ⇒ Object
48 49 50 51 52 53 54 |
# File 'lib/pseudo_cleaner/cucumber.rb', line 48 def test_location(scenario) if scenario.respond_to?(:feature) "#{scenario.location.file}:#{scenario.location.line}" elsif scenario.respond_to?(:scenario_outline) "#{scenario.scenario_outline.instance_variable_get(:@example_sections)[0][0][0].file}:#{scenario.scenario_outline.instance_variable_get(:@example_sections)[0][0][0].line}" end end |