Skip to content

Instantly share code, notes, and snippets.

View tiagoefmoraes's full-sized avatar

Tiago Moraes tiagoefmoraes

View GitHub Profile
@mattwynne
mattwynne / be_same_file_as.rb
Last active May 21, 2022 13:27
RSpec matcher to compare two file, using their MD5 hashes
RSpec::Matchers.define(:be_same_file_as) do |exected_file_path|
match do |actual_file_path|
expect(md5_hash(actual_file_path)).to eq(md5_hash(expected_file_path))
end
def md5_hash(file_path)
Digest::MD5.hexdigest(File.read(file_path))
end
end
@ddemaree
ddemaree / 01_random_specs.rake
Created June 8, 2011 21:54
Rake task for running a random sampling of RSpec tests
namespace :spec do
SPEC_SUITES = %w(models requests integration helpers controllers lib)
def sample_spec_files(num=5)
[].tap do |specs|
SPEC_SUITES.each do |dirname|
files = Dir[Rails.root.join("spec", dirname, "**", "*_spec.rb")]
specs.concat files.shuffle.first(num)
end.shuffle
end
@coreyhaines
coreyhaines / .rspec
Last active April 11, 2024 00:19
Active Record Spec Helper - Loading just active record
--colour
-I app
@petemcw
petemcw / gist:2719758
Created May 17, 2012 15:53
Commands to clean a Ubuntu install for smaller Vagrant packages
# Remove items used for building, since they aren't needed anymore
apt-get clean
apt-get -y remove linux-headers-$(uname -r) build-essential
apt-get -y autoremove
# Zero out the free space to save space in the final image:
dd if=/dev/zero of=/EMPTY bs=1M
rm -f /EMPTY
# Removing leftover leases and persistent rules
@vsavkin
vsavkin / exampe.rb
Last active February 1, 2018 10:15
Example of using EDR
#somewhere in a controller
CreateOrder.new(OrderRepository).create current_user, params
# where
class CreateOrder < UseCaseService
def initialize order_repo
@order_repo = order_repo
@henrik
henrik / big_decimal_inspect.rb
Created August 20, 2013 11:52
Better BigDecimal#inspect. Great with tests. By @aalin.
class BigDecimal
def inspect
format("#<BigDecimal:%x %s>", object_id, to_s('F'))
end
end
@skwp
skwp / dynamic_method_spec.rb
Created December 7, 2013 00:44
Fail your build for user-defined style rules.
require 'spec/support/grep_matcher'
describe do
disallow_presence_of pattern: "send(.*#",
location: "app/",
description: "Do not use dynamic method invocations",
failure: "Please change dynamic method call to something more sane."
end
@todc
todc / mac-setup.md
Last active September 25, 2021 09:21
Fresh Mac OS Setup

1. Run Software Update

Make sure everything is up to date.

Software Update

2. Install Xcode and its "Command Line Tools"

  1. Go to App Store and install Xcode.
  2. Open and accept the terms
@afcapel
afcapel / assets.rake
Last active August 29, 2015 14:01
rake assets:precompile_if_needed
# lib/tasks/assets.rake
namespace :assets do
task :precompile_if_needed do
require_relative '../assets_version'
next unless AssetsVersion.needs_precompile?
Rake::Task["assets:precompile"].invoke
AssetsVersion.current.save_to_yaml
end
require 'coverage'
require 'json'
# This must be run with this patch applied:
# https://bugs.ruby-lang.org/issues/10816
Coverage.start
require 'minitest'