Skip to content

Instantly share code, notes, and snippets.

@lukeredpath
Created June 13, 2014 16:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lukeredpath/e115ba6a011c45cdc7c4 to your computer and use it in GitHub Desktop.
Save lukeredpath/e115ba6a011c45cdc7c4 to your computer and use it in GitHub Desktop.
A small extension to RSpec that uses the Wrong gem
# 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
@lukeredpath
Copy link
Author

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).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment