1 require File.dirname(__FILE__) + '/../../spec_helper.rb'
5 module ExampleMatcherSpecHelper
7 def initialize(description)
8 @description = description
12 matcher.matches?(@description)
16 "expected matcher.matches?(#{@description.inspect}) to return true, got false"
19 def negative_failure_message
20 "expected matcher.matches?(#{@description.inspect}) to return false, got true"
23 def match_description(description)
24 MatchDescription.new(description)
28 describe ExampleMatcher, "#matches?" do
29 include ExampleMatcherSpecHelper
31 it "should match correct example_group and example" do
32 matcher = ExampleMatcher.new("example_group", "example")
33 matcher.should match_description("example_group example")
36 it "should not match wrong example" do
37 matcher = ExampleMatcher.new("example_group", "other example")
38 matcher.should_not match_description("example_group example")
41 it "should not match wrong example_group" do
42 matcher = ExampleMatcher.new("other example_group", "example")
43 matcher.should_not match_description("example_group example")
46 it "should match example only" do
47 matcher = ExampleMatcher.new("example_group", "example")
48 matcher.should match_description("example")
51 it "should match example_group only" do
52 matcher = ExampleMatcher.new("example_group", "example")
53 matcher.should match_description("example_group")
56 it "should match example_group ending with before(:all)" do
57 matcher = ExampleMatcher.new("example_group", "example")
58 matcher.should match_description("example_group before(:all)")
61 it "should escape regexp chars" do
62 matcher = ExampleMatcher.new("(con|text)", "[example]")
63 matcher.should_not match_description("con p")
66 it "should match when example_group is modularized" do
67 matcher = ExampleMatcher.new("MyModule::MyClass", "example")
68 matcher.should match_description("MyClass example")
72 describe ExampleMatcher, "#matches? normal case" do
73 it "matches when passed in example matches" do
74 matcher = ExampleMatcher.new("Foo", "bar")
75 matcher.matches?(["no match", "Foo bar"]).should == true
78 it "does not match when no passed in examples match" do
79 matcher = ExampleMatcher.new("Foo", "bar")
80 matcher.matches?(["no match1", "no match2"]).should == false
84 describe ExampleMatcher, "#matches? where description has '::' in it" do
85 it "matches when passed in example matches" do
86 matcher = ExampleMatcher.new("Foo::Bar", "baz")
87 matcher.matches?(["no match", "Foo::Bar baz"]).should == true
90 it "does not match when no passed in examples match" do
91 matcher = ExampleMatcher.new("Foo::Bar", "baz")
92 matcher.matches?(["no match1", "no match2"]).should == false