fail_fast 0.3.0 → 0.4.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.
- data/CHANGELOG.txt +2 -0
- data/README.markdown +12 -3
- data/VERSION +1 -1
- data/fail_fast.gemspec +6 -2
- data/lib/fail_fast/base/messaging.rb +39 -0
- data/lib/fail_fast/extensions/check_is_on_path.rb +40 -0
- data/lib/fail_fast/extensions/check_value.rb +1 -1
- data/lib/fail_fast/report.txt.erb +6 -45
- data/lib/fail_fast/support/error_details.rb +6 -0
- data/show_all_errors.rb +3 -0
- data/spec/extensions/check_is_on_path_spec.rb +26 -0
- data/spec/fixtures/simple.yml +2 -0
- metadata +8 -4
data/CHANGELOG.txt
CHANGED
data/README.markdown
CHANGED
@@ -7,13 +7,14 @@
|
|
7
7
|
## How to use :
|
8
8
|
|
9
9
|
|
10
|
-
### Example 0 : don't start the application if '_why' cannot be found (on the PATH).
|
10
|
+
### Example 0 : don't start the application on Sunday or if '_why' cannot be found (on the PATH).
|
11
11
|
|
12
12
|
Insert this code early in your program starting sequence :
|
13
13
|
|
14
14
|
require 'fail_fast'
|
15
15
|
FailFast().check do
|
16
|
-
|
16
|
+
is_on_path '_why'
|
17
|
+
fail "I don't work on Sunday" if 0 == Time.now.wday
|
17
18
|
end
|
18
19
|
|
19
20
|
|
@@ -195,11 +196,19 @@ You can also add custom rules, not related to any config files :
|
|
195
196
|
nda_file = value_of(:nda_file)
|
196
197
|
fail 'NDA is too old' if (Time.now - File.mtime(nda_file)) > (24 * 60 * 60) * 365
|
197
198
|
|
198
|
-
Test the file system :
|
199
|
+
Test the file system and .. :
|
199
200
|
|
201
|
+
directory_exists '/home/ci/uploads'
|
202
|
+
file_exists '/home/ci/config/secret.key'
|
203
|
+
|
204
|
+
# the keyed version :
|
200
205
|
directory_exists_for 'assets-upload_dir'
|
201
206
|
file_exists_for 'assets-nda_pdf_file'
|
202
207
|
|
208
|
+
is_on_path 'jruby' # fail if jruby cannot be found
|
209
|
+
is_on_path_for :ruby_engine
|
210
|
+
|
211
|
+
|
203
212
|
Test external services :
|
204
213
|
|
205
214
|
# is a webserver up ?
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.4.0
|
data/fail_fast.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{fail_fast}
|
8
|
-
s.version = "0.
|
8
|
+
s.version = "0.4.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Alain Ravet"]
|
12
|
-
s.date = %q{2010-07-
|
12
|
+
s.date = %q{2010-07-22}
|
13
13
|
s.description = %q{raises an error if the yaml contents of a config file does not pass a test script.}
|
14
14
|
s.email = %q{alainravet@gmail.com}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -27,12 +27,14 @@ Gem::Specification.new do |s|
|
|
27
27
|
"fail_fast.gemspec",
|
28
28
|
"lib/fail_fast.rb",
|
29
29
|
"lib/fail_fast/base/base.rb",
|
30
|
+
"lib/fail_fast/base/messaging.rb",
|
30
31
|
"lib/fail_fast/base/utils.rb",
|
31
32
|
"lib/fail_fast/base/z_only_for_tests.rb",
|
32
33
|
"lib/fail_fast/extensions/base_commands.rb",
|
33
34
|
"lib/fail_fast/extensions/check_active_record_db.rb",
|
34
35
|
"lib/fail_fast/extensions/check_email.rb",
|
35
36
|
"lib/fail_fast/extensions/check_file_system.rb",
|
37
|
+
"lib/fail_fast/extensions/check_is_on_path.rb",
|
36
38
|
"lib/fail_fast/extensions/check_mongo_db.rb",
|
37
39
|
"lib/fail_fast/extensions/check_url.rb",
|
38
40
|
"lib/fail_fast/extensions/check_value.rb",
|
@@ -52,6 +54,7 @@ Gem::Specification.new do |s|
|
|
52
54
|
"spec/extensions/check_active_record_db_spec.rb",
|
53
55
|
"spec/extensions/check_email_spec.rb",
|
54
56
|
"spec/extensions/check_file_system_spec.rb",
|
57
|
+
"spec/extensions/check_is_on_path_spec.rb",
|
55
58
|
"spec/extensions/check_mongo_db_spec.rb",
|
56
59
|
"spec/extensions/check_url_spec.rb",
|
57
60
|
"spec/extensions/check_value_spec.rb",
|
@@ -77,6 +80,7 @@ Gem::Specification.new do |s|
|
|
77
80
|
"spec/extensions/check_active_record_db_spec.rb",
|
78
81
|
"spec/extensions/check_email_spec.rb",
|
79
82
|
"spec/extensions/check_file_system_spec.rb",
|
83
|
+
"spec/extensions/check_is_on_path_spec.rb",
|
80
84
|
"spec/extensions/check_mongo_db_spec.rb",
|
81
85
|
"spec/extensions/check_url_spec.rb",
|
82
86
|
"spec/extensions/check_value_spec.rb",
|
@@ -0,0 +1,39 @@
|
|
1
|
+
class FailFast
|
2
|
+
|
3
|
+
module Messaging
|
4
|
+
|
5
|
+
def default_message_for(e)
|
6
|
+
qc_value = "'#{vcol(e.value)}'"
|
7
|
+
qc_key = "'#{kcol(e.key)}'"
|
8
|
+
details = if e.value.nil? then " for the key #{qc_key}"
|
9
|
+
elsif e.key.nil? then " #{qc_value}"
|
10
|
+
else " #{qc_value} for the key #{qc_key}"
|
11
|
+
end
|
12
|
+
|
13
|
+
case e.kind
|
14
|
+
when :config_file_not_found then mcol("The config file could not be found") + " : #{yellow(e.value)}."
|
15
|
+
when :missing_value then mcol("Missing value") +" #{details}."
|
16
|
+
when :value_does_not_match then mcol("Invalid value") +" #{details}."
|
17
|
+
when :not_an_email then mcol("Invalid email address") + " #{details}."
|
18
|
+
when :not_a_url then mcol("Invalid url") + " #{details}."
|
19
|
+
when :url_not_reachable then mcol("Could not reach the url") + " #{details}."
|
20
|
+
when :directory_not_found then mcol("Missing directory") + " #{details}."
|
21
|
+
when :file_not_found then mcol("Missing file") + " #{details}."
|
22
|
+
when :not_on_path then mcol("App not on path : ") + " #{details}."
|
23
|
+
when :mongoDB_server_not_found then mcol("Could not connect to the mongoDb server") + " #{details}."
|
24
|
+
when :mongoDB_db_not_found then mcol("Could not open the mongoDb db") + " #{details}."
|
25
|
+
when :active_record_db_connection_error then mcol("Could not connect to the DB server") + " #{details}."
|
26
|
+
when :fail then mcol(e.value)
|
27
|
+
else
|
28
|
+
"%-38s %-35s %-30s \n" % [ e.kind, e.key, qc_value]
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def mcol(msg) lred(msg) end
|
33
|
+
def kcol(key) yellow(key) end
|
34
|
+
def vcol(val) yellow(val) end
|
35
|
+
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
FailFast.send :include, FailFast::Messaging
|
@@ -0,0 +1,40 @@
|
|
1
|
+
class FailFast
|
2
|
+
module CheckIsOnPath
|
3
|
+
|
4
|
+
# Ensure the application is on the path
|
5
|
+
#
|
6
|
+
# Usage
|
7
|
+
# is_on_path 'jruby'
|
8
|
+
#
|
9
|
+
def is_on_path(app, *params)
|
10
|
+
unless found_on_the_path(app)
|
11
|
+
add_error ErrorDetails.new(nil, :not_on_path, app)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
# Ensure the key value can be found on the path
|
16
|
+
#
|
17
|
+
# Usage
|
18
|
+
# is_on_path_for 'file_compressor'
|
19
|
+
#
|
20
|
+
def is_on_path_for(key, *params)
|
21
|
+
return unless has_value_for key
|
22
|
+
|
23
|
+
p = key_value_regexp_options(key, params)
|
24
|
+
|
25
|
+
key = p.key
|
26
|
+
app = value_for_deep_key(key)
|
27
|
+
|
28
|
+
unless found_on_the_path(app)
|
29
|
+
add_error ErrorDetails.new(key, :not_on_path, app)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
private
|
34
|
+
def found_on_the_path(app)
|
35
|
+
`which #{app}` =~ /#{app}$/
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
FailFast.send :include, FailFast::CheckIsOnPath
|
@@ -28,7 +28,7 @@ class FailFast
|
|
28
28
|
|
29
29
|
nof_errors = errors.size
|
30
30
|
if blank?(p.value)
|
31
|
-
add_error ErrorDetails.new(key, :missing_value
|
31
|
+
add_error ErrorDetails.new(key, :missing_value)
|
32
32
|
|
33
33
|
elsif p.regexp
|
34
34
|
add_error ErrorDetails.new(key, :value_does_not_match, p.value) unless p.value =~ p.regexp
|
@@ -1,52 +1,13 @@
|
|
1
1
|
<% if @config_file_path %>
|
2
2
|
+------------------------------------------------------------------------------------------
|
3
|
-
| FAIL_FAST error : precondition(s) not met in
|
3
|
+
| <%= lred 'FAIL_FAST error' %> : precondition(s) not met in
|
4
4
|
| -----------------
|
5
|
-
| file
|
6
|
-
<% if @keys_prefix%>| keys prefix : <%= @keys_prefix
|
5
|
+
| file : "<%= @config_file_path %>"
|
6
|
+
<% if @keys_prefix%>| keys prefix : <%= @keys_prefix.inspect %>
|
7
7
|
<% end %>+------------------------------------------------------------------------------------------
|
8
8
|
<% else %>
|
9
9
|
+------------------------------------------------------------------------------------------
|
10
|
-
| FAIL_FAST error : precondition(s) not met.
|
10
|
+
| <%= lred 'FAIL_FAST error' %> : precondition(s) not met.
|
11
11
|
+------------------------------------------------------------------------------------------
|
12
|
-
<% end
|
13
|
-
|
14
|
-
when :config_file_not_found
|
15
|
-
red("The config file could not be found") + " : '#{yellow(lred(e.value))}'."
|
16
|
-
when :missing_value
|
17
|
-
red("Missing value") +" for the key '#{yellow(e.key)}'."
|
18
|
-
when :value_does_not_match
|
19
|
-
red("Invalid value") +" '#{lred(e.value)}' for the key '#{yellow(e.key)}'."
|
20
|
-
when :not_an_email
|
21
|
-
red("Invalid email address") + " '#{lred(e.value)}' for the key '#{yellow(e.key)}'."
|
22
|
-
when :not_a_url
|
23
|
-
red("Invalid url") + " '#{lred(e.value)}' for the key '#{yellow(e.key)}'."
|
24
|
-
when :url_not_reachable
|
25
|
-
red("Could not reach the url") + " '#{lred(e.value)}' for the key '#{yellow(e.key)}'."
|
26
|
-
when :directory_not_found
|
27
|
-
e.key ?
|
28
|
-
red("Missing directory") + " '#{lred(e.value)}' for the key '#{yellow(e.key)}'." :
|
29
|
-
red("Missing directory") + " '#{lred(e.value)}'."
|
30
|
-
when :file_not_found
|
31
|
-
e.key ?
|
32
|
-
red("Missing file") + " '#{lred(e.value)}' for the key '#{yellow(e.key)}'." :
|
33
|
-
red("Missing file") + " '#{lred(e.value)}'."
|
34
|
-
when :mongoDB_server_not_found
|
35
|
-
e.key ?
|
36
|
-
red("Could not connect to the mongoDb server") + " '#{lred(e.value)} for the key '#{yellow(e.key)}'." :
|
37
|
-
red("Could not connect to the mongoDb server") + " '#{lred(e.value)}."
|
38
|
-
when :mongoDB_db_not_found
|
39
|
-
e.key ?
|
40
|
-
red("Could not open the mongoDb db") + " '#{lred(e.value)} for the key '#{yellow(e.key)}'." :
|
41
|
-
red("Could not open the mongoDb db") + " '#{lred(e.value)}."
|
42
|
-
when :active_record_db_connection_error
|
43
|
-
e.key ?
|
44
|
-
red("Could not connect to the DB server") + " '#{lred(e.value)} for the key '#{yellow(e.key)}'." :
|
45
|
-
red("Could not connect to the DB server") + " '#{lred(e.value)}."
|
46
|
-
when :fail
|
47
|
-
red(lred(e.value))
|
48
|
-
else "%-38s %-35s %-30s \n" % [ e.kind, e.key, lred(e.value)]
|
49
|
-
end
|
50
|
-
|
51
|
-
%>| <%= @msg + "\n"%><% end
|
52
|
-
%>+------------------------------------------------------------------------------------------
|
12
|
+
<% end %>| <%= @errors.collect{|e| default_message_for(e)}.join("\n| ") %>
|
13
|
+
+------------------------------------------------------------------------------------------
|
@@ -1,5 +1,11 @@
|
|
1
1
|
class FailFast::ErrorDetails < Struct.new(:key, :kind, :value)
|
2
2
|
|
3
|
+
attr_reader :key, :kind, :value
|
4
|
+
|
5
|
+
def initialize(key, kind, value=nil)
|
6
|
+
@key, @kind, @value = key, kind, value
|
7
|
+
end
|
8
|
+
|
3
9
|
def has_key_and_kind?(akey, akind)
|
4
10
|
(key.to_s == akey.to_s) && kind.to_sym == akind.to_sym
|
5
11
|
end
|
data/show_all_errors.rb
CHANGED
@@ -60,6 +60,9 @@ FailFast(SPEC_DIR + '/fixtures/simple.yml').check_now.but_fail_later do
|
|
60
60
|
file_exists '/tmp/foo/bar/??nOTaFile' # not a file
|
61
61
|
file_exists_for 'test/a_directory' # not a file
|
62
62
|
|
63
|
+
is_on_path '_why'
|
64
|
+
is_on_path_for 'app_not_on_path'
|
65
|
+
|
63
66
|
#test mondoDB
|
64
67
|
fake_mongo_server_absent
|
65
68
|
has_mongoDB '10.0.0.123', :timeout => 1 # no mongo server at this address
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
+
|
3
|
+
|
4
|
+
describe 'is_on_path' do
|
5
|
+
|
6
|
+
context '' do
|
7
|
+
it_should_not_raise_an_error('when the app is on the path') {
|
8
|
+
is_on_path 'ls'
|
9
|
+
}
|
10
|
+
|
11
|
+
it_should_raise_a_direct_error('ls987654321', :not_on_path, 'when the app is not on the path' ) {
|
12
|
+
is_on_path 'ls987654321'
|
13
|
+
}
|
14
|
+
end
|
15
|
+
|
16
|
+
context '_for' do
|
17
|
+
it_should_not_raise_an_error('when the app is on the path') {
|
18
|
+
is_on_path_for 'app_on_path'
|
19
|
+
}
|
20
|
+
|
21
|
+
it_should_raise_an_error('app_not_on_path', :not_on_path, 'when the app is not on the path' ) {
|
22
|
+
is_on_path_for 'app_not_on_path'
|
23
|
+
}
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
data/spec/fixtures/simple.yml
CHANGED
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fail_fast
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 15
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
-
|
8
|
+
- 4
|
9
9
|
- 0
|
10
|
-
version: 0.
|
10
|
+
version: 0.4.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Alain Ravet
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-07-
|
18
|
+
date: 2010-07-22 00:00:00 +02:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -82,12 +82,14 @@ files:
|
|
82
82
|
- fail_fast.gemspec
|
83
83
|
- lib/fail_fast.rb
|
84
84
|
- lib/fail_fast/base/base.rb
|
85
|
+
- lib/fail_fast/base/messaging.rb
|
85
86
|
- lib/fail_fast/base/utils.rb
|
86
87
|
- lib/fail_fast/base/z_only_for_tests.rb
|
87
88
|
- lib/fail_fast/extensions/base_commands.rb
|
88
89
|
- lib/fail_fast/extensions/check_active_record_db.rb
|
89
90
|
- lib/fail_fast/extensions/check_email.rb
|
90
91
|
- lib/fail_fast/extensions/check_file_system.rb
|
92
|
+
- lib/fail_fast/extensions/check_is_on_path.rb
|
91
93
|
- lib/fail_fast/extensions/check_mongo_db.rb
|
92
94
|
- lib/fail_fast/extensions/check_url.rb
|
93
95
|
- lib/fail_fast/extensions/check_value.rb
|
@@ -107,6 +109,7 @@ files:
|
|
107
109
|
- spec/extensions/check_active_record_db_spec.rb
|
108
110
|
- spec/extensions/check_email_spec.rb
|
109
111
|
- spec/extensions/check_file_system_spec.rb
|
112
|
+
- spec/extensions/check_is_on_path_spec.rb
|
110
113
|
- spec/extensions/check_mongo_db_spec.rb
|
111
114
|
- spec/extensions/check_url_spec.rb
|
112
115
|
- spec/extensions/check_value_spec.rb
|
@@ -160,6 +163,7 @@ test_files:
|
|
160
163
|
- spec/extensions/check_active_record_db_spec.rb
|
161
164
|
- spec/extensions/check_email_spec.rb
|
162
165
|
- spec/extensions/check_file_system_spec.rb
|
166
|
+
- spec/extensions/check_is_on_path_spec.rb
|
163
167
|
- spec/extensions/check_mongo_db_spec.rb
|
164
168
|
- spec/extensions/check_url_spec.rb
|
165
169
|
- spec/extensions/check_value_spec.rb
|