Created
February 11, 2009 15:15
-
-
Save lmarburger/62053 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
class DslTest < Test::Unit::TestCase | |
context "The DSL" do | |
before do | |
@runner = Foundry::Runner.new | |
# Record is a simple ActiveRecord::Base class. Save its current public methods | |
# so new methods can be removed in +after+. | |
@original_record_public_methods = Record.public_methods | |
end | |
# Write tests here that add named scopes to Record. | |
it "should create factory scopes using the default name if one is not given" do | |
@runner.model Record do | |
factory do | |
{:title => "AWESOME."} | |
end | |
end | |
assert Record.respond_to?(:valid) | |
end | |
after do | |
# Remove factory methods from Record so the same method name can be added | |
# in another test (like 'valid'). | |
(Record.public_methods - @original_record_public_methods - | |
# Record gets a few methods added to it that I don't want removed. | |
['with', 'original_primary_key', 'original_locking_column'] | |
).each do |method| | |
Record.class_eval <<-EOS | |
class << self | |
remove_method(#{method.to_sym.inspect}) | |
end | |
EOS | |
end | |
end | |
end | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment