Home > Blockchain >  How create RSpec test to test an Array of invalid emails using all matcher
How create RSpec test to test an Array of invalid emails using all matcher

Time:03-19

I'm trying to make a test for an email validation pattern, to this I create a array with all invalid emails and try use not_to all matcher to test this.

       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

but I receive this error

 NotImplementedError:
       `expect().not_to all( matcher )` is not supported.

Exist another way to do this?

CodePudding user response:

You can use Array#none? with regexp

expect(invalid_emails.none?(/regexp/)).to be true

or just iterate array

invalid_emails.each { |email| expect(email).not_to match /regexp/ }
  • Related