No release in over 3 years
Low commit activity in last 3 years
Integration Test Kit provides a small DSL for defining integration test commands, and an endpoint for calling them locally.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 3.2

Runtime

>= 5.0.0
 Project Readme

Integration Test Kit

HitCount

Integration Test Kit provides a small DSL for defining integration test commands, and an endpoint for calling them locally.

The initial use case was for running integration test commands for specific testing scenarios in Cypress, such as cleaning the test database or creating seed data.

Integration Test Kit is inspired by the functionality of Cypress On Rails.

Usage

You'll need to define commands within a directory of your choosing. Commands are set up using a simple DSL:

IntegrationTestKit.define do
  command :example do
    puts 'Ruby code can be run here'
  end
end

You can then run commands with a POST to /<name_of_mount_path>/commands?name=<name_of_command>, or with "name": "example" in the body as JSON.

If you're using Cypress, you can add a command to your support/commands.js file to make this easier:

Cypress.Commands.add('appCommand', command => {
  cy.request({
    method: 'POST',
    url: `/<name_of_mount_path>/commands`,
    body: {
      name: command
    }
  })
})

Installation

Things to note

  • Integration Test Kit is meant for usage within the test environment only. Don't include it or configure it in production.
  • There is a check to ensure that the gem is only configured for the test environment during configuration and when running commands.
  • The gem is a Rails Engine, and is meant for usage within a Rails application.

Add this line to your application's Gemfile in the test group:

group :test do
  gem 'integration_test_kit'
end

And then run:

$ bundle install

Or install it yourself as:

$ gem install integration_test_kit

Configure Integration Test Kit in an initializer, or in config/environments/test.rb. Currently, the only configuration option is the commands load path:

  IntegrationTestKit.configure do |config|
    config.commands_load_path = 'spec/cypress/commands'
  end

Create commands within a Ruby file inside the commands load path directory (eg. test.rb).

require 'integration_test_kit'

IntegrationTestKit.define do
  command :example do
    puts 'Ruby code can be run here'
  end

  command :another_example do
    puts 'Ruby code can be run here'
  end
end

Mount the routes within your application (routes.rb or equivalent):

if Rails.env.test?
  mount IntegrationTestKit::Engine => '/integration_test_kit'
end

You are now able to run commands with a POST to /integration_test_kit/commands/name=example, or with "name": "example" in the body as JSON.

Contributing

Feel free to create an issue or submit a PR.

Release

  1. Bump the version
  2. Follow the standard ruby gems release guide

License

The gem is available as open source under the terms of the MIT License.