Rspec / shoulda: testing, that a custom validator is called

有些话、适合烂在心里 提交于 2019-12-02 02:15:26

Another option is to use the allow_value matcher, although not ideal it can work in some circumstances.

it { should allow_value(value_which_is_valid).for(:link) }
it { should_not allow_value(value_which_is_invalid).for(:link) }

Use factory girl to build a model object with invalid data and one with valid data and call the be_valid matcher.

#factory girl
build(:model, link: valid_uri).should be_valid
build(:model, link: invalid_uri).should_not be_valid
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!