我使用simple_form之前所以在使用rspec进行测试之前使用form_for默认为rails。 我做了我所有的规格,他们通过了。 所以我使用bootstrap样式安装simple_form,然后使用: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)"
答案 0 :(得分:1)
所以改变了顺序并且有效!
validates :title,
presence: true,
length: { minimum: 10, maximum: 100 },
uniqueness: true