changelog shortlog tags changeset manifest revisions annotate raw

vendor/plugins/rspec/lib/spec/example/example_matcher.rb

changeset 15: 64acf98d15f4
author: moriq@moriq.com
date: Mon Mar 10 10:12:58 2008 +0900 (16 years ago)
permissions: -rw-r--r--
description: add plugins rspec
1module Spec
2 module Example
3 class ExampleMatcher
4 def initialize(example_group_description, example_name)
5 @example_group_description = example_group_description
6 @example_name = example_name
7 end
8
9 def matches?(specified_examples)
10 specified_examples.each do |specified_example|
11 return true if matches_literal_example?(specified_example) || matches_example_not_considering_modules?(specified_example)
12 end
13 false
14 end
15
16 protected
17 def matches_literal_example?(specified_example)
18 specified_example =~ /(^#{example_group_regex} #{example_regexp}$|^#{example_group_regex}$|^#{example_group_with_before_all_regexp}$|^#{example_regexp}$)/
19 end
20
21 def matches_example_not_considering_modules?(specified_example)
22 specified_example =~ /(^#{example_group_regex_not_considering_modules} #{example_regexp}$|^#{example_group_regex_not_considering_modules}$|^#{example_regexp}$)/
23 end
24
25 def example_group_regex
26 Regexp.escape(@example_group_description)
27 end
28
29 def example_group_with_before_all_regexp
30 Regexp.escape("#{@example_group_description} before(:all)")
31 end
32
33 def example_group_regex_not_considering_modules
34 Regexp.escape(@example_group_description.split('::').last)
35 end
36
37 def example_regexp
38 Regexp.escape(@example_name)
39 end
40 end
41 end
42end