fail_fast 0.4.0 → 0.5.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 CHANGED
@@ -1,3 +1,5 @@
1
+ 0.5
2
+ - all checkers methods accept a ':message => "CUSTOM MSG"'
1
3
  0.4
2
4
  - added `is_on_path`
3
5
  0.3.0
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.4.0
1
+ 0.5.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.4.0"
8
+ s.version = "0.5.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-22}
12
+ s.date = %q{2010-07-28}
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 = [
@@ -45,6 +45,7 @@ Gem::Specification.new do |s|
45
45
  "lib/fail_fast/support/z_only_for_tests.rb",
46
46
  "show_all_errors.rb",
47
47
  "spec/base/base_commands_spec.rb",
48
+ "spec/base/error_details_spec.rb",
48
49
  "spec/base/errors_storage_spec.rb",
49
50
  "spec/base/file_is_empty_spec.rb",
50
51
  "spec/base/file_is_missing_spec.rb",
@@ -71,6 +72,7 @@ Gem::Specification.new do |s|
71
72
  s.summary = %q{raises an error if the yaml contents of a config file does pass a test script.}
72
73
  s.test_files = [
73
74
  "spec/base/base_commands_spec.rb",
75
+ "spec/base/error_details_spec.rb",
74
76
  "spec/base/errors_storage_spec.rb",
75
77
  "spec/base/file_is_empty_spec.rb",
76
78
  "spec/base/file_is_missing_spec.rb",
@@ -10,7 +10,7 @@ class FailFast
10
10
  else " #{qc_value} for the key #{qc_key}"
11
11
  end
12
12
 
13
- case e.kind
13
+ s = case e.kind
14
14
  when :config_file_not_found then mcol("The config file could not be found") + " : #{yellow(e.value)}."
15
15
  when :missing_value then mcol("Missing value") +" #{details}."
16
16
  when :value_does_not_match then mcol("Invalid value") +" #{details}."
@@ -27,6 +27,7 @@ class FailFast
27
27
  else
28
28
  "%-38s %-35s %-30s \n" % [ e.kind, e.key, qc_value]
29
29
  end
30
+ e.message ? "#{e.message}\n| #{s}": s
30
31
  end
31
32
 
32
33
  def mcol(msg) lred(msg) end
@@ -7,6 +7,7 @@ class FailFast
7
7
  #
8
8
  # Usage :
9
9
  # has_active_record_db :host => 'localhost', :adapter => 'sqlite3', :database=> 'prod_db'
10
+ # has_active_record_db :host => 'localhost', :adapter => 'sqlite3', :database=> 'prod_db', :message => 'custom message'
10
11
  #
11
12
  def has_active_record_db(*params)
12
13
  options = params.last.is_a?(Hash) ? params.pop : {}
@@ -19,7 +20,7 @@ class FailFast
19
20
  @error_message = e.message
20
21
  end
21
22
  unless @success
22
- add_error ErrorDetails.new(nil, :active_record_db_connection_error, @error_message)
23
+ add_error ErrorDetails.new(nil, :active_record_db_connection_error, @error_message, options[:message])
23
24
  end
24
25
  end
25
26
 
@@ -27,14 +28,14 @@ class FailFast
27
28
  #
28
29
  # Usage :
29
30
  # has_active_record_db_for 'production/database'
31
+ # has_active_record_db_for 'production/database', :message => 'custom message'
30
32
  #
31
33
  def has_active_record_db_for(key, *params)
32
- return unless has_value_for key
33
- return unless has_value_for "#{key}/adapter"
34
- return unless has_value_for "#{key}/database"
35
-
36
34
  p = key_value_regexp_options(key, params)
37
35
  key, options = p.key, p.options
36
+ return unless has_value_for key , :message => options[:message]
37
+ return unless has_value_for "#{key}/adapter" , :message => options[:message]
38
+ return unless has_value_for "#{key}/database", :message => options[:message]
38
39
 
39
40
  begin
40
41
  connection_options = p.value
@@ -46,7 +47,7 @@ class FailFast
46
47
  @error_message = e.message
47
48
  end
48
49
  unless @success
49
- add_error ErrorDetails.new(key, :active_record_db_connection_error, @error_message)
50
+ add_error ErrorDetails.new(key, :active_record_db_connection_error, @error_message, options[:message])
50
51
  end
51
52
  end
52
53
 
@@ -5,14 +5,14 @@ class FailFast
5
5
  # has_email_for 'test/admin_email'
6
6
  #
7
7
  def has_email_for(key, *params)
8
- return unless has_value_for key
9
-
10
8
  p = key_value_regexp_options(key, params)
11
9
  key, options = p.key, p.options
12
10
 
11
+ return unless has_value_for key, :message => options[:message]
12
+
13
13
  value = value_for_deep_key(key)
14
14
  if EmailValidator.invalid_email_address?(value)
15
- add_error ErrorDetails.new(key, :not_an_email, value)
15
+ add_error ErrorDetails.new(key, :not_an_email, value, options[:message])
16
16
  end
17
17
  end
18
18
  end
@@ -5,10 +5,11 @@ class FailFast
5
5
  #
6
6
  # Usage
7
7
  # directory_exists '/tmp'
8
+ # directory_exists '/tmp', :message => 'custom message'
8
9
  #
9
- def directory_exists(path, *params)
10
+ def directory_exists(path, options={})
10
11
  unless File.exists?(path) && File.directory?(path)
11
- add_error ErrorDetails.new(nil, :directory_not_found, path)
12
+ add_error ErrorDetails.new(nil, :directory_not_found, path, options[:message])
12
13
  end
13
14
  end
14
15
 
@@ -16,10 +17,11 @@ class FailFast
16
17
  #
17
18
  # Usage
18
19
  # file_exists '~/.bash_profile'
20
+ # file_exists '~/.bash_profile', :message => 'custom message'
19
21
  #
20
- def file_exists(path, *params)
22
+ def file_exists(path, options={})
21
23
  unless File.exists?(path) && File.file?(path)
22
- add_error ErrorDetails.new(nil, :file_not_found, path)
24
+ add_error ErrorDetails.new(nil, :file_not_found, path, options[:message])
23
25
  end
24
26
  end
25
27
 
@@ -27,17 +29,17 @@ class FailFast
27
29
  #
28
30
  # Usage
29
31
  # directory_exists_for 'foo/config'
32
+ # directory_exists_for 'foo/config', :message => 'custom message'
30
33
  #
31
34
  def directory_exists_for(key, *params)
32
- return unless has_value_for key
33
-
34
35
  p = key_value_regexp_options(key, params)
35
36
  key, options = p.key, p.options
36
37
 
37
- path = value_for_deep_key(key)
38
+ return unless has_value_for key, :message => options[:message]
38
39
 
40
+ path = value_for_deep_key(key)
39
41
  unless File.exists?(path) && File.directory?(path)
40
- add_error ErrorDetails.new(key, :directory_not_found, p.value)
42
+ add_error ErrorDetails.new(key, :directory_not_found, p.value, options[:message])
41
43
  end
42
44
  end
43
45
 
@@ -45,17 +47,17 @@ class FailFast
45
47
  #
46
48
  # Usage
47
49
  # file_exists_for 'foo/config/app.yml'
50
+ # file_exists_for 'foo/config/app.yml', :message => 'custom message'
48
51
  #
49
52
  def file_exists_for(key, *params)
50
- return unless has_value_for key
51
-
52
53
  p = key_value_regexp_options(key, params)
53
54
  key, options = p.key, p.options
54
55
 
55
- path = value_for_deep_key(key)
56
+ return unless has_value_for key, :message => options[:message]
56
57
 
58
+ path = value_for_deep_key(key)
57
59
  unless File.exists?(path) && File.file?(path)
58
- add_error ErrorDetails.new(key, :file_not_found, p.value)
60
+ add_error ErrorDetails.new(key, :file_not_found, p.value, options[:message])
59
61
  end
60
62
  end
61
63
 
@@ -5,10 +5,11 @@ class FailFast
5
5
  #
6
6
  # Usage
7
7
  # is_on_path 'jruby'
8
+ # is_on_path 'jruby', :message => 'custom message'
8
9
  #
9
- def is_on_path(app, *params)
10
+ def is_on_path(app, options = {})
10
11
  unless found_on_the_path(app)
11
- add_error ErrorDetails.new(nil, :not_on_path, app)
12
+ add_error ErrorDetails.new(nil, :not_on_path, app, options[:message])
12
13
  end
13
14
  end
14
15
 
@@ -16,17 +17,14 @@ class FailFast
16
17
  #
17
18
  # Usage
18
19
  # is_on_path_for 'file_compressor'
20
+ # is_on_path_for 'file_compressor', :message => 'custom message'
19
21
  #
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
22
+ def is_on_path_for(key, options = {})
23
+ return unless has_value_for key, :message => options[:message]
26
24
  app = value_for_deep_key(key)
27
25
 
28
26
  unless found_on_the_path(app)
29
- add_error ErrorDetails.new(key, :not_on_path, app)
27
+ add_error ErrorDetails.new(key, :not_on_path, app, options[:message])
30
28
  end
31
29
  end
32
30
 
@@ -5,8 +5,9 @@ class FailFast
5
5
  #
6
6
  # Usage :
7
7
  # has_mongoDB 'localhost'
8
+ # has_mongoDB 'localhost', :message => 'custom message'
8
9
  # has_mongoDB 'localhost', 'my_db', :port => 1234, :timeout => 2
9
- # has_mongoDB 'localhost', :port => 1234, :timeout => 2
10
+ # has_mongoDB 'localhost', :port => 1234, :timeout => 2, :message => 'custom message'
10
11
  #
11
12
  def has_mongoDB(host, *params)
12
13
  options = params.last.is_a?(Hash) ? params.pop : {}
@@ -16,12 +17,12 @@ class FailFast
16
17
  port = options.delete(:port)
17
18
  @conn = Mongo::Connection.new(host, port, options)
18
19
  rescue Mongo::ConnectionFailure
19
- add_error ErrorDetails.new(nil, :mongoDB_server_not_found, host)
20
+ add_error ErrorDetails.new(nil, :mongoDB_server_not_found, host, options[:message])
20
21
  return
21
22
  end
22
23
 
23
24
  if db && !@conn.database_names.include?(db)
24
- add_error ErrorDetails.new(nil, :mongoDB_db_not_found, db)
25
+ add_error ErrorDetails.new(nil, :mongoDB_db_not_found, db, options[:message])
25
26
  end
26
27
  end
27
28
 
@@ -32,12 +33,12 @@ class FailFast
32
33
  # has_mongoDB_for 'test/unknown_mongoDB_db', :check_database => false
33
34
  #
34
35
  def has_mongoDB_for(key, *params)
35
- return unless has_value_for key
36
- return unless has_value_for "#{key}/host"
37
- return unless has_value_for "#{key}/database"
38
-
39
36
  p = key_value_regexp_options(key, params)
40
37
  key, options = p.key, p.options
38
+ return unless has_value_for key , :message => options[:message]
39
+ return unless has_value_for "#{key}/host" , :message => options[:message]
40
+ return unless has_value_for "#{key}/database", :message => options[:message]
41
+
41
42
 
42
43
  value = value_for_deep_key(key)
43
44
  host, port, db = value['host'], value['port'], value['database']
@@ -45,13 +46,13 @@ class FailFast
45
46
  begin
46
47
  @conn = Mongo::Connection.new(host, port)
47
48
  rescue Mongo::ConnectionFailure
48
- add_error ErrorDetails.new(key, :mongoDB_server_not_found, host)
49
+ add_error ErrorDetails.new(key, :mongoDB_server_not_found, host, options[:message])
49
50
  return
50
51
  end
51
52
 
52
53
  must_check_db = !(false == options[:check_database])
53
54
  if must_check_db && !@conn.database_names.include?(db)
54
- add_error ErrorDetails.new(key, :mongoDB_db_not_found, db)
55
+ add_error ErrorDetails.new(key, :mongoDB_db_not_found, db, options[:message])
55
56
  end
56
57
  end
57
58
 
@@ -11,18 +11,17 @@ class FailFast
11
11
  # has_url_for 'test/server_url', :reachable => true, :may_add_trailing_slash => true
12
12
  #
13
13
  def has_url_for(key, *params)
14
- return unless has_value_for key
15
-
16
14
  p = key_value_regexp_options(key, params)
17
15
  key, options = p.key, p.options
16
+ return unless has_value_for key, :message => options[:message]
18
17
 
19
18
  value = value_for_deep_key(key)
20
19
  if UrlValidator.invalid_url?(value)
21
- add_error ErrorDetails.new(key, :not_a_url, value)
20
+ add_error ErrorDetails.new(key, :not_a_url, value, options[:message])
22
21
  return
23
22
  end
24
23
  if true==options.delete(:reachable) && UrlValidator.unreachable_url?(value, options)
25
- add_error ErrorDetails.new(key, :url_not_reachable, value)
24
+ add_error ErrorDetails.new(key, :url_not_reachable, value, options[:message])
26
25
  end
27
26
  end
28
27
  end
@@ -27,17 +27,18 @@ class FailFast
27
27
  key, options = p.key, p.options
28
28
 
29
29
  nof_errors = errors.size
30
+ message = options[:message]
30
31
  if blank?(p.value)
31
- add_error ErrorDetails.new(key, :missing_value)
32
+ add_error ErrorDetails.new(key, :missing_value, nil, message)
32
33
 
33
34
  elsif p.regexp
34
- add_error ErrorDetails.new(key, :value_does_not_match, p.value) unless p.value =~ p.regexp
35
+ add_error ErrorDetails.new(key, :value_does_not_match, p.value, message) unless p.value =~ p.regexp
35
36
 
36
37
  elsif options.is_a?(Hash) && options[:in].is_a?(Range)
37
- add_error ErrorDetails.new(key, :value_not_in_range, p.value) unless options[:in].include?(p.value)
38
+ add_error ErrorDetails.new(key, :value_not_in_range, p.value, message) unless options[:in].include?(p.value)
38
39
 
39
40
  elsif options.is_a?(Hash) && options[:in].is_a?(Array)
40
- add_error ErrorDetails.new(key, :value_not_in_array, p.value) unless options[:in].include?(p.value)
41
+ add_error ErrorDetails.new(key, :value_not_in_array, p.value, message) unless options[:in].include?(p.value)
41
42
  end
42
43
  no_new_error = nof_errors == errors.size
43
44
  end
@@ -19,5 +19,9 @@ class FailFast
19
19
  def self.key_for(config_file_path, keys_prefix=nil)
20
20
  ["<#{config_file_path}>", keys_prefix].compact.join
21
21
  end
22
+
23
+ def messages
24
+ @@hash.first[1]
25
+ end
22
26
  end
23
27
  end
@@ -1,9 +1,9 @@
1
- class FailFast::ErrorDetails < Struct.new(:key, :kind, :value)
1
+ class FailFast::ErrorDetails < Struct.new(:key, :kind, :value, :message)
2
2
 
3
- attr_reader :key, :kind, :value
3
+ attr_reader :key, :kind, :value, :message
4
4
 
5
- def initialize(key, kind, value=nil)
6
- @key, @kind, @value = key, kind, value
5
+ def initialize(key, kind, value=nil, message=nil)
6
+ @key, @kind, @value, @message = key, kind, value, message
7
7
  end
8
8
 
9
9
  def has_key_and_kind?(akey, akind)
data/show_all_errors.rb CHANGED
@@ -36,7 +36,7 @@ end
36
36
  FailFast(SPEC_DIR + '/fixtures/simple.yml').check_now.but_fail_later do
37
37
 
38
38
  #test values :
39
- has_value_for :first_keyNOT # single absent key
39
+ has_value_for :first_keyNOT , :message => 'this is a custom message' # single absent key
40
40
  has_values_for :last_keyNOT, 'number_sixNOT' # multiple absent keys
41
41
  has_value_for 'testNOT/mongoDB/database' # invalid yaml path
42
42
 
@@ -0,0 +1,11 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
+
3
+ describe FailFast::ErrorDetails do
4
+ context 'with a static message' do
5
+ subject {FailFast::ErrorDetails.new(:a_key, :a_kind, 'a_value', 'a_message')}
6
+ its(:key ){ should == :a_key }
7
+ its(:kind ){ should == :a_kind }
8
+ its(:value ){ should == 'a_value' }
9
+ its(:message){ should == 'a_message'}
10
+ end
11
+ end
@@ -36,4 +36,18 @@ describe 'has_ar_db' do
36
36
  has_active_record_db_for 'invalid_key'
37
37
  }
38
38
  end
39
+
40
+ it "should accept a custom message for those 3 cases" do
41
+ exception = StandardError.new('an-error-message')
42
+ ActiveRecord::Base.should_receive(:establish_connection).twice.and_raise(exception)
43
+
44
+ FailFast(SIMPLE_FILE_PATH).check_now.but_fail_later do
45
+ has_active_record_db_for 'invalid_key', :message => 'a_custom_message'
46
+ has_active_record_db_for 'db_connection', :message => 'a_custom_message_2'
47
+ has_active_record_db valid_connection_options = {}, :message => 'a_custom_message_3'
48
+ end
49
+ messages = FailFast.errors_db.errors_for(FailFast.errors_db.keys.first).collect { |e| e.message }
50
+ messages.should =~ %w(a_custom_message a_custom_message_2 a_custom_message_3)
51
+ end
52
+
39
53
  end
@@ -10,4 +10,13 @@ describe 'has_email_for()' do
10
10
  it_should_raise_an_error('invalid_key', :missing_value, 'when the key is invalid') {
11
11
  has_email_for 'invalid_key'
12
12
  }
13
+
14
+ it "should accept a custom message for the 2 cases" do
15
+ FailFast(SIMPLE_FILE_PATH).check_now.but_fail_later do
16
+ has_email_for 'invalid_key', :message => 'a_custom_message'
17
+ has_email_for 'test/url', :message => 'a_custom_message_2'
18
+ end
19
+ messages = FailFast.errors_db.errors_for(FailFast.errors_db.keys.first).collect { |e| e.message }
20
+ messages.should =~ %w(a_custom_message a_custom_message_2)
21
+ end
13
22
  end
@@ -19,6 +19,18 @@ describe 'directory_exists' do
19
19
  it_should_raise_an_error('test/email', :directory_not_found, 'when the directory does not exist' ) { directory_exists_for 'test/email' }
20
20
  it_should_raise_an_error('not_a_valid_key',:missing_value, 'when the key is invalid' ) { directory_exists_for 'not_a_valid_key' }
21
21
  end
22
+
23
+ it "should accept a custom message for the 5 cases" do
24
+ FailFast(SIMPLE_FILE_PATH).check_now.but_fail_later do
25
+ directory_exists_for 'test/a_file', :message => 'a_custom_message'
26
+ directory_exists_for 'test/email', :message => 'a_custom_message_2'
27
+ directory_exists_for 'INCONNU', :message => 'a_custom_message_3'
28
+ directory_exists 'XYZ', :message => 'a_custom_message_4'
29
+ directory_exists a_file, :message => 'a_custom_message_5'
30
+ end
31
+ messages = FailFast.errors_db.errors_for(FailFast.errors_db.keys.first).collect { |e| e.message }
32
+ messages.should =~ %w(a_custom_message a_custom_message_2 a_custom_message_3 a_custom_message_4 a_custom_message_5)
33
+ end
22
34
  end
23
35
 
24
36
 
@@ -37,4 +49,16 @@ describe 'file_exists' do
37
49
  it_should_raise_an_error('test/email', :file_not_found, 'when the file does not exist' ) { file_exists_for 'test/email' }
38
50
  it_should_raise_an_error('not_a_valid_key', :missing_value, 'when the key is invalid' ) { file_exists_for 'not_a_valid_key' }
39
51
  end
52
+
53
+ it "should accept a custom message for the 5 cases" do
54
+ FailFast(SIMPLE_FILE_PATH).check_now.but_fail_later do
55
+ file_exists_for 'test/a_directory', :message => 'a_custom_message'
56
+ file_exists_for 'test/email', :message => 'a_custom_message_2'
57
+ file_exists_for 'INCONNU', :message => 'a_custom_message_3'
58
+ file_exists 'XYZ', :message => 'a_custom_message_4'
59
+ file_exists a_dir, :message => 'a_custom_message_5'
60
+ end
61
+ messages = FailFast.errors_db.errors_for(FailFast.errors_db.keys.first).collect { |e| e.message }
62
+ messages.should =~ %w(a_custom_message a_custom_message_2 a_custom_message_3 a_custom_message_4 a_custom_message_5)
63
+ end
40
64
  end
@@ -23,4 +23,13 @@ describe 'is_on_path' do
23
23
  }
24
24
  end
25
25
 
26
+ it "should accept a custom message for the 3 cases" do
27
+ FailFast(SIMPLE_FILE_PATH).check_now.but_fail_later do
28
+ is_on_path 'ls987654321', :message => 'a_custom_message'
29
+ is_on_path_for 'INCONNU', :message => 'a_custom_message_2'
30
+ is_on_path_for 'app_not_on_path', :message => 'a_custom_message_3'
31
+ end
32
+ messages = FailFast.errors_db.errors_for(FailFast.errors_db.keys.first).collect { |e| e.message }
33
+ messages.should =~ %w(a_custom_message a_custom_message_2 a_custom_message_3)
34
+ end
26
35
  end
@@ -9,6 +9,15 @@ describe 'has_mongoDB' do
9
9
  it_should_raise_a_direct_error('localhost', :mongoDB_server_not_found, 'when the mongoDB server connection failed') {
10
10
  has_mongoDB 'localhost'
11
11
  }
12
+
13
+ it "should accept a custom message for this case" do
14
+ FailFast(SIMPLE_FILE_PATH).check_now.but_fail_later do
15
+ has_mongoDB 'localhost', :message => 'a_custom_message'
16
+ has_mongoDB 'localhost', :timeout => 1, :message => 'a_custom_message_2'
17
+ end
18
+ messages = FailFast.errors_db.errors_for(FailFast.errors_db.keys.first).collect { |e| e.message }
19
+ messages.should =~ %w(a_custom_message a_custom_message_2)
20
+ end
12
21
  end
13
22
 
14
23
  context 'when the mongo server can be reached' do
@@ -24,6 +33,13 @@ describe 'has_mongoDB' do
24
33
  it_should_raise_a_direct_error('not_a_known_db', :mongoDB_db_not_found, 'when the database cannot be found on the mongoDB') {
25
34
  has_mongoDB 'localhost', 'not_a_known_db'
26
35
  }
36
+ it "should accept a custom message for this case" do
37
+ FailFast(SIMPLE_FILE_PATH).check_now.but_fail_later do
38
+ has_mongoDB 'localhost', 'not_a_known_db', :message => 'a_custom_message'
39
+ end
40
+ messages = FailFast.errors_db.errors_for(FailFast.errors_db.keys.first).collect { |e| e.message }
41
+ messages.should =~ %w(a_custom_message)
42
+ end
27
43
  end
28
44
  end
29
45
 
@@ -35,6 +51,14 @@ describe 'has_mongoDB' do
35
51
  has_mongoDB_for 'test/unreachable_mongoDB_server'
36
52
  }
37
53
  it_should_raise_an_error('not_a_valid_key', :missing_value, 'when the key is invalid') { has_mongoDB_for 'not_a_valid_key' }
54
+ it "should accept a custom message for those 2 cases" do
55
+ FailFast(SIMPLE_FILE_PATH).check_now.but_fail_later do
56
+ has_mongoDB_for 'not_a_valid_key', :message => 'a_custom_message'
57
+ has_mongoDB_for 'test/unreachable_mongoDB_server', :message => 'a_custom_message_2'
58
+ end
59
+ messages = FailFast.errors_db.errors_for(FailFast.errors_db.keys.first).collect { |e| e.message }
60
+ messages.should =~ %w(a_custom_message a_custom_message_2)
61
+ end
38
62
  end
39
63
 
40
64
  context 'when the mongo server can be reached' do
@@ -51,6 +75,13 @@ describe 'has_mongoDB' do
51
75
  it_should_raise_an_error('test/unknown_mongoDB_db', :mongoDB_db_not_found,'when the database cannot be found on the mongoDB') {
52
76
  has_mongoDB_for 'test/unknown_mongoDB_db'
53
77
  }
78
+ it "should accept a custom message for this case" do
79
+ FailFast(SIMPLE_FILE_PATH).check_now.but_fail_later do
80
+ has_mongoDB_for 'test/unknown_mongoDB_db', :message => 'a_custom_message'
81
+ end
82
+ messages = FailFast.errors_db.errors_for(FailFast.errors_db.keys.first).collect { |e| e.message }
83
+ messages.should =~ %w(a_custom_message)
84
+ end
54
85
 
55
86
  it_should_not_raise_an_error('when :ignore_database => false desactivate the db check') {
56
87
  has_mongoDB_for 'test/unknown_mongoDB_db', :check_database => false
@@ -19,4 +19,14 @@ before(:all) do
19
19
  it_should_raise_an_error('test/url_not_reachable', :url_not_reachable ,'when the url is not reachable') {
20
20
  has_url_for 'test/url_not_reachable', :reachable => true
21
21
  }
22
+
23
+ it "should accept a custom message for the 3 cases" do
24
+ FailFast(SIMPLE_FILE_PATH).check_now.but_fail_later do
25
+ has_url_for 'test/email', :message => 'a_custom_message'
26
+ has_url_for 'inconnu', :message => 'a_custom_message_2'
27
+ has_url_for 'test/url_not_reachable', :reachable => true, :message => 'a_custom_message_3'
28
+ end
29
+ messages = FailFast.errors_db.errors_for(FailFast.errors_db.keys.first).collect { |e| e.message }
30
+ messages.should =~ %w(a_custom_message a_custom_message_2 a_custom_message_3)
31
+ end
22
32
  end
@@ -28,7 +28,23 @@ describe 'value_of()' do
28
28
  end
29
29
 
30
30
  describe 'has_value_for()' do
31
+ before { capture_stdout }
32
+ after { restore_stdout }
31
33
 
34
+ it "should accept a custom message for the 4 cases" do
35
+ FailFast(SIMPLE_FILE_PATH).check_now.but_fail_later do
36
+ has_value_for 'inconnu', /localhost/, :message => 'a_custom_message'
37
+ has_value_for :first_key, /nomatchhere/, :message => 'a_custom_message_2'
38
+ has_value_for :letter_x, :in => ('a'..'b'), :message => 'a_custom_message_3'
39
+ has_value_for :letter_x, :in => [6, "a"], :message => 'a_custom_message_4'
40
+ end
41
+
42
+ messages = FailFast.errors_db.errors_for(FailFast.errors_db.keys.first).collect { |e| e.message }
43
+ messages.should =~ %w(a_custom_message a_custom_message_2 a_custom_message_3 a_custom_message_4)
44
+ end
45
+
46
+
47
+ #-----------------
32
48
  context 'when the value is present' do
33
49
  it_should_not_raise_an_error('when the (string) key has a value') { has_value_for 'first_key' }
34
50
  it_should_not_raise_an_error('when the (symbol) key has a value') { has_value_for :last_key }
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: 15
4
+ hash: 11
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
- - 4
8
+ - 5
9
9
  - 0
10
- version: 0.4.0
10
+ version: 0.5.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-22 00:00:00 +02:00
18
+ date: 2010-07-28 00:00:00 +02:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -100,6 +100,7 @@ files:
100
100
  - lib/fail_fast/support/z_only_for_tests.rb
101
101
  - show_all_errors.rb
102
102
  - spec/base/base_commands_spec.rb
103
+ - spec/base/error_details_spec.rb
103
104
  - spec/base/errors_storage_spec.rb
104
105
  - spec/base/file_is_empty_spec.rb
105
106
  - spec/base/file_is_missing_spec.rb
@@ -154,6 +155,7 @@ specification_version: 3
154
155
  summary: raises an error if the yaml contents of a config file does pass a test script.
155
156
  test_files:
156
157
  - spec/base/base_commands_spec.rb
158
+ - spec/base/error_details_spec.rb
157
159
  - spec/base/errors_storage_spec.rb
158
160
  - spec/base/file_is_empty_spec.rb
159
161
  - spec/base/file_is_missing_spec.rb