Rails: How to test code in the lib/ directory?

前端 未结 7 1493

I have a model which gets its data from a parser object. I\'m thinking that the parser class should live in the lib/ directory (although I could be persuaded that it should live

相关标签:
7条回答
  • 2021-01-30 07:27

    As of Rails 4.0:

    rake test:all         # Run all tests in any subdir of `test` without resetting the DB
    rake test:all:db      # Same as above and resets the DB
    

    As of Rails 4.1, redefine test:run to include additional tasks when running rake or rake test:

    # lib/tasks/test.rake
    
    namespace :test do
      Rake::Task["run"].clear
      task run: ["test:units", "test:functionals", "test:generators", "test:integration", "test:tasks"]
    
      ["tasks"].each do |name|
        Rails::TestTask.new(name => "test:prepare") do |t|
          t.pattern = "test/#{name}/**/*_test.rb"
        end
      end
    end
    

    This has the added bonus of defining rake test:tasks in the given example.

    As of Rails 4.2, test:run includes all subdirs of test including them when running rake test, and thus rake.

    0 讨论(0)
提交回复
热议问题