Sha256: 9e92f1ef0cd66d2b03c36f431c60ee997257bee8b1f2a2c797d730e483c45262

Contents?: true

Size: 804 Bytes

Versions: 13

Compression:

Stored size: 804 Bytes

Contents

RSpec.describe Regexp, '#random_example' do
  def self.random_example_matches(*regexps)
    regexps.each do |regexp|
      it "random example for /#{regexp.source}/" do
        random_example = regexp.random_example

        expect(random_example).to be_a String # Not an Array!
        expect(random_example)
          .to match(Regexp.new("\\A(?:#{regexp.source})\\z", regexp.options))
      end
    end
  end

  context 'smoke tests' do
    # Just a few "smoke tests", to ensure the basic method isn't broken.
    # Testing of the RegexpExamples::Parser class is all
    # covered by Regexp#examples test already.
    random_example_matches(
      /\w{10}/,
      /(we(need(to(go(deeper)?)?)?)?) \1/,
      /case insensitive/i,
      /front seat|back seat/, # Which seat will I take??
    )
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
regexp-examples-1.5.1 spec/regexp-random_example_spec.rb
regexp-examples-1.5.0 spec/regexp-random_example_spec.rb
regexp-examples-1.4.4 spec/regexp-random_example_spec.rb
regexp-examples-1.4.3 spec/regexp-random_example_spec.rb
regexp-examples-1.4.2 spec/regexp-random_example_spec.rb
regexp-examples-1.4.1 spec/regexp-random_example_spec.rb
regexp-examples-1.4.0 spec/regexp-random_example_spec.rb
regexp-examples-1.3.2 spec/regexp-random_example_spec.rb
regexp-examples-1.3.1 spec/regexp-random_example_spec.rb
regexp-examples-1.3.0 spec/regexp-random_example_spec.rb
regexp-examples-1.2.1 spec/regexp-random_example_spec.rb
regexp-examples-1.2.0 spec/regexp-random_example_spec.rb
regexp-examples-1.1.4 spec/regexp-random_example_spec.rb