...index in your migration and migrate add_index :users, [:last_name, :created_at] 3. Test the index in your database ActiveRecord::Base.connection.execute('SET enable_seqscan = OFF') # Try to force index...

Note You don't need to configure this if you're using system tests with modern versions of Rails. They do exactly the same

You can use local copies of gems in your Gemfile like this: gem 'spreewald', path: '~/gems/spreewald' As soon as you...

Coverage reports are rarely useful if you run only small parts of your test suite. Just do not load SimpleCov in this case, and you will see less noise in...

...your test output: if RSpec.configuration.files_to_run.count > 5 require "simplecov" SimpleCov.start 'rails' end See also How to use Simplecov to find untested code in a Rails project with RSpec and Cucumber

...displays a beforeunload confirmation dialog, ChromeDriver will immediately close it. In consequence, any automated tests which try to interact with unload prompts will fail. This is because ChromeDriver now follows...

...that any unload prompts should be closed automatically. However, this applies only to "HTTP" test sessions, i.e. what you're using by default. The spec also defines that bi-directional...

Environment Adapter Jobs Run In Worker Needed? development :async Rails server process No test :test Not executed (stored) No production :solid_queue Separate worker Yes (bin/jobs) Development (:async)

SolidQueue::FailedExecution.last&.error # Find specific job SolidQueue::Job.where(class_name: 'HelloJob').last Test (:test) Jobs are not executed and only stored for assertions. For system tests you can...

1) first expectation failed 2) second expectation failed As you can see, the test is not being interrupted by the first two falsy expectations, the third expectation passed without...

This can be handy if you are testing for multiple values, which map to one context, e. g. mail components, in order to provide better readability of your...

The :test adapter doesn't respect limits_concurrency configuration. Switch to :solid_queue adapter in your test to verify blocking behavior. Job Configuration class MembershipJob < ApplicationJob limits_concurrency(key: ->(membership...

end The problem When using the default test mode for enqueuing jobs, both will be enqueued immediately. However, we actually we want to test that only one of both...

...consecutive calls of Time.now probably return two inequal values. Consider freezing time in your tests so it is not dependent on the speed of the executing PC: Timecop.freeze(Time.now.round) do...

config.move_to_store = true We have a separate card about that. Store test files separately. Also add support for parallel tests. You can easily do that by setting...

config.root = "#{Rails.public_path}/system/#{Rails.env}#{ENV['TEST_ENV_NUMBER']}".freeze For debugging purposes (e.g. trying to hunt down a staging bug locally), it might make sense to allow reading...

...server error, the exception that caused the error will still be raised within the test so as to provide a useful stack trace and a good debugging experience.

...previous default behavior, value false) Using the new default needs to change a RSpec test like this: Before it 'raises an exception if the page could not be found' do...

Currently we often use geordi to run cucumber and rspec tests. Geordi takes care of installing a matching chromedriver for the installed google-chrome binary. The google-chrome binary is...

...correct browser versions for you. Here is the setup you need for your integration tests: Capybara.register_driver :chrome do |app| options = Selenium::WebDriver::Chrome::Options.new options.browser_version = '138.0.7204.183' Capybara::Selenium...

...failingFunction() { throw new Error("Something went wrong") } When you call that function in a test, your test will fail: it('has a test', function() { failingFunction() // this will fail your test...

...can fix this by expecting the state of the returned promise: it('has a test', async function() { await expectAsync(failingFunction()).toBeRejected() }) When you cannot access the rejecting promise

...tool. This helps you to find out which parts of your application are not tested. Integrating this in a rails project with rspec, cucumber and parallel_tests is easy.

...it to your Gemfile and bundle group :test do gem 'simplecov', require: false end Add a .simplecov file in your project root: SimpleCov.start 'rails' do # any custom configs like groups...

...using inheritance, modules, traits or partials. When you reuse behavior you want to reuse tests as well. You are probably already reusing examples in unit tests. Unfortunately it is much...

...harder to reuse code when writing integration tests with Cucumber, where you need to express yourself with Gherkin and step definitions instead of Ruby classes and methods.

Jasmine is a great tool to unit test your JavaScript components without writing an expensive end-to-end test for every little thing. Jasmine is a purely client-side tool...

...or access the database. Any HTTP calls must be mocked. Learn What do we test with Jasmine? Just as unit tests are a direct way to closely look at your...

rspec.info

In modern default RSpec configurations, your tests are usually run in random order. This helps to detect "flickering" tests that only fail when run in a certain order.

...for this are tests that have side effects causing other tests to fail later. The hard part is to find the offending test. Enter rspec --bisect: Say you have a...

...To improve this, I have successfully been using a little "step" helper in my tests. It marks semantic sections, structuring an example while improving documentation. When the test runs, each...

...spec, as well as tracking progress during execution. # # Example: # it 'offers a login' do # # Test setup # # STEP 'Attempt login with wrong credentials' # # ... # # STEP 'Successful login' # # ... # end # Taken from https://makandracards.com...

ruby-doc.org

...be an issue, but can be annoying to deal with during development and in tests. To avoid this use Rationals conversion_factor = Rational('1') / Rational('3.6') # => (5/18) result = Rational...

evilmartians.com

...prefer writing your own code for simple requirements without many edge cases) Gem is tested well (coverage and quality) Gem has a good code quality Gem's licence fits to...

...applications that are either old or abandoned by a different team earlier: Add E2E tests for the happy path. Other than unit tests, E2E tests will not break when we...

...refactor later. Always add tests on whatever we work on. When you work on something, improve that part of the code. Make sure setup for a new developer is as...

In some projects we have issues with flaky tests. The best default is to fix them all. But in some cases it might be a pragmatic way to retry them...

...for a limit number of times. Notes: This setup was tested with a CI Pipeline that uses knapsack for parallel test balacing The official docs recommend to use rspec-retry...

Geordi's cucumber command has a --rerun option that reruns failing tests the given number of times. Usage: geordi cucumber path/to/features --rerun=2 geordi cucumber path/to/features -r2 Background and how...

...tmp/parallel_cucumber_failures.log containing the filenames and line number of the failed scenarios after a full test run. Normally you can say cucumber -p rerun (rerun is a profile defined by default...

...attributes makes it easier to find errors in your application during development and in tests. Consider this approach if you want to strengthen the params handling in your application.

...the user is missing permit(:full_name) logs the error ActionController::UnpermittedParameters in development + test and do nothing in production. Option 1: In case you use action_on_unpermitted_parameters...