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

bind, #bind, #bind_save_queue_report

Class Method Details

.test_path(object) ⇒ Object



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

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_save_report(latest_error = nil) ⇒ Object



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

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



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

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