2013-03-22 27 views
1

过去,我运行了Rails + RSpec + autotest。现在我升级到了ruby 2.0,我想在非Rails环境中使用minitest(我使用Padrino/DataMapper)。我确定我并不是唯一想要这样做的人。在autotest或Guard下安装,配置和运行minitest的简洁配方

什么是真正有用是安装和配置的东西这么简单的命令简洁配方:

$ autotest 

$ bundle exec guard 

将开始测试下/测试一切。我搜索了SO和InterWebs,并且还没有找到这样的配方。一个配方应该包括:

  • 什么宝石你应该包括在你的Gemfile?
  • 你运行什么命令来设置环境?
  • 什么样的配置和支持文件你需要创建(Rake文件?.autotest?等等)
  • 测试文件的方法来require 'test_helper'采取重复功能保健

额外信用显示如何配置咆哮和spork以获得全面的XP体验!

回答

3

嗯,我不使用自动测试,现在看来,Guard是最适合的,所以:

# Add to Gemfile 
group :development do 
    gem 'terminal-notifier-guard' # or libnotify for linux 
    gem 'rb-fsevent', require: false # or rb-inotify for linux 
    gem 'guard-minitest' 
    gem 'minitest' 
end 

# From bash 
$ bundle update 
$ guard init minitest # or bundle exec guard init minitest 

# Edit the GuardFile, mine looks like: 
guard 'minitest' do 
    # with Minitest::Unit 
    watch(%r|^test/(.*)\/?test_(.*)\.rb|) 
    watch(%r|^app/models/(.*)\.rb|) { |m| "test/test_#{m[1]}.rb" } 
    watch(%r|^lib/(.*)([^/]+)\.rb|) { |m| "test/test_#{m[2]}.rb" } 
    watch(%r|^test/helper\.rb|)  { 'test' } 
end 

# Here my test helper.rb. /test/helper.rb 
ENV['PADRINO_ENV'] ||= 'test' 
require_relative '../config/boot' 
require 'minitest/autorun' 


# Have fun! 
$ bundle exec guard 
+0

真是太好了 - 我已经切换到后卫,我喜欢它。你碰巧使用咆哮还是ruby_gntp,并且你使用spork?我试图决定使用哪个通知程序... – 2013-03-24 06:17:28

+0

在我的热情中,我检查了你的答案。但要真实地回答最初的问题,答案需要显示你在test_helper文件中的内容,或者是test.rake或者其他能够让你最小化的东西。补充一点,我会给你你的支票! – 2013-03-24 06:24:03

+0

好的,添加它。请记住,我通常将其命名为helper.rb,而不是test_helper.rb或helper_test.rb – DAddYE 2013-03-24 15:58:03