fail_fast 0.5.2 → 0.6.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 +6 -0
- data/README.markdown +16 -3
- data/fail_fast.gemspec +7 -3
- data/lib/fail_fast.rb +88 -1
- data/lib/fail_fast/base/base.rb +11 -7
- data/lib/fail_fast/base/console_utils.rb +20 -0
- data/lib/fail_fast/base/utils.rb +0 -13
- data/lib/fail_fast/error_reporter.rb +7 -0
- data/lib/fail_fast/error_reporter/base.rb +40 -0
- data/lib/fail_fast/error_reporter/hoptoad.rb +34 -0
- data/lib/fail_fast/error_reporter/hoptoad/post_error_request.xml.erb +23 -0
- data/lib/fail_fast/error_reporter/stdout.rb +9 -0
- data/lib/fail_fast/report.txt.erb +9 -4
- data/lib/fail_fast/support/error_details.rb +5 -1
- data/show_all_errors.rb +5 -5
- data/spec/{fixtures → _/fixtures}/empty.yml +0 -0
- data/spec/{fixtures → _/fixtures}/simple.yml +3 -3
- data/spec/_/support/errors.rb +13 -0
- data/spec/_/support/errors_reporters.rb +3 -0
- data/spec/_/support/hoptoad.rb +7 -0
- data/spec/_/support/it_extensions.rb +126 -0
- data/spec/_/support/stdout.rb +8 -0
- data/spec/_/support/vcr.rb +11 -0
- data/spec/_/support/webmock.rb +4 -0
- data/spec/_/support/xml.rb +4 -0
- data/spec/_vcr_cassette_library/FailFast_ErrorReporter_Hoptoad/when_1_errors_occurs_in_1_block.yml +35 -0
- data/spec/_vcr_cassette_library/FailFast_ErrorReporter_Hoptoad/when_2_errors_occur_in_1_block.yml +37 -0
- data/spec/_vcr_cassette_library/FailFast_ErrorReporter_Hoptoad/when_3_errors_occur_in_2_blocks.yml +71 -0
- data/spec/_vcr_cassette_library/FailFast_ErrorReporter_Hoptoad/when_the_API_token_is_invalid.yml +67 -0
- data/spec/_vcr_cassette_library/FailFast_ErrorReporter_Hoptoad/when_the_API_token_is_valid.yml +35 -0
- data/spec/base/error_details_spec.rb +8 -0
- data/spec/error_reporter/fail_fast_spec.rb +73 -0
- data/spec/error_reporter/global_reporters_spec.rb +22 -0
- data/spec/error_reporter/hoptoad/expected_error_1_request.xml.erb +21 -0
- data/spec/error_reporter/hoptoad/expected_error_2_request.xml.erb +22 -0
- data/spec/error_reporter/hoptoad/hoptoad_activation_spec.rb +14 -0
- data/spec/error_reporter/hoptoad/hoptoad_requests_spec.rb +63 -0
- data/spec/error_reporter/hoptoad/hoptoad_responses_spec.rb +35 -0
- data/spec/error_reporter/stdout/stdout_spec.rb +24 -0
- data/spec/extensions/file_or_directory_exists_spec.rb +2 -2
- data/spec/extensions/has_url_spec.rb +3 -6
- data/spec/extensions/key_prefix_spec.rb +1 -1
- data/spec/how_to_use_spec.rb +1 -3
- data/spec/spec_helper.rb +13 -134
- metadata +120 -18
- data/lib/fail_fast/base/messaging.rb +0 -40
- data/lib/fail_fast/main.rb +0 -34
- data/spec/base/report_printing_spec.rb +0 -29
@@ -0,0 +1,73 @@
|
|
1
|
+
# Prove that FailFast,
|
2
|
+
# - register FailFast::ErrorReporter::Stdout as default errors reporter.
|
3
|
+
# - when it detects 1/many error(s), calls report(..) with the proper parameters on its errors reporter.
|
4
|
+
|
5
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
6
|
+
|
7
|
+
describe 'FailFast and error reporters :' do
|
8
|
+
|
9
|
+
let(:ff) {FailFast.new(nil,nil)}
|
10
|
+
|
11
|
+
it 'only reports errors to Stdout by default' do
|
12
|
+
ff.error_reporters.collect{|o|o.class}.should == [FailFast::ErrorReporter::Stdout]
|
13
|
+
end
|
14
|
+
|
15
|
+
it 'can register multiple error reporters' do
|
16
|
+
ff.register_errors_reporter(DummyErrorReporter.new)
|
17
|
+
ff.error_reporters.collect{|o|o.class}.should == [FailFast::ErrorReporter::Stdout, DummyErrorReporter]
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'ignores duplicate registration' do
|
21
|
+
ff.register_errors_reporter(DummyErrorReporter.new)
|
22
|
+
ff.register_errors_reporter ff.error_reporters.first
|
23
|
+
ff.register_errors_reporter ff.error_reporters.last
|
24
|
+
ff.error_reporters.collect{|o|o.class}.should == [FailFast::ErrorReporter::Stdout, DummyErrorReporter]
|
25
|
+
end
|
26
|
+
|
27
|
+
|
28
|
+
it "calls all the registered reporters, when an error occurs" do
|
29
|
+
ff.register_errors_reporter(DummyErrorReporter.new)
|
30
|
+
ff.error_reporters[0].should_receive(:report).once
|
31
|
+
ff.error_reporters[1].should_receive(:report).once
|
32
|
+
|
33
|
+
ff.check_now.but_fail_later do # = what we test!
|
34
|
+
has_value_for(:www_unknown , :message => "www_unknown is missing" ) #
|
35
|
+
has_value_for(:www_unknown2, :message => "www_unknown2 is missing") #
|
36
|
+
end #
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
describe FailFast do
|
41
|
+
|
42
|
+
let(:error_1) { FailFast::ErrorDetails.new(:www_unknown , :missing_value, nil, "www_unknown is missing" ) }
|
43
|
+
let(:error_2) { FailFast::ErrorDetails.new(:www_unknown2, :missing_value, nil, "www_unknown2 is missing") }
|
44
|
+
let(:two_errors) { [error_1, error_2] }
|
45
|
+
let(:two_errors_context) do {:errors_to_report => two_errors, :config_file_path => SIMPLE_FILE_PATH, :keys_prefix => nil} end
|
46
|
+
|
47
|
+
describe ".check_now" do
|
48
|
+
it "passes all the detected errors and the context to Stdout.report" do
|
49
|
+
FailFast(SIMPLE_FILE_PATH).tap do |ff|
|
50
|
+
ff.error_reporters.first.should_receive(:report).with(two_errors, two_errors_context) # the test
|
51
|
+
begin
|
52
|
+
ff.check_now do # = what we test!
|
53
|
+
has_value_for(:www_unknown , :message => "www_unknown is missing" ) #
|
54
|
+
has_value_for(:www_unknown2, :message => "www_unknown2 is missing") #
|
55
|
+
end #
|
56
|
+
rescue
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
describe ".check_now.but_fail_later" do
|
63
|
+
it "passes all the detected errors and the context to Stdout.report" do
|
64
|
+
FailFast(SIMPLE_FILE_PATH).tap do |ff|
|
65
|
+
ff.error_reporters.first.should_receive(:report).with(two_errors, two_errors_context) # the test
|
66
|
+
ff.check_now.but_fail_later do # = what we test!
|
67
|
+
has_value_for(:www_unknown , :message => "www_unknown is missing" ) #
|
68
|
+
has_value_for(:www_unknown2, :message => "www_unknown2 is missing") #
|
69
|
+
end #
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
+
|
3
|
+
describe FailFast do
|
4
|
+
|
5
|
+
let(:ff) {FailFast.new(nil,nil)}
|
6
|
+
|
7
|
+
it 'reports errors only to FailFast::ErrorReporter::Stdout by default' do
|
8
|
+
ff.error_reporters.collect{|o|o.class}.should == [FailFast::ErrorReporter::Stdout]
|
9
|
+
end
|
10
|
+
|
11
|
+
describe ".report_to" do
|
12
|
+
it 'add errors reporters to the next FailFast check blocks that will be created' do
|
13
|
+
FailFast.new(nil,nil).error_reporters.collect{|o|o.class}.should == [FailFast::ErrorReporter::Stdout]
|
14
|
+
FailFast.report_to DummyErrorReporter.new
|
15
|
+
FailFast.new(nil,nil).error_reporters.collect{|o|o.class}.should == [FailFast::ErrorReporter::Stdout, DummyErrorReporter]
|
16
|
+
end
|
17
|
+
|
18
|
+
it "resets the default error reporters between each test" do
|
19
|
+
FailFast.new(nil,nil).error_reporters.collect{|o|o.class}.should == [FailFast::ErrorReporter::Stdout]
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
+
<notice version="2.0">
|
3
|
+
<api-key><%= @api_key %></api-key>
|
4
|
+
<notifier>
|
5
|
+
<name>FailFast Hoptoad Notifier</name>
|
6
|
+
<version>0.1</version>
|
7
|
+
<url>https://github.com/alainravet/fail_fast</url>
|
8
|
+
</notifier>
|
9
|
+
<error>
|
10
|
+
<class>FailFastError</class>
|
11
|
+
<message>FailFastError at <%= FROZEN_TIME %></message>
|
12
|
+
<backtrace>
|
13
|
+
<line method="<%= EMPTY_FILE_PATH %>" file="App not on path : 'azertyuiop'." number='1'/>
|
14
|
+
</backtrace>
|
15
|
+
</error>
|
16
|
+
<server-environment>
|
17
|
+
<project-root>/testapp</project-root>
|
18
|
+
<environment-name>test</environment-name>
|
19
|
+
<app-version>1.0.0</app-version>
|
20
|
+
</server-environment>
|
21
|
+
</notice>
|
@@ -0,0 +1,22 @@
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
+
<notice version="2.0">
|
3
|
+
<api-key><%= @api_key %></api-key>
|
4
|
+
<notifier>
|
5
|
+
<name>FailFast Hoptoad Notifier</name>
|
6
|
+
<version>0.1</version>
|
7
|
+
<url>https://github.com/alainravet/fail_fast</url>
|
8
|
+
</notifier>
|
9
|
+
<error>
|
10
|
+
<class>FailFastError</class>
|
11
|
+
<message>FailFastError at <%= FROZEN_TIME %></message>
|
12
|
+
<backtrace>
|
13
|
+
<line method="<%= SIMPLE_FILE_PATH %>" file="msg-A| Missing value for the key 'anykey_1'." number='1'/>
|
14
|
+
<line method="<%= SIMPLE_FILE_PATH %>" file="msg-B| Missing value for the key 'anykey_2'." number='2'/>
|
15
|
+
</backtrace>
|
16
|
+
</error>
|
17
|
+
<server-environment>
|
18
|
+
<project-root>/testapp</project-root>
|
19
|
+
<environment-name>test</environment-name>
|
20
|
+
<app-version>1.0.0</app-version>
|
21
|
+
</server-environment>
|
22
|
+
</notice>
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
|
2
|
+
|
3
|
+
describe FailFast::ErrorReporter::Hoptoad do
|
4
|
+
|
5
|
+
it 'is activated by adding it with FF#report_to to the global active error reporters' do
|
6
|
+
FailFast.report_to :hoptoad => VALID_HOPTOAD_API_KEY
|
7
|
+
|
8
|
+
FailFast.new.error_reporters.collect{|o|o.class}.
|
9
|
+
should == [FailFast::ErrorReporter::Stdout, FailFast::ErrorReporter::Hoptoad]
|
10
|
+
# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
11
|
+
# The new global errors reporter
|
12
|
+
end
|
13
|
+
|
14
|
+
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
|
2
|
+
|
3
|
+
describe FailFast::ErrorReporter::Hoptoad do
|
4
|
+
|
5
|
+
let(:request_for_1_error_in_1_block){
|
6
|
+
a_request(:post, 'http://hoptoadapp.com/notifier_api/v2/notices').
|
7
|
+
with(:headers => {'Accept'=>'text/xml', 'Content-Type' => 'text/xml'},
|
8
|
+
:body => evaluate_xml_erb(File.join(File.dirname(__FILE__), 'expected_error_1_request.xml.erb')))
|
9
|
+
|
10
|
+
}
|
11
|
+
|
12
|
+
let(:request_for_2_errors_in_1_block){
|
13
|
+
a_request(:post, 'http://hoptoadapp.com/notifier_api/v2/notices').
|
14
|
+
with(:headers => {'Accept'=>'text/xml', 'Content-Type' => 'text/xml'},
|
15
|
+
:body => evaluate_xml_erb(File.join(File.dirname(__FILE__), 'expected_error_2_request.xml.erb')))
|
16
|
+
|
17
|
+
}
|
18
|
+
|
19
|
+
#--------------------------------------------------------
|
20
|
+
|
21
|
+
before { Timecop.freeze(FROZEN_TIME); } #capture_stdout}
|
22
|
+
after { Timecop.return ; } #restore_stdout}
|
23
|
+
before do
|
24
|
+
@api_key = VALID_HOPTOAD_API_KEY
|
25
|
+
@reporter = FailFast.report_to(:hoptoad => @api_key).first
|
26
|
+
end
|
27
|
+
|
28
|
+
#--------------------------------------------------------
|
29
|
+
|
30
|
+
|
31
|
+
context 'when 1 errors occurs in 1 block' do
|
32
|
+
use_vcr_cassette :record => :new_episodes
|
33
|
+
|
34
|
+
it 'POSTs 1 xml request to hoptoadapp.com' do
|
35
|
+
produce_1_error_in_1_check_block
|
36
|
+
request_for_1_error_in_1_block.should have_been_made
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
|
41
|
+
context 'when 2 errors occur in 1 block' do
|
42
|
+
use_vcr_cassette :record => :new_episodes
|
43
|
+
|
44
|
+
it 'POSTs 1 xml request to hoptoadapp.com' do
|
45
|
+
produce_2_errors_in_1_check_block
|
46
|
+
request_for_2_errors_in_1_block.should have_been_made
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
|
51
|
+
context 'when 3 errors occur in 2 blocks' do
|
52
|
+
use_vcr_cassette :record => :new_episodes
|
53
|
+
|
54
|
+
it 'POSTs 2 xml requests to hoptoadapp.com' do
|
55
|
+
produce_1_error_in_1_check_block
|
56
|
+
produce_2_errors_in_1_check_block
|
57
|
+
|
58
|
+
request_for_1_error_in_1_block .should have_been_made
|
59
|
+
request_for_2_errors_in_1_block.should have_been_made
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
|
2
|
+
|
3
|
+
describe FailFast::ErrorReporter::Hoptoad do
|
4
|
+
|
5
|
+
context 'when the API token is invalid' do
|
6
|
+
use_vcr_cassette :record => :new_episodes
|
7
|
+
before do
|
8
|
+
FailFast.send :reset_global_error_reporters
|
9
|
+
@api_key = INVALID_HOPTOAD_API_KEY
|
10
|
+
@reporter = FailFast.report_to(:hoptoad => @api_key).first
|
11
|
+
end
|
12
|
+
|
13
|
+
example 'POST => 422' do
|
14
|
+
produce_1_error_in_1_check_block
|
15
|
+
@reporter.response.code.to_i.should == 422
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
|
20
|
+
context 'when the API token is valid' do
|
21
|
+
use_vcr_cassette :record => :new_episodes
|
22
|
+
|
23
|
+
before do
|
24
|
+
FailFast.send :reset_global_error_reporters
|
25
|
+
@api_key = VALID_HOPTOAD_API_KEY
|
26
|
+
@reporter = FailFast.report_to(:hoptoad => @api_key).first
|
27
|
+
end
|
28
|
+
|
29
|
+
example 'POST => 200' do
|
30
|
+
produce_1_error_in_1_check_block
|
31
|
+
@reporter.response.code.to_i.should == 200
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
|
2
|
+
|
3
|
+
describe FailFast::ErrorReporter::Stdout do
|
4
|
+
before(:each) { capture_stdout }
|
5
|
+
after( :each) { restore_stdout }
|
6
|
+
|
7
|
+
context 'when 2 errors are detected in a config file' do
|
8
|
+
before do
|
9
|
+
produce_2_errors_in_1_check_block
|
10
|
+
end
|
11
|
+
it("prints to $stdout the config file path") do
|
12
|
+
$stdout.string.should match(/error.*#{SIMPLE_FILE_PATH}/mi)
|
13
|
+
end
|
14
|
+
it "prints to $stdout the 1st error details" do
|
15
|
+
$stdout.string.should match(/error.*msg-A.*missing value.*anykey_1/mi)
|
16
|
+
end
|
17
|
+
it "prints to $stdout the 2nd error details" do
|
18
|
+
$stdout.string.should match(/error.*msg-B.*missing value.*anykey_2/mi)
|
19
|
+
end
|
20
|
+
it "prints everything in sequence and in the right order" do
|
21
|
+
$stdout.string.should match(/error.*#{SIMPLE_FILE_PATH}.*msg-A.*missing value.*anykey_1.*msg-B.*missing value.*anykey_2/mi)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
2
|
|
3
|
-
a_dir = SPEC_DIR + '/fixtures'
|
4
|
-
a_file = SPEC_DIR + '/fixtures/simple.yml'
|
3
|
+
a_dir = SPEC_DIR + '/_/fixtures'
|
4
|
+
a_file = SPEC_DIR + '/_/fixtures/simple.yml'
|
5
5
|
|
6
6
|
|
7
7
|
describe 'directory_exists' do
|
@@ -1,12 +1,9 @@
|
|
1
1
|
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
2
|
|
3
3
|
describe 'has_url_for()' do
|
4
|
-
before(:
|
5
|
-
|
6
|
-
|
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
|
4
|
+
before(:each) do
|
5
|
+
stub_request(:get, "http://example.com" ).to_return(:body => "I'm reachable!")
|
6
|
+
end
|
10
7
|
|
11
8
|
it_should_return_true( 'when the value is an url') { has_url_for 'test/url' }
|
12
9
|
it_should_not_raise_an_error('when the value is an url') { has_url_for 'test/url' }
|
@@ -3,7 +3,7 @@ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
|
3
3
|
describe 'the key prefix' do
|
4
4
|
|
5
5
|
example 'works fine in all the checkers' do
|
6
|
-
|
6
|
+
stub_request(:get, "http://localhost:3200").to_return(:body => "I'm reachable!")
|
7
7
|
|
8
8
|
conn = Mongo::Connection.new
|
9
9
|
conn.should_receive(:database_names).any_number_of_times.and_return %w(sample_mongoDB)
|
data/spec/how_to_use_spec.rb
CHANGED
@@ -35,9 +35,7 @@ describe "typical usage" do
|
|
35
35
|
end
|
36
36
|
|
37
37
|
def fake_the_remote_services
|
38
|
-
|
39
|
-
FakeWeb.register_uri(:get, "http://localhost/index.html", :body => "I'm reachable!")
|
40
|
-
FakeWeb.register_uri(:get, "http://example.com", :body => "I'm reachable!")
|
38
|
+
stub_request(:get, "http://example.com" ).to_return(:body => "I'm reachable!")
|
41
39
|
|
42
40
|
conn = Mongo::Connection.new
|
43
41
|
conn.should_receive(:database_names).any_number_of_times.and_return %w(sample_mongoDB)
|
data/spec/spec_helper.rb
CHANGED
@@ -1,148 +1,27 @@
|
|
1
1
|
require 'rubygems'
|
2
2
|
require 'fail_fast'
|
3
|
+
|
3
4
|
require 'spec'
|
4
|
-
require '
|
5
|
-
require 'fakeweb'
|
6
|
-
#gem 'mongo', '1.0'
|
5
|
+
require 'timecop'
|
7
6
|
require 'mongo'
|
7
|
+
require 'active_support/inflector'
|
8
8
|
|
9
|
-
SPEC_DIR
|
10
|
-
UNKNOWN_FILE_PATH = 'an_unknown_file_path'
|
11
|
-
EMPTY_FILE_PATH = File.expand_path(File.dirname(__FILE__) + '/fixtures/empty.yml')
|
12
|
-
SIMPLE_FILE_PATH = File.expand_path(File.dirname(__FILE__) + '/fixtures/simple.yml')
|
13
|
-
|
14
|
-
class ExitTriggered < StandardError ; end
|
15
|
-
module Kernel
|
16
|
-
def exit(param=nil)
|
17
|
-
raise ExitTriggered.new('Kernel.exit was called')
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
|
22
|
-
module DSLMacros
|
23
|
-
module InstanceMethods
|
24
|
-
def capture_stdout
|
25
|
-
@@original_stdout = STDOUT
|
26
|
-
$stdout = StringIO.new
|
27
|
-
end
|
28
|
-
|
29
|
-
def restore_stdout
|
30
|
-
$stdout = @@original_stdout
|
31
|
-
end
|
32
|
-
end
|
33
|
-
module ClassMethods
|
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
|
9
|
+
SPEC_DIR = File.dirname(File.expand_path(__FILE__))
|
69
10
|
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
begin
|
74
|
-
FailFast(SIMPLE_FILE_PATH).check do
|
75
|
-
raise "BUG : @@errorz should be empty \n#{errors.inspect}" unless errors.empty?
|
76
|
-
self.instance_eval(&block)
|
77
|
-
end
|
78
|
-
rescue => e
|
79
|
-
raise e
|
80
|
-
ensure
|
81
|
-
if FailFast.failed?
|
82
|
-
fail "ZZshould not have raised an error, but it raised\n#{FailFast.global_errors.join("\n")}"
|
83
|
-
end
|
84
|
-
end
|
85
|
-
restore_stdout
|
86
|
-
end
|
87
|
-
end
|
11
|
+
UNKNOWN_FILE_PATH = 'an_unknown_file_path'
|
12
|
+
EMPTY_FILE_PATH = SPEC_DIR + '/_/fixtures/empty.yml'
|
13
|
+
SIMPLE_FILE_PATH = SPEC_DIR + '/_/fixtures/simple.yml'
|
88
14
|
|
89
|
-
|
90
|
-
|
91
|
-
capture_stdout
|
92
|
-
begin
|
93
|
-
FailFast(SIMPLE_FILE_PATH).check do
|
94
|
-
raise "BUG : @@errorz should be empty \n#{errors.inspect}" unless errors.empty?
|
95
|
-
self.instance_eval(&block)
|
96
|
-
end
|
97
|
-
rescue => e
|
98
|
-
# uncomment the next line after the refactoring/once error are no longer raise
|
99
|
-
# raise e
|
100
|
-
ensure
|
101
|
-
if !FailFast.failed?
|
102
|
-
fail "\ne2d\nshould have raised a #{kind} error for #{key} \n==#{e}"
|
103
|
-
elsif FailFast.global_errors.length == 1 && !FailFast.global_errors.first.has_key_and_kind?(key, kind)
|
104
|
-
fail "\ne2e\nshould have raised a #{kind.inspect} error for #{key.inspect}, but raised instead #{FailFast.global_errors.inspect}"
|
105
|
-
elsif 2 <= FailFast.global_errors.length
|
106
|
-
fail "\ne2f\nshould have raised only a #{kind} error for #{key}\n#{FailFast.global_errors.join("\n")}"
|
107
|
-
end
|
108
|
-
end
|
109
|
-
restore_stdout
|
110
|
-
end
|
111
|
-
end
|
112
|
-
def it_should_raise_a_direct_error(value, kind, msg, &block)
|
113
|
-
it "raises an error #{kind}-#{value}-#{msg}" do
|
114
|
-
capture_stdout
|
115
|
-
begin
|
116
|
-
FailFast(SIMPLE_FILE_PATH).check do
|
117
|
-
raise "BUG : @@errorz should be empty \n#{errors.inspect}" unless errors.empty?
|
118
|
-
self.instance_eval(&block)
|
119
|
-
end
|
120
|
-
rescue => e
|
121
|
-
# uncomment the next line after the refactoring/once error are no longer raise
|
122
|
-
# raise e
|
123
|
-
ensure
|
124
|
-
if !FailFast.failed?
|
125
|
-
fail "\ne2d\nshould have raised a #{kind} error for #{value} \n==#{e}"
|
126
|
-
elsif FailFast.global_errors.length == 1 && !FailFast.global_errors.first.has_value_and_kind?(value, kind)
|
127
|
-
fail "\ne2e\nshould have raised a #{kind.inspect} error for #{value.inspect}\n, but raised instead\n#{FailFast.global_errors.inspect}"
|
128
|
-
elsif 2 <= FailFast.global_errors.length
|
129
|
-
fail "\ne2f\nshould have raised only 1 #{kind} error for #{value}\nbut raised instead\n#{FailFast.global_errors.join("\n")}"
|
130
|
-
end
|
131
|
-
end
|
132
|
-
restore_stdout
|
133
|
-
end
|
134
|
-
end
|
15
|
+
require 'time'
|
16
|
+
FROZEN_TIME = Time.parse('1999-05-04 03:02:01 +0200')
|
135
17
|
|
136
|
-
end
|
137
18
|
|
138
|
-
def self.included(receiver)
|
139
|
-
receiver.extend(ClassMethods)
|
140
|
-
receiver.send :include, InstanceMethods
|
141
|
-
end
|
142
|
-
end
|
143
19
|
Spec::Runner.configure do |config|
|
144
|
-
config.include(DSLMacros)
|
145
20
|
config.before(:each) do
|
146
21
|
FailFast.reset_error_db!
|
22
|
+
FailFast.send :reset_global_error_reporters
|
147
23
|
end
|
148
24
|
end
|
25
|
+
|
26
|
+
|
27
|
+
Dir[File.join(SPEC_DIR, '_/support/**/*.rb')].each {|f| require f}
|