Module: Crab::Utilities

Included in:
Rally
Defined in:
lib/crab/utilities.rb

Instance Method Summary collapse

Instance Method Details

#add_or_update_options(banner) ⇒ Object

TODO REFACTOR testcase related stuff that didn’t have a good home



44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/crab/utilities.rb', line 44

def add_or_update_options(banner)
  Trollop::options do
    banner banner
    opt :priority, "Priority (one of: #{Crab::TestCase::PRIORITIES.join(" ")}", :default => "important", :short => '-p'
    opt :risk,     "Risk (one of: #{Crab::TestCase::RISKS.join(" ")})", :default => "medium", :short => '-r'
    opt :method,   "Method (one of: #{Crab::TestCase::METHODS.join(" ")})", :default => "automated", :short => '-m'
    opt :type,     "Type (one of: #{Crab::TestCase::TYPES.join(" ")})", :default => "acceptance", :short => '-t'
    opt :pre,      "Pre-conditions", :default => "N/A"
    opt :post,     "Post-conditions", :default => "N/A"
    opt :desc,     "Description", :default => "N/A", :short => '-d'

    opt :dry, "Dry-run (don't change anything)", :short => "-D", :default => false
  end
end

#credentials_fileObject



4
5
6
7
# File 'lib/crab/utilities.rb', line 4

def credentials_file
  FileUtils.mkdir_p File.expand_path("~/.crab")
  File.expand_path("~/.crab/credentials")
end

#current_project_nameObject



20
21
22
23
24
# File 'lib/crab/utilities.rb', line 20

def current_project_name
  if File.exists? ".crab/project"
    File.read(".crab/project").strip
  end
end

#sanitize_options(opts, creating = true) ⇒ Object

TODO REFACTOR testcase related stuff that didn’t have a good home



60
61
62
63
64
65
66
67
68
69
70
# File 'lib/crab/utilities.rb', line 60

def sanitize_options(opts, creating=true)
  result = {}
  result[:priority] = opts[:priority].capitalize if creating || opts[:priority_given]
  result[:risk] = opts[:risk].capitalize if creating || opts[:risk_given]
  result[:method] = opts[:method].capitalize if creating || opts[:method_given]
  result[:type] = opts[:type].capitalize if creating || opts[:type_given]
  result[:pre_conditions] = opts[:pre] if creating || opts[:pre_given]
  result[:post_conditions] = opts[:post] if creating || opts[:post_given]
  result[:description] = opts[:desc] if creating || opts[:desc_given]
  result
end

#state_after(state) ⇒ Object



37
38
39
40
41
# File 'lib/crab/utilities.rb', line 37

def state_after(state)
  i = (Crab::Story::VALID_STATES.index(state) || 0) + 1
  max = Crab::Story::VALID_STATES.size
  Crab::Story::VALID_STATES[i >= max ? max -1 : i]
end

#state_before(state) ⇒ Object



32
33
34
35
# File 'lib/crab/utilities.rb', line 32

def state_before(state)
  i = (Crab::Story::VALID_STATES.index(state) || 0) - 1
  Crab::Story::VALID_STATES[i < 0 ? 0 : i]
end

#state_from(option) ⇒ Object



26
27
28
29
30
# File 'lib/crab/utilities.rb', line 26

def state_from(option)
  fixed_option = option.gsub(/(^\w|[-_]\w)/) { $1.upcase.gsub(/_/, '-') }
  Trollop::die :state, "has an invalid value" unless Crab::Story::VALID_STATES.include? fixed_option
  fixed_option
end

#valid_credentials_fileObject



9
10
11
12
# File 'lib/crab/utilities.rb', line 9

def valid_credentials_file
  Trollop::die "Please log in first" unless File.exists? credentials_file
  credentials_file
end

#valid_project_name(cmd_opts) ⇒ Object



14
15
16
17
18
# File 'lib/crab/utilities.rb', line 14

def valid_project_name(cmd_opts)
  project_name = cmd_opts[:project_given] ? cmd_opts[:project] : current_project_name
  Trollop::die :project, "must be specified" if project_name.blank?
  project_name
end