Skip to content

Instantly share code, notes, and snippets.

@natritmeyer
natritmeyer / purge.rb
Created November 1, 2011 12:07
HTTP Purge, for use with Varnish
require 'rest-client'
class Net::HTTP::Purge < Net::HTTPRequest
METHOD = 'PURGE'
REQUEST_HAS_BODY = false
RESPONSE_HAS_BODY = true
end
module RestClient
def self.purge(url, headers={}, &block)
@natritmeyer
natritmeyer / tag_based_logic.rb
Created December 12, 2011 18:20
A cucumber formatter to allow doing stuff when a tag is first come across
#cucumber -f TestManagement::TagLogic -o /dev/null
module TestManagement
class TagLogic
#leave this alone...
def initialize(step_mother, io, options)
@old_tags = []
end
#leave this alone too...
@natritmeyer
natritmeyer / daily_readings_generator.rb
Last active September 29, 2015 02:38
Robert Roberts Daily Readings iCalendar file generator and output
=begin
Copyright (c) 2011, Nathaniel Ritmeyer
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
@natritmeyer
natritmeyer / integer_position_suffix.rb
Created January 6, 2012 14:59
Ruby monkeypatch: Integer#position_suffix
# 1.position_suffix => "st"
# 2.position_suffix => "nd"
# 3.position_suffix => "rd"
# 4.position_suffix => "th"
# 11.position_suffix => "th"
# 21.position_suffix => "st"
# 345678.position_suffix => "th"
class Integer
def position_suffix
@natritmeyer
natritmeyer / spotlight_cli.sh
Created January 18, 2012 09:28
An alias for your .bash_profile that allows you to search in the current folder using spotlight
function sl() {
/usr/bin/mdfind -onlyin \. $@
}
#usage:
# sl Search for this phrase
@natritmeyer
natritmeyer / env.rb
Created February 20, 2012 20:02
Accessing cucumber scenario tags
Before do |scenario|
p scenario.source_tag_names #=> ["@complete", "@slow"]
end
@natritmeyer
natritmeyer / env.rb
Created February 24, 2012 11:04
Fix for ajax problems in tests
module AjaxWaiter
def wait_for_ajax
wait_until { page.evaluate_script("jQuery.active") == 0 }
end
end
World(AjaxWaiter)
@natritmeyer
natritmeyer / tests.rb
Created March 15, 2012 00:44
(Possibly) The World's Smallest Ruby Unit Test Tool
require './tinytest'
class MyTests < TinyTest
def setup
@name = "Bob"
end
def teardown
@name = ""
end
@natritmeyer
natritmeyer / bring_browser_to_front.rb
Created April 20, 2012 10:16
Example ruby/applescript combo that brings browsers to the front - useful in browser test automation...
#you probably only need one of these, but here's the lot of them...
#prepare the commands that will bring the various browsers to the front
bring_chrome_to_front = %Q{ osascript -e "tell application \\\"Google Chrome\\\" to activate" }
bring_firefox_to_front = %Q{ osascript -e "tell application \\\"Firefox\\\" to activate" }
#execute the applescript commands to bring the browsers to the front
`#{bring_chrome_to_front}`
`#{bring_firefox_to_front}`
@natritmeyer
natritmeyer / Usage.txt
Last active January 16, 2017 01:56
JUnit formatter for RSpec
NOTE: I've created a gem based on this: https://github.com/natritmeyer/yarjuf
---------
rspec my_spec.rb -r ./junit.rb -f JUnit -o results.xml