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

When your cucumber features grow massively over time, the test execution can take a lot of time. One easy way to speed up your test execution is to use the...

...parallel_tests gem. It comes along with some useful rake tasks that let you setup your local test environment shortly to run your features, specs or unit-tests in parallel...

...method to (un)check checkboxes. But there's one problem, if you want to test a custom styled checkbox, which hides its -Tag: The methods cannot (un)check checkboxes without...

...Some label', allow_label_click: true). Solution 2 Make hidden inputs visible in integration tests via data-environment. Depending on your CSS framework you also need to adjust the z...

...that behave differently (like mobile vs desktop navigation menus). Since you want your integration tests to behave consistently, you want to set a specific size for your tests' browser windows...

...simply switch the driver via Capybara.current_driver = :selenium. If you use Cucumber for integration testing, wrap that into something like Before('@javascript') {...

Benefits of using device metrics are:

makandra dev

10.0.0 2024-03-07 Compatible changes console command: You can now globally disable the IRB multiline feature by setting irb...

If you need a sample video with certain properties for a test you can create one using ffmpeg. You might want a very low bitrate file to speed up processing...

...in your test. (e.g. you only care about the length, then you can create a video with a very low resolution and framerate) Create a 21s video with 1fps and...

We prefer to run our end-to-end tests with headless Chrome. While it's a very stable solution overall, we sometimes see the headless Chrome process freeze (or the...

...Capybara driver losing connection, we're not sure). The effect is that your test suite suddenly stops progressing without an error. You will eventually see an error after a long...

makandra dev

Just found out about a great feature in Rails that seems to be around since Rails 2. Start a console...

...your stubs, so it is always http://example.com/?foo[]=1&foo[]=2&foo[]=3. This might lead to green tests, but in fact crashes in real world. Rack::Utils.build_nested_query might help to build...

Jasmine has spyOnProperty(), but it only works if the property is implemented using getter and setter functions. This is a...

makandra dev

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

We currently test most of our gems on Travis CI, but want to migrate those tests to Github Actions. This is a step-by-step guide on how to do...

...Gemfiles needed which database, but is not currently very smart about it. If your test.yml does not set up the database correctly, please adjust it by comparing it with...

...usually just want to print error messages), but it can be useful when writing tests. As an example, consider the following model which uses two validations on the email attribute...

...active class switches to the clicked link. In a Jasmine spec I wanted to test this behaviour. Unpoly's up.hello emits an up:fragment:inserted event, in whose callback function...

...add logic to your application code that helps to modify the Accept-Language in tests. Here is an example for a Rails application with Cucumber integration tests: class ApplicationController

Here is how to switch your Selenium to Chrome: Make sure you've got a recent version of chromedriver in...

...and will cause unexpected errors with Selenium. You will see errors in your integration tests like below if you are affected by the issue: The field's content "" did not...

After removing the line above in the configuration it could happen that the tests are no longer running in headless mode. Updating the selenium-webdriver gem to >= 3.13.0 fixed...

...external URL (like http://somehost.com/some/path) you will find that this is hard to test with Cucumber and Capybara: A non-Javascript Rack::Test scenario will just ignore the host...

...and try to open /some/path in your local application A Selenium test will actually follow the redirect, which you probably don't want either There are two workarounds for this...

whattrainisitnow.com

...subsequent ESR releases overlap for three months. This way enterprises have a quarter to test the new version and migrate their clients...

To test concurrent code, you will need to run multiple threads. Unfortunately, when you use blocking system calls (e.g. locks on the database), Ruby 1.8 threads won't work because...

@writer.puts "Started: #{i}" sleep 0.01 @writer.puts "Finished: #{i}" end @writer.close end end @writer.close # test whether we always get alternating "Started" / "Finished" lines lines = @reader.lines.to_a lines.should be_present # it...

tl;dr: Always have your attachment path start with :rails_root/storage/#{Rails.env}#{ENV['RAILS_TEST_NUMBER']}/. The directory where you save your Paperclip attachments should not look like this: storage/photos/1...

...storage/attachments/1/... storage/attachments/2/... The problem with this is that multiple environments (at least development and test) will share the same directory structure. This will cause you pain eventually. Files will get...

tl;dr You can use ordered to ensure that messages are received in a specific order. Example expect(ClassA).to...

RSpec 1, RSpec 2 To test whether two arrays have the same elements regardless of order, RSpec 1 and 2 give you the =~ matcher: actual_array.should =~ expected_array Rspec 3

...array takes an argument, but contain_exactly takes a list of elements as varargs. Test::Unit If you install shoulda-matchers you can say: assert_same_elements([:a, :b, :c...

Instead of running all missing migrations on your test database with rake db:migrate RAILS_ENV=test you can also use a handful of rake tasks to prepare the database...

...structure directly. They can produce different results, though. In a nutshell, to ensure your test database gains the correct structure: Don't use rake db:test:prepare carelessly