Class: CLI

Inherits:
Thor
  • Object
show all
Includes:
TestRail
Defined in:
lib/test_rail_integration/cli.rb

Instance Method Summary collapse

Instance Method Details

#check_test_run_and_updateObject



17
18
19
20
21
22
23
# File 'lib/test_rail_integration/cli.rb', line 17

def check_test_run_and_update
  if options[:test_run_id]
    TestRail::Check.check_test_run_statuses(options[:test_run_id])
  else
    puts "You must set correct test run id through --test_run_id"
  end
end

#create_test_runObject



27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/test_rail_integration/cli.rb', line 27

def create_test_run
  test_run_name = options[:test_run_name]
  if test_run_name
    if test_run_name == ''
      puts "Test_run_name parameter should not be empty"
    else
      test_run = TestRail::TestRun.create(test_run_name)
      puts "You successfully created test run with id #{test_run.id}"
    end
  else
    puts "You must set correct test run name through --test_run_name\n"
  end
end

#performObject



11
12
13
# File 'lib/test_rail_integration/cli.rb', line 11

def perform
  TestRail::Generators::Project.copy_file("test_rail_data.yml", "config/data/")
end

#shootObject



57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
# File 'lib/test_rail_integration/cli.rb', line 57

def shoot
  if options[:test_run_id]
    test_run_id = options[:test_run_id]
    Connection.test_run_id = test_run_id
    TestRailTools.write_test_run_id(test_run_id)
    command = TestRail::Command.new(test_run_id)
    if options[:auto]
      parameters = TestRail::TestRun.get_by_id(test_run_id).name.downcase.match(/(#{TestRunParameters::VENTURE_REGEX}) (#{TestRunParameters::ENVIRONMENT_REGEX})*/)
      if parameters.nil?
        puts "Your test run name is not correct. It don't contain venture, env params. Please provide correct name for test run on test rail side."
        return
      end
      if parameters[1].nil?
        puts "Your test run name is not correct. It don't contain venture param. Please provide correct name for test run on test rail side."
        return
      end
      if parameters[2].nil?
        puts "Your test run name is not correct. It don't contain env param. Please provide correct name for test run on test rail side."
        return
      end
      if parameters
        # TODO venture can be everything
        if options[:venture]
          command.venture = options[:venture]
        else
          command.venture = parameters[1]
        end
        command.env = parameters[2]
      end
    elsif options[:simple] && !options[:command]
      puts "You should add command param to execute simple execution"
      return
    elsif !options[:simple] && !options[:command]
      if options[:venture].nil? && options[:env].nil?
        puts "You must set correct env, venture params through --env, --venture in order to execute command"
        return
      end
      if options[:venture].nil?
        puts "You must set correct venture param through --venture in order to execute command"
        return
      end
      if options[:env].nil?
        puts "You must set correct env param through --env in order to execute command"
        return
      end
      command.venture = options[:venture]
      command.env = options[:env]
    end
    if options[:env] == "showroom" && options[:showroom]
      command.env = command.env + " SR='#{options[:showroom]}'"
    end
    if options[:command]
      command.command = options[:command]
    else
      command.command = TestRunParameters::EXEC_COMMAND
    end
    command.generate
    command.execute
  else
    puts "You must set correct test run id through --test_run_id"
  end
end