Skip to content

Instantly share code, notes, and snippets.

@ohokay
Created March 26, 2009 23:14
Show Gist options
  • Save ohokay/86436 to your computer and use it in GitHub Desktop.
Save ohokay/86436 to your computer and use it in GitHub Desktop.
# The macro
class Test::Unit::TestCase
def self.should_be_in_state(state)
klass = self.name.gsub(/Test$/, '').constantize
context "#{klass}" do
should "be #{state}" do
assert_equal klass.new.state_name.to_s, state.to_s
end
end
end
end
# my model, using a simple state machine plugin, like this one: http://github.com/pluginaweek/state_machine
class Post < ActiveRecord::Base
state_machine :state, :initial => :active do
state [:active, :inactive]
end
end
# the test
require 'test_helper'
class PostTest < ActiveSupport::TestCase
should_be_in_state :active
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment