Skip to content

Instantly share code, notes, and snippets.

@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)