-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Some simple "smoke tests" for Regexp#random_example
Possible future tests to add, if needed: * Performance test * "How random is it?" test
- Loading branch information
Tom Lord
committed
Mar 8, 2015
1 parent
1938157
commit fe506bd
Showing
1 changed file
with
22 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
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 | ||
) | ||
end | ||
end |