0.01
No commit activity in last 3 years
No release in over 3 years
A collection of helpers.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 0
>= 2
 Project Readme

test-helpers

Build Status

A collection of helper methods, matchers, and other various other freebies that we all use across multiple projects.

Usage

Get the gem:

gem install test-helpers

or add to your Gemfile

gem 'test-helpers'

Require parts of the gem that you want to use (or require everything):

require 'test-helpers/wait'

or

require 'test-helpers/all'

TestHelpers::Wait

The wait module contains two methods: poll_and_assert and wait_until.

poll_and_assert

is useful when you are asserting on something that has a timing componenet. For example, you need to assert on an asynchronous response to an API request but the response isn't immediately available. In these types of situation, use the poll_and_assert method and pass in your expectation. The method will poll the assertion until it returns true or it times out. If it times out, you will get the actual assertion message back instead of a generic timeout message.

#will poll the assert until true or default timeout
poll_and_assert { expect(true).to be false } 
#will poll the assert until true or specified
poll_and_assert(timeout: 30) { expect(true).to be false }  timeout
wait_until

is useful when you want to wait until something happens before continuing. This method will trap all StandardErrors until the block returns true or it times out. If it times out, you will get the default timeout error message or you can pass in a custom error message for better reporting.

#will poll the assert until true or specified timeout every 0.5 seconds
poll_and_assert(interval: 0.5) { expect(true).to be false } 
#raise a TimeoutError with the given error message.
wait_until(error_message:  'True never equaled false' ) { true == false } 
Configuration

There are multiple default configuration options that you can set.

# features\support\env.rb
# or
# spec_helper.rb
TestHelpers::Wait.configure do |config|
  config.wait_timeout = 30 #timeout after 30 seconds
  config.wait_interval = 0.5 #poll the given block every 0.5 seconds
  config.error_message = 'My default error message'
end

If you don't set your own defaults the following defaults will apply:

TestHelpers::Wait.configure do |config|
  config.wait_timeout = 5.0
  config.wait_interval = 0.1
  config.error_message = 'Timed out waiting for block'
end

(optional) Include it in Cucumber's World object:

#features\support\env.rb
World(TestHelpers::Wait)

Contribute

  1. Fork the project
  2. Write specs
  3. Implement code
  4. Create Pull Request