waitfor 0.1.0 → 0.1.7

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,74 +1,60 @@
1
1
  require File.dirname( __FILE__ ) + '/spec_helper.rb'
2
2
 
3
- describe WaitFor, "when event is true" do
4
- it "should halt execution for under 1 second" do
5
- elapsed_time = timer {
6
- WaitFor.upto 1.second do
7
- true
8
- end
9
- }
10
-
11
- elapsed_time.should be < 1.second
3
+ describe WaitFor do
4
+ context "when event is true" do
5
+ it "should continue code execution without delay" do
6
+ Time.should_receive( :now ).once.and_return( NOW )
7
+ Kernel.should_not_receive( :sleep )
8
+
9
+ WaitFor.upto( :seconds => 1 ) { true }
10
+ end
12
11
  end
13
- end
14
12
 
15
- describe WaitFor, "when event is false" do
16
- it "should halt execution for at least 2 seconds, but less than 4 seconds before raising an error" do
17
- elapsed_time = timer {
13
+ context "when event is false" do
14
+ it "should halt code execution until timer expires then raise an error" do
15
+ Time.should_receive( :now ).exactly( 3 ).times.and_return( NOW, NOW + 1, NOW + 2 )
16
+ Kernel.should_receive( :sleep ).once
17
+
18
18
  lambda {
19
- WaitFor.upto 2.seconds do
20
- false
21
- end
19
+ WaitFor.upto( :seconds => 2 ) { false }
22
20
  }.should raise_error
23
- }
24
-
25
- elapsed_time.should be > 2
26
- elapsed_time.should be < 4
21
+ end
27
22
  end
28
- end
29
23
 
30
- describe WaitFor, "when event is false and has custom exception" do
31
- it "should raise a CustomTestError error" do
32
- lambda {
33
- WaitFor.upto( :seconds => 0, :exception => CustomTestError ) do
34
- false
35
- end
36
- }.should raise_error( CustomTestError )
37
- end
38
- end
24
+ context "when event is initially false but becomes true" do
25
+ before do
26
+ ToggleBetweenFalseAndTrue.reset_status
27
+ end
39
28
 
40
- describe WaitFor, "when event is false and has custom message" do
41
- it "should raise an error with a custom message" do
42
- lambda {
43
- WaitFor.upto( :seconds => 0, :message => "Custom Error Message" ) do
44
- false
45
- end
46
- }.should raise_error( "Custom Error Message" )
47
- end
48
- end
29
+ it "should halt code execution until event becomes true then continue" do
30
+ Time.should_receive( :now ).exactly( 2 ).times.and_return( NOW, NOW + 1 )
31
+ Kernel.should_receive( :sleep ).once
49
32
 
50
- describe WaitFor, "when event is false and has custom exception with a custom message" do
51
- it "should raise a CustomTestError error with a custom message" do
52
- lambda {
53
- WaitFor.upto( :seconds => 0, :exception => CustomTestError, :message => "Custom Error Message" ) do
54
- false
55
- end
56
- }.should raise_error( CustomTestError, "Custom Error Message" )
33
+ WaitFor.upto( :seconds => 2 ) { ToggleBetweenFalseAndTrue.status? }
34
+ end
57
35
  end
58
- end
59
36
 
60
- describe WaitFor, "when event is initially false but becomes true " do
61
- it "should halt execution for at least 1 second but no more than 3 seconds before continuing on" do
62
- event = ToggleBetweenFalseAndTrue.new
37
+ context "when event is false and has custom exception" do
38
+ it "should raise a CustomTestError error" do
39
+ lambda {
40
+ WaitFor.upto( :seconds => 0, :exception => CustomTestError ) { false }
41
+ }.should raise_error( CustomTestError )
42
+ end
43
+ end
63
44
 
64
- elapsed_time = timer {
65
- WaitFor.upto 2.seconds do
66
- event.status
67
- end
68
- }
45
+ context "when event is false and has custom message" do
46
+ it "should raise an error with a custom message" do
47
+ lambda {
48
+ WaitFor.upto( :seconds => 0, :message => "Custom Error Message" ) { false }
49
+ }.should raise_error( "Custom Error Message" )
50
+ end
51
+ end
69
52
 
70
- elapsed_time.should be > 1
71
- elapsed_time.should be < 3
53
+ context "when event is false and has custom exception with a custom message" do
54
+ it "should raise a CustomTestError error with a custom message" do
55
+ lambda {
56
+ WaitFor.upto( :seconds => 0, :exception => CustomTestError, :message => "Custom Error Message" ) { false }
57
+ }.should raise_error( CustomTestError, "Custom Error Message" )
58
+ end
72
59
  end
73
60
  end
74
-
metadata CHANGED
@@ -1,7 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: waitfor
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ hash: 21
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 1
9
+ - 7
10
+ version: 0.1.7
5
11
  platform: ruby
6
12
  authors:
7
13
  - James Bobowski
@@ -9,20 +15,25 @@ autorequire:
9
15
  bindir: bin
10
16
  cert_chain: []
11
17
 
12
- date: 2010-02-03 00:00:00 -06:00
13
- default_executable:
18
+ date: 2011-04-19 00:00:00 Z
14
19
  dependencies:
15
20
  - !ruby/object:Gem::Dependency
16
21
  name: hoe
17
- type: :development
18
- version_requirement:
19
- version_requirements: !ruby/object:Gem::Requirement
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ none: false
20
25
  requirements:
21
26
  - - ">="
22
27
  - !ruby/object:Gem::Version
28
+ hash: 5
29
+ segments:
30
+ - 2
31
+ - 3
32
+ - 3
23
33
  version: 2.3.3
24
- version:
25
- description: Blocks execution until a specified statement becomes true, or a specified time interval is reached, at which point an error is raised.
34
+ type: :development
35
+ version_requirements: *id001
36
+ description: Simple solution to the sleep( ) test anti-pattern. Blocks execution until a supplied block returns true, or a specified time interval is reached, at which point an error is raised.
26
37
  email:
27
38
  - james.bobowski@gmail.com
28
39
  executables: []
@@ -39,17 +50,22 @@ files:
39
50
  - README.rdoc
40
51
  - lib/waitfor.rb
41
52
  - lib/waitfor/fixnum.rb
53
+ - lib/waitfor/timeout_error.rb
42
54
  - lib/waitfor/timer.rb
43
55
  - lib/waitfor/version.rb
44
- - lib/waitfor/waitfor_timeout_error.rb
56
+ - lib/waitfor/settings/configuration.rb
57
+ - lib/waitfor/settings/legacy_parser.rb
58
+ - lib/waitfor/settings/parser.rb
59
+ - spec/configuration_spec.rb
45
60
  - spec/fixnum_spec.rb
61
+ - spec/legacy_parser_spec.rb
62
+ - spec/parser_spec.rb
46
63
  - spec/spec.opts
47
64
  - spec/spec_helper.rb
48
65
  - spec/spec_helper_spec.rb
66
+ - spec/timeout_error_spec.rb
49
67
  - spec/timer_spec.rb
50
68
  - spec/waitfor_spec.rb
51
- - spec/waitfor_timeout_error_spec.rb
52
- has_rdoc: true
53
69
  homepage: http://github.com/jamesbobowski/waitfor
54
70
  licenses: []
55
71
 
@@ -60,21 +76,27 @@ rdoc_options:
60
76
  require_paths:
61
77
  - lib
62
78
  required_ruby_version: !ruby/object:Gem::Requirement
79
+ none: false
63
80
  requirements:
64
81
  - - ">="
65
82
  - !ruby/object:Gem::Version
83
+ hash: 3
84
+ segments:
85
+ - 0
66
86
  version: "0"
67
- version:
68
87
  required_rubygems_version: !ruby/object:Gem::Requirement
88
+ none: false
69
89
  requirements:
70
90
  - - ">="
71
91
  - !ruby/object:Gem::Version
92
+ hash: 3
93
+ segments:
94
+ - 0
72
95
  version: "0"
73
- version:
74
96
  requirements: []
75
97
 
76
98
  rubyforge_project: waitfor
77
- rubygems_version: 1.3.5
99
+ rubygems_version: 1.8.7
78
100
  signing_key:
79
101
  specification_version: 3
80
102
  summary: Generic 'wait for' method
@@ -1,5 +0,0 @@
1
- module WaitFor #:nodoc:
2
- class TimeoutError < RuntimeError #:nodoc:
3
-
4
- end
5
- end
@@ -1,6 +0,0 @@
1
- describe WaitFor::TimeoutError do
2
- it "should be of a kind of RuntimeError" do
3
- exception = WaitFor::TimeoutError.new
4
- exception.should be_a_kind_of( RuntimeError )
5
- end
6
- end