Some key highlights and points from the linked article TestProf II: Factory therapy for your Ruby tests. The Problem with Factories in Ruby Tests Factories are used to easily generate...
However, they can unintentionally slow down test suites by creating unnecessary or excessive associated data (factory cascades). Understanding Factory-Induced Slowdowns Factories often create additional data (e.g., associated...
...environments except production: config.action_controller.perform_caching = false config.cache_store = :null_store If you want to test caching you have at least two possibilities: Enable caching for every test (not covered by...
...this card and straightforward) Enable caching for individual test Enable caching for individual test (file cache) 1. Leave the default configuration 2. Add a caching helper which gives you a...
...is handled by Carrierwave uploaders (or maybe any other attachment solution for Rails) in tests allows different approaches. Here is a short summary of the most common methods.
...also be interested in this card if you see the following error in your test environment: CarrierWave::FormNotMultipart: You tried to assign a String or a Pathname to an uploader...
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...
For Selenium tests, your browser starts in your local timezone, or whatever your system's environment specifies. This is usually good enough. To test any timezone-dependent behavior in Chrome...
...session. You need to remove the time zone override at the end of each test explicitly, or it affects other tests. The CDP specifies that resetting works by setting an...
...favicon.ico in your project but also PNGs of different sizes and backgrounds, you should test if all those files are actually reachable. Here are a few selectors to get you...
...pass visible: false for each selector so Capybara can find them. Example The following test was taken from a project using ActionDispatch::IntegrationTest. Though we usually use RSpec, this should...
...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
The linked article suggests an interesting way to speed up tests of Rails + Postgres apps: PostgreSQL allows the creation of “unlogged” tables, which do not record data in the PostgreSQL...
...production environments. If you would like all created tables to be unlogged in the test environment you can add the following to your test.rb file: # config/environments/test.rb ActiveSupport.on_load(:active_record...
Sometimes you want to write a test for a business rule that's based on multiple variables. In your goal to cover the rule thoroughly, you start writing tests for...
...business rule, you get 2n permutations/test cases. This is manageable with 2 variables (4 test cases), but at 3 variables (8 test cases) it becomes ridiculous, and anything beyond that...
...as well as their programmatic variants up.observe() and up.autosubmit() are a nightmare for integration tests. Tests are usually much faster than the configured up.form.config.observeDelay. Therefore, it may happen that you...
...waiting for the observeDelay to run out, there is no XHR request and the test will continue. The solutions Lower the observeDelay in tests This will always help you. Your...
Imagine you want to write a cucumber test for a user-to-user chat. To do this, you need the test to work with several browser sessions, logged in as...
...cleaner gem with strategy :transaction, after_commit callbacks will not be fired in your tests. Rails 5+ Rails 5 has a fix for this issue and no further action is...
Rails 3, Rails 4 Add the gem test_after_commit to your test group in the Gemfile and you are done. You don't need to change the database...
...show a "Choose your search engine" popup in Europe. This might make your Cucumber tests fail. Fortunately there is a flag to disable the popup. Add the following option to...
You may have asked yourself how you're able to keep your test databases clean, if you're running multiple databases with full read and write access at...
development: primary: <<: *default database: my_app_development migration: <<: *default database: my_app_migration test: &test primary: <<: *default database: my_app_test_<%= ENV['TEST_ENV_NUMBER'] %> pool: 20 migration: <<: *default...
To navigate between test and test subject Rubymine requires you to set the test root sources as Test Sources Root. In case you are using the keyboard shortcut "CTRL + ALT...
...SHIFT + c" to copy the reference path + you have set the "Test Sources Root" for your test folders, you might consider setting this keyboard to "Copy From Repository Root". This...
I recently was in a weird situation where my (Jest/CLI) tests were referencing a function that was no longer part of my code - I had just refactored it. Apparently Jest...
Within development and test environments, Rails is usually configured to show a detailed debug page instead of 404s. However, there might be some cases where you expect a 404 and...
...want to test for it. An example would be request-specs that check authorization rules. (If you use a gem like consul for managing authorization rules, you should always check...
When you need to see the content of a page (i.e. not all the HTML but the relevant text body...
...afterwards again. CSSnext Input: body { font-variant: small-caps; background-image: image-set(url(test_1.svg) 1x, url(test_2.svg) 2x); } Output: body { -webkit-font-feature-settings: "c2sc"; font-feature-settings: "c2sc...
...font-variant: small-caps; background-image: -webkit-image-set(url(test_1.svg) 1x, url((test_2.svg) 2x); background-image: image-set(url(test_1.svg) 1x, url(test_2.svg); } Autoprefixer Input: body { ::placeholder { color: gray...
With this command you can run all the spec files which have been edited or added in the current branch...
While we are used to run our JavaScript tests on a test page within our Browser, it's also possible to run them on the command line with NodeJS. I...
...think that's actually the most common way to run JS tests. Given a Vue project that uses Jest (via vue-cli-service) with the following package.json: { "scripts": { "test": "vue...
Here is how to switch your Selenium to Chrome: Make sure you've got a recent version of chromedriver in...
Webpack is the future. We're using it in our latest Rails applications. For tests, we want to compile assets like for production. For parallel tests, we want to avoid...
Here is our solution for all that. Its concept should work for all test suites. Copy the following to config/initializers/webpacker_compile_once.rb. It will patch Webpacker, but only for the test...
Testing your responses in Rails allows to parse the body depending on the response MIME type with parsed_body. get '/posts.json' response.parsed_body # => [{'id' => 42, 'title' => 'Title'}, ...]