Researching in the Hash ruby class, I needed to initialize values to 0. It is really easy, passing default value to construnctor:
store = Hash.new(0)
Then we can accumulate candles from the creation of the key without the “undefined ‘+’ for nil:NilClass” error.
Ruby 3.2 came with a new class Data to defile structs:
Measure = Data.define(:amount, :unit)
# Positional arguments constructor is provided
distance = Measure.new(100, 'km')
# Keyword arguments constructor is provided
weight = Measure.new(amount: 50, unit: 'kg')
# Alternative form to construct an object:
speed = Measure[10, 'mPh']
# Works with keyword arguments, too:
area = Measure[amount: 1.5, unit: 'm^2']
# Argument accessors are provided:
distance.amount #=> 100
distance.unit #=> "km"
Basically the same as Struct, but remember that Struct has arguments writers.
11 years ago now, Jonas Nicklas, Capybara’s leader, removed wait_until from the code. Basically it introduced an abuse of this clause in our tests, and random execution times. Here you can read some well explained reasons, with the basic recommendatio to reasearch why are happenning these timeouts instead of waiting long times in your test suites. Delay can be huge when you have a good amount of tests.
But Capybara introduced some wait clauses tha I will explain below….
You can increate wait time in capybara assertions at `spec/rails_helper.rb`:
Capybara.default_max_wait_time = 10 # default is 2
Sometimes developers use `sleep 0.5` on their code. Problem here is that they are fixed waits, opposite than ‘wait’ or ‘wait_until’ which exit when a condition is achieved.
As alternative wyou can use `wait:` options in all contions like `have_….`:
expect(page).to have_text(I18n.t('investments.sale_movements.form.title'), wait: 20)
This option waits the amount of 20 second, then, fails:
In case you are not using a Capybara assertion, you can use the following block:
using_wait_time 60 do
expect(Organization.find_by(subdomain: organization.subdomain)).to be_present
These two last cases modify the default time inculded in configuration file.
This does not remove all failures, but it improves legibility. And you can check in tests logs if test is failing by a timeout or antother reason.