Skip to content

Instantly share code, notes, and snippets.

<form id="some-form">
<input type="text" id="some-field" value="Fill me in" class="input_prompt" />
<input type="submit" value="Go!" />
</form>
require 'rubygems'
require 'riot'
require 'riot/rr'
context "foo" do
asserts("your mom") { stub(Time).now { Time.parse("1970/1/1") }; Time.now }
end
# foo
# ! asserts your mom: stack level too deep
require 'pp'
votes = {
"gus" => ["Colonel Panic", "Cigar Heroes"],
"shinji" => ["Bomb Squad","Taco Town"],
"nawara" => ["Colonel Panic", "Taco Town", "Danger!! Death Ray"],
"richie" => ["Bomb Squad", "Death Ray", "Bomb Ray Death Squad"],
"colin" => ["Colonel Panic", "Taco Town"],
"joey" => ["Danger!! Death Ray", "Bomb Squad"]
}
# See: http://projecteuler.net/index.php?section=problems&id=12
#
# We don't need to actually store the individual factors so long as we know how many were identified
def divisors(limit)
triangle, triangle_sum, found_divisors = 0, 0, 0
while found_divisors < limit
triangle_sum += (triangle += 1)
next unless triangle_sum % 2 == 0 # Only caring about even numbers
found_divisors = 2 # default = [1, triangle_sum]
def submit_request(http_method, action, parameters = nil, session = nil, flash = nil)
@request.recycle!
@response.recycle!
@controller.response_body = nil
@controller.formats = nil
@controller.params = nil
@html_document = nil
@request.env['REQUEST_METHOD'] = http_method
module RiotRails
register_context_helper do
def prepare_context(description, context)
context.premium_setup { description.new } if active_record_context?(description)
context.transaction do |&original_block|
::ActiveRecord::Base.transaction do
original_block.call
raise ::ActiveRecord::Rollback
end
# A snippet from gmail/message.rb
def label(name)
@gmail.in_mailbox(@mailbox) do
begin
@gmail.imap.uid_copy(uid, name)
rescue Net::IMAP::NoResponseError
raise Gmail::NoLabel, "No label `#{name}' exists!"
end
end
test:
adapter: sqlite3
database: ":memory:"
rails_context "something" do
set :transactional, true
context "do something isolated" do
end
context "do another isolated thing" do
end
end
# KEEPING HERE FOR POSTERITY (_gus)
# Allows for a named_scope chain like this,
# Business.owned_by(current_user).limit(10)
# to be cleanly tested like this,
# assert_named_scope_chain(Business, { :owned_by => current_user }, { :limit => 10 })
# rather than having to create nasty mock objects.
def expected_named_scope_chain(*ordered_chain)
results = []