I recently noticed a new kind of flaky tests on the slow free tier GitHub Action runners: Integration tests were running on smaller screen sizes than specified in the device...

...browser_to(MOBILE_WIDTH, MOBILE_HEIGHT) else # Nothing to do in case of rack tests end end end This could however reduce your test performance...

...does not have any log or debugging statements like console.log(...), byebug etc. has green tests has tests for new features has been manually tested in the browser has no missing...

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

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

relishapp.com

...and not_change { Video.count } The above example will call playlist.destroy only once, but test both assertions. Note When you chain multiple Capybara matchers using and, Capybara will retry all matchers...

...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...

You can explain our approach to adopting a legacy app: end-to-end tests for the happy paths first, tests for everything you touch, improving whatever you work on...

...and regular time set aside for stability. You can explain why end-to-end tests, unlike unit tests, survive a refactoring — and why that makes them the first tests to...

Apply Test Driven Development(TDD) to the process of building container images by defining test before writing code and automate the testing process. Iterate through the TDD cycle while developing...

...and running the tests later in continuous integration to ensure robust and reliable container images. Installation We create a Gemfile for installing all required gems. Gemfile # Gemfile gem 'docker-api...

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...

...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...

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

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...

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...

...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...

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...

...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...

...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...

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...

...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...

Jasmine is a great tool to unit test your JavaScript components without writing an expensive end-to-end test for every little thing. Important Work on this lesson in builder...

...Any HTTP calls must be mocked. Learning goals You can explain what JavaScript unit tests cover that end-to-end tests shouldn't: a component's details and edge cases...

...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

...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.

We use Selenium WebDriver with Capybara for end-to-end tests that need a real browser. Important Work on this lesson in advisor mode. Learning goals You can explain how...

...Capybara drives a browser, how its drivers differ (e.g. rack_test vs. Selenium), and when a feature spec needs a real browser. You can run a feature spec in a...