test/glue/tc_fixture.rb in glue-0.29.0 vs test/glue/tc_fixture.rb in glue-0.30.0

- old
+ new

@@ -1,11 +1,13 @@ $:.unshift File.join(File.dirname(__FILE__), 'lib') require 'test/unit' require 'glue/fixture' -class TestFixture < Test::Unit::TestCase # :nodoc: all +RootDir = File.expand_path(File.join(File.dirname(__FILE__), '..', 'fixture')) + +class TestFixtureExplicitRootDir < Test::Unit::TestCase # :nodoc: all include Glue class User attr_accessor :name attr_accessor :age @@ -15,10 +17,62 @@ attr_accessor :title attr_accessor :body end def test_all + users = Fixture.new(User, :root_dir => RootDir) + + assert_equal 3, users.size + george = users['george'] + assert_equal 30, george.age + assert_equal 'Renos', users['renos'].name + + articles = Fixture.new(Article, :root_dir => RootDir) + + assert_equal 9, articles.size + assert_equal 'This is cool', articles['article_1'].title + assert_equal 'Another', articles['article_2'].title + assert_equal 'I love this', articles['Test'].title + + assert_equal 'title 3', articles['Auto3'].title + end + + def test_global + "This is not supported with explicit root directory setting" +=begin + assert_raises(RuntimeError, "This test will fail when running via rake") do + Fixtures.load User, Article + end # Fixtures.load _only_ uses Fixtures.root_dir setting. +=end + end + +end + +class TestFixtureRootDirSetting < Test::Unit::TestCase # :nodoc: all + include Glue + + class User + attr_accessor :name + attr_accessor :age + end + + class Article + attr_accessor :title + attr_accessor :body + end + + def setup + @old_rootdir = Fixtures.root_dir + Fixtures.root_dir = RootDir + end + + def teardown + Fixtures.root_dir = @old_rootdir + @old_rootdir = nil + end + + def test_all users = Fixture.new(User) assert_equal 3, users.size george = users['george'] assert_equal 30, george.age @@ -33,10 +87,10 @@ assert_equal 'title 3', articles['Auto3'].title end def test_global - Fixtures.load User, Article + Fixtures.load User, Article assert_equal 3, Fixtures.user.size assert_equal 'This is cool', Fixtures.article['article_1'].title end end