Shoulda/RSpec: Make sure that validation message “xxx” is on :base

点点圈 提交于 2019-12-04 20:40:16

Right, it's looking good. Inline rspec tests are using subject. You could rewrite your test like this:

describe 'my method' do
  before { contact.valid? }

  context 'contact is not valid' do
    subject { contact.errors[:base] }
    it { should include 'xxx' }
  end
end

The should method is called on the subject. It can be more readable sometimes. And you don't have to write descriptions for specs that are self-explanatory ;-)

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!