Skip to content

Instantly share code, notes, and snippets.

View lazyatom's full-sized avatar
🤠
Yes

James Adam lazyatom

🤠
Yes
View GitHub Profile
#blue API tokens
===============
George (07716354418) - *d204423528650370012868f1c96c6407*
Julian (07716354340) - *d204423528650370012868ea84466226*
Anne (07716354432) - *d204423928681a7f012868f1434e4834*
Timmy (07716354419) - *d204423a28681c3b012868f6db715a59*
Dick (07716354406) - *d204423a28681c3b012868fd10f25cf1*
context "Given a bunch of stuff" do
setup do
@thing = Factory(:thingy)
@user = Factory(:user)
@user.register_with(@thing)
end
# THIS is the code I'm actually testing, isolated from the rest of the setup
action("the user activates the thing") do
@user.activate(@thing)
# I've been thinking about high level testing, and trying to describe behaviour in ways that
# make it easier to add new tests in the future. Using Chromaroma collections as a base,
# here are some thoughts:
# So, starting with the first tests that we might write:
a normal player
should not be able to view the collection admin page
should not be able to create a new collection
should not be able to edit an existing collection
require "ruby_manor_participation"
conversations = YAML.load_file("ruby_manor_participation.yml")
manor_harder = conversations.select { |c| Date.parse(c.date) > Date.parse("2009-10-01") }
conversations_by_participant = manor_harder.inject({}) do |a, c|
c.participants.uniq.each do |p|
a[p] ||= []
a[p] << c
end
source :rubygems
gem 'rails', '2.3.4'
gem 'mysql'
gem 'RedCloth'
gem 'is_paranoid' # though apparently it's deprecated: http://blog.semanticart.com/killing_is_paranoid/
gem 'freerange-deploy', :git => "git://github.com/freerange/deploy.git"
gem 'freerange-puppet', :git => "git://github.com/freerange/freerange-puppet.git", :branch => "support-ubuntu"
class BetterNews
def initialize(string, required)
@age = required
@string = string
end
attr_reader :age
def method_missing(name, *args)
self.class.new(@string.send(name, *args), @age)
@lazyatom
lazyatom / test.rb
Created December 13, 2010 10:15
Hmm.
context "a thing" do
setup do
@mailer = TestMailer.new
@thing = Thing.new(@mailer)
end
should "send an email when poked" do
@mailer.expects(:send_email)
@thing.poke
end
@lazyatom
lazyatom / 1_composed_setups_test.rb
Created January 2, 2011 11:53
Another approach
context "Posting" do
# this is what we are testing, and is run for each test
action do
post "/#{@stream}/messages?type=#{@type}&oauth_token=#{@token}", @payload
end
# this is basically setup, but describing the values as defaults clarifies their
# relationship to the action above. each further setup or test can modify these values
# before the action is actually invoked.
defaults do
@lazyatom
lazyatom / edit_definition.rb
Created January 25, 2011 12:56
Take me to the definition of a method in TextMate
# put this in your .irbrc
class Object
def __edit_method(method_name, object=self)
method = object.method(method_name.to_sym)
`open txmt://open?url=file://#{method.__file__}&line=#{method.__line__}`
end
end
@lazyatom
lazyatom / check_for_escaping_issues.sh
Created February 14, 2011 18:03
log_escaping.diff
#!/bin/sh
wget -O - --save-cookies cookies.txt --post-data "save_login=1&email=EMAIL&password=PASSWORD" http://SITE/session > /dev/null
wget -r -l 1 --spider --save-cookies cookies.txt --load-cookies cookies.txt http://SITE/home