【问题标题】:my tests don't run with minitest我的测试不与 minitest 一起运行
【发布时间】:2013-11-02 03:30:02
【问题描述】:

我是一个全新的测试新手,经过两年的 Rails 开发,它必须改变!

因此,我正在尝试在 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

生成了一个具有一些“测试”测试文件的脚手架,比如这个:

models/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 运行但我的测试没有执行。怎么了?

谢谢!!!

【问题讨论】:

  • 您在 Gemfile.lock 文件中看到 rspec 了吗?

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


【解决方案1】:

这个问题是由于与 rspec 冲突造成的,该冲突是由 guard-rspec 作为依赖项添加的。

非常感谢@blowmage!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-12-01
    • 1970-01-01
    • 1970-01-01
    • 2015-11-29
    • 1970-01-01
    • 2021-06-27
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多