Skip to content

Instantly share code, notes, and snippets.

👨‍🔬

Luján Fernaud lujanfernaud

👨‍🔬
View GitHub Profile
View rspec_add_metadata_based_on_path.md

RSpec: Add metadata based on path

RSpec.configure do |config|
  config.define_derived_metadata(file_path: %r{platforms/.*/spec/controllers/}) do |metadata|
    metadata[:type] = :controller
    metadata[:platform_controller] = true
  end

  config.include MainAppRoutesHelper, platform_controller: true
@lujanfernaud
lujanfernaud / rspec_include_based_on_type.md
Last active May 8, 2020
RSpec: Include based on type
View rspec_include_based_on_type.md

RSpec: Include based on type

# spec/support/user_support.rb
RSpec.configure do |config|
 config.include UserHelper, type: :user
 config.include_context "user_context", type: :use
end
View rails_tables_finder.rb
# Example:
#
# > TablesFinder.call(column_name: 'site_id')
# => ['events', 'users']
class TablesFinder
VALID_ATTRIBUTES = %w[
COLUMN_NAME
].freeze
def self.call(args)
@lujanfernaud
lujanfernaud / rake_tasks_helper.rb
Last active Mar 27, 2020
RSpec: Rake Tasks Helper
View rake_tasks_helper.rb
# Example usage =============
#
# describe :namespace do
# include RakeTasksHelper
#
# describe ':task' do
# it 'works' do
# invoke_task('namespace:task')
# end
# end
@lujanfernaud
lujanfernaud / rubocop_autocorrect_specific_cops.md
Last active Feb 27, 2020
RuboCop: Autocorrect Using Specific Cops
View rubocop_autocorrect_specific_cops.md

RuboCop: Autocorrect Using Specific Cops

We can autocorrect using only some cops by passing --only CopType/CopName.

rubocop --only Style/HashTransformKeys

First run with --safe-auto-correct to see the affected changes:

View rails_url_helpers.md

Rails: URL Helpers

Access path helpers from outside controllers.

Rails.application.routes.url_helpers
Rails.application.routes.url_helpers.dashboard_path
Rails.application.routes.url_helpers.users_path
Rails.application.routes.url_helpers.pages_path
@lujanfernaud
lujanfernaud / rspec_only_failures.md
Last active Jan 28, 2020
RSpec: Run Only Failures
View rspec_only_failures.md

RSpec: Run Only Failures

In spec/spec_helper.rb:

RSpec.configure do |config|
  # This setting allows us to only re-run examples that had failures.
  # https://relishapp.com/rspec/rspec-core/docs/command-line/only-failures
  #
  # Usage:
@lujanfernaud
lujanfernaud / rofi_alt_tab_window_switching.md
Last active Dec 27, 2019
Rofi: Alt+Tab Window Switching
View rofi_alt_tab_window_switching.md

Rofi: Alt+Tab (Super+Tab) Window Switching

This is using “Super” instead of “Alt”. If you want to use the latter you only need to replace all “Super” instances with “Tab”.

Bash Script

#!/bin/bash

# Related discussion:
@lujanfernaud
lujanfernaud / problem_solving_for_developers.md
Last active Feb 22, 2019
Problem Solving for Developers
View problem_solving_for_developers.md
@lujanfernaud
lujanfernaud / javascript_avoiding_mutations_the_easy_way.md
Last active Feb 2, 2019
Javascript: Avoiding Mutations the Easy Way
View javascript_avoiding_mutations_the_easy_way.md

JavaScript: Avoiding Mutations the Easy Way

Removing an Element from an Array

// Bad:
list.pop()

// Good:
list.filter(element => element !== 'hi')
You can’t perform that action at this time.