...column} <@ array[:expected_values]", expected_values:) end end ..and include their specs to your test suite: describe ApplicationRecord do describe '.where_array_matches!' do let!(:matching_user) { create(:user, movie...
I recently stumbled over a problem that my feature tests broke in CI because of a mismatching chromedriver version. In this specific project we have a fixed Chromium version in...
...a Debian 12 environment instead of Chrome. The tests however used a recent chrome version instead. $ chromedriver --version ChromeDriver 117.0.5938.149 (e3344ddefa12e60436fa28c81cf207c1afb4d0a9-refs/branch-heads/5938@{#1539}) $ chromium --version Chromium 117.0.5938.149 built on...
...for the required model Write the controller first for the required model Write the tests first for the code bad: While doing this you can for example see easier when...
...so that only this will be run. This is very useful when using a test runner like guard. Add the following config to spec/spec_helper.rb: RSpec.configure do |config| # These two settings...
...updating the corresponding mailer preview can be forgotten very easily. Mailer previews can be tested like other code as well and I sometimes add the following tests to test suites...
...want to define a global matcher since you need it only for your specific test, there are two ways to do it: Custom matcher for a single group
...don't need any "conversion" hacks which try to replace commas with dots. Additionally, tests which control browsers with Selenium will also see point-formatted values on non-English locales...
...the number of requests for a single IP address. Bash Command awk '{ print $1}' test.log | sort | uniq --count Result 1 87.140.79.41 3 87.140.79.42 Explain awk '{ print $1}' test.log...
...that, so I hope it will be fixed with a future release. The following test succeeds: context 'factories' do let(:test_case) { FactoryBot.create(:test_case) } it 'are valid' do
...test_case).to be_valid end end But when I did the same in byebug the following happened: (byebug) FactoryBot.create(:test_case) *** NameError Exception: uninitialized constant # ::TargetLimitation
...marked for destruction self.amount = invoice_items.reject(&:marked_for_destruction?).sum(&:amount) end end How to test the correct behaviour in rspec it 'ignores invoice items marked for destruction in a nested...
If a project ist configured to spawn CI runners for tests or deployment when pushing to the Repo, a habit of pushing WIP commits regularly may conflict with that.
# At this point we want to stop in the debugger for all following tests, when the :lock call runs into the after_save $debug = true expect { user.lock }.to change...
...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...
...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...
...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...
RSpec Rails can automatically mix in different behaviors to your tests based on their type tag, for example enabling you to call get and post in specs with the tag...
...will automatically choose the right type context based on the file location of the test. For instance, specs in spec/features/requests are automatically tagged with { type: :request...
...show the message "Your account is not activated yet." super && active? end end Your tests should at least cover: Signed in users are logged out on the next request once...
...to use Edge Rider for new projects, which is being actively maintained and has test coverage for all versions of Rails...
Don't use reruns as a mean to work around flaky tests. You should always try to fix those instead of rerunning them regularly. Setup Configure RSpec to persist...
...the result of your test runs to a file. This is necessary to be able to rerun examples. Add this to your spec/spec_helper.rb : config.example_status_persistence_file_path = 'spec/examples.txt'
...you use Rubocop or Capybara. These gems most often live in your development and/or test group of the Gemfile and require English for you. Therefore to ensure that the library...
When your application is open for public sign up and sends out transactional e-mails to a large number of...
...introduced rules. You can use them in your .gitlab-ci.yml in your project. To limit test runs to merge requests and the master branch, you can write this: tests: script: bundle...
...exec rake tests rules: - if: '$CI_COMMIT_BRANCH == "master"' - if: '$CI_PIPELINE_SOURCE == "merge_request_event...
...controllers' #index actions. This way, when a change introduces an n+1 query, your test suite will blow up. Example A typical #index action looks like this. class CardsController < ApplicationController...
...that behave differently (like mobile vs desktop navigation menus). Since you want your integration tests to behave consistently, you want to set a specific size for your tests' browser windows...
...simply switch the driver via Capybara.current_driver = :selenium. If you use Cucumber for integration testing, wrap that into something like Before('@javascript') {...
Benefits of using device metrics are: