Class: KnapsackPro::Adapters::CucumberAdapter

Inherits:
BaseAdapter
  • Object
show all
Defined in:
lib/knapsack_pro/adapters/cucumber_adapter.rb

Constant Summary collapse

TEST_DIR_PATTERN =
'features/**{,/*/**}/*.feature'

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BaseAdapter

adapter_bind_method_called_file, bind, #bind, slow_test_file?, split_by_test_cases_enabled?, test_file_cases_for, verify_bind_method_called

Class Method Details

.test_path(object) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/knapsack_pro/adapters/cucumber_adapter.rb', line 8

def self.test_path(object)
  if ::Cucumber::VERSION.to_i >= 2
    test_case = object
    test_case.location.file
  else
    if object.respond_to?(:scenario_outline)
      if object.scenario_outline.respond_to?(:feature)
        # Cucumber < 1.3
        object.scenario_outline.feature.file
      else
        # Cucumber >= 1.3
        object.scenario_outline.file
      end
    else
      if object.respond_to?(:feature)
        # Cucumber < 1.3
        object.feature.file
      else
        # Cucumber >= 1.3
        object.file
      end
    end
  end
end

Instance Method Details

#bind_before_queue_hookObject



58
59
60
61
62
63
64
65
66
# File 'lib/knapsack_pro/adapters/cucumber_adapter.rb', line 58

def bind_before_queue_hook
  Around do |object, block|
    unless ENV['KNAPSACK_PRO_BEFORE_QUEUE_HOOK_CALLED']
      KnapsackPro::Hooks::Queue.call_before_queue
      ENV['KNAPSACK_PRO_BEFORE_QUEUE_HOOK_CALLED'] = 'true'
    end
    block.call
  end
end

#bind_queue_modeObject



68
69
70
71
72
73
74
75
# File 'lib/knapsack_pro/adapters/cucumber_adapter.rb', line 68

def bind_queue_mode
  super

  ::Kernel.at_exit do
    KnapsackPro::Hooks::Queue.call_after_subset_queue
    KnapsackPro::Report.save_subset_queue_to_file
  end
end

#bind_save_report(latest_error = nil) ⇒ Object



46
47
48
49
50
51
52
53
54
55
56
# File 'lib/knapsack_pro/adapters/cucumber_adapter.rb', line 46

def bind_save_report(latest_error = nil)
  ::Kernel.at_exit do
    # $! is latest error message
    latest_error = (latest_error || $!)
    exit_status = latest_error.status if latest_error.is_a?(SystemExit)
    # saving report makes API call which changes exit status
    # from cucumber so we need to preserve cucumber exit status
    KnapsackPro::Report.save
    ::Kernel.exit exit_status if exit_status
  end
end

#bind_time_trackerObject



33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/knapsack_pro/adapters/cucumber_adapter.rb', line 33

def bind_time_tracker
  Around do |object, block|
    KnapsackPro.tracker.current_test_path = KnapsackPro::Adapters::CucumberAdapter.test_path(object)
    KnapsackPro.tracker.start_timer
    block.call
    KnapsackPro.tracker.stop_timer
  end

  ::Kernel.at_exit do
    KnapsackPro.logger.debug(KnapsackPro::Presenter.global_time)
  end
end