测试 RSpec 未显示错误不能为空它显示最小和上升错误的验证

Test RSpec is not showing the error can't be blank it's showing the validates for minimum and rising error

我正在使用 simple_form,所以在我用 rspec 和 rails 默认的 form_for 进行测试之前。 我做了我所有的规格,他们通过了。 所以我安装了 simple_form 和 bootstrap 样式,然后配置使用 :full_error 方法。 而且我为属性(标题和内容)编写的测试不能为空。它首先显示验证属性标题或内容的最小值并抱怨错误的错误消息。 我需要做什么?我擦除此测试或配置一些东西以保留此测试。 所以这是我的模型 post.rb

class Post < ActiveRecord::Base
  validates :title,
              length: { minimum: 10, maximum: 100 },
              presence: true,
              uniqueness: true

这是我在 RSpec 上的场景:

  scenario "title can't be blank" do
      click_button  "Create Post"

      expect(page).to have_content "Post has not been created."
      expect(page).to have_content "Title can't be blank"
    end

The failure it's complaining:
Failures:

  1) Users can create posts when providing invalid attributes title can't be blank
     Failure/Error: expect(page).to have_content "Title can't be blank"
       expected to find text "Title can't be blank" in "×Post has not been created.{\"alert\"=>\"Post has not been created.\"}New Post* TitleTitle is too short (minimum is 10 characters)Subtitle* Content Content is too short (minimum is 30 characters)"

所以改变了顺序并且成功了!

validates :title,
              presence: true,
              length: { minimum: 10, maximum: 100 },
              uniqueness: true