Class: KnapsackPro::Adapters::BaseAdapter

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

Constant Summary collapse

TEST_DIR_PATTERN =

Just example, please overwrite constant in subclass

'test/**{,/*/**}/*_test.rb'

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.adapter_bind_method_called_fileObject



9
10
11
12
# File 'lib/knapsack_pro/adapters/base_adapter.rb', line 9

def self.adapter_bind_method_called_file
  adapter_name = self.to_s.gsub('::', '-')
  "#{KnapsackPro::Config::TempFiles::TEMP_DIRECTORY_PATH}/#{adapter_name}-bind_method_called_for_node_#{KnapsackPro::Config::Env.ci_node_index}.txt"
end

.bindObject



38
39
40
41
42
# File 'lib/knapsack_pro/adapters/base_adapter.rb', line 38

def self.bind
  adapter = new
  adapter.bind
  adapter
end

.slow_test_file?(adapter_class, test_file_path) ⇒ Boolean

Returns:

  • (Boolean)


22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/knapsack_pro/adapters/base_adapter.rb', line 22

def self.slow_test_file?(adapter_class, test_file_path)
  @slow_test_file_paths ||=
    begin
      slow_test_files =
        if KnapsackPro::Config::Env.slow_test_file_pattern
          KnapsackPro::TestFileFinder.slow_test_files_by_pattern(adapter_class)
        else
          # get slow test files from JSON file based on data from API
          KnapsackPro::SlowTestFileDeterminer.read_from_json_report
        end
      KnapsackPro::TestFilePresenter.paths(slow_test_files)
    end
  clean_path = KnapsackPro::TestFileCleaner.clean(test_file_path)
  @slow_test_file_paths.include?(clean_path)
end

.split_by_test_cases_enabled?Boolean

Returns:

  • (Boolean)


14
15
16
# File 'lib/knapsack_pro/adapters/base_adapter.rb', line 14

def self.split_by_test_cases_enabled?
  false
end

.test_file_cases_for(slow_test_files) ⇒ Object

Raises:

  • (NotImplementedError)


18
19
20
# File 'lib/knapsack_pro/adapters/base_adapter.rb', line 18

def self.test_file_cases_for(slow_test_files)
  raise NotImplementedError
end

.verify_bind_method_calledObject



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

def self.verify_bind_method_called
  ::Kernel.at_exit do
    if File.exist?(adapter_bind_method_called_file)
      File.delete(adapter_bind_method_called_file)
    else
      puts "\n\n"
      KnapsackPro.logger.error('-'*10 + ' Configuration error ' + '-'*50)
      KnapsackPro.logger.error("You forgot to call #{self}.bind method in your test runner configuration file. It is needed to record test files time execution. Please follow the installation guide to configure your project properly #{KnapsackPro::Urls::INSTALLATION_GUIDE}")
      KnapsackPro.logger.error("If you already have #{self}.bind method added and you still see this error then one of your tests must have deleted the .knapsack_pro directory from the disk accidentally. Please ensure you do not remove the .knapsack_pro directory: #{KnapsackPro::Urls::DASHBOARD__ZEROISH_TEST_EXECUTION_TIMES}")
      Kernel.exit(1)
    end
  end
end

Instance Method Details

#bindObject



58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/knapsack_pro/adapters/base_adapter.rb', line 58

def bind
  KnapsackPro::Config::TempFiles.ensure_temp_directory_exists!
  File.write(self.class.adapter_bind_method_called_file, nil)

  if KnapsackPro::Config::Env.regular_mode?
    KnapsackPro.logger.debug('Regular Mode enabled.')
    bind_time_tracker
    bind_save_report
  end

  if KnapsackPro::Config::Env.queue_mode?
    KnapsackPro.logger.debug('Queue Mode enabled.')
    bind_queue_mode
  end
end

#bind_after_queue_hookObject

Raises:

  • (NotImplementedError)


86
87
88
# File 'lib/knapsack_pro/adapters/base_adapter.rb', line 86

def bind_after_queue_hook
  raise NotImplementedError
end

#bind_before_queue_hookObject

Raises:

  • (NotImplementedError)


82
83
84
# File 'lib/knapsack_pro/adapters/base_adapter.rb', line 82

def bind_before_queue_hook
  raise NotImplementedError
end

#bind_queue_modeObject



90
91
92
93
94
# File 'lib/knapsack_pro/adapters/base_adapter.rb', line 90

def bind_queue_mode
  bind_before_queue_hook
  bind_after_queue_hook
  bind_time_tracker
end

#bind_save_reportObject

Raises:

  • (NotImplementedError)


78
79
80
# File 'lib/knapsack_pro/adapters/base_adapter.rb', line 78

def bind_save_report
  raise NotImplementedError
end

#bind_time_trackerObject

Raises:

  • (NotImplementedError)


74
75
76
# File 'lib/knapsack_pro/adapters/base_adapter.rb', line 74

def bind_time_tracker
  raise NotImplementedError
end