Created
June 13, 2014 16:14
-
-
Save lukeredpath/e115ba6a011c45cdc7c4 to your computer and use it in GitHub Desktop.
A small extension to RSpec that uses the Wrong gem
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# gem install wrong | |
require 'wrong' | |
class RSpec::Expectations::ExpectationTarget | |
include Wrong::Assert | |
include Wrong::Eventually | |
def will(matcher) | |
eventually { to(matcher) } | |
end | |
def will_not(matcher) | |
eventually { not_to(matcher) } | |
end | |
end | |
# usage - very helpful for things like automated UI tests | |
describe "Something that happens asynchronously" do | |
it "will timeout if it doesn't match in time" do | |
expect(future_value).will eql("expected result") | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I added this to a project as I got fed up wrapping my expect(foo).to calls in eventually blocks.
The only downside is the inability to specify a specific timeout, in which case you might want to still use eventually directly (or just set a sensible global default).