relishapp.com

In RSpec you can tag examples or example groups with any tags you like simply by saying describe ReportCreator, slow: true do # .. end describe ReportCreator do it 'generates reports', slow...

# ... end end You can then only run examples with these tags. rspec --tag slow rspec -t slow # Using the parallel_tests gem rake "parallel:spec[,,--tag slow]"

Let's say you want to find the element with the text hello in the following DOM tree: hello world You might think of XPath's contain() function: page.find(:xpath...

...contains(text(), 'hello') and not (./*[contains(text(), 'hello')])]") With jQuery jQuery has a custom selector :contains() that you can use in the same fashion: $(":contains('hello'):not(:has(:contains('hello...

relishapp.com

In most projects I know, Cucumber test suite speed is not an issue. Of course, running 350 features takes its time, but still each test for itself is reasonably fast...

...There is nothing you can do to fundamentally speed up such a test (of course, you should be using parallel_tests). However, in projects that go beyond clicking around in...

makandra dev
developer.mozilla.org

The standard way to abort async code is that your function takes a AbortSignal { signal } property. The caller can use this signal to send an abort request to your function...

...with a new DOMException('Message here', 'AbortError') when canceled. This already has good browser support and can be polyfilled on older browsers. Example Here is an async function countDown(). It...

makandra dev

When RSpecs runs the first feature spec, you may see log output like this: Capybara starting Puma... * Version 6.5.0, codename: Sky's Version * Min threads: 0, max threads: 4

...on http://127.0.0.1:39949 You can disable this behavior by tweaking Capybara's Puma server in your spec/support/capybara.rb: Capybara.server = :puma, { Silent: true } Note You don't need to configure this...

It's possible to implement simple custom RuboCop cops with very little code. They work exactly the same like existing rubocop cops and fail the pipeline if they find an...

...offense. This is handy for project specific internal rules or conventions. The following cop looks at every ruby file and searches for TODO or WIP comments and adds an offense...

makandra dev

...of passwords for the root user and you prefer using a password for root. Solution Step 1 is getting a root mysql shell that allows us to change user credentials...

...and MySQL since they share names of binaries. sudo systemctl stop mysql sudo mysqld_safe --skip-grant-tables & This starts the mysql daemon in the background and we can now...

If validations failed for a record, and you want to find out if a specific validation failed, you can leverage ActiveModel's error objects. You rarely need this in application...

...name (e.g. :blank for :presence, :taken for :uniqueness). You may also use where to see all errors of an attribute: >> user.errors.where(:email) => [#<ActiveModel::Error attribute=email, type=blank, options={}>]

...the commit which was deployed. If you want to know the currently deployed release, simply SSH to a server and view that file. $ cat /var/www/my-project/current/REVISION cf8734ece3938fc67262ad5e0d4336f820689307 Capistrano task

...application is deployed to multiple servers, you probably want to see a result for all of them. Here is a Capistrano task that checks all servers with the :app role...

Cucumber up to version 2 had a neat feature called Step Argument Transforms which was dropped in favor of Cucumber 3 ParameterTypes. While I strongly encourage you to drop your...

...keep the exact same functionality of your old Transforms while writing them in the style of new ParameterTypes. Why would I want to keep my Transforms? Transforms allowed you to...

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

...specific moment in time, use travel_to: travel_to 1.hour.from_now Important When freezing time with #travel_to, time will be frozen (like with freeze_time). This means that your...

To query for identical arrays independent of their order you have to either: Sort both the query and database content. If you're on Rails 7.1 you can use...

...the new normalizes macro for this. This solution would still use any indexes on the column. Check for inclusion in both directions, as implemented by the where_array_matches method...

...automatically. If you delete records regularly, this may be an annoyance. Here is a solution which was adapted from the Carrierwave GitHub wiki and cleans up any empty parent directories...

class ExampleUploader < CarrierWave::Uploader::Base storage :file after :remove, :remove_empty_container_directory def store_dir # You implemented this in your uploaders already. end def remove_empty...

...you have too many inotify instances you may run into limits of your operating system. To find out which process is using them all up you can run:

Our preferred way of testing ActiveRecord is to simply create/update/destroy the record and then check if the expected behavior has happened. We used to bend over backwards to avoid touching...

...the database for this. For this we used a lot of stubbing and tricks like it_should_run_callbacks. Today we would rather make a few database queries than have...

...is defined incorrectly. Raise the attributes hash given to your :reject_if lambda to see if it looks like you expect. If you are nesting forms into nested forms, each...

...a new parent record together with a new child record and will need to save the parent before you can save the child. You can opt to only show the...

...the cogwheel icon (or press F1 when focusing the dev tools) to open the settings overlay. Under "Preferences", in the "Appearance" section, find the "Panel layout" option. Set it to...

Alternatively, press Ctrl+Shift+P and search for "panel layout". Wat? Vertical means that the DOM tree is next to the styles/etc panel, like so:

...For ages, CSS transforms had to be defined using the transform property. For a single transformation, this was something like transform: scale(1.5), and multiple transformations could be applied by...

.example { transform: scale(1.5) rotate(45deg) translateY(-50%); } All modern browsers (Chrome & Edge 104+, Firefox 72+, Safari 14.1+, Samsung Internet 20+) also support individual properties for transforms.

ImageMagick can convert SVGs to raster image formats. Example for PNG: convert input.svg output.png If the SVG has a size of 24x24 (viewBox="0 0 24 24"), the resulting...

...PNG will also have a size of 24x24. Resizing An SVG's viewBox specifies the intended size, but vector image formats can be scaled freely. Resize flag (poor results)

makandra dev

Or: How to avoid and refactor spaghetti code Please note that I tried to keep the examples small. The effects of the methods in this card are of course much...

...more significant with real / more complex code. What are the benefits of more modular code? Code is written once but read often (by your future self and other developers who...

Don't sum up columns with + in a sql-query if NULL-Values can be present. MySQL and PostgreSQL cannot sum up NULL values with the + value. The sum value...

MySQL: mysql> select 1 + 2 + 3; +-----------+ | 1 + 2 + 3 | +-----------+ | 6 | +-----------+ 1 row in set (0,00 sec) mysql> select 1 + NULL + 3; +--------------+ | 1 + NULL + 3 | +--------------+ | NULL...

github.com

...to lock a user in devise. Using the lockable module Customizing the user account status validation when logging in. It depends on your requirements which methods works best.

...user on soft delete We recommend to use option 2 when you want to couple the lock to the model's soft delete logic. Option 1 might also work when...

When doing some meta-programming magic and you want to do something for all attributes of a class, you may need to access connection or some of its methods (e.g...

...will encounter fun errors such as: PG::ConnectionBad (for missing databases on PostgreSQL) ActiveRecord::StatementInvalid: PG::UndefinedTable (when database exists, but has no tables) Generally speaking, evaluating model columns during...

...come across objects created by some gem or framework. You don't have the source code at hand, still need to inspect this object. Here are some tools to do...

...from Object. This makes the methods list drastically more relevant. You can also try subtracting other base classes like ActiveRecord::Base.methods etc. To further narrow it down you can also...