Skip to content

Instantly share code, notes, and snippets.

View jamesmartin's full-sized avatar
🤫
Shhh

James Martin jamesmartin

🤫
Shhh
View GitHub Profile
# AppleScript to reset safari.
# Originally found at http://macscripter.net/viewtopic.php?id=30178&action=new
tell application "Safari" to set ResetSafari_loc to localized string "Reset Safari…"
if ResetSafari_loc ends with "…" then
set ResetSafari_loc to text 1 thru -2 of ResetSafari_loc
else if ResetSafari_loc ends with "..." then
set ResetSafari_loc to text 1 thru -4 of ResetSafari_loc
end if
# Example SConstruct File for a CppUTest project
import os.path
from os import getcwd
# Construct variables for the SUT and test binaries
# This is based on the base directory name that SConstruct lives in
component_name = os.path.basename(getcwd())
component_tests_name = component_name + "_tests"
# Construct the list of source files for the SUT
# Example SConstruct File for a Igloo-test project
import os.path
from os import getcwd
# Construct variables for the SUT and test binaries
# This is based on the base directory name that SConstruct lives in
component_name = os.path.basename(getcwd())
component_tests_name = component_name + "_tests"
# Construct the list of source files for the SUT
ls _posts/* | grep -c -E '[0-9]{4}-[0-9]{2}-[0-9]{2}' | while read fn; do day=`grep '#postdate\|#date' $fn | cut -d '-' -f 3 | cut -d ' ' -f 1`; git mv $fn `echo $fn | sed -E "s/-\([0-9]{2}\)-/-\1-$day-/"`; done
require 'rake'
require 'rake/testtask'
task :default => [:test_units]
desc "Run basic tests"
Rake::TestTask.new("test_units") do |test|
test.pattern = 'test/*_test.rb'
test.verbose = true
test.warning = true
@jamesmartin
jamesmartin / http_test_spec.rb
Created January 21, 2011 03:44
An example custom RSpec matcher that makes describing expectations on HTTP failures nicer and gives more information when it fails (like the response body)
require 'spec_helper'
describe "Fun REST API Function" do
before(:each) do
@api = FunRestApi.new
end
context "when creating a valid widget" do
it "responds with a success message" do
@jamesmartin
jamesmartin / Rakefile
Created February 9, 2011 01:30
Running groups of specs in subdirs of the spec/ dir
desc "Run both API v2 and v3 specs"
task :api => [:apiv2, :apiv3]
desc "Run only API v2 specs"
RSpec::Core::RakeTask.new(:apiv2) do |task|
task.pattern = 'spec/v2/*_spec.rb'
task.rspec_opts = "--format progress --fail-fast"
end
desc "Run only API v3 + Webhooks specs"
module RadioChannels
def self.get_data(url)
# Some code
end
def mixed_in_method(url)
RadioChannels.get_data(url)
end
end
@jamesmartin
jamesmartin / app.rb
Created February 11, 2011 02:52
Testing instance methods defined on a Sinatra application using the helpers module using RSpec
require 'rubygems'
require 'sinatra'
Sinatra::Base.show_exceptions = false
class App < Sinatra::Base
helpers do
def my_helper_method
@jamesmartin
jamesmartin / account.rb
Created February 16, 2011 10:13
Simplified illustrative example of 'collaboration' tests between two objects in RSpec
class Account
attr_writer :logger, :username, :password
def logger logger
@logger ||= logger
end
def login
# do authentication stuff...
begin