changelog shortlog tags changeset manifest revisions annotate raw

vendor/plugins/rspec/examples/pure/shared_example_group_example.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'
2
3module SharedExampleGroupExample
4 class OneThing
5 def what_things_do
6 "stuff"
7 end
8 end
9
10 class AnotherThing
11 def what_things_do
12 "stuff"
13 end
14 end
15
16 class YetAnotherThing
17 def what_things_do
18 "stuff"
19 end
20 end
21
22 # A SharedExampleGroup is an example group that doesn't get run.
23 # You can create one like this:
24 share_examples_for "most things" do
25 def helper_method
26 "helper method"
27 end
28
29 it "should do what things do" do
30 @thing.what_things_do.should == "stuff"
31 end
32 end
33
34 # A SharedExampleGroup is also module. If you create one like this
35 # it gets assigned to the constant AllThings
36 share_as :MostThings do
37 def helper_method
38 "helper method"
39 end
40
41 it "should do what things do" do
42 @thing.what_things_do.should == "stuff"
43 end
44 end
45
46 describe OneThing do
47 # Now you can include the shared example group like this, which
48 # feels more like what you might say ...
49 it_should_behave_like "most things"
50
51 before(:each) { @thing = OneThing.new }
52
53 it "should have access to helper methods defined in the shared example group" do
54 helper_method.should == "helper method"
55 end
56 end
57
58 describe AnotherThing do
59 # ... or you can include the example group like this, which
60 # feels more like the programming language we love.
61 it_should_behave_like MostThings
62
63 before(:each) { @thing = AnotherThing.new }
64
65 it "should have access to helper methods defined in the shared example group" do
66 helper_method.should == "helper method"
67 end
68 end
69
70 describe YetAnotherThing do
71 # ... or you can include the example group like this, which
72 # feels more like the programming language we love.
73 include MostThings
74
75 before(:each) { @thing = AnotherThing.new }
76
77 it "should have access to helper methods defined in the shared example group" do
78 helper_method.should == "helper method"
79 end
80 end
81end