debt_ceiling 0.3.2 → 0.3.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +6 -3
- data/lib/debt_ceiling/audit.rb +18 -16
- data/lib/debt_ceiling/version.rb +1 -1
- data/spec/debt_ceiling_spec.rb +9 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1125eec0668d278a574a419d40d4b40996e3a318
|
4
|
+
data.tar.gz: f6ae9f67c06f1ee678bb07e53df65b14a9c8cafd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ff07b0f6c4d044c439ab9a376586f9fb13b00db3c1dbded832851d591454624324ac6ab0ea3f1e5318001b377070efe5022ef6f710ae9dcc293575069e966654
|
7
|
+
data.tar.gz: ef856854187389e9f2c89b7337446c97ebe6091d0ffdf4efe3d655539843fa2bdbd6758bf20cf0e19d877c9b43d02444a1cb69f0cf035edb03bfb216fcf01ee9
|
data/README.md
CHANGED
@@ -24,18 +24,21 @@ Current features include:
|
|
24
24
|
* Running from a test suite to fail if debt ceiling is exceeded
|
25
25
|
* Running from a test suite to fail if debt deadline is missed (currently only supports a single deadline, could add support for multiple targets if there's interest)
|
26
26
|
|
27
|
-
To integrate in a test suite, set a value for `debt_ceiling`, `max_debt_per_module` and/or `reduction_target` and `reduction_date` in your configuration and call `DebtCeiling.audit
|
27
|
+
To integrate in a test suite, set a value for `debt_ceiling`, `max_debt_per_module` and/or `reduction_target` and `reduction_date` in your configuration and call `DebtCeiling.audit` from your test helper as an additional test, or drop the call and/or configuration directly in your spec helper:
|
28
28
|
```ruby
|
29
|
+
require 'debt_ceiling'
|
29
30
|
config.after(:all) do
|
30
31
|
DebtCeiling.configure do |c|
|
31
32
|
c.whitelist = %w(app lib)
|
32
33
|
c.max_debt_per_module = 150
|
33
34
|
c.debt_ceiling = 250
|
34
35
|
end
|
35
|
-
DebtCeiling.audit(
|
36
|
+
DebtCeiling.audit(preconfigured: true)
|
36
37
|
end
|
37
38
|
```
|
38
|
-
|
39
|
+
`audit` defaults to '.' as root directory, since specs are usually run from root, but you can pass it a relative path as an argument, i.e. `DebtCeiling.audit('./lib')`
|
40
|
+
|
41
|
+
It will exit with a non-zero failure, failing the test suite, if you exceed your ceiling(s) or miss your target and print the failure and reason for failure. If you wish debt ceiling to run and print the failures, but not fail the test suite when thresholds are exceeded or targets are missed, call the audit method with the `warn_only` option, i.e.: `DebtCeiling.audit(warn_only: true)`
|
39
42
|
|
40
43
|
These features are largely demonstrated/discussed in [examples/.debt_ceiling.rb.example](https://github.com/bglusman/debt_ceiling/blob/master/examples/.debt_ceiling.rb.example) or below snippet which demonstrates configuring debt ceiling around a team or maintainer's agreed ideas about how to quantify debt automatically and/or manually in the project source code.
|
41
44
|
|
data/lib/debt_ceiling/audit.rb
CHANGED
@@ -6,7 +6,11 @@ module DebtCeiling
|
|
6
6
|
|
7
7
|
CONFIG_FILE_NAME = ".debt_ceiling.rb"
|
8
8
|
CONFIG_LOCATIONS = ["#{Dir.pwd}/#{CONFIG_FILE_NAME}", "#{Dir.home}/#{CONFIG_FILE_NAME}"]
|
9
|
-
|
9
|
+
FAILURE_MESSAGE = "DEBT CEILING FAILURE: "
|
10
|
+
TOTAL_LIMIT = "EXCEEDED TOTAL DEBT CEILING "
|
11
|
+
NO_CONFIG_FOUND = "No #{CONFIG_FILE_NAME} configuration file detected in #{Dir.pwd} or ~/, using defaults"
|
12
|
+
PER_MODULE_MESSAGE = "MAX DEBT PER MODULE EXCEEDED IN AT LEAST ONE LOCATION"
|
13
|
+
MISSED_TARGET_MESSAGE = "MISSED DEBT REDUCTION TARGET "
|
10
14
|
|
11
15
|
attr_reader :accounting, :dir, :loaded
|
12
16
|
|
@@ -20,7 +24,8 @@ module DebtCeiling
|
|
20
24
|
@dir = dir
|
21
25
|
@accounting = perform_accounting
|
22
26
|
accounting.print_results unless opts[:skip_report]
|
23
|
-
|
27
|
+
puts failure_message
|
28
|
+
fail_test if failed_condition? && !opts[:warn_only]
|
24
29
|
end
|
25
30
|
|
26
31
|
private
|
@@ -55,33 +60,30 @@ module DebtCeiling
|
|
55
60
|
end
|
56
61
|
|
57
62
|
def failed_condition?
|
58
|
-
exceeded_total_limit
|
63
|
+
exceeded_total_limit || missed_target || max_debt_per_module_exceeded
|
59
64
|
end
|
60
65
|
|
61
66
|
def failure_message
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
message += "MAX DEBT PER MODULE EXCEEDED IN AT LEAST ONE LOCATION" if max_debt_per_module_exceeded?
|
67
|
-
message
|
67
|
+
<<-MESG
|
68
|
+
#{FAILURE_MESSAGE if failed_condition?}#{exceeded_total_limit}#{missed_target}
|
69
|
+
#{max_debt_per_module_exceeded}
|
70
|
+
MESG
|
68
71
|
end
|
69
72
|
|
70
|
-
def exceeded_total_limit
|
71
|
-
debt_ceiling && debt_ceiling <= total_debt
|
73
|
+
def exceeded_total_limit
|
74
|
+
TOTAL_LIMIT if debt_ceiling && debt_ceiling <= total_debt
|
72
75
|
end
|
73
76
|
|
74
|
-
def missed_target
|
75
|
-
reduction_target && reduction_target <= total_debt &&
|
77
|
+
def missed_target
|
78
|
+
MISSED_TARGET_MESSAGE if reduction_target && reduction_target <= total_debt &&
|
76
79
|
Time.now > Chronic.parse(reduction_date)
|
77
80
|
end
|
78
81
|
|
79
|
-
def max_debt_per_module_exceeded
|
80
|
-
max_debt_per_module && max_debt_per_module <= accounting.max_debt.to_i
|
82
|
+
def max_debt_per_module_exceeded
|
83
|
+
PER_MODULE_MESSAGE if max_debt_per_module && max_debt_per_module <= accounting.max_debt.to_i
|
81
84
|
end
|
82
85
|
|
83
86
|
def fail_test
|
84
|
-
puts failure_message
|
85
87
|
at_exit do
|
86
88
|
Kernel.exit 1
|
87
89
|
end
|
data/lib/debt_ceiling/version.rb
CHANGED
data/spec/debt_ceiling_spec.rb
CHANGED
@@ -16,13 +16,21 @@ describe DebtCeiling do
|
|
16
16
|
DebtCeiling.audit('.', preconfigured: true)
|
17
17
|
end
|
18
18
|
|
19
|
-
it 'has failing exit status when max debt per
|
19
|
+
it 'has failing exit status when max debt per module is exceeded' do
|
20
20
|
DebtCeiling.configure {|c| c.max_debt_per_module =5 }
|
21
21
|
expect(DebtCeiling.debt_ceiling).to eq(nil)
|
22
22
|
expect_any_instance_of(DebtCeiling::Audit).to receive(:fail_test)
|
23
23
|
DebtCeiling.audit('.', preconfigured: true)
|
24
24
|
end
|
25
25
|
|
26
|
+
it 'has no failing exit status when in warn only mode' do
|
27
|
+
DebtCeiling.configure {|c| c.max_debt_per_module =5 }
|
28
|
+
expect(DebtCeiling.debt_ceiling).to eq(nil)
|
29
|
+
expect_any_instance_of(DebtCeiling::Audit).to receive(:failed_condition?).at_least(:once).and_return(true)
|
30
|
+
expect_any_instance_of(DebtCeiling::Audit).not_to receive(:fail_test)
|
31
|
+
DebtCeiling.audit('.', preconfigured: true, warn_only: true)
|
32
|
+
end
|
33
|
+
|
26
34
|
it 'returns quantity of total debt' do
|
27
35
|
expect(DebtCeiling.audit('.').total_debt).to be > 5 # arbitrary non-zero amount
|
28
36
|
end
|