我的测试不适用于minitest

时间:2013-10-23 17:44:42

标签: ruby-on-rails ruby-on-rails-4 minitest specifications

我是测试的新手,经过两年的轨道开发,它必须改变!

因此,我正在尝试在rails 4应用程序上安装minitest。

我做了以下事情:

更新了我的gemfile:

group :test do
  gem 'factory_girl'
  gem 'minitest-rails'
  gem 'minitest-rails-capybara'
  gem 'minitest-colorize'
  gem 'minitest-focus'
  gem "shoulda-matchers"
  gem "guard-rspec"
end

在test / test_helper.rb

中创建了一个帮助器
ENV["RAILS_ENV"] = "test"
require File.expand_path("../../config/environment", __FILE__)
require "rails/test_help"
#require "minitest/rails"
require "minitest/spec"
require 'minitest/focus'

# To add Capybara feature tests add `gem "minitest-rails-capybara"`
# to the test group in the Gemfile and uncomment the following:
 require "minitest/rails/capybara"

# Uncomment for awesome colorful output
 require "minitest/pride"

class ActiveSupport::TestCase
  # Setup all fixtures in test/fixtures/*.(yml|csv) for all tests in alphabetical order.
  ActiveRecord::Migration.check_pending!
  fixtures :all
  extend MiniTest::Spec::DSL

  #use ActiveSupport::TestCase when describing an ActiveRecord model
  register_spec_type self do |desc|
      desc < ActiveRecord::Base if desc.is_a? Class
  end

  # Add more helper methods to be used by all tests here...
  def self.prepare
     # Add code that needs to be executed before test suite start
   end
   prepare

   def setup
     # Add code that need to be executed before each test
   end

   def teardown
     # Add code that need to be executed after each test
   end

end

生成了一个脚手架,有一些“测试”测试文件,如下所示:

模型/ project_test.rb

require "test_helper"

describe Project do
  before do
    @project = Project.new
  end

  it "must be valid" do
    @project.valid?.must_equal true
  end
end

当我在终端输入rake minitest:models时,这就是我得到的:

Run options: --seed 40421

# Running tests:



Fabulous tests in 0.049207s, 0.0000 tests/s, 0.0000 assertions/s.

0 tests, 0 assertions, 0 failures, 0 errors, 0 skips

显然,minitest运行但我的测试没有执行。怎么了?

感谢!!!

1 个答案:

答案 0 :(得分:0)

问题是由于与rspec的冲突,后者被guard-rspec添加为依赖。

非常感谢@blowmage!