Sha256: 0b17fa66c1e5c5bb0ef9c78e6ef6fe12d76d76084b1ee3da960722f877d13994

Contents?: true

Size: 1.46 KB

Versions: 61

Compression:

Stored size: 1.46 KB

Contents

module Spec
  module Example
    class ExampleMatcher
      def initialize(example_group_description, example_name)
        @example_group_description = example_group_description
        @example_name = example_name
      end
      
      def matches?(specified_examples)
        specified_examples.each do |specified_example|
          return true if matches_literal_example?(specified_example) || matches_example_not_considering_modules?(specified_example)
        end
        false
      end
      
      protected
      def matches_literal_example?(specified_example)
        specified_example =~ /(^#{example_group_regex} #{example_regexp}$|^#{example_group_regex}$|^#{example_group_with_before_all_regexp}$|^#{example_regexp}$)/
      end

      def matches_example_not_considering_modules?(specified_example)
        specified_example =~ /(^#{example_group_regex_not_considering_modules} #{example_regexp}$|^#{example_group_regex_not_considering_modules}$|^#{example_regexp}$)/
      end

      def example_group_regex
        Regexp.escape(@example_group_description)
      end

      def example_group_with_before_all_regexp
        Regexp.escape("#{@example_group_description} before(:all)")
      end

      def example_group_regex_not_considering_modules
        Regexp.escape(@example_group_description.split('::').last)
      end

      def example_regexp
        Regexp.escape(@example_name)
      end
    end

    ExampleGroupMethods.matcher_class = ExampleMatcher
  end
end

Version data entries

61 entries across 61 versions & 10 rubygems

Version Path
dchelimsky-rspec-1.1.10 lib/spec/example/example_matcher.rb
dchelimsky-rspec-1.1.11.1 lib/spec/example/example_matcher.rb
dchelimsky-rspec-1.1.11.2 lib/spec/example/example_matcher.rb
dchelimsky-rspec-1.1.11.3 lib/spec/example/example_matcher.rb
dchelimsky-rspec-1.1.11.4 lib/spec/example/example_matcher.rb
dchelimsky-rspec-1.1.11.5 lib/spec/example/example_matcher.rb
dchelimsky-rspec-1.1.11.6 lib/spec/example/example_matcher.rb
dchelimsky-rspec-1.1.11.7 lib/spec/example/example_matcher.rb
dchelimsky-rspec-1.1.11 lib/spec/example/example_matcher.rb
dchelimsky-rspec-1.1.12 lib/spec/example/example_matcher.rb
dchelimsky-rspec-1.1.99.1 lib/spec/example/example_matcher.rb
dchelimsky-rspec-1.1.99.13 lib/spec/example/example_matcher.rb
dchelimsky-rspec-1.1.99.2 lib/spec/example/example_matcher.rb
dchelimsky-rspec-1.1.99.3 lib/spec/example/example_matcher.rb
dchelimsky-rspec-1.1.99.4 lib/spec/example/example_matcher.rb
dchelimsky-rspec-1.1.99.5 lib/spec/example/example_matcher.rb
dchelimsky-rspec-1.1.99.6 lib/spec/example/example_matcher.rb
dchelimsky-rspec-1.1.99.7 lib/spec/example/example_matcher.rb
dchelimsky-rspec-1.1.99.8 lib/spec/example/example_matcher.rb
dchelimsky-rspec-1.1.99.9 lib/spec/example/example_matcher.rb