Class: DocYoSelf

Inherits:
Object
  • Object
show all
Defined in:
lib/base.rb

Defined Under Namespace

Classes: Conf, TestCase

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeDocYoSelf

Returns a new instance of DocYoSelf.



3
4
5
6
# File 'lib/base.rb', line 3

def initialize
  @tests = []
  @skip = 0 # <= Hate this.
end

Instance Attribute Details

#testsObject

Returns the value of attribute tests.



2
3
4
# File 'lib/base.rb', line 2

def tests
  @tests
end

Class Method Details

.config {|self::Conf| ... } ⇒ Object

Yields:

  • (self::Conf)


80
81
82
# File 'lib/base.rb', line 80

def self.config(&block)
  yield(self::Conf)
end

.currentObject



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

def self.current
  Thread.current[:dys_instance] ||= self.new
end

.finish!Object

= = =



58
59
60
61
62
# File 'lib/base.rb', line 58

def self.finish!
  current.sort_by_url!
  current.output_testcases_to_file
  current.clean_up!
end

.note(msg) ⇒ Object



72
73
74
# File 'lib/base.rb', line 72

def self.note(msg)
  current.note(msg)
end

.run!(request, response) ⇒ Object



64
65
66
# File 'lib/base.rb', line 64

def self.run!(request, response)
  current.run!(request, response)
end

.skipObject



68
69
70
# File 'lib/base.rb', line 68

def self.skip
  current.skip
end

Instance Method Details

#add_test_case(request, response, note) ⇒ Object



31
32
33
34
35
# File 'lib/base.rb', line 31

def add_test_case(request, response, note)
  test = self.class::TestCase.new(request, response, note)
  test.template = self.class::Conf.template
  self.tests << test
end

#clean_up!Object



14
15
16
# File 'lib/base.rb', line 14

def clean_up!
  @tests = []
end

#note(msg) ⇒ Object



18
19
20
# File 'lib/base.rb', line 18

def note(msg)
  @note = msg || ''
end

#output_testcases_to_fileObject



41
42
43
44
45
46
# File 'lib/base.rb', line 41

def output_testcases_to_file
  docs = self.class::Conf.output_file
  raise 'No output file specific for DocYoSelf' unless docs
  File.delete docs if File.exists? docs
  write_to_file
end

#run!(request, response) ⇒ Object



22
23
24
25
26
27
28
29
# File 'lib/base.rb', line 22

def run!(request, response)
  @skip += 1
  return if @skip == 2 # Gross.
  add_test_case(request, response, @note)
  @note = ''
  @skip = 0
  self
end

#skipObject



37
38
39
# File 'lib/base.rb', line 37

def skip
  @skip += 1
end

#sort_by_url!Object



8
9
10
11
12
# File 'lib/base.rb', line 8

def sort_by_url!
  @tests.sort! do |x, y|
    x.request.path <=> y.request.path
  end
end

#write_to_fileObject



48
49
50
51
52
53
54
# File 'lib/base.rb', line 48

def write_to_file
  File.open(self.class::Conf.output_file, 'a') do |file|
    @tests.each do |test|
      file.write(test.compile_template)
    end
  end
end