Created
February 7, 2020 10:27
-
-
Save jonnyom/d87607ce60e50f8b9516cb59fb4d420c to your computer and use it in GitHub Desktop.
An Rspec it block that pulls out all the descriptions of the test, with a regex to match "#method_name" describe blocks. Useful for testing that all public methods of a class have been tested in a spec.
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
it "pulls out the specs descriptions" do | |
parent_groups = self.class.instance_eval { @parent_groups } | |
descriptions = parent_groups.each(&:children).map do |child_group| | |
child_group.instance_eval { @descendant_filtered_examples }.map do |example| | |
example.full_description | |
end | |
end.flatten | |
matched_descriptions = descriptions.map { |description| description.match(/#([[:word:]]*\??)/) }.compact.map { |match| match[1] }.uniq | |
expect(matched_descriptions.first).to eq("test_method") | |
end | |
describe "#test_method" do | |
it { expect(true).to be_truthy } | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment