...so you can build on previous scripts for a similar task You can have tests (see below) Although not part of the application, your script is code and should adhere...
...ActiveRecord::RecordInvalid # Handle error end On error, log the record for manual care. Consider testing your script Not every script needs a test. However, sometimes you'll want to add...
...Chaining / fluent interfaces Note that you can also make your matcher chainable, so a test can modifier its behavior. Using chaining you can write a matcher like this:
...expected #{given.inspect} not to rhyme with #{expected.inspect}" given.rhymes_with? expected end end end ActiveSupport::TestCase.send :include, RhymeWithMatcher 4) Write a matcher class (for complex matchers) module Aegis module Matchers
...limited to 3 e-mails per day. Further reading ActionMailer: How to send a test mail directly from the console Debugging SPF records
We prefer to run our end-to-end tests with headless Chrome. While it's a very stable solution overall, we sometimes see the headless Chrome process freeze (or the...
...Capybara driver losing connection, we're not sure). The effect is that your test suite suddenly stops progressing without an error. You will eventually see an error after a long...
Test-Driven Development (TDD) in its most dogmatic form (red-green-refactor in micro-iterations) can be tedious. It does not have to be this way! This guide shows a...
...start writing them out and implementing them. As with the integration tests, the order of test-writing and implementation is up to you. When you're done, return to writing...
The solution is reasonably simple and fits the existing architecture. You have manually tested the change in an actual browser. The UI/UX looks and feels good. Agent checks
...diff contains no unrelated changes, accidental edits, or debugging statements (console.log, debugger, etc.). All tests are passing. New or changed behavior is covered by tests. Prefer few E2E tests for...
...as well as their programmatic variants up.observe() and up.autosubmit() are a nightmare for integration tests. Tests are usually much faster than the configured up.form.config.watchInputDelay. Therefore, it may happen that you...
...waiting for the watchInputDelay to run out, there is no XHR request and the test will continue. The solutions Lower the watchInputDelay in tests This will always help you. Your...
...Yourself (or DRY if you prefer). Identical blocks of code to set up a test sure does look like repetition, so we extract it into a before block.
...a mistake for tests. The article explains about how sharing setup between examples make test files harder to read and evolve. A related frustration I have is working on ultra...
Both knapsack and parallel_tests have the option to split groups by historic execution time. The required logs for this might be outdated since you manually have to update and...
...no extra effort locally and/or remotely. How to always split by execution logs Parallel Tests The parallel_tests gem has the option flag --group-by to change the default splitting...
Try to break your refactoring down in different parts. Try to make tests green for each part of your refactoring as soon as possible and only move to...
...the next big part if your tests are fixed. It's not a good idea to work for weeks or months and wait for all puzzle pieces to come together...
...run a Rails app that is using Turbo, you might observe that your integration tests are unstable depending on the load of your machine. We have a card "Fixing flaky...
...E2E tests" that explains various reasons for that in detail. Turbo currently ships with three modules: Turbo Drive accelerates links and form submissions by negating the need for full page...
If you already selected an element and want to get its parent, you can call find(:xpath, '..') on it.
Getting an entire test suite green can be a tedious task which involves frequent switches between the CLI that is running tests back to the IDE where its cause can...
...example_status_persistence_file_path as it allows RSpec to keep track of failing tests. See this card for set-up instructions. If you don't use RSpec for all...
...wrong number of arguments. This dual approach allows you to move very quickly and test components in isolation, while giving you confidence that your doubles are not a complete fiction...
...a commit between the given good and bad commits. You could then run a test (*) revealing the problem or inspect the issue manually. Keep in mind that you may need...
...you are done bisecting you can go back with git bisect reset (*) Such a test would need to live outside the repository as you are constantly switching your working directory...
By default parallel_tests will spawn as many test processes as you have CPUs. If you have issues with flaky tests, reducing the number of parallel processes may help.
...Flaky test suites can and should be fixed. This card is only relevant if you need to run a flaky test suite that you cannot fix for some reason. If...
Delete the static error pages 404.html, 422.html and 500.html from public/. Add some tests, for example a cucumber feature: @allow-rescue Scenario: 404 page When I go to the...
...on VCR and WebMock to prevent any real network connection when running our unit tests. This is not entirely true: They are both limited to a set of HTTP libraries...
...OpenURI#open_uri are not mocked and will trigger real network requests even in tests. This might bite you e.g. in older versions of CarrierWave with remote file URLs.
...or when working on a project without LoDash. Booleans This one is straightforward to test with typeof: x = true typeof x === 'boolean' // => true Strings Strings can exist as literal ("foo...
...we cannot rely on typeof: typeof "foo" // => "string" typeof new String("foo") // => "object" Your test should check both forms: x = 'foo' typeof x === 'string' || x instanceof String // => true Numbers
...data-environment=<%= Rails.env %>> Now you can say in a piece of Javascript: if (document.documentElement.dataset.environment == 'test') { // Code that should happen in Selenium tests } else { // Code that should happen for other environments...
...Or in your CSS / Sass: html[data-environment="test"] { * { text-transform: none !important; } } See also Cucumber: Detect if the current Capybara driver supports Javascript
...won't notice for a while (ask me how I know) but occasionally encounter tests which are "randomly failing". Example When users change their name and visit a page they...
...present. Otherwise, the browser uses its local time. This can lead to issues in tests with mocked time or inconsistent cache behavior. Cookie Expires depends on the Date header or...
...lead to unexpected issues in specific scenarios. Why does this matter? Mocked time in tests Consider a Rails application where you use the remember_me feature of Clearance for authentication...
Capybara-screenshot can automatically save screenshots and the HTML for failed Capybara tests in Cucumber, RSpec or Minitest. Requires Capybara-Webkit, Selenium or poltergeist for making screenshots. Screenshots are saved...
...Manually saving a page Additionally you can trigger the same behavior manually from the test using Capybara::Session#save_and_open_page and Capybara::Session#save_screenshot. Use Rails' built...
For my computer science bachelor's thesis I programmed and evaluated a CLI Test Case Prioritization (TCP) tool for makandra. It has been written as a Ruby Gem and was...
...modifications, to prioritize test cases which might be failing due to these modifications. Newly added test-cases have to granted high priority within the calculated prioritization. Test Case Prioritization