]> git.openstreetmap.org Git - rails.git/blob - vendor/gems/rspec-1.1.2/spec/spec/example/example_methods_spec.rb
added RSpec and RSpec on Rails
[rails.git] / vendor / gems / rspec-1.1.2 / spec / spec / example / example_methods_spec.rb
1 require File.dirname(__FILE__) + '/../../spec_helper'
2
3 module Spec
4   module Example
5     module ModuleThatIsReopened
6     end
7
8     module ExampleMethods
9       include ModuleThatIsReopened
10     end
11
12     module ModuleThatIsReopened
13       def module_that_is_reopened_method
14       end
15     end
16
17     describe "ExampleMethods with an included module that is reopened" do
18       it "should have repoened methods" do
19         method(:module_that_is_reopened_method).should_not be_nil
20       end
21     end
22
23     describe ExampleMethods, "lifecycle" do
24       before do
25         @options = ::Spec::Runner::Options.new(StringIO.new, StringIO.new)
26         @options.formatters << mock("formatter", :null_object => true)
27         @options.backtrace_tweaker = mock("backtrace_tweaker", :null_object => true)
28         @reporter = FakeReporter.new(@options)
29         @options.reporter = @reporter
30
31         ExampleMethods.before_all_parts.should == []
32         ExampleMethods.before_each_parts.should == []
33         ExampleMethods.after_each_parts.should == []
34         ExampleMethods.after_all_parts.should == []
35         def ExampleMethods.count
36           @count ||= 0
37           @count = @count + 1
38           @count
39         end
40       end
41
42       after do
43         ExampleMethods.instance_variable_set("@before_all_parts", [])
44         ExampleMethods.instance_variable_set("@before_each_parts", [])
45         ExampleMethods.instance_variable_set("@after_each_parts", [])
46         ExampleMethods.instance_variable_set("@after_all_parts", [])
47       end
48
49       it "should pass before and after callbacks to all ExampleGroup subclasses" do
50         ExampleMethods.before(:all) do
51           ExampleMethods.count.should == 1
52         end
53
54         ExampleMethods.before(:each) do
55           ExampleMethods.count.should == 2
56         end
57
58         ExampleMethods.after(:each) do
59           ExampleMethods.count.should == 3
60         end
61
62         ExampleMethods.after(:all) do
63           ExampleMethods.count.should == 4
64         end
65
66         @example_group = Class.new(ExampleGroup) do
67           it "should use ExampleMethods callbacks" do
68           end
69         end
70         @example_group.run
71         ExampleMethods.count.should == 5
72       end
73       
74       describe "run_with_description_capturing" do
75         before(:each) do
76           @example_group = Class.new(ExampleGroup) do end
77           @example = @example_group.new("foo", &(lambda { 2.should == 2 }))
78           @example.run_with_description_capturing
79         end
80       
81         it "should provide the generated description" do
82           @example.instance_eval { @_matcher_description }.should == "should == 2"
83         end
84       
85         it "should clear the global generated_description" do
86           Spec::Matchers.generated_description.should == nil
87         end
88       end
89     end
90   end
91 end