active_mocker 2.2.1 → 2.2.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/active_mocker/display_errors.rb +76 -26
- data/lib/active_mocker/mock/base.rb +1 -1
- data/lib/active_mocker/mock/queries.rb +8 -6
- data/lib/active_mocker/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6e14ca018eff8f1c0f6c575322ae1cf79d48a3c9
|
4
|
+
data.tar.gz: 71fd81a8740ccd5d08a71186b096a1bef03a0b97
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4c9e9c1b8bfd686ed562218d52f8324fd50f642ce29f105a61ea384745dcadf99d4764a18352771e1b387232d056186aba8b5bc62f5623078cba43ec86db7185
|
7
|
+
data.tar.gz: 217ec8087dedb24510a5ecd6e95b2b1e1da24853b830c922292fe8f74ccdafc7c23bde72a0e788e2dfa8c6e6c559d1c094540574f521e73f3f4500af614bc152
|
@@ -1,4 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
+
require "colorize"
|
2
3
|
module ActiveMocker
|
3
4
|
class DisplayErrors
|
4
5
|
attr_reader :errors, :model_count, :out
|
@@ -28,43 +29,92 @@ module ActiveMocker
|
|
28
29
|
@uniq_errors ||= errors.flatten.compact.uniq.sort_by(&:class_name)
|
29
30
|
end
|
30
31
|
|
32
|
+
def any_errors?
|
33
|
+
uniq_errors.count > 0
|
34
|
+
end
|
35
|
+
|
31
36
|
def display_errors
|
32
37
|
uniq_errors.each do |e|
|
33
38
|
next unless ENV["DEBUG"] || !(e.level == :debug)
|
34
|
-
|
35
|
-
|
36
|
-
out.puts e.message.colorize(e.level_color)
|
37
|
-
out.puts e.level
|
38
|
-
out.puts e.original_error.message.colorize(e.level_color) if e.original_error?
|
39
|
-
out.puts e.original_error.backtrace if e.original_error?
|
40
|
-
out.puts e.original_error.class.name.colorize(e.level_color) if e.original_error?
|
41
|
-
elsif ActiveMocker::Config.error_verbosity == 2
|
42
|
-
out.puts "#{e.class_name} has the following errors:"
|
43
|
-
out.puts e.message.colorize(e.level_color)
|
44
|
-
end
|
45
|
-
end
|
46
|
-
if ActiveMocker::Config.error_verbosity > 0 && uniq_errors.count > 0
|
47
|
-
out.puts "Error Summary"
|
48
|
-
error_summary
|
49
|
-
end
|
50
|
-
failure_count_message
|
51
|
-
if ActiveMocker::Config.error_verbosity > 0 && uniq_errors.count > 0
|
52
|
-
out.puts "To see more/less detail set error_verbosity = 0, 1, 2, 3"
|
39
|
+
|
40
|
+
display_verbosity_three(e) || display_verbosity_two(e)
|
53
41
|
end
|
42
|
+
|
43
|
+
display_verbosity_one
|
54
44
|
end
|
55
45
|
|
56
46
|
def error_summary
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
out.puts "errors: #{error_count}, warn: #{warn}, info: #{info}"
|
61
|
-
out.puts "Failed models: #{failed_models.join(", ")}" if failed_models.count > 0
|
47
|
+
display "Error Summary"
|
48
|
+
display "errors: #{error_count}, warn: #{warn}, info: #{info}"
|
49
|
+
display "Failed models: #{failed_models.join(", ")}" if failed_models.count > 0
|
62
50
|
end
|
63
51
|
|
64
52
|
def failure_count_message
|
65
|
-
if
|
66
|
-
|
53
|
+
if success_count < model_count || any_errors?
|
54
|
+
display "#{model_count - success_count} mock(s) out of #{model_count} failed."
|
67
55
|
end
|
68
56
|
end
|
57
|
+
|
58
|
+
private
|
59
|
+
|
60
|
+
def display(msg)
|
61
|
+
out.puts(msg)
|
62
|
+
end
|
63
|
+
|
64
|
+
def display_verbosity_three(error)
|
65
|
+
return unless ActiveMocker::Config.error_verbosity == 3
|
66
|
+
|
67
|
+
display_error_header(error)
|
68
|
+
display error.level
|
69
|
+
|
70
|
+
display_original_error(error)
|
71
|
+
end
|
72
|
+
|
73
|
+
def display_original_error(e)
|
74
|
+
original = e.original_error
|
75
|
+
return unless original
|
76
|
+
|
77
|
+
display original.message.colorize(e.level_color)
|
78
|
+
display original.backtrace
|
79
|
+
display original.class.name.colorize(e.level_color)
|
80
|
+
end
|
81
|
+
|
82
|
+
def display_verbosity_two(e)
|
83
|
+
return unless ActiveMocker::Config.error_verbosity == 2
|
84
|
+
|
85
|
+
display_error_header(e)
|
86
|
+
end
|
87
|
+
|
88
|
+
def display_error_header(e)
|
89
|
+
display "#{e.class_name} has the following errors:"
|
90
|
+
display e.message.colorize(e.level_color)
|
91
|
+
end
|
92
|
+
|
93
|
+
def display_verbosity_one
|
94
|
+
return unless ActiveMocker::Config.error_verbosity > 0
|
95
|
+
|
96
|
+
error_summary if any_errors?
|
97
|
+
|
98
|
+
failure_count_message
|
99
|
+
|
100
|
+
return unless any_errors?
|
101
|
+
display "To see more/less detail set error_verbosity = 0, 1, 2, 3"
|
102
|
+
end
|
103
|
+
|
104
|
+
def error_count
|
105
|
+
errors_for(:red)
|
106
|
+
end
|
107
|
+
|
108
|
+
def warn
|
109
|
+
errors_for(:yellow)
|
110
|
+
end
|
111
|
+
|
112
|
+
def info
|
113
|
+
errors_for(:default)
|
114
|
+
end
|
115
|
+
|
116
|
+
def errors_for(level)
|
117
|
+
uniq_errors.count { |e| [level].include? e.level_color }
|
118
|
+
end
|
69
119
|
end
|
70
120
|
end
|
@@ -58,12 +58,10 @@ module ActiveMocker
|
|
58
58
|
# Post.limit(100).delete_all
|
59
59
|
# # => ActiveMocker::Error: delete_all doesn't support limit scope
|
60
60
|
def delete_all(conditions = nil)
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
end
|
66
|
-
where(conditions).map(&:delete).count
|
61
|
+
check_for_limit_scope!
|
62
|
+
|
63
|
+
collection = conditions.nil? ? to_a.each(&:delete).clear : where(conditions)
|
64
|
+
collection.map(&:delete).count
|
67
65
|
end
|
68
66
|
|
69
67
|
alias destroy_all delete_all
|
@@ -346,6 +344,10 @@ module ActiveMocker
|
|
346
344
|
|
347
345
|
private
|
348
346
|
|
347
|
+
def check_for_limit_scope!
|
348
|
+
raise ActiveMocker::Error.new("delete_all doesn't support limit scope") if from_limit?
|
349
|
+
end
|
350
|
+
|
349
351
|
def values_by_key(key)
|
350
352
|
all.map { |obj| obj.send(key) }
|
351
353
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: active_mocker
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.2.
|
4
|
+
version: 2.2.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dustin Zeisler
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-05-
|
11
|
+
date: 2016-05-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|