fixme 1.1.3 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +29 -5
- data/lib/fixme/version.rb +1 -1
- data/lib/fixme.rb +21 -4
- data/spec/fixme_spec.rb +41 -5
- 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: f17c8f6e1e7bf078eb5aecf0ff123ff697518798
|
4
|
+
data.tar.gz: 9d4e88a2b29c7be13ab6744dc3a90cfa1a71f251
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 22bed2eda72ded7cda30319e24aa4e80f1cb76583c65ed456871fd71b4a0e9470bec39c3a1f5846655c4803a28ac91e21956bf48d1435c29d035e215389c7431
|
7
|
+
data.tar.gz: d664dc80938522c5d978b30bccbf34b0e2e01f0f7dbb147deced872daf2e5a4fd3b9f7b8b7ef914f7f6354fbd3e88a221d057b8e339c2790e256ebcb374cc45f
|
data/README.md
CHANGED
@@ -18,15 +18,39 @@ You may want to use these bad boys next to:
|
|
18
18
|
* Experiments, to remember to evaluate them and make a decision.
|
19
19
|
* Anything else you can't do now but should fix later.
|
20
20
|
|
21
|
-
If `Rails.environment` (Ruby on Rails) or `ENV["RACK_ENV"]` (e.g. Sinatra) is present, it will only ever raise in the `"test"` and `"development"` environments. That is, the production app will never raise these exceptions.
|
22
|
-
|
23
|
-
If you don't want your CI server to raise, make it set the environment variable `DO_NOT_RAISE_FIXMES`. I like having CI raise them, though.
|
24
|
-
|
25
21
|
For simplicity, the date comparison uses machine-local time (not e.g. the Rails configured time zone).
|
26
22
|
|
27
23
|
Protip: make sure it's clear from the exception or from a separate comment just what should be done – sometimes not even the person who wrote the quickfix will remember what you're meant to change.
|
28
24
|
|
29
|
-
|
25
|
+
### Environment awareness
|
26
|
+
|
27
|
+
If `Rails.env` (Ruby on Rails) or `ENV["RACK_ENV"]` (e.g. Sinatra) is present, it will only ever raise in the `"test"` and `"development"` environments. That is, the production app will never raise these exceptions.
|
28
|
+
|
29
|
+
### Selectively disable
|
30
|
+
|
31
|
+
If you e.g. don't want your CI server to raise, make it set the environment variable `DISABLE_FIXME_LIB`.
|
32
|
+
|
33
|
+
### Do something other than raise
|
34
|
+
|
35
|
+
When these exceptions trigger on your CI server they stop the line, blocking your delivery chain until they're addressed. This could be what you want, or it could be a little annoying.
|
36
|
+
|
37
|
+
So you can configure the library to do something other than raise:
|
38
|
+
|
39
|
+
```
|
40
|
+
# In a Rails project, this might be in config/initializers/fixme.rb:
|
41
|
+
Fixme.explode_with do |message|
|
42
|
+
YourOwnCodeOrSomeLibrary.email_developers(message)
|
43
|
+
YourOwnCodeOrSomeLibrary.notify_chat(message)
|
44
|
+
end
|
45
|
+
```
|
46
|
+
|
47
|
+
If you want the parsed date and the message separately, do:
|
48
|
+
|
49
|
+
```
|
50
|
+
Fixme.explode_with do |_, date, message|
|
51
|
+
YourOwnCodeOrSomeLibrary.log(date, message)
|
52
|
+
end
|
53
|
+
```
|
30
54
|
|
31
55
|
|
32
56
|
## Installation
|
data/lib/fixme/version.rb
CHANGED
data/lib/fixme.rb
CHANGED
@@ -4,6 +4,25 @@ require "date"
|
|
4
4
|
module Fixme
|
5
5
|
class UnfixedError < StandardError; end
|
6
6
|
|
7
|
+
DEFAULT_EXPLODER = proc { |message| raise(UnfixedError, message) }
|
8
|
+
|
9
|
+
def self.reset_configuration
|
10
|
+
explode_with(&DEFAULT_EXPLODER)
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.explode_with(&block)
|
14
|
+
@explode_with = block
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.explode(date, message)
|
18
|
+
full_message = "Fix by #{date}: #{message}"
|
19
|
+
@explode_with.call(full_message, date, message)
|
20
|
+
end
|
21
|
+
|
22
|
+
reset_configuration
|
23
|
+
end
|
24
|
+
|
25
|
+
module Fixme
|
7
26
|
module Mixin
|
8
27
|
def FIXME(date_and_message)
|
9
28
|
# In a separate class to avoid mixing in privates.
|
@@ -20,15 +39,13 @@ module Fixme
|
|
20
39
|
end
|
21
40
|
|
22
41
|
def run
|
23
|
-
return if ENV["
|
42
|
+
return if ENV["DISABLE_FIXME_LIB"]
|
24
43
|
return unless RUN_ONLY_IN_FRAMEWORK_ENVS.include?(framework_env.to_s)
|
25
44
|
|
26
45
|
due_date, message = parse
|
27
46
|
|
28
47
|
disallow_timecop do
|
29
|
-
if Date.today >= due_date
|
30
|
-
raise UnfixedError, "Fix by #{due_date}: #{message}"
|
31
|
-
end
|
48
|
+
Fixme.explode(due_date, message) if Date.today >= due_date
|
32
49
|
end
|
33
50
|
end
|
34
51
|
|
data/spec/fixme_spec.rb
CHANGED
@@ -2,6 +2,10 @@ require "fixme"
|
|
2
2
|
require "timecop"
|
3
3
|
|
4
4
|
describe Fixme, "#FIXME" do
|
5
|
+
before do
|
6
|
+
Fixme.reset_configuration
|
7
|
+
end
|
8
|
+
|
5
9
|
it "raises after the given date" do
|
6
10
|
expect {
|
7
11
|
FIXME "2013-12-31: Remove this stuff."
|
@@ -9,9 +13,11 @@ describe Fixme, "#FIXME" do
|
|
9
13
|
end
|
10
14
|
|
11
15
|
it "raises on the given date" do
|
16
|
+
today = Date.today
|
17
|
+
|
12
18
|
expect {
|
13
|
-
FIXME "#{
|
14
|
-
}.to raise_error(Fixme::UnfixedError, "Fix by #{
|
19
|
+
FIXME "#{today}: Remove this stuff."
|
20
|
+
}.to raise_error(Fixme::UnfixedError, "Fix by #{today}: Remove this stuff.")
|
15
21
|
end
|
16
22
|
|
17
23
|
it "does not raise before the given date" do
|
@@ -68,7 +74,7 @@ describe Fixme, "#FIXME" do
|
|
68
74
|
|
69
75
|
context "when a Rack environment is detected" do
|
70
76
|
before do
|
71
|
-
stub_env "
|
77
|
+
stub_env "DISABLE_FIXME_LIB", nil
|
72
78
|
end
|
73
79
|
|
74
80
|
it "raises in the 'test' environment" do
|
@@ -87,11 +93,41 @@ describe Fixme, "#FIXME" do
|
|
87
93
|
end
|
88
94
|
end
|
89
95
|
|
90
|
-
it "does not raise when the
|
91
|
-
stub_env "
|
96
|
+
it "does not raise when the DISABLE_FIXME_LIB environment variable is set" do
|
97
|
+
stub_env "DISABLE_FIXME_LIB", true
|
92
98
|
expect_not_to_raise
|
93
99
|
end
|
94
100
|
|
101
|
+
context "configuring an alternative to raising" do
|
102
|
+
it "lets you provide a block" do
|
103
|
+
log = []
|
104
|
+
|
105
|
+
Fixme.explode_with do |full_message, date, message|
|
106
|
+
log << [ full_message, date, message ]
|
107
|
+
end
|
108
|
+
|
109
|
+
FIXME "2013-12-31: Do not explode."
|
110
|
+
|
111
|
+
expect(log.last).to eq [
|
112
|
+
"Fix by 2013-12-31: Do not explode.",
|
113
|
+
Date.new(2013, 12, 31),
|
114
|
+
"Do not explode.",
|
115
|
+
]
|
116
|
+
end
|
117
|
+
|
118
|
+
it "lets the block take a subset of parameters" do
|
119
|
+
log = []
|
120
|
+
|
121
|
+
Fixme.explode_with do |full_message|
|
122
|
+
log << full_message
|
123
|
+
end
|
124
|
+
|
125
|
+
FIXME "2013-12-31: Do not explode."
|
126
|
+
|
127
|
+
expect(log.last).to eq "Fix by 2013-12-31: Do not explode."
|
128
|
+
end
|
129
|
+
end
|
130
|
+
|
95
131
|
private
|
96
132
|
|
97
133
|
def stub_rails_env(value)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fixme
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Henrik Nyh
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-06-
|
11
|
+
date: 2014-06-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|