fail_fast 0.5.1 → 0.5.2

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.
Files changed (44) hide show
  1. data/.gitignore +2 -0
  2. data/.rvmrc +1 -0
  3. data/CHANGELOG.txt +9 -0
  4. data/Gemfile +3 -0
  5. data/README.markdown +15 -1
  6. data/Rakefile +8 -36
  7. data/fail_fast.gemspec +22 -107
  8. data/lib/fail_fast/base/base.rb +1 -1
  9. data/lib/fail_fast/base/messaging.rb +1 -1
  10. data/lib/fail_fast/base/utils.rb +3 -2
  11. data/lib/fail_fast/base/z_only_for_tests.rb +2 -2
  12. data/lib/fail_fast/extensions/directory_exists.rb +41 -0
  13. data/lib/fail_fast/extensions/file_exists.rb +41 -0
  14. data/lib/fail_fast/extensions/{check_active_record_db.rb → has_active_record_db.rb} +4 -2
  15. data/lib/fail_fast/extensions/{check_email.rb → has_email.rb} +7 -5
  16. data/lib/fail_fast/extensions/{check_mongo_db.rb → has_mongo_db.rb} +13 -9
  17. data/lib/fail_fast/extensions/{check_url.rb → has_url.rb} +8 -6
  18. data/lib/fail_fast/extensions/{check_value.rb → has_value.rb} +3 -3
  19. data/lib/fail_fast/extensions/{check_is_on_path.rb → is_on_path.rb} +10 -6
  20. data/lib/fail_fast/main.rb +1 -1
  21. data/lib/fail_fast/support/error_db.rb +1 -1
  22. data/lib/fail_fast/support/error_details.rb +2 -2
  23. data/lib/fail_fast/support/z_only_for_tests.rb +1 -1
  24. data/spec/base/base_commands/fail_spec.rb +7 -0
  25. data/spec/base/base_commands/failed_spec.rb +19 -0
  26. data/spec/base/base_commands/only_if_spec.rb +15 -0
  27. data/spec/base/base_commands/skip_if_spec.rb +29 -0
  28. data/spec/base/errors_storage_spec.rb +1 -1
  29. data/spec/base/multiple_blocks_support_spec.rb +3 -3
  30. data/spec/base/{not_linked_to_a_file_spec.rb → not_linked_to_a_config_file_spec.rb} +3 -3
  31. data/spec/base/{file_is_empty_spec.rb → when_config_file_is_empty_spec.rb} +3 -3
  32. data/spec/base/{file_is_missing_spec.rb → when_config_file_is_missing_spec.rb} +2 -2
  33. data/spec/extensions/{check_file_system_spec.rb → file_or_directory_exists_spec.rb} +18 -2
  34. data/spec/extensions/{check_active_record_db_spec.rb → has_active_record_db_spec.rb} +11 -6
  35. data/spec/extensions/{check_email_spec.rb → has_email_spec.rb} +11 -6
  36. data/spec/extensions/{check_mongo_db_spec.rb → has_mongoDB_spec.rb} +28 -9
  37. data/spec/extensions/{check_url_spec.rb → has_url_spec.rb} +4 -1
  38. data/spec/extensions/{check_value_spec.rb → has_value_spec.rb} +15 -11
  39. data/spec/extensions/{check_is_on_path_spec.rb → is_on_path_spec.rb} +9 -5
  40. data/spec/spec_helper.rb +39 -4
  41. metadata +78 -55
  42. data/VERSION +0 -1
  43. data/lib/fail_fast/extensions/check_file_system.rb +0 -67
  44. data/spec/base/base_commands_spec.rb +0 -67
@@ -0,0 +1,19 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
2
+
3
+ describe 'failed?' do
4
+ example "is false when there are no errors" do
5
+ FailFast(SIMPLE_FILE_PATH ).check_now.but_fail_later {}
6
+ FailFast.failed?.should be_false
7
+ end
8
+
9
+ example "is true when there is 1 block and 1 error" do
10
+ FailFast(UNKNOWN_FILE_PATH).check_now.but_fail_later {} # <-- 1 error here
11
+ FailFast.failed?.should be_true
12
+ end
13
+
14
+ example "is true when the error block is followed by and error-free empty file block (BUG FIX)" do
15
+ FailFast(UNKNOWN_FILE_PATH).check_now.but_fail_later {} # <-- 1 error here
16
+ FailFast(EMPTY_FILE_PATH ).check_now.but_fail_later {} #no errors in the last block
17
+ FailFast.failed?.should be_true
18
+ end
19
+ end
@@ -0,0 +1,15 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
2
+
3
+ describe "only_if" do
4
+ it_should_not_raise_an_error('only_if false does not run the block') {
5
+ only_if false do
6
+ fail 'never executed'
7
+ end
8
+ }
9
+
10
+ it_should_raise_a_direct_error('message 456', :fail, 'only_if true runs the block') {
11
+ only_if true do
12
+ fail 'message 456'
13
+ end
14
+ }
15
+ end
@@ -0,0 +1,29 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
2
+
3
+ describe "skip_if" do
4
+ it_should_not_raise_an_error('skip_if(true) does not run the block') {
5
+ skip_if true do
6
+ fail 'never executed'
7
+ end
8
+ }
9
+
10
+ it_should_raise_a_direct_error('message 456', :fail, 'skip_if(false) runs the block') {
11
+ skip_if false do
12
+ fail 'message 456'
13
+ end
14
+ }
15
+ end
16
+
17
+ describe "skip_if" do
18
+ it_should_not_raise_an_error('skip_if(true) does not run the block') {
19
+ skip_if true do
20
+ fail 'never executed'
21
+ end
22
+ }
23
+
24
+ it_should_raise_a_direct_error('message 456', :fail, 'skip_if(false) runs the block') {
25
+ skip_if false do
26
+ fail 'message 456'
27
+ end
28
+ }
29
+ end
@@ -4,7 +4,7 @@ describe "errors" do
4
4
  before(:each) { capture_stdout }
5
5
  after( :each) { restore_stdout }
6
6
 
7
- it "should use the filename and the prefix as key" do
7
+ it "uses the filename and the prefix as key" do
8
8
  begin
9
9
  FailFast('invalid_file_path', 'a_prefix').check() do
10
10
  has_value_for :unknown
@@ -4,7 +4,7 @@ describe "FailFast.check_now.but_fail_later" do
4
4
  before(:all) { capture_stdout }
5
5
  after( :all) { restore_stdout }
6
6
 
7
- it 'should not raise an error on the check(..) call' do
7
+ it 'does not raise an error on the check(..) call' do
8
8
  lambda {
9
9
  FailFast(UNKNOWN_FILE_PATH).check_now.but_fail_later {}
10
10
  }.should_not raise_error
@@ -21,13 +21,13 @@ describe "FailFast.check_now.but_fail_later" do
21
21
  FailFast(EMPTY_FILE_PATH ).check_now.but_fail_later {} #no errors in the last block
22
22
  end
23
23
 
24
- it("should detect and collect all the errors") {
24
+ it("detects and collect all the errors") {
25
25
  FailFast.errors_db.errors_for(FailFast::ErrorDb.key_for(UNKNOWN_FILE_PATH)).collect(&:kind).should == [:config_file_not_found]
26
26
  FailFast.errors_db.errors_for(FailFast::ErrorDb.key_for(SIMPLE_FILE_PATH )).collect(&:kind).should == [:missing_value, :missing_value]
27
27
  FailFast.errors_db.errors_for(FailFast::ErrorDb.key_for(EMPTY_FILE_PATH )).collect(&:kind).should == []
28
28
  }
29
29
  context "after FailFast.fail_now" do
30
- it "should raise an error" do
30
+ it "raises an error" do
31
31
  lambda {
32
32
  FailFast.fail_now
33
33
  }.should raise_error(ExitTriggered)
@@ -5,14 +5,14 @@ describe "check not linked to a config file" do
5
5
  after( :each) { restore_stdout }
6
6
 
7
7
 
8
- it "should not raise an error when there are no checks" do
8
+ it "does not raise an error when there are no checks" do
9
9
  lambda {
10
10
  FailFast().check do end
11
11
  }.should_not raise_error
12
12
  FailFast.failed?.should be_false
13
13
  end
14
14
 
15
- it "should raise an error when there is a failing check" do
15
+ it "raises an error when there is a failing check" do
16
16
  lambda {
17
17
  FailFast().check do
18
18
  fail 'error'
@@ -21,7 +21,7 @@ describe "check not linked to a config file" do
21
21
  FailFast.failed?.should be_true
22
22
  end
23
23
 
24
- it "should raise a delayed error when there is a failing check" do
24
+ it "raises a delayed error when there is a failing check" do
25
25
  lambda {
26
26
  FailFast().check_now.but_fail_later do
27
27
  fail 'error'
@@ -5,14 +5,14 @@ describe "ConfigCheck on an empty file" do
5
5
  after( :each) { restore_stdout }
6
6
 
7
7
 
8
- it "should not raise an error when there are no checks" do
8
+ it "does not raise an error when there are no checks" do
9
9
  lambda {
10
10
  FailFast(EMPTY_FILE_PATH).check do end
11
11
  }.should_not raise_error
12
12
  FailFast.failed?.should be_false
13
13
  end
14
14
 
15
- it "should raise an error when there is a failing check" do
15
+ it "raises an error when there is a failing check" do
16
16
  lambda {
17
17
  FailFast(EMPTY_FILE_PATH).check do
18
18
  has_value_for :anykey
@@ -21,7 +21,7 @@ describe "ConfigCheck on an empty file" do
21
21
  FailFast.failed?.should be_true
22
22
  end
23
23
 
24
- it "should raise a delayed error when there is a failing check" do
24
+ it "raises a delayed error when there is a failing check" do
25
25
  lambda {
26
26
  FailFast(EMPTY_FILE_PATH).check_now.but_fail_later do
27
27
  has_value_for :anykey
@@ -4,12 +4,12 @@ describe "ConfigCheck on an unknown file" do
4
4
  before(:all) { capture_stdout }
5
5
  after( :all) { restore_stdout }
6
6
 
7
- it "should not raise an error in new()" do
7
+ it "does not raise an error in new()" do
8
8
  FailFast(UNKNOWN_FILE_PATH)
9
9
  fail if FailFast.failed?
10
10
  end
11
11
 
12
- it "should raise an error in fail_fast()" do
12
+ it "raises an error in fail_fast()" do
13
13
  lambda {
14
14
  FailFast(UNKNOWN_FILE_PATH).check do end
15
15
  }.should raise_error(ExitTriggered)
@@ -6,6 +6,10 @@ a_file = SPEC_DIR + '/fixtures/simple.yml'
6
6
 
7
7
  describe 'directory_exists' do
8
8
  context '' do
9
+ it_should_return_true( 'when the directory exists' ) { directory_exists a_dir }
10
+ it_should_return_false('when the directory does not exists' ) { directory_exists 'XYZ' }
11
+ it_should_return_false('when the directory is a dir' ) { directory_exists a_file }
12
+
9
13
  it_should_not_raise_an_error('when the directory exists' ) { directory_exists a_dir }
10
14
 
11
15
  it_should_raise_a_direct_error('XYZ', :directory_not_found, 'when the directory does not exist' ) { directory_exists 'XYZ' }
@@ -13,6 +17,10 @@ describe 'directory_exists' do
13
17
  end
14
18
 
15
19
  context '_for' do
20
+ it_should_return_true( 'when the file exists' ) { directory_exists_for 'test/a_directory' }
21
+ it_should_return_false('when the file does not exists' ) { directory_exists_for 'test/UNKNOWN' }
22
+ it_should_return_false('when the file is a dir' ) { directory_exists_for 'test/a_file' }
23
+
16
24
  it_should_not_raise_an_error('when the directory exists' ) { directory_exists_for 'test/a_directory' }
17
25
 
18
26
  it_should_raise_an_error('test/a_file', :directory_not_found, 'when the path points to a File' ) { directory_exists_for 'test/a_file' }
@@ -20,7 +28,7 @@ describe 'directory_exists' do
20
28
  it_should_raise_an_error('not_a_valid_key',:missing_value, 'when the key is invalid' ) { directory_exists_for 'not_a_valid_key' }
21
29
  end
22
30
 
23
- it "should accept a custom message for the 5 cases" do
31
+ it "accepts a custom message for the 5 cases" do
24
32
  FailFast(SIMPLE_FILE_PATH).check_now.but_fail_later do
25
33
  directory_exists_for 'test/a_file', :message => 'a_custom_message'
26
34
  directory_exists_for 'test/email', :message => 'a_custom_message_2'
@@ -36,6 +44,10 @@ end
36
44
 
37
45
  describe 'file_exists' do
38
46
  context '' do
47
+ it_should_return_true( 'when the file exists' ) { file_exists a_file }
48
+ it_should_return_false('when the file does not exists' ) { file_exists 'XYZ' }
49
+ it_should_return_false('when the file is a dir' ) { file_exists a_dir }
50
+
39
51
  it_should_not_raise_an_error('when the file exists' ) { file_exists a_file}
40
52
 
41
53
  it_should_raise_a_direct_error('XYZ', :file_not_found, 'when the file does not exist' ) { file_exists 'XYZ' }
@@ -43,6 +55,10 @@ describe 'file_exists' do
43
55
  end
44
56
 
45
57
  context '_for' do
58
+ it_should_return_true( 'when the file exists' ) { file_exists_for 'test/a_file' }
59
+ it_should_return_false('when the file does not exists' ) { file_exists_for 'test/UNKNOWN' }
60
+ it_should_return_false('when the file is a dir' ) { file_exists_for 'test/a_directory' }
61
+
46
62
  it_should_not_raise_an_error('when the file exists' ) { file_exists_for 'test/a_file' }
47
63
 
48
64
  it_should_raise_an_error('test/a_directory', :file_not_found, 'when the path points to a dir' ) { file_exists_for 'test/a_directory' }
@@ -50,7 +66,7 @@ describe 'file_exists' do
50
66
  it_should_raise_an_error('not_a_valid_key', :missing_value, 'when the key is invalid' ) { file_exists_for 'not_a_valid_key' }
51
67
  end
52
68
 
53
- it "should accept a custom message for the 5 cases" do
69
+ it "accepts a custom message for the 5 cases" do
54
70
  FailFast(SIMPLE_FILE_PATH).check_now.but_fail_later do
55
71
  file_exists_for 'test/a_directory', :message => 'a_custom_message'
56
72
  file_exists_for 'test/email', :message => 'a_custom_message_2'
@@ -6,14 +6,16 @@ describe 'has_ar_db' do
6
6
  conn = Object.new ; conn.should_receive(:active?).and_return(true)
7
7
  ActiveRecord::Base.should_receive(:connection).and_return(conn)
8
8
 
9
- has_active_record_db :host => 'localhost', :adapter => 'mysql', :database=> 'a-db', :username => 'root'
9
+ result = has_active_record_db :host => 'localhost', :adapter => 'mysql', :database=> 'a-db', :username => 'root'
10
+ result.should == true
10
11
  }
11
12
 
12
13
  it_should_raise_a_direct_error('ze-error-message', :active_record_db_connection_error, 'when the connection fails' ) {
13
14
  exception = StandardError.new('ze-error-message')
14
15
  ActiveRecord::Base.should_receive(:establish_connection).and_raise(exception)
15
16
 
16
- has_active_record_db valid_connection_options = {}
17
+ result = has_active_record_db valid_connection_options = {}
18
+ result.should == false
17
19
  }
18
20
  end
19
21
 
@@ -22,22 +24,25 @@ describe 'has_ar_db' do
22
24
  conn = Object.new ; conn.should_receive(:active?).and_return(true)
23
25
  ActiveRecord::Base.should_receive(:connection).and_return(conn)
24
26
 
25
- has_active_record_db_for 'db_connection'
27
+ result = has_active_record_db_for 'db_connection'
28
+ result.should == true
26
29
  }
27
30
 
28
31
  it_should_raise_an_error('db_connection', :active_record_db_connection_error, 'when the connection fails' ) {
29
32
  exception = StandardError.new('an-error-message')
30
33
  ActiveRecord::Base.should_receive(:establish_connection).and_raise(exception)
31
34
 
32
- has_active_record_db_for 'db_connection'
35
+ result = has_active_record_db_for 'db_connection'
36
+ result.should == false
33
37
  }
34
38
 
35
39
  it_should_raise_an_error('invalid_key', :missing_value, 'when the key is invalid' ) {
36
- has_active_record_db_for 'invalid_key'
40
+ result = has_active_record_db_for 'invalid_key'
41
+ result.should == false
37
42
  }
38
43
  end
39
44
 
40
- it "should accept a custom message for those 3 cases" do
45
+ it "accepts a custom message for those 3 cases" do
41
46
  exception = StandardError.new('an-error-message')
42
47
  ActiveRecord::Base.should_receive(:establish_connection).twice.and_raise(exception)
43
48
 
@@ -2,19 +2,24 @@ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
2
 
3
3
  describe 'has_email_for()' do
4
4
  it_should_not_raise_an_error('when the value is an email') {
5
- has_email_for 'test/email'
5
+ result = has_email_for 'test/email'
6
+ result.should == true
6
7
  }
7
8
  it_should_raise_an_error('test/url', :not_an_email, 'when the value is not an email') {
8
- has_email_for 'test/url'
9
+ result = has_email_for 'test/url'
10
+ result.should == false
9
11
  }
10
12
  it_should_raise_an_error('invalid_key', :missing_value, 'when the key is invalid') {
11
- has_email_for 'invalid_key'
13
+ result = has_email_for 'invalid_key'
14
+ result.should == false
12
15
  }
13
16
 
14
- it "should accept a custom message for the 2 cases" do
17
+ it "accepts a custom message for the 2 cases" do
15
18
  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'
19
+ result = has_email_for 'invalid_key', :message => 'a_custom_message'
20
+ result.should == false
21
+ result = has_email_for 'test/url', :message => 'a_custom_message_2'
22
+ result.should == false
18
23
  end
19
24
  messages = FailFast.errors_db.errors_for(FailFast.errors_db.keys.first).collect { |e| e.message }
20
25
  messages.should =~ %w(a_custom_message a_custom_message_2)
@@ -9,11 +9,16 @@ 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
+ it_should_return_false('when the mongoDB server connection failed') {
13
+ has_mongoDB 'localhost'
14
+ }
12
15
 
13
- it "should accept a custom message for this case" do
16
+ it "accepts a custom message for this case" do
14
17
  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'
18
+ result = has_mongoDB 'localhost', :message => 'a_custom_message'
19
+ result.should == false
20
+ result = has_mongoDB 'localhost', :timeout => 1, :message => 'a_custom_message_2'
21
+ result.should == false
17
22
  end
18
23
  messages = FailFast.errors_db.errors_for(FailFast.errors_db.keys.first).collect { |e| e.message }
19
24
  messages.should =~ %w(a_custom_message a_custom_message_2)
@@ -27,13 +32,17 @@ describe 'has_mongoDB' do
27
32
  Mongo::Connection.should_receive(:new).and_return(conn)
28
33
  end
29
34
 
35
+ it_should_return_true('when the mongoDB server responds' ) { has_mongoDB 'localhost' }
36
+ it_should_return_true('when the mongoDB server responds and the db can be found' ) { has_mongoDB 'localhost', 'sample_mongoDB' }
37
+ it_should_return_false('when the database cannot be found on the mongoDB' ) { has_mongoDB 'localhost', 'not_a_known_db' }
38
+
30
39
  it_should_not_raise_an_error('when the mongoDB server responds' ) { has_mongoDB 'localhost' }
31
40
  it_should_not_raise_an_error('when the mongoDB server responds and the db can be found' ) { has_mongoDB 'localhost', 'sample_mongoDB' }
32
41
 
33
42
  it_should_raise_a_direct_error('not_a_known_db', :mongoDB_db_not_found, 'when the database cannot be found on the mongoDB') {
34
43
  has_mongoDB 'localhost', 'not_a_known_db'
35
44
  }
36
- it "should accept a custom message for this case" do
45
+ it "accepts a custom message for this case" do
37
46
  FailFast(SIMPLE_FILE_PATH).check_now.but_fail_later do
38
47
  has_mongoDB 'localhost', 'not_a_known_db', :message => 'a_custom_message'
39
48
  end
@@ -47,14 +56,19 @@ describe 'has_mongoDB' do
47
56
  context 'when the mongo server cannot be reached' do
48
57
  before(:each) { Mongo::Connection.should_receive(:new).any_number_of_times.and_raise(Mongo::ConnectionFailure) }
49
58
 
59
+ it_should_return_false('when the mongoDB server connection failed') { has_mongoDB_for 'test/unreachable_mongoDB_server' }
60
+ it_should_return_false('when the key is invalid' ) { has_mongoDB_for 'not_a_valid_key' }
61
+
50
62
  it_should_raise_an_error('test/unreachable_mongoDB_server', :mongoDB_server_not_found, 'when the mongoDB server connection failed') {
51
63
  has_mongoDB_for 'test/unreachable_mongoDB_server'
52
64
  }
53
65
  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
66
+ it "accepts a custom message for those 2 cases" do
55
67
  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'
68
+ result = has_mongoDB_for 'not_a_valid_key', :message => 'a_custom_message'
69
+ result.should == false
70
+ result = has_mongoDB_for 'test/unreachable_mongoDB_server', :message => 'a_custom_message_2'
71
+ result.should == false
58
72
  end
59
73
  messages = FailFast.errors_db.errors_for(FailFast.errors_db.keys.first).collect { |e| e.message }
60
74
  messages.should =~ %w(a_custom_message a_custom_message_2)
@@ -68,6 +82,8 @@ describe 'has_mongoDB' do
68
82
  Mongo::Connection.should_receive(:new).and_return(conn)
69
83
  end
70
84
 
85
+ it_should_return_true('when the mongoDB server responds and the database can be found') { has_mongoDB_for 'test/mongoDB' }
86
+
71
87
  it_should_not_raise_an_error('when the mongoDB server responds and the database can be found') {
72
88
  has_mongoDB_for 'test/mongoDB'
73
89
  }
@@ -75,7 +91,7 @@ describe 'has_mongoDB' do
75
91
  it_should_raise_an_error('test/unknown_mongoDB_db', :mongoDB_db_not_found,'when the database cannot be found on the mongoDB') {
76
92
  has_mongoDB_for 'test/unknown_mongoDB_db'
77
93
  }
78
- it "should accept a custom message for this case" do
94
+ it "accepts a custom message for this case" do
79
95
  FailFast(SIMPLE_FILE_PATH).check_now.but_fail_later do
80
96
  has_mongoDB_for 'test/unknown_mongoDB_db', :message => 'a_custom_message'
81
97
  end
@@ -83,7 +99,10 @@ describe 'has_mongoDB' do
83
99
  messages.should =~ %w(a_custom_message)
84
100
  end
85
101
 
86
- it_should_not_raise_an_error('when :ignore_database => false desactivate the db check') {
102
+ it_should_return_true('when :ignore_database => false deactivates the db check') {
103
+ has_mongoDB_for 'test/unknown_mongoDB_db', :check_database => false
104
+ }
105
+ it_should_not_raise_an_error('when :ignore_database => false deactivates the db check') {
87
106
  has_mongoDB_for 'test/unknown_mongoDB_db', :check_database => false
88
107
  }
89
108
  end
@@ -8,8 +8,11 @@ before(:all) do
8
8
  FakeWeb.register_uri(:get, "http://localhost:3200" , :body => "I'm reachable!")
9
9
  end
10
10
 
11
+ it_should_return_true( 'when the value is an url') { has_url_for 'test/url' }
11
12
  it_should_not_raise_an_error('when the value is an url') { has_url_for 'test/url' }
12
13
  it_should_not_raise_an_error("when the domain is 'localhost'") { has_url_for 'test/url_localhost' }
14
+
15
+ it_should_return_false( 'when the value is not an url') { has_url_for 'test/email' }
13
16
  it_should_raise_an_error('test/email', :not_a_url, 'when the value is not an url') { has_url_for 'test/email' }
14
17
 
15
18
  it_should_raise_an_error('not_a_valid_key', :missing_value ,'when the value is blank or absent') { has_url_for 'not_a_valid_key' }
@@ -21,7 +24,7 @@ end
21
24
  has_url_for 'test/url_not_reachable', :reachable => true
22
25
  }
23
26
 
24
- it "should accept a custom message for the 3 cases" do
27
+ it "accepts a custom message for the 3 cases" do
25
28
  FailFast(SIMPLE_FILE_PATH).check_now.but_fail_later do
26
29
  has_url_for 'test/email', :message => 'a_custom_message'
27
30
  has_url_for 'inconnu', :message => 'a_custom_message_2'
@@ -1,27 +1,27 @@
1
1
  require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
2
 
3
3
  describe 'value_of()' do
4
- it 'should return nil when the value is blank' do
4
+ it 'returns nil when the value is blank' do
5
5
  FailFast(SIMPLE_FILE_PATH).check { @@val = value_of(:key_with_blank_value) }
6
6
  @@val.should be_nil
7
7
  end
8
8
 
9
- it 'should return nil when the key is unknown' do
9
+ it 'returns nil when the key is unknown' do
10
10
  FailFast(EMPTY_FILE_PATH).check { @@val = value_of(:anykey) }
11
11
  @@val.should be_nil
12
12
  end
13
- it 'should return the value when it is a leaf'do
13
+ it 'returns the value when it is a leaf'do
14
14
  FailFast(SIMPLE_FILE_PATH).check { @@val = value_of(:first_key) }
15
15
  @@val.should == 'premier'
16
16
  end
17
17
 
18
- it 'should return the values in a hash when the value is a tree' do
18
+ it 'returns the values in a hash when the value is a tree' do
19
19
  FailFast(SIMPLE_FILE_PATH).check { @@val = value_of(:test) }
20
20
  @@val.should be_a(Hash)
21
21
  @@val['mongoDB']['host'].should == 'localhost'
22
22
  end
23
23
 
24
- it 'should preprend the prefix to the key' do
24
+ it 'prepends the prefix to the key' do
25
25
  FailFast(SIMPLE_FILE_PATH, 'test').check { @@val = value_of(:mongoDB) }
26
26
  @@val['host'].should == 'localhost'
27
27
  end
@@ -31,12 +31,16 @@ describe 'has_value_for()' do
31
31
  before { capture_stdout }
32
32
  after { restore_stdout }
33
33
 
34
- it "should accept a custom message for the 4 cases" do
34
+ it "accepts a custom message for the 4 cases" do
35
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'
36
+ result = has_value_for 'inconnu', /localhost/, :message => 'a_custom_message'
37
+ result.should == false
38
+ result = has_value_for :first_key, /nomatchhere/, :message => 'a_custom_message_2'
39
+ result.should == false
40
+ result = has_value_for :letter_x, :in => ('a'..'b'), :message => 'a_custom_message_3'
41
+ result.should == false
42
+ result = has_value_for :letter_x, :in => [6, "a"], :message => 'a_custom_message_4'
43
+ result.should == false
40
44
  end
41
45
 
42
46
  messages = FailFast.errors_db.errors_for(FailFast.errors_db.keys.first).collect { |e| e.message }
@@ -101,7 +105,7 @@ describe 'has_value_for()' do
101
105
  end
102
106
 
103
107
  context 'when a prefix is specified' do
104
- it "should not raise an error when a prefix is used" do
108
+ it "does not raise an error when a prefix is used" do
105
109
  lambda {
106
110
  FailFast(SIMPLE_FILE_PATH, 'test').check do
107
111
  has_value_for 'mongoDB/host', /localhost/
@@ -5,25 +5,29 @@ describe 'is_on_path' do
5
5
 
6
6
  context '' do
7
7
  it_should_not_raise_an_error('when the app is on the path') {
8
- is_on_path 'ls'
8
+ result = is_on_path 'ls'
9
+ result.should == true
9
10
  }
10
11
 
11
12
  it_should_raise_a_direct_error('ls987654321', :not_on_path, 'when the app is not on the path' ) {
12
- is_on_path 'ls987654321'
13
+ result = is_on_path 'ls987654321'
14
+ result.should == false
13
15
  }
14
16
  end
15
17
 
16
18
  context '_for' do
17
19
  it_should_not_raise_an_error('when the app is on the path') {
18
- is_on_path_for 'app_on_path'
20
+ result = is_on_path_for 'app_on_path'
21
+ result.should == true
19
22
  }
20
23
 
21
24
  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'
25
+ result = is_on_path_for 'app_not_on_path'
26
+ result.should == false
23
27
  }
24
28
  end
25
29
 
26
- it "should accept a custom message for the 3 cases" do
30
+ it "accepts a custom message for the 3 cases" do
27
31
  FailFast(SIMPLE_FILE_PATH).check_now.but_fail_later do
28
32
  is_on_path 'ls987654321', :message => 'a_custom_message'
29
33
  is_on_path_for 'INCONNU', :message => 'a_custom_message_2'
data/spec/spec_helper.rb CHANGED
@@ -3,7 +3,7 @@ require 'fail_fast'
3
3
  require 'spec'
4
4
  require 'spec/autorun'
5
5
  require 'fakeweb'
6
- gem 'mongo', '1.0'
6
+ #gem 'mongo', '1.0'
7
7
  require 'mongo'
8
8
 
9
9
  SPEC_DIR = File.dirname(File.expand_path(__FILE__))
@@ -32,8 +32,43 @@ module DSLMacros
32
32
  end
33
33
  module ClassMethods
34
34
 
35
+ def it_should_return_true(msg, &block)
36
+ it "returns true #{msg}" do
37
+ capture_stdout
38
+ begin
39
+ FailFast(SIMPLE_FILE_PATH).check.but_fail_later do
40
+ raise "BUG : @@errorz should be empty \n#{errors.inspect}" unless errors.empty?
41
+ result = self.instance_eval(&block)
42
+ #TODO : BETTER ERROR REPORTING
43
+ result.should == true
44
+ end
45
+ rescue => e
46
+ raise e
47
+ end
48
+ restore_stdout
49
+ end
50
+ end
51
+
52
+
53
+ def it_should_return_false(msg, &block)
54
+ it "returns false #{msg}" do
55
+ capture_stdout
56
+ begin
57
+ FailFast(SIMPLE_FILE_PATH).check.but_fail_later do
58
+ raise "BUG : @@errorz should be empty \n#{errors.inspect}" unless errors.empty?
59
+ result = self.instance_eval(&block)
60
+ #TODO : BETTER ERROR REPORTING
61
+ result.should == false
62
+ end
63
+ rescue => e
64
+ raise e
65
+ end
66
+ restore_stdout
67
+ end
68
+ end
69
+
35
70
  def it_should_not_raise_an_error(msg, &block)
36
- it "should not raise an error #{msg}" do
71
+ it "does not raise an error #{msg}" do
37
72
  capture_stdout
38
73
  begin
39
74
  FailFast(SIMPLE_FILE_PATH).check do
@@ -52,7 +87,7 @@ module DSLMacros
52
87
  end
53
88
 
54
89
  def it_should_raise_an_error(key, kind, msg, &block)
55
- it "should raise an error #{kind}-#{key}-#{msg}" do
90
+ it "raises an error #{kind}-#{key}-#{msg}" do
56
91
  capture_stdout
57
92
  begin
58
93
  FailFast(SIMPLE_FILE_PATH).check do
@@ -75,7 +110,7 @@ module DSLMacros
75
110
  end
76
111
  end
77
112
  def it_should_raise_a_direct_error(value, kind, msg, &block)
78
- it "should raise an error #{kind}-#{value}-#{msg}" do
113
+ it "raises an error #{kind}-#{value}-#{msg}" do
79
114
  capture_stdout
80
115
  begin
81
116
  FailFast(SIMPLE_FILE_PATH).check do