Created
March 26, 2009 23:14
-
-
Save ohokay/86436 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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