Skip to content

Instantly share code, notes, and snippets.

@dreamcat4
Created July 5, 2009 17:55
Show Gist options
  • Save dreamcat4/141065 to your computer and use it in GitHub Desktop.
Save dreamcat4/141065 to your computer and use it in GitHub Desktop.
Shoulda macros
class Test::Unit::TestCase
# http://programblings.com/2008/10/31/two-shoulda-best-practices/
# Sets the current person in the session from the person fixtures.
def self.logged_in_as(person, &block)
context "logged in as #{person}" do
setup do
@request.session[:person] = people(person).id
end
context '' do
yield
end
end
end
# Use this macro as a block
logged_in_as :mat do
# Contexts, setup
# Shoulda tests
end
# Declare a shoulda macro
def self.should_build_request_path(path)
should "build request path of #{path}" do
assert {path == @api_call.build_request_path}
end
end
should_raise(LoadError, :message => "such file to load") do
require "more vespene gas"
end
should_build_request_path '/v1/tags/get'
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment