Skip to content

Instantly share code, notes, and snippets.

@elbartostrikesagain
elbartostrikesagain / rspec_perform_under_variance.rb
Created October 16, 2025 23:49
Matcher to like perform_under but gets rid of results outside a standard deviation range
it "maintains acceptable performance for the index action", skip_db_cleaner: true do # for some reason skip_db_cleaner: true when running the whole test suite wasn't being inherited, so I had to dup it :( . When running the describe, it was being inherited by the 'it' blocks, and once you run it and try to run the whole suite again, it starts passing.
expect { get :index, params: params, format: :json }.to meet_performance_threshold(4.0)
.sample(5)
.under_standard_deviations(2)
# Also see rspec-benchmark. This matcher is like perform_under but it removes results outside a defined standard deviation range reduce high variance.
RSpec::Matchers.define :meet_performance_threshold do |threshold_seconds|
chain :sample do |sample_size|
@with_sample_size = sample_size
end
@elbartostrikesagain
elbartostrikesagain / concept.md
Last active July 11, 2024 18:48
Address Cache Proof of Concept

Given address ids 1,2,3, we would want a single query to returns rows for every combination of directions, ie:

1,2
1,3
2,1
2,3
3,1
3,2
@elbartostrikesagain
elbartostrikesagain / mocha addPath sample
Created February 18, 2014 00:33
mocha add all files in a path or directory to run tests on
var Mocha = require('mocha'),
fs = require('fs'),
_ = require('underscore');
var mocha = new Mocha({reporter: 'spec', ui: 'bdd'});
mocha.addPath = function(dir){
fs.readdirSync(dir).filter(function(file){
var fileArray = file.split('.');
@elbartostrikesagain
elbartostrikesagain / Rails vs Geddy
Created February 14, 2014 21:24
Geddy for Rails Developers
Rails => Geddy
**Models**
User.new(params) => User.create(params);
-----
User.create(params) => var u = User.create(params);
// saves the user then calls the callback function
u.save(function (err, data) { // do things });
-----
@elbartostrikesagain
elbartostrikesagain / attr_encrypted_rspec_matcher.rb
Created September 20, 2013 22:12
attr_encrypted rspec matcher. "it {should encrypt(:column_here) }"
RSpec::Matchers.define :encrypt do |attribute|
encrypted_attribute = ('encrypted_' + attribute.to_s)
match do |model|
model.respond_to?(attribute) && model.respond_to?(encrypted_attribute.intern) && model.class.column_names.include?(encrypted_attribute)
end
failure_message_for_should do |model|
unless model.class.column_names.include?(encrypted_attribute)