Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

eventually: docs, included in Wrong module

  • Loading branch information...
commit cae852f09a3d4dcb3f014b486a10d5eb7a10e7f5 1 parent e6b7502
@alexch authored
Showing with 33 additions and 0 deletions.
  1. +22 −0 README.markdown
  2. +9 −0 examples.rb
  3. +2 −0  lib/wrong.rb
View
22 README.markdown
@@ -110,6 +110,28 @@ We also implement the most amazing debugging method ever, `d`, which gives you a
Remember, if you want `d` to work at runtime (e.g. in a webapp) then you must `include Wrong::D` inside your app, e.g. in your `environment.rb` file.
+### eventually
+
+If you care that something is going to be true *soon*, but maybe not *right* now, use `eventually`. It will keep executing the block, up to 4 times a second, until either
+
+ * the block returns true(ish)
+ * 5 seconds elapse
+
+If the block raises an exception, then `eventually` will treat that as a false and keep trying. The last time it fails, it'll raise that exception instead of a mere `AssertionFailedError`. That way, the following are all possible:
+
+ eventually { false }
+ eventually { assert { false } }
+ eventually { false.should be_true } # in RSpec
+
+and you should get the expected failure after time expires.
+
+You can also send options to eventually as hash parameters.
+
+ eventually(:timeout => 10) { false } # keep trying for 10 sec
+ eventually(:delay => 1) { false } # try every 1.0 sec, not every 0.25 sec
+
+(For now, `eventually` is in its own module, but you get it when you `include Wrong`. Maybe it should be in Helpers like the rest?)
+
## Test Framework Adapters ##
Adapters for various test frameworks sit under wrong/adapters.
View
9 examples.rb
@@ -118,3 +118,12 @@ def initialize(*args)
x = 7
d { x * 2 }
end
+
+example "eventually fails after 5 seconds" do
+ eventually { false }
+end
+
+example "eventually fails with a friendly error" do
+ x = 2
+ eventually { x + x == 5 }
+end
View
2  lib/wrong.rb
@@ -19,6 +19,8 @@ module Wrong
extend Wrong::Assert
include Wrong::Helpers
extend Wrong::Helpers
+ include Wrong::Eventually
+ extend Wrong::Eventually
end
# this does some magic; if you don't like it...
Please sign in to comment.
Something went wrong with that request. Please try again.