Posts Tagged ‘rspec’

textmate rspec bundle (datamapper) helpers

I found that I often want to add debug outputs to the specs while working on them. Since I use textmate’s rspec bundle to run (focused) unit tests, I needed my debug messages to be html. Here’s what I came up with

http://gist.github.com/92470

support for speccing datamapper models with rspec

# Put this in spec_helper.rb
module SpecSupport

  def self.unload_class(*classes)
    classes.each do |c|
      Object.send(:remove_const, c) if Object.const_defined?(c)
    end
  end

  def self.fresh_class(name, superclass = nil, &block)
    unload_class(name)
    args = superclass ? [ superclass ] : []
    Object.const_set(name, Class.new(*args))
    Object.const_get(name).class_eval(&block)
  end

  def self.fresh_model(name)
    fresh_class(name) do
      include DataMapper::Resource
      property :id,         DataMapper::Types::Serial
      property :created_at, DateTime
      property :updated_at, DateTime
    end
  end

end