Updated to latest rspec
[gitorious:georgyos-clone.git] / vendor / plugins / rspec / 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 do
18       describe "with an included module that is reopened" do
19         it "should have repoened methods" do
20           method(:module_that_is_reopened_method).should_not be_nil
21         end
22       end
23
24       describe "lifecycle" do
25         before do
26           @original_rspec_options = $rspec_options
27           @options = ::Spec::Runner::Options.new(StringIO.new, StringIO.new)
28           $rspec_options = @options
29           @options.formatters << mock("formatter", :null_object => true)
30           @options.backtrace_tweaker = mock("backtrace_tweaker", :null_object => true)
31           @reporter = FakeReporter.new(@options)
32           @options.reporter = @reporter
33
34           ExampleMethods.before_all_parts.should == []
35           ExampleMethods.before_each_parts.should == []
36           ExampleMethods.after_each_parts.should == []
37           ExampleMethods.after_all_parts.should == []
38           def ExampleMethods.count
39             @count ||= 0
40             @count = @count + 1
41             @count
42           end
43         end
44
45         after do
46           $rspec_options = @original_rspec_options
47           ExampleMethods.instance_variable_set("@before_all_parts", [])
48           ExampleMethods.instance_variable_set("@before_each_parts", [])
49           ExampleMethods.instance_variable_set("@after_each_parts", [])
50           ExampleMethods.instance_variable_set("@after_all_parts", [])
51         end
52
53         it "should pass before and after callbacks to all ExampleGroup subclasses" do
54           ExampleMethods.before(:suite) do
55             ExampleMethods.count.should == 1
56           end
57
58           ExampleMethods.before(:all) do
59             ExampleMethods.count.should == 2
60           end
61
62           ExampleMethods.before(:each) do
63             ExampleMethods.count.should == 3
64           end
65
66           ExampleMethods.after(:each) do
67             ExampleMethods.count.should == 4
68           end
69
70           ExampleMethods.after(:all) do
71             ExampleMethods.count.should == 5
72           end
73
74           ExampleMethods.after(:suite) do
75             ExampleMethods.count.should == 6
76           end
77
78           @example_group = Class.new(ExampleGroup) do
79             it "should use ExampleMethods callbacks" do
80             end
81           end
82           @options.run_examples
83           ExampleMethods.count.should == 7
84         end
85
86         describe "run_with_description_capturing" do
87           before(:each) do
88             @example_group = Class.new(ExampleGroup) do end
89             @example = @example_group.new("foo", &(lambda { 2.should == 2 }))
90             @example.run_with_description_capturing
91           end
92
93           it "should provide the generated description" do
94             @example.instance_eval { @_matcher_description }.should == "should == 2"
95           end
96
97           it "should clear the global generated_description" do
98             Spec::Matchers.generated_description.should == nil
99           end
100         end
101       end
102
103       describe "#implementation_backtrace" do
104         it "returns the backtrace of where the implementation was defined" do
105           example_group = Class.new(ExampleGroup) do
106             it "should use ExampleMethods callbacks" do
107             end
108           end
109           example = example_group.examples.first
110           example.implementation_backtrace.join("\n").should include("#{__FILE__}:#{__LINE__-4}")
111         end
112       end
113
114       describe "#__full_description" do
115         it "should return the full description of the ExampleGroup and Example" do
116           example_group = Class.new(ExampleGroup).describe("An ExampleGroup") do
117             it "should do something" do
118             end
119           end
120           example = example_group.examples.first
121           example.__full_description.should == "An ExampleGroup should do something"
122         end
123       end
124     end
125   end
126 end