Skip to content

Instantly share code, notes, and snippets.

View krzykamil's full-sized avatar
🤔

Krzysztof Piotrowski krzykamil

🤔
View GitHub Profile
@krzykamil
krzykamil / basic.rb
Created October 25, 2023 09:18
Interrupt - dry-effects error flow
# frozen_string_literal: true
require 'dry/effects'
class LoginManager
include Dry::Effects::Handler.Interrupt(:invalid_credentials, as: :catch_invalid_credentials)
def call
error, message = catch_invalid_credentials do
yield
end
@krzykamil
krzykamil / download_all_at_once_later.rb
Last active January 9, 2024 16:42
Deffer - dry-effects
# frozen_string_literal: true
require 'dry/effects'
class DownloadManager
include Dry::Effects.Defer
def initialize(number_of_files)
@downloaded_files = []
@number_of_files = number_of_files
end
@krzykamil
krzykamil / text.md
Created February 27, 2024 11:18
Capybara

Capybara

Capybara is good when it's good, and it's bad when it's bad. When you don't know how to use it, it can be tragic. When you use it for the wrong job, it is a pain.

Here us a quick, and absolutely subjective guide to using it correctly, which mostly means adapting it to the needs of your project, handling it limitations, and connecting it to RSpec.

Matchers

Main problem with asserting in RSpec and Capybara for me is that there is too many options. However RSpec makes it relatively easy to build your own. So instead of always googling and checking documentation while making sure you are looking at the right version of it, you can adapt those matchers to the needs of your projects.