github.com

...you are using a driver that supports it (e.g. Selenium, not the default Rack::Test driver). Consider the following HTML: One Two With some CSS: .test1 { display: block } .test2 { display...

...Default: visible: :visible As described above, by default Capybara finds only visible elements. find('.test1') finds the .test1 element find('.test2') raises a Capybara::ElementNotFound error, as the .test2 element...

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

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

Learn to create test data effectively using factories. Decouple tests by having each test start with an empty database and create only the records needed for the test.

...Factories, not fixtures By default Rails uses global fixtures for its tests. This is a giant world of example data that grows with every test. In our experience the use...

jsfiddle.net

When you need test images, instead of using services like lorempixel or placehold.it you may generate test images yourself. Here we build a simple SVG image and wrap it into...

masilotti.com

Slow test suites are a major pain point in projects, often due to RSpec and FactoryBot. Although minitest and fixtures are sometimes viewed as outdated, they can greatly improve test...

...fixtures, and while it required some initial refactoring and establishing good practices, the faster test suite was well worth it! Stick with me to explore how these tools might actually...

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

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

evilmartians.com

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

Prefer request specs over end-to-end tests (Capybara) to joyfully test file downloads! Why? Testing file downloads via Capybara is not easy and results in slow and...

...fragile tests. We tried different approaches and the best one is just okay. Tests for file downloads via Capybara ... ... are slow, ... are fragile (breaks CI, breaks if Selenium driver changes...

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

api.rubyonrails.org

ActiveSupport (since 4.1) includes test helpers to manipulate time, just like the Timecop gem: To freeze the current time, use freeze_time (ActiveSupport 5.2+): freeze_time To travel to a...

...back) once you are done. Simply load the TimeHelpers module as required by your test framework. Example: RSpec.configure do |config| config.include ActiveSupport::Testing::TimeHelpers end Comparison to Timecop Timecop allows...

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

github.com

The issue: You are using stub_const to change a constant value for your test. stub_const "SomeClass::CONST", 'test' All of a sudden, tests fail with undefined method 'some...

...workaround, use stub_const in your Rails specs like this: stub_const "#{SomeClass}::CONST", 'test' This will invoke Rails' autoloading and fix RSpec's behavior for you...

DevOps Curriculum

Beim schreiben von Scripts ist es nützlich Tests zu schreiben um bei Änderungen nicht alles nochmals manuell testen zu müssen. Außerdem stellt man sicher, dass immer alle Bestandteile getestet werden...

...wenn man eine Änderung vornimmt. Ziele Verstehe warum man Tests schreiben möchte Neue Features können bestehende Features brechen Besser schlafen, weil man weiß, dass die Software gut funktioniert und getestet...

...Shift. The achieved scores should not be lost again, so I fixed them with tests. How to test Web Vital scores In a test: Build & open the (stereotype) page you...

...want to ensure Web Vital scores for Throttle test browser I/O (because your development machine is more powerful than real-world devices) Expect Web Vital scores For this to work...

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

Sometimes a link or input field has no visible label. E.g. a text field with a magnifying glass icon 🔎 and...

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

...NODE_INDEX starts at 0 As an alternative you can copy and paste the test files from both sections Report specs + Leftover specs in rspec 3/8 and run them with...

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

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

Click around a bit. Fix all errors you can find. Fix tests Fix unit tests. Fix integration tests. Upgrade to new framework defaults Flip each config in...

...after you've upgraded to the latest major version.) Fix deprecation warnings. Run your tests and fix all deprecation warnings. If you have added many constraints in your Gemfile to...