]> git.openstreetmap.org Git - rails.git/blob - vendor/gems/rspec-1.1.2/lib/spec/runner.rb
added RSpec and RSpec on Rails
[rails.git] / vendor / gems / rspec-1.1.2 / lib / spec / runner.rb
1 require 'spec/runner/options'
2 require 'spec/runner/option_parser'
3 require 'spec/runner/example_group_runner'
4 require 'spec/runner/command_line'
5 require 'spec/runner/drb_command_line'
6 require 'spec/runner/backtrace_tweaker'
7 require 'spec/runner/reporter'
8 require 'spec/runner/spec_parser'
9 require 'spec/runner/class_and_arguments_parser'
10
11 module Spec
12   # == ExampleGroups and Examples
13   # 
14   # Rather than expressing examples in classes, RSpec uses a custom DSLL (DSL light) to 
15   # describe groups of examples.
16   # 
17   # A ExampleGroup is the equivalent of a fixture in xUnit-speak. It is a metaphor for the context
18   # in which you will run your executable example - a set of known objects in a known starting state.
19   # We begin be describing
20   # 
21   #   describe Account do
22   # 
23   #     before do
24   #       @account = Account.new
25   #     end
26   # 
27   #     it "should have a balance of $0" do
28   #       @account.balance.should == Money.new(0, :dollars)
29   #     end
30   # 
31   #   end
32   # 
33   # We use the before block to set up the Example (given), and then the #it method to
34   # hold the example code that expresses the event (when) and the expected outcome (then).
35   # 
36   # == Helper Methods
37   # 
38   # A primary goal of RSpec is to keep the examples clear. We therefore prefer
39   # less indirection than you might see in xUnit examples and in well factored, DRY production code. We feel
40   # that duplication is OK if removing it makes it harder to understand an example without
41   # having to look elsewhere to understand its context.
42   # 
43   # That said, RSpec does support some level of encapsulating common code in helper
44   # methods that can exist within a context or within an included module.
45   # 
46   # == Setup and Teardown
47   # 
48   # You can use before and after within a Example. Both methods take an optional
49   # scope argument so you can run the block before :each example or before :all examples
50   # 
51   #   describe "..." do
52   #     before :all do
53   #       ...
54   #     end
55   # 
56   #     before :each do
57   #       ...
58   #     end
59   # 
60   #     it "should do something" do
61   #       ...
62   #     end
63   # 
64   #     it "should do something else" do
65   #       ...
66   #     end
67   # 
68   #     after :each do
69   #       ...
70   #     end
71   # 
72   #     after :all do
73   #       ...
74   #     end
75   # 
76   #   end
77   # 
78   # The <tt>before :each</tt> block will run before each of the examples, once for each example. Likewise,
79   # the <tt>after :each</tt> block will run after each of the examples.
80   # 
81   # It is also possible to specify a <tt>before :all</tt> and <tt>after :all</tt>
82   # block that will run only once for each behaviour, respectively before the first <code>before :each</code>
83   # and after the last <code>after :each</code>. The use of these is generally discouraged, because it
84   # introduces dependencies between the examples. Still, it might prove useful for very expensive operations
85   # if you know what you are doing.
86   # 
87   # == Local helper methods
88   # 
89   # You can include local helper methods by simply expressing them within a context:
90   # 
91   #   describe "..." do
92   #   
93   #     it "..." do
94   #       helper_method
95   #     end
96   # 
97   #     def helper_method
98   #       ...
99   #     end
100   # 
101   #   end
102   # 
103   # == Included helper methods
104   # 
105   # You can include helper methods in multiple contexts by expressing them within
106   # a module, and then including that module in your context:
107   # 
108   #   module AccountExampleHelperMethods
109   #     def helper_method
110   #       ...
111   #     end
112   #   end
113   # 
114   #   describe "A new account" do
115   #     include AccountExampleHelperMethods
116   #     before do
117   #       @account = Account.new
118   #     end
119   # 
120   #     it "should have a balance of $0" do
121   #       helper_method
122   #       @account.balance.should eql(Money.new(0, :dollars))
123   #     end
124   #   end
125   # 
126   # == Shared Example Groups
127   # 
128   # You can define a shared Example Group, that may be used on other groups
129   #
130   #  share_examples_for "All Editions" do
131   #    it "all editions behaviour" ...
132   #  end
133   #
134   #  describe SmallEdition do
135   #    it_should_behave_like "All Editions"
136   #  
137   #    it "should do small edition stuff" do
138   #      ...
139   #    end
140   #  end
141   #
142   # You can also assign the shared group to a module and include that
143   #
144   #  share_as :AllEditions do
145   #    it "should do all editions stuff" ...
146   #  end
147   #
148   #  describe SmallEdition do
149   #    it_should_behave_like AllEditions
150   #  
151   #    it "should do small edition stuff" do
152   #      ...
153   #    end
154   #  end
155   #
156   # And, for those of you who prefer to use something more like Ruby, you
157   # can just include the module directly
158   #
159   #  describe SmallEdition do
160   #    include AllEditions
161   #  
162   #    it "should do small edition stuff" do
163   #      ...
164   #    end
165   #  end
166   module Runner
167     class << self
168       def configuration # :nodoc:
169         @configuration ||= Spec::Example::Configuration.new
170       end
171       
172       # Use this to configure various configurable aspects of
173       # RSpec:
174       #
175       #   Spec::Runner.configure do |configuration|
176       #     # Configure RSpec here
177       #   end
178       #
179       # The yielded <tt>configuration</tt> object is a
180       # Spec::Example::Configuration instance. See its RDoc
181       # for details about what you can do with it.
182       #
183       def configure
184         yield configuration
185       end
186     end
187   end
188 end