如何在Rails中使用具有Minitest Specs样式的shoulda-matchers?

时间:2016-02-19 23:22:58

标签: ruby-on-rails minitest shoulda

Minitest用法的shoulda-matchers文档提供了如何在断言样式中使用它们的示例,如下所示:

class PersonTest < ActiveSupport::TestCase
  should validate_presence_of(:name)
end

但是如何使用Minitest的Spec风格来使用它们?

以下内容会产生错误:Minitest::UnexpectedError: NoMethodError: undefined method 'validate_presence_of'

describe Person do
  it { should validate_presence_of(:name) }
end

1 个答案:

答案 0 :(得分:0)

它实际上与原始方式非常相似。对于我的一个个人项目,这就是我VideoTest课程的样子,我一直在使用MiniTest Spec。

require 'test_helper'

describe VideoTest do
  let(:video) { build :video }

  should belong_to :course

  should validate_presence_of :title
  should validate_presence_of :description
end
相关问题