Try to break your refactoring down in different parts. Try to make tests green for each part of your refactoring as soon as possible and only move to...
...the next big part if your tests are fixed. It's not a good idea to work for weeks or months and wait for all puzzle pieces to come together...
...your timestamp holds milliseconds, they are discarded. While that is fine for humans, automated tests may fail because of that: If two tests run within the same second frame, your...
...application's response will have the same Last-Modified header value, even when both tests actually have different data. While test browsers usually clear all data (cookies, LocalStorage, etc.), at...
...return means "exit the lambda" How to define a lambda With the lambda keyword test = lambda do |arg| puts arg end With the lambda literal -> (since Ruby 1.9.1)
...also are next and continue How to define a block With the proc keyword: test = proc do |arg| puts arg end With Proc.new: test = Proc.new do |arg| puts arg
...text-transform: uppercase - especially on form labels - can cause you serious headaches in Selenium tests. Sometimes the web driver will see the uppercase text, sometimes it won't, and umlauts...
...will be a problem as well. Simply disable it in tests, by adding a body class for tests %body{'data-environment' => Rails.env} overriding the transforms [data-environment="test"] * text-transform...
...present. Otherwise, the browser uses its local time. This can lead to issues in tests with mocked time or inconsistent cache behavior. Cookie Expires depends on the Date header or...
...lead to unexpected issues in specific scenarios. Why does this matter? Mocked time in tests Consider a Rails application where you use the remember_me feature of Clearance for authentication...
Sometimes you have a test expectation but actually want a better error message in case of a failure. Here is how to do that. Background Consider this test: expect(User.last...
expect(User.last).to be_present, 'Could not find a user!' Now your test will fail with an actually helpful error message: Could not find a user! (Spec::Expectations...
...or when working on a project without LoDash. Booleans This one is straightforward to test with typeof: x = true typeof x === 'boolean' // => true Strings Strings can exist as literal ("foo...
...we cannot rely on typeof: typeof "foo" // => "string" typeof new String("foo") // => "object" Your test should check both forms: x = 'foo' typeof x === 'string' || x instanceof String // => true Numbers
These steps are now part of Spreewald. The step definitions below allow you to test the filename suggested by the server: When I follow "Export as ZIP"
...should extract that behavior into a trait or module. This card describes how to test that extracted behavior without repeating yourself. Note that the examples below use Modularity traits to...
...app/models/page.rb class Page < ApplicationRecord include DoesSanitizeHtml end # app/models/template.rb class Template < ApplicationRecord include DoesSanitizeHtml end Testing test trait usage with a shared example group When two classes share behavior through a...
No one wants to cry over regression issues in views; does testing HTML and CSS have to be such a back and forth between designers and devs? Why is it...
...presentation layer? Well, GreenOnion is here to help you get the same results on testing front-end styling that you've enjoyed in your unit and integration tests up to...
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...
...integration of Pivotal's excellent license_finder that validates all dependencies during a regular test run. It will protect you from accidentally adding libraries with problematic licenses. Installation
LicenseFinder can exclude certain dependency groups from its report, for example development and test (add devDependencies for yarn). This only works with certain package managers (among which Bundler and...
...Add continuous integration in Gitlab 4 0 - 5 Dev machines are not blocked on test runs; Code Reviews include test badge; Automatically merge a PR on green tests
...library has a better API Add capybara_lockstep 2 0 - 5 Reduce flaky integration tests
...implement sending an error notification if the data (in the db) is too old. Testing: If you use sidekiq_retries_exhausted (unit test): https://stackoverflow.com/questions/33930199/rspec-sidekiq-how-to-test-within-sidekiq-retries-exhausted-block-with-another If you use the...
...global option (manual test): # Use this worker to test if the exception notifier for sidekiq works as expected and the retries total duration fits. # Example: TestWorker.perform_async('foo', 'bar')
end end def bar 'New bar' end end module SuperClient prepend SuperClientExtension end Test class Test; include SuperClient; end Test.foo => 'New foo' Test.new.bar => 'New bar' Good practice
...you need additional form fields (like tax IDs) to bill customers in another language. Tests Tests should continue to use the base language you had before starting localization. Don't...
...rewrite all tests and don't test every screens with every language unless repeatedly broken translations becomes a pain point. Do test non-trivial language-specific customizations like the parsing...
Haml HTML generated by Haml 5 HTML generated by Haml 6 %button(up-test) %button(up-test=true) %button(up-test=false) %button(up-test=nil) %button(up-test...
same %button(up-test='false') same %button(up-test='') same Extending the list of attributes considered "boolean" You can add to the list of "boolean attributes", but please do...
The linked MDN article is quite informative of a neat feature supported by all major browsers: Unicode character class escape...
...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...
Capybara-screenshot can automatically save screenshots and the HTML for failed Capybara tests in Cucumber, RSpec or Minitest. Requires Capybara-Webkit, Selenium or poltergeist for making screenshots. Screenshots are saved...
...Manually saving a page Additionally you can trigger the same behavior manually from the test using Capybara::Session#save_and_open_page and Capybara::Session#save_screenshot. Use Rails' built...
Tests are about 100% control over UI interaction and your test scenario. Randomness makes writing tests hard. You will also push tests that are green for you today, but red...
This creates ugly sample data like "First3 Last3", but e.g. doesn't make tests pass when they shouldn't...
...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...
Usually our code lives on GitLab, therefore our documentation for CI testing is extensive in this environment. If you are tied to GitHub e.g. because your customer uses it, you...
...template uses two such custom actions: setup-node and setup-ruby .github/workflows/integration-testing.yml name: Integration Testing on: push: branches: [ main, production ] pull_request: branches: [ main, production ] # Display "Run Workflow" button on...
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...