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
# spec/support/user_support.rb
RSpec.configure do |config|
config.include UserHelper, type: :user
config.include_context "user_context", type: :use
end
# Example: | |
# | |
# > TablesFinder.call(column_name: 'site_id') | |
# => ['events', 'users'] | |
class TablesFinder | |
VALID_ATTRIBUTES = %w[ | |
COLUMN_NAME | |
].freeze | |
def self.call(args) |
# Example usage ============= | |
# | |
# describe :namespace do | |
# include RakeTasksHelper | |
# | |
# describe ':task' do | |
# it 'works' do | |
# invoke_task('namespace:task') | |
# end | |
# end |
# We need to use 'remote_<object>_url' as attribute instead of '<object>'. | |
# Having Image, we would use 'remote_image_url: <url>'. | |
titles = [Faker::RockBand.name, Faker::BossaNova.artist, Faker::Book.title] | |
54.times do |n| | |
start_date = Faker::Date.between(1.day.from_now, 6.months.from_now) | |
end_date = start_date + 1.day | |
Event.create!(title: titles.sample + " ##{n}", |
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:
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
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:
This is using “Super” instead of “Alt”. If you want to use the latter you only need to replace all “Super” instances with “Tab”.
#!/bin/bash
# Related discussion:
A selection of problem solving resources that can be helpful for developers.
// Bad:
list.pop()
// Good:
list.filter(element => element !== 'hi')