Skip to content

Instantly share code, notes, and snippets.

View phosphene's full-sized avatar

Ed Phillips phosphene

View GitHub Profile
@phosphene
phosphene / testing_principles.txt
Last active December 12, 2015 05:08
Practical Parsimonious Testing Design
Testing Principles:
Proving and Documenting Behaviour and Effectiveness
First Cut with the Razor:
A. Integration/Acceptance testing
1. Acceptance testing with Capybara
@phosphene
phosphene / parsimony.txt
Last active December 12, 2015 05:08
Law of Parsimony in Practical Object-Oriented Design
Occam's Razor or Lex Parsimoniae or the Law of Parsimony
"It is vain to do with more what can be done with fewer"
It is an heuristic for design; it is not a golden hammer.
applying the razor to SOLID:
We get: Cohesive responsibility, cohesion, object coherence, or single responsibility.
@phosphene
phosphene / sandis_rules.txt
Last active December 12, 2015 05:08
Sandi Metz's Rules of Parsimony for Rails
1. Your classes should be no longer than (200) 100 lines of code.
2. Your methods should be no longer than (10) five lines of code.
3. You should pass no more than four parameters into a method.
4. Your controller should only instantiate one object to do whatever it is that needs to be done.
5. Your view can only know about one instance variable.
6. Err on the side of many small objects
7. Thin Models/Thin Controllers
8. Drive design through tests
9. See "Lex Parsimoniae" for advice
@phosphene
phosphene / zumbach.jpeg
Last active February 3, 2021 17:17
Zumbach the Tailor
zumbach.jpeg
# http://blog.firsthand.ca/2011/12/example-using-rspec-double-mock-and.html
describe Transfer do
context "transfer with amount of 10" do
let(:source_account) { double :source_account, :decrease => nil }
let(:destination_account) { double :destination_account, :increase => nil }
def transfer_amount(amount)
Transfer.new(source_account, destination_account, amount).call
end
@phosphene
phosphene / add_numbers_in_text.rb
Created February 11, 2012 21:17
find and add numbers at first position of lines only in text file
File.open('test.txt', 'r') do |f|
count = 0
f.each_line do |line|
if line =~ /^(\d+)/
count = count + $1.to_i
end
end
puts count
end
require 'spec_helper'
module UserSpecHelper
def valid_user_attributes
{ 'email' => '[email protected]',
'username' => 'faustrolle',
'password' => 'abcdefg',
'zip_code' => '97221' }
end
end
class User < ActiveResource::Base
#generic user class for test
#include ActiveModel::Validations
self.site = "http://localhost:9292/"
self.format = :json
end
opening connection to localhost...
opened
opening connection to localhost...
opened
<- "POST /users.json HTTP/1.1\r\nContent-Type: application/json\r\nAccept: */*\r\nUser-Agent: Ruby\r\nConnection: close\r\nHost: localhost:9292\r\nContent-Length: 209\r\n\r\n"
<- "{\"user\":{\"email\":\"[email protected]\",\"encrypted_password\":\"$2a$10$fsLeIBMVmx8nfmKs3mp3R.HbUgTmivddTUuO.0GzQkONMWV.ylaAe\",\"password_salt\":\"$2a$10$fsLeIBMVmx8nfmKs3mp3R.\",\"username\":\"faustrolle\",\"zip_code\":\"97221\"}}"
-> "HTTP/1.1 500 Internal Server Error \r\n"
-> "Content-Length: 321\r\n"
-> "Content-Type: text/html\r\n"
-> "Server: WEBrick/1.3.1 (Ruby/1.8.7/2011-01-18)\r\n"
@phosphene
phosphene / disk_usage_culprits_fine_grained
Created January 8, 2011 20:53
du -ch piped to ack find dir outputs with Gig multiples and hundreds of megs
[root@phosphene /]# du -ch | ack "^[\d\.]+?G|^\d{3,4}M"