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

...close them as well! See the suggested helper at the bottom of this card. Test support If you access Redis in tests, I suggest introducing a helper method. Example for...

...redis ||= Redis.new(url: REDIS_URL) end end RSpec.configure do |config| config.include(RedisHelpers) end Your Tests may then say redis.get('example'). But I still want to use a global

makandra Curriculum

...should have an overview which kinds of validations are built into Rails. Also read Testing ActiveRecord validations with RSpec. Make the following changes to your MovieDB: Make sure your MovieDB...

...for black and white movies and release_year >= 1917 for color movies. Add tests for your validation. Make sure you have a test for each case...

...navigate to Settings -> Editor -> File and Code Templates. Example You can navigate to the test file of the currently open file with the shortcut Ctrl + T. If no test file...

...exists, you can generate a new test file. If you are not pleased with the output, you can adjust the related code template. To do this, open the project settings...

...and expected constants are resolved: class_name = params[:type].presence_in(%w[User Post Test]) if class_name class_name.safe_constantize.new # either User, Post or Test else Rails.logger.error "This should not happen...

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

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

makandra dev

...single feature/spec: Just paste the reference into your terminal (you need to "unmark" the test directories "as test sources root" to get a path relative to the project root).

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

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

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

makandra dev

...at least 2.2.0. Set a cookie with options secure: true, samesite: 'strict|lax|none'. Testing in advance To test the effect of the new Chrome behavior on your site or...

...geordi png-optimize Carrierwave Go through our Carrierwave checklist if used. Maintenance Integrate and test the capistrano maintenance task. Accessibility Decide what effort you want to put in improving accessibility...

...follow this workflow. Finishing a feature When you're done with your feature and tests are green, and your changes pass our merge request checklist: Within your feature branch, merge...

...Our first implementation might look like this: def group(content) " #{content} " end We run tests and realize that our helper escapes too much. Content appears like this:

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

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

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

...wipes the database just when it is called. The above configurations make sure the test database(s) are emptied up-front. The :transaction strategy does not work with Selenium.

...see Understanding database cleaning strategies in tests...

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

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

kernel.org

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

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

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