2

The shoulda-matchers documentation for Minitest usage provide an example for how to use them in the assertion style, like so:

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

But how do I use them using the Minitest's Spec style?

The following produces the error: Minitest::UnexpectedError: NoMethodError: undefined method 'validate_presence_of'

describe Person do
  it { should validate_presence_of(:name) }
end
user1647525
  • 311
  • 3
  • 14
  • 1
    You may check this: https://github.com/thoughtbot/shoulda-matchers/wiki/Usage-with-standard-MiniTest-tests – Rubyrider May 06 '18 at 13:19

1 Answers1

0

Its actually quite similar to the original way. For one of my personal projects, this is what my VideoTest class looks like, and I've been using 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
BenMorganIO
  • 2,036
  • 17
  • 37
  • Thanks Ben. This is correct. I was pretty sure I did it that way originally and it wasn't working, but I tried it again and it's working. Your answer helped validate that it should work. Thanks! – user1647525 Feb 21 '16 at 03:12