【发布时间】:2016-03-27 03:26:50
【问题描述】:
我在 rspec 中有以下测试
it 'passes regex rules' do
job = create(:job)
job.valid?
expect(job.title).to match(/\A[\w\d .,:-@]+\z/)
end
这个正则表达式模式匹配模型模式。推荐的测试方法是什么,以确保未来开发人员的模型不会改变这种模式?
基本上我想测试不属于批准的条件:can only have 0-9, A-Z, periods, colons, hypens, underscores, and spaces. No new lines (enter keys)
更新
基于Generate random string based on Regex?,我决定现在使用(0..255).map(&:chr).select{|x| x != /\A[\w\d .,:-@]+\z/}.sample(5).join,这似乎可行,想法?
【问题讨论】:
标签: ruby-on-rails rspec