fail_fast 0.5.0 → 0.5.1
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.txt +5 -2
- data/README.markdown +5 -2
- data/VERSION +1 -1
- data/fail_fast.gemspec +4 -2
- data/lib/fail_fast/extensions/check_active_record_db.rb +5 -5
- data/lib/fail_fast/extensions/check_email.rb +3 -3
- data/lib/fail_fast/extensions/check_file_system.rb +6 -6
- data/lib/fail_fast/extensions/check_url.rb +3 -3
- data/lib/fail_fast/support/z_only_for_tests.rb +1 -1
- data/show_all_errors.rb +1 -0
- data/spec/base/base_commands_spec.rb +18 -0
- data/spec/extensions/check_url_spec.rb +3 -2
- data/spec/extensions/key_prefix_spec.rb +27 -0
- data/spec/fixtures/simple.yml +8 -1
- data/spec/spec_helper.rb +1 -0
- metadata +6 -4
data/CHANGELOG.txt
CHANGED
data/README.markdown
CHANGED
@@ -37,9 +37,11 @@ Early in your project boot sequence insert this code :
|
|
37
37
|
|
38
38
|
require 'fail_fast'
|
39
39
|
FailFast("path/to/database.yml").check do
|
40
|
-
has_active_record_db_for 'production'
|
40
|
+
has_active_record_db_for 'production', :message => 'The main DB cannot be reached :'
|
41
41
|
end
|
42
42
|
|
43
|
+
remark : the :message part is always optional.
|
44
|
+
|
43
45
|
|
44
46
|
If the DB connection fails,
|
45
47
|
* the application will exit immediately and
|
@@ -53,6 +55,7 @@ If the DB connection fails,
|
|
53
55
|
+------------------------------------------------------------------------------------------
|
54
56
|
| error key value
|
55
57
|
+------------------------------------------------------------------------------------------
|
58
|
+
| The main DB cannot be reached :
|
56
59
|
| * active_record_db_connection_error production Unknown database 'a_db'
|
57
60
|
+------------------------------------------------------------------------------------------
|
58
61
|
|
@@ -79,7 +82,7 @@ If you want to collect and report all the errors before exiting, use `check_now.
|
|
79
82
|
has_url_for 'bug_tracker/url', :reachable => true
|
80
83
|
end
|
81
84
|
|
82
|
-
directory_exists_for '/tmp'
|
85
|
+
directory_exists_for '/tmp', :message => 'the log '
|
83
86
|
file_exists_for 'public/nda.pdf'
|
84
87
|
|
85
88
|
skip_if Rails.env.development? do
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.5.
|
1
|
+
0.5.1
|
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.5.
|
8
|
+
s.version = "0.5.1"
|
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-29}
|
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 = [
|
@@ -59,6 +59,7 @@ Gem::Specification.new do |s|
|
|
59
59
|
"spec/extensions/check_mongo_db_spec.rb",
|
60
60
|
"spec/extensions/check_url_spec.rb",
|
61
61
|
"spec/extensions/check_value_spec.rb",
|
62
|
+
"spec/extensions/key_prefix_spec.rb",
|
62
63
|
"spec/fixtures/empty.yml",
|
63
64
|
"spec/fixtures/simple.yml",
|
64
65
|
"spec/how_to_use_spec.rb",
|
@@ -86,6 +87,7 @@ Gem::Specification.new do |s|
|
|
86
87
|
"spec/extensions/check_mongo_db_spec.rb",
|
87
88
|
"spec/extensions/check_url_spec.rb",
|
88
89
|
"spec/extensions/check_value_spec.rb",
|
90
|
+
"spec/extensions/key_prefix_spec.rb",
|
89
91
|
"spec/how_to_use_spec.rb",
|
90
92
|
"spec/spec_helper.rb"
|
91
93
|
]
|
@@ -30,12 +30,12 @@ class FailFast
|
|
30
30
|
# has_active_record_db_for 'production/database'
|
31
31
|
# has_active_record_db_for 'production/database', :message => 'custom message'
|
32
32
|
#
|
33
|
-
def has_active_record_db_for(
|
34
|
-
p = key_value_regexp_options(
|
33
|
+
def has_active_record_db_for(raw_key, *params)
|
34
|
+
p = key_value_regexp_options(raw_key, params)
|
35
35
|
key, options = p.key, p.options
|
36
|
-
return unless has_value_for
|
37
|
-
return unless has_value_for "#{
|
38
|
-
return unless has_value_for "#{
|
36
|
+
return unless has_value_for raw_key , :message => options[:message]
|
37
|
+
return unless has_value_for "#{raw_key}/adapter" , :message => options[:message]
|
38
|
+
return unless has_value_for "#{raw_key}/database", :message => options[:message]
|
39
39
|
|
40
40
|
begin
|
41
41
|
connection_options = p.value
|
@@ -4,11 +4,11 @@ class FailFast
|
|
4
4
|
# Usage
|
5
5
|
# has_email_for 'test/admin_email'
|
6
6
|
#
|
7
|
-
def has_email_for(
|
8
|
-
p = key_value_regexp_options(
|
7
|
+
def has_email_for(raw_key, *params)
|
8
|
+
p = key_value_regexp_options(raw_key, params)
|
9
9
|
key, options = p.key, p.options
|
10
10
|
|
11
|
-
return unless has_value_for
|
11
|
+
return unless has_value_for raw_key, :message => options[:message]
|
12
12
|
|
13
13
|
value = value_for_deep_key(key)
|
14
14
|
if EmailValidator.invalid_email_address?(value)
|
@@ -31,11 +31,11 @@ class FailFast
|
|
31
31
|
# directory_exists_for 'foo/config'
|
32
32
|
# directory_exists_for 'foo/config', :message => 'custom message'
|
33
33
|
#
|
34
|
-
def directory_exists_for(
|
35
|
-
p = key_value_regexp_options(
|
34
|
+
def directory_exists_for(raw_key, *params)
|
35
|
+
p = key_value_regexp_options(raw_key, params)
|
36
36
|
key, options = p.key, p.options
|
37
37
|
|
38
|
-
return unless has_value_for
|
38
|
+
return unless has_value_for raw_key, :message => options[:message]
|
39
39
|
|
40
40
|
path = value_for_deep_key(key)
|
41
41
|
unless File.exists?(path) && File.directory?(path)
|
@@ -49,11 +49,11 @@ class FailFast
|
|
49
49
|
# file_exists_for 'foo/config/app.yml'
|
50
50
|
# file_exists_for 'foo/config/app.yml', :message => 'custom message'
|
51
51
|
#
|
52
|
-
def file_exists_for(
|
53
|
-
p = key_value_regexp_options(
|
52
|
+
def file_exists_for(raw_key, *params)
|
53
|
+
p = key_value_regexp_options(raw_key, params)
|
54
54
|
key, options = p.key, p.options
|
55
55
|
|
56
|
-
return unless has_value_for
|
56
|
+
return unless has_value_for raw_key, :message => options[:message]
|
57
57
|
|
58
58
|
path = value_for_deep_key(key)
|
59
59
|
unless File.exists?(path) && File.file?(path)
|
@@ -10,10 +10,10 @@ class FailFast
|
|
10
10
|
# (ex: http://example.com + http://example.com/)
|
11
11
|
# has_url_for 'test/server_url', :reachable => true, :may_add_trailing_slash => true
|
12
12
|
#
|
13
|
-
def has_url_for(
|
14
|
-
p = key_value_regexp_options(
|
13
|
+
def has_url_for(raw_key, *params)
|
14
|
+
p = key_value_regexp_options(raw_key, params)
|
15
15
|
key, options = p.key, p.options
|
16
|
-
return unless has_value_for
|
16
|
+
return unless has_value_for raw_key, :message => options[:message]
|
17
17
|
|
18
18
|
value = value_for_deep_key(key)
|
19
19
|
if UrlValidator.invalid_url?(value)
|
data/show_all_errors.rb
CHANGED
@@ -47,3 +47,21 @@ describe "skip_if" do
|
|
47
47
|
end
|
48
48
|
}
|
49
49
|
end
|
50
|
+
|
51
|
+
describe 'failed?' do
|
52
|
+
example "is false when there are no errors" do
|
53
|
+
FailFast(SIMPLE_FILE_PATH ).check_now.but_fail_later {}
|
54
|
+
FailFast.failed?.should be_false
|
55
|
+
end
|
56
|
+
|
57
|
+
example "is true when there is 1 block and 1 error" do
|
58
|
+
FailFast(UNKNOWN_FILE_PATH).check_now.but_fail_later {} # <-- 1 error here
|
59
|
+
FailFast.failed?.should be_true
|
60
|
+
end
|
61
|
+
|
62
|
+
example "is true when the error block is followed by and error-free empty file block (BUG FIX)" do
|
63
|
+
FailFast(UNKNOWN_FILE_PATH).check_now.but_fail_later {} # <-- 1 error here
|
64
|
+
FailFast(EMPTY_FILE_PATH ).check_now.but_fail_later {} #no errors in the last block
|
65
|
+
FailFast.failed?.should be_true
|
66
|
+
end
|
67
|
+
end
|
@@ -4,8 +4,9 @@ describe 'has_url_for()' do
|
|
4
4
|
before(:all) do
|
5
5
|
FakeWeb.register_uri(:get, "http://example.com/index.html", :body => "I'm reachable!")
|
6
6
|
FakeWeb.register_uri(:get, "http://localhost/index.html" , :body => "I'm reachable!")
|
7
|
-
FakeWeb.register_uri(:get, "http://
|
8
|
-
|
7
|
+
FakeWeb.register_uri(:get, "http://localhost/index.html" , :body => "I'm reachable!")
|
8
|
+
FakeWeb.register_uri(:get, "http://localhost:3200" , :body => "I'm reachable!")
|
9
|
+
end
|
9
10
|
|
10
11
|
it_should_not_raise_an_error('when the value is an url') { has_url_for 'test/url' }
|
11
12
|
it_should_not_raise_an_error("when the domain is 'localhost'") { has_url_for 'test/url_localhost' }
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
+
|
3
|
+
describe 'the key prefix' do
|
4
|
+
|
5
|
+
example 'works fine in all the checkers' do
|
6
|
+
FakeWeb.register_uri(:get, "http://localhost:3200" , :body => "I'm reachable!")
|
7
|
+
|
8
|
+
conn = Mongo::Connection.new
|
9
|
+
conn.should_receive(:database_names).any_number_of_times.and_return %w(sample_mongoDB)
|
10
|
+
Mongo::Connection.should_receive(:new).and_return(conn)
|
11
|
+
|
12
|
+
arconn = Object.new
|
13
|
+
arconn.should_receive(:active?).and_return(true)
|
14
|
+
ActiveRecord::Base.should_receive(:connection).and_return(arconn)
|
15
|
+
|
16
|
+
FailFast(SIMPLE_FILE_PATH, 'test').check do
|
17
|
+
has_value_for 'email'
|
18
|
+
has_email_for 'email'
|
19
|
+
has_url_for 'url'
|
20
|
+
directory_exists_for 'a_directory'
|
21
|
+
file_exists_for 'a_file'
|
22
|
+
has_mongoDB 'mongoDB'
|
23
|
+
has_active_record_db_for 'db_connection'
|
24
|
+
is_on_path_for 'app_on_path'
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
data/spec/fixtures/simple.yml
CHANGED
@@ -4,12 +4,16 @@ last_key: dernier
|
|
4
4
|
app_on_path: ls
|
5
5
|
app_not_on_path: ls0123
|
6
6
|
test:
|
7
|
+
app_on_path: ls
|
7
8
|
host: localhost
|
8
9
|
url: http://example.com/index.html
|
9
10
|
url_localhost: http://localhost/index.html
|
10
11
|
email: test@example.com
|
11
12
|
url_reachable: http://example.com
|
12
13
|
url_not_reachable: http://xxx.zzz
|
14
|
+
db_connection:
|
15
|
+
adapter: mysql
|
16
|
+
database: a_db
|
13
17
|
mongoDB:
|
14
18
|
host: localhost
|
15
19
|
database: sample_mongoDB
|
@@ -32,4 +36,7 @@ db_connection:
|
|
32
36
|
|
33
37
|
number_six: 6
|
34
38
|
letter_x: x
|
35
|
-
nda_file: <%= SPEC_DIR + '/fixtures/simple.yml' %>
|
39
|
+
nda_file: <%= SPEC_DIR + '/fixtures/simple.yml' %>
|
40
|
+
development:
|
41
|
+
t_url: 'http://localhost:3200'
|
42
|
+
t_email: t_email@test.com
|
data/spec/spec_helper.rb
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: 9
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 5
|
9
|
-
-
|
10
|
-
version: 0.5.
|
9
|
+
- 1
|
10
|
+
version: 0.5.1
|
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-29 00:00:00 +02:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -114,6 +114,7 @@ files:
|
|
114
114
|
- spec/extensions/check_mongo_db_spec.rb
|
115
115
|
- spec/extensions/check_url_spec.rb
|
116
116
|
- spec/extensions/check_value_spec.rb
|
117
|
+
- spec/extensions/key_prefix_spec.rb
|
117
118
|
- spec/fixtures/empty.yml
|
118
119
|
- spec/fixtures/simple.yml
|
119
120
|
- spec/how_to_use_spec.rb
|
@@ -169,5 +170,6 @@ test_files:
|
|
169
170
|
- spec/extensions/check_mongo_db_spec.rb
|
170
171
|
- spec/extensions/check_url_spec.rb
|
171
172
|
- spec/extensions/check_value_spec.rb
|
173
|
+
- spec/extensions/key_prefix_spec.rb
|
172
174
|
- spec/how_to_use_spec.rb
|
173
175
|
- spec/spec_helper.rb
|