class Object

Constants

MAX_HEIGHT
MAX_WIDTH

Public Instance Methods

capture_row_with(matches, example, csv, file_name) click to toggle source
# File lib/SimpliTest/tasks/document.rb, line 117
def capture_row_with(matches, example, csv, file_name)
  step_elements = value_of([file_name, matches[0], example,  matches[2]])
  if csv
    csv << step_elements
  elsif @html
    @table_body << generate_table_row_from(step_elements)
  else
    OpenStruct.new(
      :step => value_of(matches[0]),
      :example => value_of(example),
      :arguments => value_of(matches[2])
    )
  end
end
category_from(file_name) click to toggle source
# File lib/SimpliTest/tasks/document.rb, line 160
def category_from(file_name)
  File.basename(file_name).gsub(/\.rb/,'').gsub(/_/,' ').gsub(/steps/,'')
end
generate_html_document() click to toggle source
# File lib/SimpliTest/tasks/document.rb, line 138
def generate_html_document
  content = @html_content.gsub('@table_body', @table_body)
  content_with_responsive_label = content.gsub('@responsive_label', responsive_labels_for(@columns))
  css = File.read(@css_file)
  content_with_css = content_with_responsive_label.gsub('@css', css)
  content_with_version_number = content_with_css.gsub('@version', SimpliTest::VERSION)
  document = File.open(@html_document, "w") {|file| file.write(content_with_version_number)}
end
generate_steps_document(csv=nil) click to toggle source
# File lib/SimpliTest/tasks/document.rb, line 74
def generate_steps_document(csv=nil)
  print_heading_on_console
  Dir.glob(File.join(@step_definition_dir,'*.rb')).each do |step_file|
    print_file_name_for(step_file, csv)
    results = []
    File.new(step_file).read.each_line.each_cons(3) do |previous_line, line, next_line|
      #next unless line =~ @potential_step
      step_match = @step_regex.match(line)
      next unless step_match
      example_match = @example_regex.match(previous_line)
      example = example_match ? example_match[1] : 'N/A'
      matches = step_match.captures
      results << capture_row_with(matches, example, csv, @category)
    end
    print_on_console(results)
    generate_html_document if @html
  end
end
generate_table_row_from(array, header=false) click to toggle source
# File lib/SimpliTest/tasks/document.rb, line 132
def generate_table_row_from(array, header=false)
  tag = header ? 'th' : 'td'
  row = array.map{|x| "<#{tag}>#{x}</#{tag}>"}.join
  "<tr>#{row}</tr>"
end
hirb_installed?() click to toggle source
# File lib/SimpliTest/tasks/document.rb, line 164
def hirb_installed?
  dep = Gem::Dependency.new('hirb')
  hirb = dep.matching_specs
  !hirb.empty?
end
initialize_html_variables() click to toggle source
# File lib/SimpliTest/tasks/document.rb, line 63
def initialize_html_variables
  @templates_dir = SimpliTest.path_to_templates_dir
  @new_project_documentation_dir = File.join(@templates_dir, 'NewSimpliTestProject', 'documentation')
  @html_template = File.join(@templates_dir, "document/index.html")
  @html_dir = File.join(@templates_dir, "document")
  @html_content = File.join(@gem_dir, File.read(@html_template))
  @css_file = File.join(@templates_dir, "document/css/style.css")
  @html_document = "step_definitions.html"
  @table_body = ''
end
initialize_variables() click to toggle source
# File lib/SimpliTest/tasks/document.rb, line 54
def initialize_variables
  #@potential_step = /^\s*(?:Given|When|Then|And)\s+|\//
  @gem_dir = SimpliTest.path_to_gem_dir
  @step_regex =  /(?:Given|When|Then|And)[\s\(]*\/(.*)\/([imxo]*)[\s\)]*do\s*(?:$|\|(.*)\|)/
  @step_definition_dir = SimpliTest.path_to_steps_dir
  @example_regex = /#Example:(.*)/
  @columns = [:category, :step, :example, :arguments]
end
print_file_name_for(step_file, csv) click to toggle source
print_heading_on_console() click to toggle source
print_on_console(results) click to toggle source
responsive_labels_for(array) click to toggle source
# File lib/SimpliTest/tasks/document.rb, line 147
def responsive_labels_for(array)
  label = ''
  array.each_with_index.collect do |header, index|
    label << "td:nth-of-type(#{index+1}):before { content: '#{header}'; }"
  end
  label
end
value_of(value) click to toggle source
# File lib/SimpliTest/tasks/document.rb, line 155
def value_of(value)
  return value.map {|member| value_of(member) } if value.is_a?(Array)
  (value.nil? || value.empty?) ? 'N/A' : value
end