class SmashingDocs

Attributes

tests[RW]

Public Class Methods

config() { |Conf| ... } click to toggle source
# File lib/base.rb, line 121
def self.config(&block)
  yield(self::Conf)
end
current() click to toggle source
# File lib/base.rb, line 116
def self.current
  # Behaves like an instance of SmashingDocs class
  Thread.current[:instance] ||= self.new
end
finish!() click to toggle source

= = =

These class methods are used to persist test data across tests RSpec and Minitest do not support hooks that would allow for an instance variable to be declared and used

# File lib/base.rb, line 95
def self.finish!
  unless current.tests.empty?
    current.sort_by_url!
    current.output_testcases_to_file
    current.add_docs_to_wiki if current.auto_push?
    current.clean_up!
  end
end
information(key, value) click to toggle source
# File lib/base.rb, line 112
def self.information(key, value)
  current.information(key, value)
end
new() click to toggle source
# File lib/base.rb, line 3
def initialize
  @tests = []
  @skip = false
  @information = {}
end
run!(request, response, called_by_test_hook = false) click to toggle source
# File lib/base.rb, line 104
def self.run!(request, response, called_by_test_hook = false)
  current.run!(request, response, called_by_test_hook)
end
skip() click to toggle source
# File lib/base.rb, line 108
def self.skip
  current.skip
end

Public Instance Methods

add_docs_to_wiki() click to toggle source
# File lib/base.rb, line 19
def add_docs_to_wiki
  wiki_repo = "../#{app_name}.wiki"
  if wiki_repo && wiki_repo_exists?(wiki_repo)
    copy_docs_to_wiki_repo(wiki_repo)
    push_docs_to_github(wiki_repo)
  else
    puts "Wiki folder was not found. Please set up and clone your"\
         " wiki before using auto push"
  end
end
add_test_case(request, response) click to toggle source
# File lib/base.rb, line 49
def add_test_case(request, response)
  test = self.class::TestCase.new(request, response, @information)
  test.template = self.class::Conf.template
  self.tests << test
end
auto_push?() click to toggle source
# File lib/base.rb, line 86
def auto_push?
  self.class::Conf.auto_push
end
clean_up!() click to toggle source
# File lib/base.rb, line 15
def clean_up!
  @tests = []
end
information(key, value) click to toggle source
# File lib/base.rb, line 30
def information(key, value)
  @information[key] = value
end
output_compiled_template(file) click to toggle source
# File lib/base.rb, line 72
def output_compiled_template(file)
  @tests.each do |test|
    begin
      file.write(test.compile_template)
    rescue Exception => e
      STDERR.write "\n"
      STDERR.write "❌  An error occurred for: #{test.information[:endpoint_title]}\n"
      STDERR.write "🔗  #{test.request.method} #{test.request.path}\n"
      STDERR.write "⚠️  #{e.message}\n"
      STDERR.write "\n"
    end
  end
end
output_testcases_to_file() click to toggle source
# File lib/base.rb, line 59
def output_testcases_to_file
  docs = self.class::Conf.output_file
  raise 'No output file specific for SmashingDocs' unless docs
  File.delete docs if File.exists? docs
  write_to_file
end
run!(request, response, called_by_test_hook) click to toggle source
# File lib/base.rb, line 34
def run!(request, response, called_by_test_hook)
  run_all = self.class::Conf.run_all
  if @skip
    @skip = false
    return
  end
  if run_all
    add_test_case(request, response)
  else
    add_test_case(request, response) unless called_by_test_hook
  end
  @information = {}
  self
end
skip() click to toggle source
# File lib/base.rb, line 55
def skip
  @skip = true
end
sort_by_url!() click to toggle source
# File lib/base.rb, line 9
def sort_by_url!
  @tests.sort! do |x, y|
    x.request.path <=> y.request.path
  end
end
write_to_file() click to toggle source
# File lib/base.rb, line 66
def write_to_file
  File.open(self.class::Conf.output_file, 'a') do |file|
    output_compiled_template(file)
  end
end