开发者

how to add to rspec-rails callbacks

I have some code that adds to the callbacks that rspec-rails adds by default to setup and teardown fixtures.

My code looks something like:

开发者_JAVA技巧
module Test
  module Unit

    class TestCase
      append_before(:each) do
       Test::Unit::AfterFixturesLoaded.custom_stuff1
      end

      append_after(:each) do
        Test::Unit::AfterFixturesLoaded.custom_stuff2
      end
    end

    class AfterFixturesLoaded

      def self.custom_stuff1
        #do some stuff here
      end

      def self.custom_stuff2
        #do some other stuff here
      end
    end

  end
end

This code works fine if I put it in the config\initializers directory in the rails app, but then running the app fails because it doesn't load test unit. So my question is where can I put this code so that it will always be included when running rspec?


Since you are only going to use this code for testing so it make sense to put it in a separate file and then require it in the environments/test.rb for example require 'filename.rb'

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜