Module: Crab::Utilities

Includes:
Logging
Included in:
CucumberFeature, CucumberScenario, Rally, RallyToCucumberAdapter, Story, TestCase
Defined in:
lib/crab/utilities.rb

Instance Method Summary collapse

Methods included from Logging

#logger

Instance Method Details

#add_or_update_options(banner, args) ⇒ Object

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



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

def add_or_update_options(banner, args)
  Trollop::options(args) 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 => "manual", :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



6
7
8
9
# File 'lib/crab/utilities.rb', line 6

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

#current_project_nameObject



22
23
24
25
26
# File 'lib/crab/utilities.rb', line 22

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

#sanitize(source) ⇒ Object

took a while to figure out that we need to remove the CSS from inside embedded <style> tags! Rally uses some crazy rich text editor that I’d be soooooo happy to disable, somehow. Chrome Extension, perhaps?



76
77
78
# File 'lib/crab/utilities.rb', line 76

def sanitize(source)
  Sanitize.clean source, :remove_contents => %w{style}
end

#sanitize_options(opts, creating = true) ⇒ Object

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



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

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



39
40
41
42
43
# File 'lib/crab/utilities.rb', line 39

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



34
35
36
37
# File 'lib/crab/utilities.rb', line 34

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



28
29
30
31
32
# File 'lib/crab/utilities.rb', line 28

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



11
12
13
14
# File 'lib/crab/utilities.rb', line 11

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

#valid_project_name(cmd_opts) ⇒ Object



16
17
18
19
20
# File 'lib/crab/utilities.rb', line 16

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