All Projects → ParamagicDev → evil_systems

ParamagicDev / evil_systems

Licence: MIT license
An easy way to enhance your system tests with Rails and Capybara using EvilMartians System of a Test.

Programming Languages

ruby
36898 projects - #4 most used programming language
HTML
75241 projects
CSS
56736 projects
javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to evil systems

intransient capybara
A set of improvements to Minitest/Capybara/Poltergeist/PhantomJS test stack that reduces the occurrence of transient failures.
Stars: ✭ 25 (-39.02%)
Mutual labels:  capybara, minitest
cats-effect-testing
Integration between cats-effect and test frameworks
Stars: ✭ 155 (+278.05%)
Mutual labels:  minitest
Email Spec
Collection of RSpec/MiniTest matchers and Cucumber steps for testing email in a ruby app using ActionMailer or Pony
Stars: ✭ 1,142 (+2685.37%)
Mutual labels:  minitest
Still life
Rails upgrade's best friend
Stars: ✭ 213 (+419.51%)
Mutual labels:  minitest
Vim Ruby Minitest
Vim highlighting & completion for MiniTest
Stars: ✭ 97 (+136.59%)
Mutual labels:  minitest
rubium
Rubium is a lightweight alternative to Selenium/Capybara/Watir if you need to perform some operations (like web scraping) using Headless Chromium and Ruby
Stars: ✭ 65 (+58.54%)
Mutual labels:  capybara
Vscode Ruby Test Adapter
A Ruby test adapter extension for the VS Code Test Explorer
Stars: ✭ 50 (+21.95%)
Mutual labels:  minitest
bdd
Given/When/Then/And/But output to RSpec and Minitest
Stars: ✭ 33 (-19.51%)
Mutual labels:  minitest
capybara-chrome
Chrome driver for Capybara using Chrome's remote debugging protocol
Stars: ✭ 27 (-34.15%)
Mutual labels:  capybara
Action Cable Testing
Action Cable testing utils
Stars: ✭ 192 (+368.29%)
Mutual labels:  minitest
Factory trace
Simple tool to maintain factories and traits from FactoryBot
Stars: ✭ 184 (+348.78%)
Mutual labels:  minitest
With model
Dynamically build an Active Record model (with table) within a test context
Stars: ✭ 119 (+190.24%)
Mutual labels:  minitest
Mutant
Automated code reviews via mutation testing - semantic code coverage.
Stars: ✭ 1,794 (+4275.61%)
Mutual labels:  minitest
Fake ftp
A fake FTP server for use with ruby tests
Stars: ✭ 77 (+87.8%)
Mutual labels:  minitest
capybara-chromedriver-logger
Enables console.log/error/info output from Javascript feature specs running with Chromedriver
Stars: ✭ 54 (+31.71%)
Mutual labels:  capybara
Mocha
Mocha is a mocking and stubbing library for Ruby
Stars: ✭ 1,065 (+2497.56%)
Mutual labels:  minitest
Rantly
Ruby Imperative Random Data Generator and Quickcheck
Stars: ✭ 241 (+487.8%)
Mutual labels:  minitest
capybara select2
Capybara helpers for https://select2.org select box (supports Select2 version 2/3/4)
Stars: ✭ 48 (+17.07%)
Mutual labels:  minitest
mache
A library for writing cleaner and more expressive acceptance tests using page objects.
Stars: ✭ 40 (-2.44%)
Mutual labels:  capybara
LocalSupport
A directory of local support services and volunteer opportunities
Stars: ✭ 60 (+46.34%)
Mutual labels:  capybara

Purpose

I write tests using Minitest and routinely reference EvilMartians System of a Test blog post for best practices for system tests. In this blog post, they also have an opinionated way of setting up System Tests.

EvilSystems offers 3 distinct advantages over the setup provided by EvilMartians System of a Test:

1.) The blog post was built with RSpec in mind, but we use Minitest here!

2.) Constantly copying 5 files over into every new Rails app is annoying. Lets make that easier!

3.) File changes can end up out of sync, a gem makes sure updates can be pushed to all users.

EvilSystems is a quick, easy, reusable way to apply the SoaT concepts and settings to projects for system tests using Minitest.

Full API documentation can be found here:

https://rdoc.info/github/paramagicdev/evil_systems/main

Installation

bundle add evil_systems --group=test

Make sure the following 3 gems are in your Gemfile as well:

# Gemfile

group :test do
  gem 'capybara'
  gem 'cuprite' # Optional
  gem 'selenium-webdriver' # Not required if using Cuprite and using Rails >= 6.1
end

Note: bundle add by default appends the gem to the bottom of your Gemfile, which means not in the test group of gems. If the capybara gem is in the test group, but evil_systems is not, you will not be able to load your application in production. Be sure that evil_systems is placed in the same group as capybara (we recommend the test group).

Setup

Minitest

Navigate to test/application_system_test_case.rb in your Rails app.

Setup your file like so:

# test/application_system_test_case.rb

require 'test_helper'

# 'capybara' and 'capybara/cuprite' need to be defined for EvilSystems to work properly.
require 'capybara'
require 'capybara/cuprite'

require 'evil_systems'

EvilSystems.initial_setup
# To pass in driver_options to cuprite you can do the following:
# EvilSystems.initial_setup(driver_options: { process_timeout: 20 })

class ApplicationSystemTestCase < ActionDispatch::SystemTestCase
  driven_by :evil_cuprite

  include EvilSystems::Helpers
end

RSpec

Maybe in the future?

Whats included?

Usage

EvilSystems.initial_setup takes three keyword arguments, :task, and silent, skip_task.

They all have to do with precompiling assets.

:silent by default is set to true and will only tell you when assets are compiling, and how long the compilation took.

:task defaults to assets:precompile, System of a test uses webpacker:compile.

:skip_task when true says you dont want to run any Rake tasks. Default is false

Example:

EvilSystems.initial_setup(task: "webpacker:compile", silent: false)

Settings

  • - Automatically registers a :evil_cuprite driver if Capybara::Cuprite is defined.

  • - Automatically sets Capybara's default and javascript driver to :evil_cuprite

  • - Automatically sets Capybara.app_host

How `app_host` is set

app_host will first use ENV["APP_HOST"] then falls back to the systems hostname if the APP_HOST ENV var is not defined. If neither are defined, it will then default to "0.0.0.0"

  • - Capybara.server_host = "0.0.0.0" Make server listening on all hosts

  • - Capybara.default_max_wait_time = 2 Dont spend forever waiting for matchers

  • - Capybara.default_normalize_ws = true normalizes whitespace in has_text? and similar matchers.

  • - Sets the Capybara.save_path Uses ENV["CAPYBARA_ARTIFACTS"] and falls back to "./tmp/capybara"

  • - Sets a REMOTE_CHROME instance if a ENV["CHROME_URL"] is found

  • - Prepends a last_used_session attribute accessor to Capybara.

Helpers

EvilSystems::Helpers

Automatically includes ActionView::RecordIdentifier if Rails is defined.

Also includes:

EvilSystems::CupriteHelpers
EvilSystems::SessionHelpers

Regular Helpers

# The full path to be prepended to a screen shot
absolute_image_path

# The relative path to be prepended to a screenshot message to make it clickable
image_path

# Make failure screenshots compatible with multi-session setup
take_screenshot

# Prepends a '#' to the +dom_id+ method provided by Rails
dom_id(*args)

SessionHelpers

# Small wrapper around Capybara.using_session thats easy to call from an instance
within_session(name_or_session, &block)

Cuprite Helpers

# pauses the page
pause

# Opens a Pry or IRB repl. Will use Pry if Pry is defined, fallsback
# to debugging with IRB
debug binding

# waits to make sure theres no active connections.
wait_for_network_idle!

Env Variables

ENV variables used by this gem.

ENV["APP_HOST"] # used for Capybara.app_host
ENV["CAPYBARA_ARTIFACTS"] # used for Capybara.save_path
ENV["CHROME_URL"] # used for setting a remote chrome instance for Cuprite
ENV["PROCESS_TIMEOUT"] # How long to wait before killing the process, default is 5 seconds
ENV["CI"] # Whether or not to run Cuprite in headless mode, defaults to true.
ENV["SLOWMO"] # Delay in seconds before sending a command (default 0). Also see https://github.com/rubycdp/ferrum#customization
ENV["DISABLE_ANIMATION"] # Configure whether Capybara should render animations, default is true

I don't want to use Cuprite.

Thats fine! I totally get it. Selenium is battle tested. Simply remove the require "capybara/cuprite" line and EvilSystems will detect that Cuprite is not defined and not setup a driver for you and not include Cuprite helpers.

Omissions and differences

  • Will use assets:precompile instead of webpacker:compile before systems tests (configurable)

  • Does not set the Rails.application.default_url_options[:host] due to parallelization issues found while testing the dummy app.

License

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

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].