Class: HookUtils

Inherits:
Object
  • Object
show all
Defined in:
lib/utils/hook_utils.rb

Class Method Summary collapse

Class Method Details

.generate_hook(support_folder, hook_version) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/utils/hook_utils.rb', line 22

def self.generate_hook (support_folder, hook_version)
  support_folder_path = support_folder + 'hook/'
  if !File.directory? (support_folder_path)
    FileUtils.mkdir(support_folder_path)
  end

  version_file_path = support_folder_path + 'hook_version'
  hook_file_path = support_folder_path + 'hooks.rb'
  generate_hook = generate_hooks?(version_file_path, hook_file_path, hook_version)

  if (generate_hook)
    File.open(version_file_path, 'wb') do |f|
      f << hook_version
    end
    generate_hook_file (hook_file_path)
  end
end

.generate_hook_file(hook_file_path) ⇒ Object



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/utils/hook_utils.rb', line 40

def self.generate_hook_file(hook_file_path)
  File.open(hook_file_path, 'wb') do |f|
    f.puts 'require \'qTestScenarioRuby\''
    f.puts ''
    f.puts '$plugin = QTestScenario::QTestScenarioPlugin.new({'
    f.puts '  \'server\' => ENV[\'QTSCN_SERVER\'],'
    f.puts '  \'api_key\' => ENV[\'QTSCN_SERVER_API_KEY\'],'
    f.puts '  \'destination_dir\' => ENV[\'QTSCN_SERVER_FEATURE_DIR\'],'
    f.puts '  \'jql\' => ENV[\'QTSCN_JQL\'],'
    f.puts '  \'keys\' => ENV[\'QTSCN_KEYS\'],'
    f.puts '  \'support_folder\' => ENV[\'QTSCN_SUPPORT_DIR\']'
    f.puts '})'
    f.puts ''
    f.puts 'Before do |scenario|'
    f.puts '  $plugin.before_scenario scenario'
    f.puts 'end'
    f.puts ''
    f.puts 'After do |scenario|'
    f.puts '  $plugin.after_scenario scenario'
    f.puts 'end'
    f.puts ''
    f.puts 'at_exit do'
    f.puts '  $plugin.at_exit'
    f.puts 'end'
  end
end

.generate_hooks?(version_file_path, hook_file_path, hook_version) ⇒ Boolean

Returns:

  • (Boolean)


5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/utils/hook_utils.rb', line 5

def self.generate_hooks? (version_file_path, hook_file_path, hook_version)
  generate_hook = false
  begin
    File.open(version_file_path, 'r') do |f|
      versionUsed = f.gets
      if !hook_version.eql? versionUsed
        File.delete(hook_file_path)
        generate_hook = true
      end
    end
  rescue
    # hook_version does not exist, then generate hook

    generate_hook = true
  end
  generate_hook
end