thegnar.com

View specs are a powerful tool to test several rendering paths by their cases instead of using a more costing feature spec. This is especially useful because they become quite...

...the view independent from the controller-logic. Therefore it will be more applicable to test views within request specs. But, even then, you still can use Caypbara's matchers within...

When you find similar groups of expect calls in your tests, you can improve readability by extracting the group into its own matcher. RSpec makes this easy by allowing matchers...

...to call other matchers. Example The following test checks that two variables foo and bar (1) have no lowercase characters and (2) end with an exclamation mark: expect(foo).to...

...directly on GitLab, or by checking out the corresponding branch. You can assume that tests are green, but you need to confirm that everything requested in the issue is implemented...

...test coverage is good the code is maintainable What to do if the code is okay If the code is okay, you may either merge it into main yourself:

...than Dir.tmpdir e.g. Dir.mktmpdir('foo', Rails.root.join('tmp')) => /home/user/rails_example/tmp/foo20220912-14561-pyr8qd. This might be necessary when your tests are running on CI. For this you might also want to commit tmp/.gitkeep to git...

...tmp dir inside your project is present. Example Dir.mktmpdir('exports') => "/tmp/exports20220912-14561-pobh0a" Improving your parallel tests with Dir.mktmpdir When creating directories in parallel tests manually, you normally need to handle these...

makandra dev

helps you debugging errors like DNS lookup limit reached it also lets you test a new SPF strings before applying it. This can save you time as you don...

...with operations Also the advanced check at vamsoft.com has a very good interface to test new SPF policies...

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

...options to disable password leak detection and suppress the warning. Problem When running Selenium tests with recent versions of Chrome and Chromedriver (e.g., version 136+), entering “unsafe” (weak or reused...

"This password has appeared in a data breach…" This alert can break automated test runs, especially in CI/CD pipelines. Solution You can disable Chrome’s password leak detection to...

...vcr, a cassette with an automatically determined name will be generated on the first test run and replayed on subsequent runs: Here is an example for a spec using the...

...current JavaScript VM: window.addEventListener('error', function(event) { console.log("Got an uncaught error: ", event.error) }) Tip Testing tools like Jasmine might also listen to the error event and fail your test if...

...search results for example to the /app/ directory can be helpful to exclude all test files. The probably easiest way to start this kind of search is from the project...

...If you are unsure if you applied this technique correctly, here is a simple test: Delete all files from app/models/* and run your migration. If it completes successfully, you are...

...might look as follows: shared: &shared email: info@example.com google_analytics: container: UA-123456-12 test: <<: *shared development: <<: *shared production: <<: *shared email: production@example.com Keys under the shared namespace are shared between...

If you need to test interaction with a remote API, check out the VCR gem as an alternative to Webmock or stubbing hell. The idea behind VCR is that is...

...HTTP requests and logs the interaction in a .yml file. When you run the test again, requests and responses are stubbed from the log and the test can run offline...

...setInterval and setTimeout calls from tabs that are currently in the background. You can test it yourself by running the test below and change to a different...

...tab during its runtime. The expected runtime drastically increases in Chrome, Firefox and Safari: https://testbed.nicon.nl/timeouttest/ See also: Stop animations and network polling when the document tab isn't...

...k] + (f * (values_sorted[k + 1] - values_sorted[k])) end benchmarks = [ %(User.where('name ILIKE ?', '%test%').first), %(User.where('email ILIKE ?', '%test%').first), ] measurements = benchmarks.index_with do |_benchmark| [] end benchmarks.each do |benchmark...

Sidekiq.configure_client do |config| if ENV['RAILS_ENV'] == 'development' || ENV['RAILS_ENV'] == 'test' stdout_logger = ActiveSupport::Logger.new(STDOUT) file_logger = ActiveSupport::Logger.new("log/sidekiq_#{ENV['RAILS_ENV']}.log")

end Sidekiq.configure_server do |config| if ENV['RAILS_ENV'] == 'development' || ENV['RAILS_ENV'] == 'test' stdout_logger = ActiveSupport::Logger.new(STDOUT) file_logger = ActiveSupport::Logger.new("log/sidekiq_#{ENV['RAILS_ENV']}.log")

...processing library. See here for a list of supported queueing adapters. For development and test it also brings its own queue adapters (async, inline and test). Note: For production use...

...have different adapters for different environments): config.active_job.queue_adapter = :sidekiq To set specific adapters in tests, you can create a spec/support/active_job.rb with: RSpec.configure do |config| config.before(:suite) do ActiveJob::Base.queue_adapter...

makandra dev

...lazy, i.e. page 2 is only requested after page 1 is done processing in tests, I could write video_service.each_video.to_a.should == [video_1,...] Lazy enumerators It is possible to chain methods on...

to add the Ruby, Rails and RSpec cops to include the unit test 2. Report all existing offenses and exclude them initially To start your Rubocop integration it...

...rubocop --auto-gen-config to create a file that excludes all current violations. Your tests (including the Rubocop spec) should now all be green. Commit theses changes and consider whether...

...is because Redis defaults to at most 16 databases (0 to 15) and running tests in parallel might exceed that (your tests might run on databases 1..n or...

...it becomes more difficult to optimize this query when joining other records (for my tests PostgreSQL was not able to use the GIN index on the joined table within a...

makandra dev

RubyMine has a HTTP Client that can be useful to test web APIs. Just create a .http scratch file an write your request in it. The request can then be...

In tests, it is sometimes useful to create records with specific ids. On PostgreSQL this can cause problems: Usually, PostgreSQL uses an "autoincrement" sequences to provide sequential ids for new...

...cause an SQL error 'duplicate key value violates unique constraint "records_pkey"' Workaround In tests, one workaround would be to simply initialize all sequences with a large value, so that...

...false e.g. to not cancel deploys by accident). Consider setting the interruptible flag for test jobs to reduce the load on your runners like in the following example .gitlab-ci.yml: