Class: Fitting::Log
- Inherits:
-
Object
- Object
- Fitting::Log
- Defined in:
- lib/fitting/log.rb
Class Method Summary collapse
Instance Method Summary collapse
- #access! ⇒ Object
- #body ⇒ Object
- #content_type ⇒ Object
- #error ⇒ Object
- #failure!(error) ⇒ Object
- #failure? ⇒ Boolean
- #host ⇒ Object
-
#initialize(log, type) ⇒ Log
constructor
A new instance of Log.
- #method ⇒ Object
- #path ⇒ Object
- #pending! ⇒ Object
- #pending? ⇒ Boolean
- #status ⇒ Object
- #type ⇒ Object
- #url ⇒ Object
Constructor Details
#initialize(log, type) ⇒ Log
Returns a new instance of Log.
3 4 5 6 7 8 |
# File 'lib/fitting/log.rb', line 3 def initialize(log, type) @log = log @type = type @error = nil @skip = false end |
Class Method Details
.all ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/fitting/log.rb', line 10 def self.all logs = [] Dir["log/fitting*.log"].each do |file_path| testlog = File.read(file_path) testlog.split("\n").select { |f| f.include?('incoming request ') }.each do |test| logs.push(new(JSON.load(test.split('incoming request ')[1]), 'incoming')) end testlog.split("\n").select { |f| f.include?('outgoing request ') }.each do |test| logs.push(new(JSON.load(test.split('outgoing request ')[1]), 'outgoing')) end end logs.sort { |a, b| b.path <=> a.path } end |
.failure(logs) ⇒ Object
78 79 80 81 82 |
# File 'lib/fitting/log.rb', line 78 def self.failure(logs) logs.select do |log| log.failure? end end |
.pending(logs) ⇒ Object
88 89 90 91 92 |
# File 'lib/fitting/log.rb', line 88 def self.pending(logs) logs.select do |log| log.pending? end end |
.report(logs) ⇒ Object
94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
# File 'lib/fitting/log.rb', line 94 def self.report(logs) puts "\n\n" Fitting::Log.failure(logs).each_with_index do |log, index| puts "\e[31m #{index + 1}) #{log.error.class} #{log.error.}\n\n\e[0m" end failure_count = Fitting::Log.failure(logs).size color_code = failure_count > 0 ? 31 : 32 print "\e[#{color_code}m#{logs.size} examples, #{failure_count} failure, #{Fitting::Log.pending(logs).size} pending\e[0m\n" unless Fitting::Log.failure(logs).size <= 0 exit 1 end end |
Instance Method Details
#access! ⇒ Object
56 57 58 |
# File 'lib/fitting/log.rb', line 56 def access! print "\e[32m.\e[0m" end |
#body ⇒ Object
40 41 42 |
# File 'lib/fitting/log.rb', line 40 def body @log['response']['body'] end |
#content_type ⇒ Object
44 45 46 |
# File 'lib/fitting/log.rb', line 44 def content_type @log['response']['content_type'] end |
#error ⇒ Object
70 71 72 |
# File 'lib/fitting/log.rb', line 70 def error @error end |
#failure!(error) ⇒ Object
65 66 67 68 |
# File 'lib/fitting/log.rb', line 65 def failure!(error) @error = error print "\e[31mF\e[0m" end |
#failure? ⇒ Boolean
74 75 76 |
# File 'lib/fitting/log.rb', line 74 def failure? @error.present? end |
#host ⇒ Object
48 49 50 |
# File 'lib/fitting/log.rb', line 48 def host @log['host'] || 'www.example.com' end |
#method ⇒ Object
32 33 34 |
# File 'lib/fitting/log.rb', line 32 def method @log['method'] end |
#path ⇒ Object
28 29 30 |
# File 'lib/fitting/log.rb', line 28 def path @log['path'] end |
#pending! ⇒ Object
60 61 62 63 |
# File 'lib/fitting/log.rb', line 60 def pending! @skip = true print "\e[33m*\e[0m" end |
#pending? ⇒ Boolean
84 85 86 |
# File 'lib/fitting/log.rb', line 84 def pending? @skip end |
#status ⇒ Object
36 37 38 |
# File 'lib/fitting/log.rb', line 36 def status @log['response']['status'].to_s end |
#type ⇒ Object
52 53 54 |
# File 'lib/fitting/log.rb', line 52 def type @type end |
#url ⇒ Object
24 25 26 |
# File 'lib/fitting/log.rb', line 24 def url "#{host}#{path}" end |