waitfor 0.1.0 → 0.1.7
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/History.txt +30 -2
- data/Manifest.txt +10 -4
- data/README.rdoc +41 -24
- data/Rakefile +4 -4
- data/lib/waitfor.rb +26 -2
- data/lib/waitfor/fixnum.rb +29 -13
- data/lib/waitfor/settings/configuration.rb +35 -0
- data/lib/waitfor/settings/legacy_parser.rb +44 -0
- data/lib/waitfor/settings/parser.rb +59 -0
- data/lib/waitfor/timeout_error.rb +4 -0
- data/lib/waitfor/timer.rb +36 -27
- data/lib/waitfor/version.rb +6 -5
- data/spec/configuration_spec.rb +34 -0
- data/spec/fixnum_spec.rb +18 -20
- data/spec/legacy_parser_spec.rb +50 -0
- data/spec/parser_spec.rb +147 -0
- data/spec/spec.opts +3 -1
- data/spec/spec_helper.rb +9 -16
- data/spec/spec_helper_spec.rb +9 -19
- data/spec/timeout_error_spec.rb +10 -0
- data/spec/timer_spec.rb +90 -63
- data/spec/waitfor_spec.rb +44 -58
- metadata +36 -14
- data/lib/waitfor/waitfor_timeout_error.rb +0 -5
- data/spec/waitfor_timeout_error_spec.rb +0 -6
data/lib/waitfor/version.rb
CHANGED
@@ -1,9 +1,10 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
# @author James Bobowski
|
2
|
+
module WaitFor
|
3
|
+
module VERSION
|
3
4
|
MAJOR = 0
|
4
5
|
MINOR = 1
|
5
|
-
TINY =
|
6
|
-
|
7
|
-
STRING = [MAJOR, MINOR, TINY].join('.')
|
6
|
+
TINY = 7
|
7
|
+
|
8
|
+
STRING = [ MAJOR, MINOR, TINY ].join( '.' )
|
8
9
|
end
|
9
10
|
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require File.dirname( __FILE__ ) + '/spec_helper.rb'
|
2
|
+
require 'lib/waitfor/settings/configuration'
|
3
|
+
|
4
|
+
describe WaitFor::Settings::Configuration do
|
5
|
+
|
6
|
+
# This isn't working like it's supposed to!
|
7
|
+
# context ".new" do
|
8
|
+
# it "should accept an options parameter then hand off the parsing to the parser classes" do
|
9
|
+
# new_method = WaitFor::Settings::Configuration.method( :new )
|
10
|
+
#
|
11
|
+
# WaitFor::Settings::Configuration.stub!( :new ).and_return do |*args|
|
12
|
+
# config = new_method.call( *args )
|
13
|
+
# config.should_receive( :parser_factory )
|
14
|
+
# config
|
15
|
+
# end
|
16
|
+
# end
|
17
|
+
# end
|
18
|
+
|
19
|
+
context "#parser_factory" do
|
20
|
+
it "should use the LegacyParser class when the options parameter's Class is of type Fixnum" do
|
21
|
+
WaitFor::Settings::LegacyParser.should_receive( :parse ).with( 0, an_instance_of( WaitFor::Settings::Configuration ) )
|
22
|
+
WaitFor::Settings::Configuration.new( 0 )
|
23
|
+
end
|
24
|
+
|
25
|
+
it "should use the Parser class when the options parameter's Class is of type Hash" do
|
26
|
+
WaitFor::Settings::Parser.should_receive( :parse ).with( { }, an_instance_of( WaitFor::Settings::Configuration ) )
|
27
|
+
WaitFor::Settings::Configuration.new( { } )
|
28
|
+
end
|
29
|
+
|
30
|
+
it "should raise an exception when the options parameter's Class isn't either Fixnum or Hash" do
|
31
|
+
lambda { WaitFor::Settings::Configuration.new( false ) }.should raise_error
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
data/spec/fixnum_spec.rb
CHANGED
@@ -1,29 +1,27 @@
|
|
1
1
|
require File.dirname( __FILE__ ) + '/spec_helper.rb'
|
2
2
|
|
3
|
-
describe Fixnum
|
4
|
-
|
5
|
-
|
3
|
+
describe Fixnum do
|
4
|
+
context ".second" do
|
5
|
+
it "should take the singular unit of 'second' and return the number of seconds" do
|
6
|
+
1 == 1.second
|
7
|
+
end
|
6
8
|
end
|
7
9
|
|
8
|
-
|
9
|
-
|
10
|
+
context ".seconds" do
|
11
|
+
it "should take the plural unit of 'seconds' and return the number of seconds" do
|
12
|
+
5 == 5.seconds
|
13
|
+
end
|
10
14
|
end
|
11
15
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
end
|
16
|
-
|
17
|
-
describe Fixnum, "Convert Minutes to Seconds" do
|
18
|
-
it "should take the unit of 'minute' ( singular ) with the amount of 1 and return 60" do
|
19
|
-
60 == 1.minute
|
16
|
+
context ".minute" do
|
17
|
+
it "should take the singular unit of 'minute' and return the number of seconds" do
|
18
|
+
60 == 1.minute
|
19
|
+
end
|
20
20
|
end
|
21
21
|
|
22
|
-
|
23
|
-
|
22
|
+
context ".minutes" do
|
23
|
+
it "should take the plural unit of 'minutes' and return the number of seconds" do
|
24
|
+
300 == 5.minutes
|
25
|
+
end
|
24
26
|
end
|
25
|
-
|
26
|
-
it "should take the unit of 'minutes' with the amount of 5 and return 300" do
|
27
|
-
300 == 5.minutes
|
28
|
-
end
|
29
|
-
end
|
27
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
require File.dirname( __FILE__ ) + '/spec_helper.rb'
|
2
|
+
require 'lib/waitfor/settings/legacy_parser'
|
3
|
+
|
4
|
+
describe WaitFor::Settings::LegacyParser do
|
5
|
+
context ".parse" do
|
6
|
+
before do
|
7
|
+
@mock_legacy_parser = mock( WaitFor::Settings::LegacyParser )
|
8
|
+
@mock_config = mock( WaitFor::Settings::Configuration )
|
9
|
+
|
10
|
+
WaitFor::Settings::Configuration.stub!( :new ).and_return( @mock_config )
|
11
|
+
WaitFor::Settings::LegacyParser.stub!( :new ).and_return( @mock_legacy_parser )
|
12
|
+
end
|
13
|
+
|
14
|
+
it "should accept Fixnum and call the parse method then return a populated Configuration object" do
|
15
|
+
WaitFor::Settings::LegacyParser.should_receive( :new ).once.with( 0, @mock_config )
|
16
|
+
@mock_legacy_parser.should_receive( :parse ).once
|
17
|
+
@mock_legacy_parser.should_receive( :config ).once.and_return( @mock_config )
|
18
|
+
|
19
|
+
WaitFor::Settings::LegacyParser.parse( 0, @mock_config ).should == @mock_config
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
context "#parse" do
|
24
|
+
before do
|
25
|
+
@mock_config = mock( WaitFor::Settings::Configuration )
|
26
|
+
end
|
27
|
+
|
28
|
+
it "should call each of the private parse methods" do
|
29
|
+
@mock_config.should_receive( :exception= ).once.with( WaitFor::TimeoutError )
|
30
|
+
|
31
|
+
@legacy_parser = WaitFor::Settings::LegacyParser.new( 0, @mock_config )
|
32
|
+
@legacy_parser.should_receive( :parse_time ).once
|
33
|
+
@legacy_parser.parse
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
context "#parse_time" do
|
38
|
+
before do
|
39
|
+
@mock_config = mock( WaitFor::Settings::Configuration )
|
40
|
+
end
|
41
|
+
|
42
|
+
it "should accept Fixnum and set it to the Configuration object's seconds attribute" do
|
43
|
+
@mock_config.should_receive( :exception= ).once.with( WaitFor::TimeoutError )
|
44
|
+
@mock_config.should_receive( :seconds= ).once.with( 0 )
|
45
|
+
|
46
|
+
@legacy_parser = WaitFor::Settings::LegacyParser.new( 0, @mock_config )
|
47
|
+
@legacy_parser.send( :parse_time )
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
data/spec/parser_spec.rb
ADDED
@@ -0,0 +1,147 @@
|
|
1
|
+
require File.dirname( __FILE__ ) + '/spec_helper.rb'
|
2
|
+
require 'lib/waitfor/settings/legacy_parser'
|
3
|
+
require 'lib/waitfor/settings/parser'
|
4
|
+
|
5
|
+
describe WaitFor::Settings::Parser do
|
6
|
+
context ".parse" do
|
7
|
+
before do
|
8
|
+
@mock_parser = mock( WaitFor::Settings::Parser )
|
9
|
+
@mock_config = mock( WaitFor::Settings::Configuration )
|
10
|
+
|
11
|
+
WaitFor::Settings::Configuration.stub!( :new ).and_return( @mock_config )
|
12
|
+
WaitFor::Settings::Parser.stub!( :new ).and_return( @mock_parser )
|
13
|
+
end
|
14
|
+
|
15
|
+
it "should accept Hash and call the parse method then return a populated Configuration object" do
|
16
|
+
WaitFor::Settings::Parser.should_receive( :new ).once.with( { }, @mock_config )
|
17
|
+
@mock_parser.should_receive( :parse ).once
|
18
|
+
@mock_parser.should_receive( :config ).once.and_return( @mock_config )
|
19
|
+
|
20
|
+
WaitFor::Settings::Parser.parse( { }, @mock_config ).should == @mock_config
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
context "#parse" do
|
25
|
+
before do
|
26
|
+
@mock_config = mock( WaitFor::Settings::Configuration )
|
27
|
+
end
|
28
|
+
|
29
|
+
it "should call each of the private parse methods" do
|
30
|
+
@parser = WaitFor::Settings::Parser.new( { }, @mock_config )
|
31
|
+
|
32
|
+
@parser.should_receive( :parse_seconds ).once
|
33
|
+
@parser.should_receive( :parse_minutes ).once
|
34
|
+
@parser.should_receive( :parse_exception ).once
|
35
|
+
@parser.should_receive( :parse_message ).once
|
36
|
+
|
37
|
+
@parser.parse
|
38
|
+
end
|
39
|
+
|
40
|
+
it "should parse any combination of :second, :seconds, :minute or :minutes and combine them into seconds" do
|
41
|
+
@parser = WaitFor::Settings::Parser.new( { :second => 1, :seconds => 1, :minute => 1, :minutes => 1 }, @mock_config )
|
42
|
+
|
43
|
+
# Retrieve the existing number of seconds
|
44
|
+
# Should be 0 initially since this is first time we retrieve it
|
45
|
+
# Then should be 2 after that because we parsed seconds
|
46
|
+
@mock_config.should_receive( :seconds ).and_return( 0, 2 )
|
47
|
+
|
48
|
+
# We expect the parse_seconds method will attempt to set :seconds to 2
|
49
|
+
@mock_config.should_receive( :seconds= ).with( 2 )
|
50
|
+
|
51
|
+
# We expect the parse_minutes method will attempt to set :seconds to 122, which 2 minutes with the 2 seconds above added in
|
52
|
+
@mock_config.should_receive( :seconds= ).with( 122 )
|
53
|
+
|
54
|
+
# We expect the parse_exception method to set the default exception
|
55
|
+
@mock_config.should_receive( :exception= ).once.with( WaitFor::TimeoutError )
|
56
|
+
|
57
|
+
# We expect the parse_exception method to set the default message
|
58
|
+
@mock_config.should_receive( :message= ).once.with( "WaitFor timed out!" )
|
59
|
+
|
60
|
+
@parser.parse
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
context "#parse_seconds" do
|
65
|
+
before do
|
66
|
+
@mock_config = mock( WaitFor::Settings::Configuration )
|
67
|
+
end
|
68
|
+
|
69
|
+
it "should accept a hash containing :second or :seconds and set it to the setting object's seconds attribute" do
|
70
|
+
@parser = WaitFor::Settings::Parser.new( { :second => 1, :seconds => 1 }, @mock_config )
|
71
|
+
@mock_config.should_receive( :seconds ).once.and_return( 0 )
|
72
|
+
@mock_config.should_receive( :seconds= ).once.with( 2 )
|
73
|
+
|
74
|
+
@parser.send( :parse_seconds )
|
75
|
+
end
|
76
|
+
|
77
|
+
it "should set object's seconds attribute to 0 when hash does not contain :second or :seconds" do
|
78
|
+
@parser = WaitFor::Settings::Parser.new( { }, @mock_config )
|
79
|
+
@mock_config.should_receive( :seconds ).once.and_return( 0 )
|
80
|
+
@mock_config.should_receive( :seconds= ).once.with( 0 )
|
81
|
+
|
82
|
+
@parser.send( :parse_seconds )
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
context "#parse_minutes" do
|
87
|
+
before do
|
88
|
+
@mock_config = mock( WaitFor::Settings::Configuration )
|
89
|
+
end
|
90
|
+
|
91
|
+
it "should accept a hash containing :minute or :minutes and set it to the setting object's seconds attribute" do
|
92
|
+
@parser = WaitFor::Settings::Parser.new( { :minute => 1, :minutes => 1 }, @mock_config )
|
93
|
+
@mock_config.should_receive( :seconds ).once.and_return( 0 )
|
94
|
+
@mock_config.should_receive( :seconds= ).once.with( 120 )
|
95
|
+
|
96
|
+
@parser.send( :parse_minutes )
|
97
|
+
end
|
98
|
+
|
99
|
+
it "should set object's seconds attribute to 0 when hash does not contain :minute or :minutes" do
|
100
|
+
@parser = WaitFor::Settings::Parser.new( { }, @mock_config )
|
101
|
+
@mock_config.should_receive( :seconds ).once.and_return( 0 )
|
102
|
+
@mock_config.should_receive( :seconds= ).once.with( 0 )
|
103
|
+
|
104
|
+
@parser.send( :parse_minutes )
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
context "#parse_exception" do
|
109
|
+
before do
|
110
|
+
@mock_config = mock( WaitFor::Settings::Configuration )
|
111
|
+
end
|
112
|
+
|
113
|
+
it "should accept a hash containing :exception and set it to the setting object's exception attribute" do
|
114
|
+
@parser = WaitFor::Settings::Parser.new( { :exception => WaitFor::TimeoutError }, @mock_config )
|
115
|
+
@mock_config.should_receive( :exception= ).once.with( WaitFor::TimeoutError )
|
116
|
+
|
117
|
+
@parser.send( :parse_exception )
|
118
|
+
end
|
119
|
+
|
120
|
+
it "should set object's exception attribute to WaitFor::TimeoutError when hash does not contain :exception" do
|
121
|
+
@parser = WaitFor::Settings::Parser.new( { }, @mock_config )
|
122
|
+
@mock_config.should_receive( :exception= ).once.with( WaitFor::TimeoutError )
|
123
|
+
|
124
|
+
@parser.send( :parse_exception )
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
128
|
+
context "#parse_message" do
|
129
|
+
before do
|
130
|
+
@mock_config = mock( WaitFor::Settings::Configuration )
|
131
|
+
end
|
132
|
+
|
133
|
+
it "should accept a hash containing :message and set it to the setting object's message attribute" do
|
134
|
+
@parser = WaitFor::Settings::Parser.new( { :message => "Message" }, @mock_config )
|
135
|
+
@mock_config.should_receive( :message= ).once.with( "Message" )
|
136
|
+
|
137
|
+
@parser.send( :parse_message )
|
138
|
+
end
|
139
|
+
|
140
|
+
it "should set object's message attribute to the default error message when hash does not contain :message" do
|
141
|
+
@parser = WaitFor::Settings::Parser.new( { }, @mock_config )
|
142
|
+
@mock_config.should_receive( :message= ).once.with( "WaitFor timed out!" )
|
143
|
+
|
144
|
+
@parser.send( :parse_message )
|
145
|
+
end
|
146
|
+
end
|
147
|
+
end
|
data/spec/spec.opts
CHANGED
data/spec/spec_helper.rb
CHANGED
@@ -10,30 +10,23 @@ $:.unshift( File.dirname( __FILE__ ) + '/../lib' )
|
|
10
10
|
require File.dirname( __FILE__ ) + '/../lib/waitfor.rb'
|
11
11
|
require File.dirname( __FILE__ ) + '/../lib/waitfor/fixnum.rb'
|
12
12
|
require File.dirname( __FILE__ ) + '/../lib/waitfor/timer.rb'
|
13
|
-
require File.dirname( __FILE__ ) + '/../lib/waitfor/
|
13
|
+
require File.dirname( __FILE__ ) + '/../lib/waitfor/timeout_error.rb'
|
14
14
|
|
15
|
-
|
16
|
-
start_time = Time.now
|
17
|
-
yield
|
18
|
-
Time.now - start_time
|
19
|
-
end
|
15
|
+
NOW = Time.mktime( 1970, 01, 01, 00, 00, 00 )
|
20
16
|
|
21
17
|
class CustomTestError < RuntimeError
|
22
18
|
|
23
19
|
end
|
24
20
|
|
25
21
|
class ToggleBetweenFalseAndTrue
|
26
|
-
|
27
|
-
|
22
|
+
@@status = true
|
23
|
+
|
24
|
+
def self.reset_status
|
25
|
+
@@status = true
|
28
26
|
end
|
29
27
|
|
30
|
-
def status
|
31
|
-
|
32
|
-
|
33
|
-
true
|
34
|
-
else
|
35
|
-
@status = true
|
36
|
-
false
|
37
|
-
end
|
28
|
+
def self.status?
|
29
|
+
@@status = ( not @@status )
|
30
|
+
@@status
|
38
31
|
end
|
39
32
|
end
|
data/spec/spec_helper_spec.rb
CHANGED
@@ -1,30 +1,20 @@
|
|
1
1
|
require File.dirname(__FILE__) + '/spec_helper.rb'
|
2
2
|
|
3
|
-
describe "timer method" do
|
4
|
-
it "should report an elapsed time of at least 1 second but not more than 2 seconds for the code 'sleep 1'" do
|
5
|
-
elapsed_time = timer {
|
6
|
-
sleep 1
|
7
|
-
}
|
8
|
-
|
9
|
-
elapsed_time.should be > 1
|
10
|
-
elapsed_time.should be < 2
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
14
3
|
describe CustomTestError do
|
15
4
|
it "should be of a kind of RuntimeError" do
|
16
|
-
|
17
|
-
exception.should be_a_kind_of( RuntimeError )
|
5
|
+
CustomTestError.new.should be_a_kind_of( RuntimeError )
|
18
6
|
end
|
19
7
|
end
|
20
8
|
|
21
9
|
describe ToggleBetweenFalseAndTrue do
|
22
|
-
|
23
|
-
|
10
|
+
before do
|
11
|
+
ToggleBetweenFalseAndTrue.reset_status
|
12
|
+
end
|
24
13
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
14
|
+
it "should have a status method that returns false then true then false then true" do
|
15
|
+
ToggleBetweenFalseAndTrue.status?.should be( false )
|
16
|
+
ToggleBetweenFalseAndTrue.status?.should be( true )
|
17
|
+
ToggleBetweenFalseAndTrue.status?.should be( false )
|
18
|
+
ToggleBetweenFalseAndTrue.status?.should be( true )
|
29
19
|
end
|
30
20
|
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
require File.dirname( __FILE__ ) + '/spec_helper.rb'
|
2
|
+
|
3
|
+
describe WaitFor::TimeoutError do
|
4
|
+
context ".new" do
|
5
|
+
it "should be of a kind of RuntimeError" do
|
6
|
+
exception = WaitFor::TimeoutError.new
|
7
|
+
exception.should be_a_kind_of( RuntimeError )
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
data/spec/timer_spec.rb
CHANGED
@@ -1,83 +1,110 @@
|
|
1
|
-
require File.dirname(__FILE__) + '/spec_helper.rb'
|
1
|
+
require File.dirname( __FILE__ ) + '/spec_helper.rb'
|
2
2
|
|
3
|
-
describe Timer
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
3
|
+
describe WaitFor::Timer do
|
4
|
+
context ".new" do
|
5
|
+
before do
|
6
|
+
@mock_config = mock( WaitFor::Settings::Configuration )
|
7
|
+
WaitFor::Settings::Configuration.stub!( :new ).and_return( @mock_config )
|
8
|
+
end
|
8
9
|
|
9
|
-
|
10
|
-
|
11
|
-
lambda {
|
12
|
-
timer.out_of_time?.should be( true )
|
13
|
-
}.should raise_error( WaitFor::TimeoutError )
|
14
|
-
end
|
15
|
-
end
|
10
|
+
it "should accept a hash of options and return a new WaitFor::Timer object with the options hash passed to a new Configuration object" do
|
11
|
+
WaitFor::Settings::Configuration.should_receive( :new ).once.with( { } )
|
16
12
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
end
|
13
|
+
new_timer = WaitFor::Timer.new( { } )
|
14
|
+
new_timer.instance_variable_get( :@config ).should == @mock_config
|
15
|
+
end
|
21
16
|
|
22
|
-
|
23
|
-
|
24
|
-
end
|
17
|
+
it "should return a new WaitFor::Timer object with the start_time attribute set to the current time" do
|
18
|
+
Time.should_receive( :now ).once.and_return( Time.at( 0 ) )
|
25
19
|
|
26
|
-
|
27
|
-
|
20
|
+
new_timer = WaitFor::Timer.new( { } )
|
21
|
+
new_timer.instance_variable_get( :@start_time ).should == Time.at( 0 )
|
22
|
+
end
|
28
23
|
end
|
29
24
|
|
30
|
-
|
31
|
-
|
32
|
-
|
25
|
+
context "#out_of_time?" do
|
26
|
+
before do
|
27
|
+
@new_timer = WaitFor::Timer.new( 0 )
|
28
|
+
end
|
33
29
|
|
34
|
-
|
35
|
-
|
36
|
-
|
30
|
+
it "should raise an exception if the elapsed time has passed" do
|
31
|
+
@new_timer.stub!( :timed_out? ).and_return true
|
32
|
+
lambda { @new_timer.out_of_time? }.should raise_error
|
33
|
+
end
|
37
34
|
|
38
|
-
|
39
|
-
|
35
|
+
it "should return false if the elapsed time has not passed" do
|
36
|
+
@new_timer.stub!( :timed_out? ).and_return false
|
37
|
+
lambda { @new_timer.out_of_time? }.should_not raise_error
|
38
|
+
end
|
40
39
|
end
|
41
40
|
|
42
|
-
|
43
|
-
|
44
|
-
|
41
|
+
context "#timed_out?" do
|
42
|
+
before do
|
43
|
+
@new_timer = WaitFor::Timer.new( 1 )
|
44
|
+
end
|
45
45
|
|
46
|
-
|
47
|
-
|
48
|
-
|
46
|
+
it "should return true if the elapsed time has passed is greater than or equal the limit" do
|
47
|
+
@new_timer.stub!( :elapsed_time ).and_return( 1 )
|
48
|
+
@new_timer.send( :timed_out? ).should be true
|
49
|
+
end
|
49
50
|
|
50
|
-
|
51
|
-
|
51
|
+
it "should return false if the elapsed time has passed is less than the limit" do
|
52
|
+
@new_timer.stub!( :elapsed_time ).and_return( 0 )
|
53
|
+
@new_timer.send( :timed_out? ).should be false
|
54
|
+
end
|
52
55
|
end
|
53
|
-
end
|
54
56
|
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
}.should raise_error( CustomTestError )
|
61
|
-
end
|
57
|
+
context "#elapsed_time" do
|
58
|
+
before do
|
59
|
+
Time.should_receive( :now ).twice.and_return( Time.at( 0 ), Time.at( 1 ) )
|
60
|
+
@new_timer = WaitFor::Timer.new( 1 )
|
61
|
+
end
|
62
62
|
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
timer.out_of_time?.should be( true )
|
67
|
-
}.should raise_error( CustomTestError )
|
63
|
+
it "should return the elapsed time in seconds" do
|
64
|
+
@new_timer.send( :elapsed_time ).should == 1
|
65
|
+
end
|
68
66
|
end
|
69
67
|
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
68
|
+
context "#raise_exception" do
|
69
|
+
before do
|
70
|
+
@new_timer = WaitFor::Timer.new( 0 )
|
71
|
+
end
|
72
|
+
|
73
|
+
it "should raise the default WaitFor exception" do
|
74
|
+
@mock_config = mock( WaitFor::Settings::Configuration )
|
75
|
+
@mock_config.should_receive( :exception ).once.and_return( WaitFor::TimeoutError )
|
76
|
+
@mock_config.should_receive( :message ).once.and_return( nil )
|
77
|
+
@new_timer.instance_variable_set( :@config, @mock_config )
|
78
|
+
|
79
|
+
lambda { @new_timer.send( :raise_exception ) }.should raise_error( WaitFor::TimeoutError, "WaitFor::TimeoutError" )
|
80
|
+
end
|
81
|
+
|
82
|
+
it "should raise the default WaitFor exception with the specified message" do
|
83
|
+
@mock_config = mock( WaitFor::Settings::Configuration )
|
84
|
+
@mock_config.should_receive( :exception ).once.and_return( WaitFor::TimeoutError )
|
85
|
+
@mock_config.should_receive( :message ).once.and_return( "Timeout Error!" )
|
86
|
+
@new_timer.instance_variable_set( :@config, @mock_config )
|
87
|
+
|
88
|
+
lambda { @new_timer.send( :raise_exception ) }.should raise_error( WaitFor::TimeoutError, "Timeout Error!" )
|
89
|
+
end
|
76
90
|
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
91
|
+
it "should raise the specified exception" do
|
92
|
+
@mock_config = mock( WaitFor::Settings::Configuration )
|
93
|
+
@mock_config.should_receive( :exception ).once.and_return( CustomTestError )
|
94
|
+
@mock_config.should_receive( :message ).once.and_return( nil )
|
95
|
+
@new_timer.instance_variable_set( :@config, @mock_config )
|
96
|
+
|
97
|
+
lambda { @new_timer.send( :raise_exception ) }.should raise_error( CustomTestError, "CustomTestError" )
|
98
|
+
end
|
99
|
+
|
100
|
+
|
101
|
+
it "should raise the specified exception with the specified message" do
|
102
|
+
@mock_config = mock( WaitFor::Settings::Configuration )
|
103
|
+
@mock_config.should_receive( :exception ).once.and_return( CustomTestError )
|
104
|
+
@mock_config.should_receive( :message ).once.and_return( "Custom Test Error" )
|
105
|
+
@new_timer.instance_variable_set( :@config, @mock_config )
|
106
|
+
|
107
|
+
lambda { @new_timer.send( :raise_exception ) }.should raise_error( CustomTestError, "Custom Test Error" )
|
108
|
+
end
|
82
109
|
end
|
83
|
-
end
|
110
|
+
end
|