changelog shortlog tags changeset manifest revisions annotate raw

vendor/plugins/rspec/spec/spec/example/example_methods_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'
2
3module 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 @options = ::Spec::Runner::Options.new(StringIO.new, StringIO.new)
27 @options.formatters << mock("formatter", :null_object => true)
28 @options.backtrace_tweaker = mock("backtrace_tweaker", :null_object => true)
29 @reporter = FakeReporter.new(@options)
30 @options.reporter = @reporter
31
32 ExampleMethods.before_all_parts.should == []
33 ExampleMethods.before_each_parts.should == []
34 ExampleMethods.after_each_parts.should == []
35 ExampleMethods.after_all_parts.should == []
36 def ExampleMethods.count
37 @count ||= 0
38 @count = @count + 1
39 @count
40 end
41 end
42
43 after do
44 ExampleMethods.instance_variable_set("@before_all_parts", [])
45 ExampleMethods.instance_variable_set("@before_each_parts", [])
46 ExampleMethods.instance_variable_set("@after_each_parts", [])
47 ExampleMethods.instance_variable_set("@after_all_parts", [])
48 end
49
50 it "should pass before and after callbacks to all ExampleGroup subclasses" do
51 ExampleMethods.before(:all) do
52 ExampleMethods.count.should == 1
53 end
54
55 ExampleMethods.before(:each) do
56 ExampleMethods.count.should == 2
57 end
58
59 ExampleMethods.after(:each) do
60 ExampleMethods.count.should == 3
61 end
62
63 ExampleMethods.after(:all) do
64 ExampleMethods.count.should == 4
65 end
66
67 @example_group = Class.new(ExampleGroup) do
68 it "should use ExampleMethods callbacks" do
69 end
70 end
71 @example_group.run
72 ExampleMethods.count.should == 5
73 end
74
75 describe "run_with_description_capturing" do
76 before(:each) do
77 @example_group = Class.new(ExampleGroup) do end
78 @example = @example_group.new("foo", &(lambda { 2.should == 2 }))
79 @example.run_with_description_capturing
80 end
81
82 it "should provide the generated description" do
83 @example.instance_eval { @_matcher_description }.should == "should == 2"
84 end
85
86 it "should clear the global generated_description" do
87 Spec::Matchers.generated_description.should == nil
88 end
89 end
90 end
91
92 describe "#implementation_backtrace" do
93 it "returns the backtrace of where the implementation was defined" do
94 example_group = Class.new(ExampleGroup) do
95 it "should use ExampleMethods callbacks" do
96 end
97 end
98 example = example_group.examples.first
99 example.implementation_backtrace.join("\n").should include("#{__FILE__}:#{__LINE__-4}")
100 end
101 end
102 end
103 end
104end