changelog shortlog tags changeset manifest revisions annotate raw

vendor/plugins/rspec/spec/spec/example/example_matcher_spec.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
1require File.dirname(__FILE__) + '/../../spec_helper.rb'
2
3module Spec
4 module Example
5 module ExampleMatcherSpecHelper
6 class MatchDescription
7 def initialize(description)
8 @description = description
9 end
10
11 def matches?(matcher)
12 matcher.matches?(@description)
13 end
14
15 def failure_message
16 "expected matcher.matches?(#{@description.inspect}) to return true, got false"
17 end
18
19 def negative_failure_message
20 "expected matcher.matches?(#{@description.inspect}) to return false, got true"
21 end
22 end
23 def match_description(description)
24 MatchDescription.new(description)
25 end
26 end
27
28 describe ExampleMatcher, "#matches?" do
29 include ExampleMatcherSpecHelper
30
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")
34 end
35
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")
39 end
40
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")
44 end
45
46 it "should match example only" do
47 matcher = ExampleMatcher.new("example_group", "example")
48 matcher.should match_description("example")
49 end
50
51 it "should match example_group only" do
52 matcher = ExampleMatcher.new("example_group", "example")
53 matcher.should match_description("example_group")
54 end
55
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)")
59 end
60
61 it "should escape regexp chars" do
62 matcher = ExampleMatcher.new("(con|text)", "[example]")
63 matcher.should_not match_description("con p")
64 end
65
66 it "should match when example_group is modularized" do
67 matcher = ExampleMatcher.new("MyModule::MyClass", "example")
68 matcher.should match_description("MyClass example")
69 end
70 end
71
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
76 end
77
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
81 end
82 end
83
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
88 end
89
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
93 end
94 end
95 end
96end