...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
...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
...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...
...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...
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"
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...
1) first expectation failed 2) second expectation failed As you can see, the test is not being interrupted by the first two falsy expectations, the third expectation passed without...
This can be handy if you are testing for multiple values, which map to one context, e. g. mail components, in order to provide better readability of your...
...pack is application.js): = image_pack_tag('media/application/images/logo.png') Deployment Follow Configuring Webpacker deployments with Capistrano. Tests In your cucumber test, you will want to regenerate your assets before each test suite...
...run. Since this is a bit slow, especially when using multiple processes with parallel_test, read this card. jQuery If you still require jQuery, add it to your webpacker project...
...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')
...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...
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
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...
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...
...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...
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...
...can use this command: :%s/{{\([^\}]*\)}}/%{\1}/cg Fix deprecation warnings with :overwrite_params Run tests Deploy See the commit log for a detailed list of changes. 2.3.9 to 2.3.10
...Upgrade rails gem Change your environment.rb so it says RAILS_GEM_VERSION = '2.3.10' Run tests Deploy Also see commit log. From 2.3.10 to 2.3.11 Fixes multiple security issues.
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...