class CucumberHook

Attributes

first_test_run[RW]

Public Class Methods

new() click to toggle source
# File lib/pseudo_cleaner/cucumber.rb, line 15
def initialize
  @first_test_run = false
end

Public Instance Methods

end_test(scenario) click to toggle source
# 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() click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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