Class: SmashingDocs
- Inherits:
-
Object
- Object
- SmashingDocs
- Defined in:
- lib/base.rb
Defined Under Namespace
Instance Attribute Summary collapse
-
#tests ⇒ Object
Returns the value of attribute tests.
Class Method Summary collapse
- .config {|self::Conf| ... } ⇒ Object
- .current ⇒ Object
-
.finish! ⇒ Object
= = = 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.
- .information(key, value) ⇒ Object
- .run!(request, response, called_by_test_hook = false) ⇒ Object
- .skip ⇒ Object
Instance Method Summary collapse
- #add_docs_to_wiki ⇒ Object
- #add_test_case(request, response) ⇒ Object
- #auto_push? ⇒ Boolean
- #clean_up! ⇒ Object
- #information(key, value) ⇒ Object
-
#initialize ⇒ SmashingDocs
constructor
A new instance of SmashingDocs.
- #output_testcases_to_file ⇒ Object
- #run!(request, response, called_by_test_hook) ⇒ Object
- #skip ⇒ Object
- #sort_by_url! ⇒ Object
- #write_to_file ⇒ Object
Constructor Details
#initialize ⇒ SmashingDocs
Returns a new instance of SmashingDocs.
3 4 5 6 7 |
# File 'lib/base.rb', line 3 def initialize @tests = [] @skip = false @information = {} end |
Instance Attribute Details
#tests ⇒ Object
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
109 110 111 |
# File 'lib/base.rb', line 109 def self.config(&block) yield(self::Conf) end |
.current ⇒ Object
104 105 106 107 |
# File 'lib/base.rb', line 104 def self.current # Behaves like an instance of SmashingDocs class Thread.current[:instance] ||= self.new end |
.finish! ⇒ Object
= = =
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
83 84 85 86 87 88 89 90 |
# File 'lib/base.rb', line 83 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) ⇒ Object
100 101 102 |
# File 'lib/base.rb', line 100 def self.information(key, value) current.information(key, value) end |
.run!(request, response, called_by_test_hook = false) ⇒ Object
92 93 94 |
# File 'lib/base.rb', line 92 def self.run!(request, response, called_by_test_hook = false) current.run!(request, response, called_by_test_hook) end |
.skip ⇒ Object
96 97 98 |
# File 'lib/base.rb', line 96 def self.skip current.skip end |
Instance Method Details
#add_docs_to_wiki ⇒ Object
19 20 21 22 23 24 25 26 27 28 |
# 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) ⇒ Object
49 50 51 52 53 |
# 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? ⇒ Boolean
74 75 76 |
# File 'lib/base.rb', line 74 def auto_push? self.class::Conf.auto_push end |
#clean_up! ⇒ Object
15 16 17 |
# File 'lib/base.rb', line 15 def clean_up! @tests = [] end |
#information(key, value) ⇒ Object
30 31 32 |
# File 'lib/base.rb', line 30 def information(key, value) @information[key] = value end |
#output_testcases_to_file ⇒ Object
59 60 61 62 63 64 |
# 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) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# 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 ⇒ Object
55 56 57 |
# File 'lib/base.rb', line 55 def skip @skip = true end |
#sort_by_url! ⇒ Object
9 10 11 12 13 |
# 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 ⇒ Object
66 67 68 69 70 71 72 |
# File 'lib/base.rb', line 66 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 |