我正在嘗試對電子郵件驗證模式進行測驗,為此我創建了一個包含所有無效電子郵件的陣列并嘗試使用not_to all匹配器來測驗它。
context 'when invalid email' do
let(:invalid_emails) do
[
'plainaddress',
'#@%^%#$@#$@#.com',
'@example.com',
'Joe Smith <[email protected]>',
'email.example.com',
'email@[email protected]',
'[email protected]',
'[email protected]',
'[email protected]',
'あいうえお@example.com',
'[email protected] (Joe Smith)',
'email@example',
'[email protected]',
'[email protected]',
'[email protected]',
'[email protected]',
'[email protected]'
]
end
it 'no match' do
expect(invalid_emails).not_to all(match(helper.html_validation_pattern))
end
end
但我收到此錯誤
NotImplementedError:
`expect().not_to all( matcher )` is not supported.
是否存在另一種方法來做到這一點?
uj5u.com熱心網友回復:
您可以使用正則Array#none?運算式
expect(invalid_emails.none?(/regexp/)).to be true
或者只是迭代陣列
invalid_emails.each { |email| expect(email).not_to match /regexp/ }
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/445707.html
