rspec 1.1.8 → 1.1.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/History.txt +30 -3
- data/License.txt +22 -0
- data/Manifest.txt +3 -3
- data/README.txt +1 -25
- data/Rakefile +4 -2
- data/TODO.txt +5 -4
- data/bin/autospec +1 -1
- data/examples/pure/shared_example_group_example.rb +2 -2
- data/lib/autotest/rspec.rb +1 -1
- data/lib/spec.rb +5 -1
- data/lib/spec/example.rb +1 -1
- data/lib/spec/example/before_and_after_hooks.rb +93 -0
- data/lib/spec/example/configuration.rb +10 -1
- data/lib/spec/example/example_group.rb +2 -1
- data/lib/spec/example/example_group_factory.rb +18 -1
- data/lib/spec/example/example_group_methods.rb +45 -123
- data/lib/spec/example/example_methods.rb +9 -6
- data/lib/spec/example/shared_example_group.rb +6 -12
- data/lib/spec/extensions/main.rb +1 -1
- data/lib/spec/interop/test/unit/testcase.rb +1 -1
- data/lib/spec/mocks/error_generator.rb +1 -1
- data/lib/spec/mocks/message_expectation.rb +19 -4
- data/lib/spec/mocks/methods.rb +2 -2
- data/lib/spec/mocks/proxy.rb +4 -5
- data/lib/spec/runner.rb +3 -4
- data/lib/spec/runner/formatter/nested_text_formatter.rb +3 -3
- data/lib/spec/runner/option_parser.rb +23 -22
- data/lib/spec/version.rb +1 -1
- data/rspec.gemspec +19 -8
- data/spec/autotest/rspec_spec.rb +5 -1
- data/spec/spec/example/configuration_spec.rb +229 -215
- data/spec/spec/example/example_group_class_definition_spec.rb +9 -9
- data/spec/spec/example/example_group_factory_spec.rb +48 -27
- data/spec/spec/example/example_group_methods_spec.rb +436 -426
- data/spec/spec/example/example_group_spec.rb +459 -500
- data/spec/spec/example/example_methods_spec.rb +92 -86
- data/spec/spec/example/shared_example_group_spec.rb +219 -203
- data/spec/spec/extensions/main_spec.rb +23 -23
- data/spec/spec/interop/test/unit/resources/spec_with_options_hash.rb +13 -0
- data/spec/spec/interop/test/unit/spec_spec.rb +15 -8
- data/spec/spec/mocks/mock_spec.rb +12 -2
- data/spec/spec/mocks/nil_expectation_warning_spec.rb +0 -1
- data/spec/spec/mocks/partial_mock_spec.rb +10 -5
- data/spec/spec/package/bin_spec_spec.rb +8 -0
- data/spec/spec/runner/command_line_spec.rb +101 -100
- data/spec/spec/runner/drb_command_line_spec.rb +0 -2
- data/spec/spec/runner/formatter/html_formatter_spec.rb +1 -4
- data/spec/spec/runner/formatter/nested_text_formatter_spec.rb +230 -245
- data/spec/spec/runner/formatter/spec_mate_formatter_spec.rb +2 -3
- data/spec/spec/runner/formatter/specdoc_formatter_spec.rb +110 -109
- data/spec/spec/runner/option_parser_spec.rb +18 -6
- data/spec/spec_helper.rb +26 -5
- data/stories/mock_framework_integration/use_flexmock.story +1 -1
- metadata +38 -7
- data/lib/spec/example/module_inclusion_warnings.rb +0 -38
- data/spec/spec/example/example_group/described_module_spec.rb +0 -20
- data/spec/spec/example/example_group/warning_messages_spec.rb +0 -76
@@ -7,33 +7,33 @@ module Spec
|
|
7
7
|
attr_accessor :examples_ran
|
8
8
|
end
|
9
9
|
|
10
|
-
@@
|
11
|
-
CONSTANT = :
|
10
|
+
@@class_variable = :class_variable
|
11
|
+
CONSTANT = :constant
|
12
12
|
|
13
13
|
before do
|
14
|
-
@instance_variable = :
|
14
|
+
@instance_variable = :instance_variable
|
15
15
|
end
|
16
|
-
|
17
|
-
|
16
|
+
|
17
|
+
after(:all) do
|
18
18
|
self.class.examples_ran = true
|
19
19
|
end
|
20
20
|
|
21
21
|
it "should have access to instance variables" do
|
22
|
-
@instance_variable.should == :
|
22
|
+
@instance_variable.should == :instance_variable
|
23
23
|
end
|
24
24
|
|
25
25
|
it "should have access to class variables" do
|
26
|
-
@@
|
26
|
+
@@class_variable.should == :class_variable
|
27
27
|
end
|
28
28
|
|
29
29
|
it "should have access to constants" do
|
30
|
-
CONSTANT.should == :
|
30
|
+
CONSTANT.should == :constant
|
31
31
|
end
|
32
32
|
|
33
33
|
it "should have access to methods defined in the Example Group" do
|
34
34
|
a_method.should == 22
|
35
35
|
end
|
36
|
-
|
36
|
+
|
37
37
|
def a_method
|
38
38
|
22
|
39
39
|
end
|
@@ -6,34 +6,34 @@ module Spec
|
|
6
6
|
describe "#get" do
|
7
7
|
attr_reader :example_group
|
8
8
|
before do
|
9
|
-
@
|
10
|
-
ExampleGroupFactory.register(:registered_type, @
|
9
|
+
@example_group_class = Class.new(ExampleGroup)
|
10
|
+
ExampleGroupFactory.register(:registered_type, @example_group_class)
|
11
11
|
end
|
12
12
|
|
13
13
|
after do
|
14
14
|
ExampleGroupFactory.reset
|
15
15
|
end
|
16
16
|
|
17
|
-
it "should
|
17
|
+
it "should return the default ExampleGroup type for nil" do
|
18
18
|
ExampleGroupFactory.get(nil).should == ExampleGroup
|
19
19
|
end
|
20
20
|
|
21
|
-
it "should
|
21
|
+
it "should return the default ExampleGroup for an unregistered non-nil value" do
|
22
22
|
ExampleGroupFactory.get(:does_not_exist).should == ExampleGroup
|
23
23
|
end
|
24
24
|
|
25
|
-
it "should
|
26
|
-
ExampleGroupFactory.get(:registered_type).should == @
|
25
|
+
it "should return custom type if registered" do
|
26
|
+
ExampleGroupFactory.get(:registered_type).should == @example_group_class
|
27
27
|
end
|
28
28
|
|
29
|
-
it "should
|
30
|
-
ExampleGroupFactory.get(@
|
29
|
+
it "should return the actual type when that is what is submitted" do
|
30
|
+
ExampleGroupFactory.get(@example_group_class).should == @example_group_class
|
31
31
|
end
|
32
32
|
|
33
33
|
it "should get the custom type after setting the default" do
|
34
|
-
@
|
35
|
-
ExampleGroupFactory.default(@
|
36
|
-
ExampleGroupFactory.get(:registered_type).should == @
|
34
|
+
@alternate_example_group_class = Class.new(ExampleGroup)
|
35
|
+
ExampleGroupFactory.default(@alternate_example_group_class)
|
36
|
+
ExampleGroupFactory.get(:registered_type).should == @example_group_class
|
37
37
|
end
|
38
38
|
end
|
39
39
|
|
@@ -57,15 +57,8 @@ module Spec
|
|
57
57
|
example_group.superclass.should == Spec::Example::ExampleGroup
|
58
58
|
end
|
59
59
|
|
60
|
-
describe "
|
61
|
-
it "should create a Spec::Example::
|
62
|
-
example_group = Spec::Example::ExampleGroupFactory.create_example_group(
|
63
|
-
"example_group", :type => :default
|
64
|
-
) {}
|
65
|
-
example_group.superclass.should == Spec::Example::ExampleGroup
|
66
|
-
end
|
67
|
-
|
68
|
-
it "should create a Spec::Example::Example" do
|
60
|
+
describe "with :type => :default" do
|
61
|
+
it "should create a Spec::Example::ExampleGroup" do
|
69
62
|
example_group = Spec::Example::ExampleGroupFactory.create_example_group(
|
70
63
|
"example_group", :type => :default
|
71
64
|
) {}
|
@@ -73,8 +66,8 @@ module Spec
|
|
73
66
|
end
|
74
67
|
end
|
75
68
|
|
76
|
-
describe "
|
77
|
-
it "should create specified type" do
|
69
|
+
describe "with :type => :something_other_than_default" do
|
70
|
+
it "should create the specified type" do
|
78
71
|
Spec::Example::ExampleGroupFactory.register(:something_other_than_default, parent_example_group)
|
79
72
|
non_default_example_group = Spec::Example::ExampleGroupFactory.create_example_group(
|
80
73
|
"example_group", :type => :something_other_than_default
|
@@ -100,15 +93,14 @@ module Spec
|
|
100
93
|
custom_example_group.superclass.should == parent_example_group
|
101
94
|
end
|
102
95
|
|
103
|
-
describe "
|
104
|
-
|
105
|
-
|
106
|
-
@shared_example_group = Spec::Example::ExampleGroupFactory.create_example_group(
|
96
|
+
describe "with :shared => true" do
|
97
|
+
def shared_example_group
|
98
|
+
@shared_example_group ||= Spec::Example::ExampleGroupFactory.create_example_group(
|
107
99
|
"name", :spec_path => '/blah/spec/models/blah.rb', :type => :controller, :shared => true
|
108
100
|
) {}
|
109
101
|
end
|
110
102
|
|
111
|
-
it "should create and register a Spec::Example::
|
103
|
+
it "should create and register a Spec::Example::SharedExampleGroup" do
|
112
104
|
shared_example_group.should be_an_instance_of(Spec::Example::SharedExampleGroup)
|
113
105
|
SharedExampleGroup.shared_example_groups.should include(shared_example_group)
|
114
106
|
end
|
@@ -139,6 +131,35 @@ module Spec
|
|
139
131
|
Spec::Example::ExampleGroupFactory.reset
|
140
132
|
end
|
141
133
|
end
|
134
|
+
|
135
|
+
describe "#all_registered?" do
|
136
|
+
before(:each) do
|
137
|
+
@unregistered_parent = Class.new(ExampleGroup)
|
138
|
+
@registered_child = Class.new(@unregistered_parent)
|
139
|
+
@unregistered_grandchild = Class.new(@registered_child)
|
140
|
+
Spec::Example::ExampleGroupFactory.register :registered_child, @registered_child
|
141
|
+
end
|
142
|
+
|
143
|
+
it "should return true for empty list" do
|
144
|
+
Spec::Example::ExampleGroupFactory.all_registered?([]).should be_true
|
145
|
+
end
|
146
|
+
|
147
|
+
it "should return true for a registered example group class" do
|
148
|
+
Spec::Example::ExampleGroupFactory.all_registered?([@registered_child]).should be_true
|
149
|
+
end
|
150
|
+
|
151
|
+
it "should return true for an ancestor of a registered example_group_classes" do
|
152
|
+
Spec::Example::ExampleGroupFactory.all_registered?([@unregistered_parent]).should be_true
|
153
|
+
end
|
154
|
+
|
155
|
+
it "should return false for a subclass of a registered example_group_class" do
|
156
|
+
Spec::Example::ExampleGroupFactory.all_registered?([@unregistered_grandchild]).should be_false
|
157
|
+
end
|
158
|
+
|
159
|
+
after(:each) do
|
160
|
+
Spec::Example::ExampleGroupFactory.reset
|
161
|
+
end
|
162
|
+
end
|
142
163
|
end
|
143
164
|
end
|
144
165
|
end
|
@@ -3,569 +3,579 @@ require File.dirname(__FILE__) + '/../../spec_helper'
|
|
3
3
|
module Spec
|
4
4
|
module Example
|
5
5
|
describe 'ExampleGroupMethods' do
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
6
|
+
with_sandboxed_options do
|
7
|
+
attr_reader :example_group, :result, :reporter
|
8
|
+
before(:each) do
|
9
|
+
# See http://rspec.lighthouseapp.com/projects/5645-rspec/tickets/525-arity-changed-on-partial-mocks#ticket-525-2
|
10
|
+
method_with_three_args = lambda { |arg1, arg2, arg3| }
|
11
|
+
options.formatters << mock("formatter", :null_object => true, :example_pending => method_with_three_args)
|
12
|
+
options.backtrace_tweaker = mock("backtrace_tweaker", :null_object => true)
|
13
|
+
@reporter = FakeReporter.new(@options)
|
14
|
+
options.reporter = reporter
|
15
|
+
@example_group = Class.new(ExampleGroup) do
|
16
|
+
describe("ExampleGroup")
|
17
|
+
it "does nothing"
|
18
|
+
end
|
19
|
+
class << example_group
|
20
|
+
public :include
|
21
|
+
end
|
22
|
+
@result = nil
|
21
23
|
end
|
22
|
-
@result = nil
|
23
|
-
end
|
24
24
|
|
25
|
-
|
26
|
-
|
27
|
-
|
25
|
+
after(:each) do
|
26
|
+
ExampleGroup.reset
|
27
|
+
end
|
28
28
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
29
|
+
["describe","context"].each do |method|
|
30
|
+
describe "##{method}" do
|
31
|
+
describe "when creating an ExampleGroup" do
|
32
|
+
attr_reader :child_example_group
|
33
|
+
before do
|
34
|
+
@child_example_group = @example_group.send method, "Another ExampleGroup" do
|
35
|
+
it "should pass" do
|
36
|
+
true.should be_true
|
37
|
+
end
|
37
38
|
end
|
38
39
|
end
|
39
|
-
end
|
40
40
|
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
41
|
+
it "should create a subclass of the ExampleGroup when passed a block" do
|
42
|
+
child_example_group.superclass.should == @example_group
|
43
|
+
@options.example_groups.should include(child_example_group)
|
44
|
+
end
|
45
45
|
|
46
|
-
|
47
|
-
|
46
|
+
it "should not inherit examples" do
|
47
|
+
child_example_group.examples.length.should == 1
|
48
|
+
end
|
48
49
|
end
|
49
|
-
end
|
50
50
|
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
51
|
+
describe "when creating a SharedExampleGroup" do
|
52
|
+
attr_reader :name, :shared_example_group
|
53
|
+
before do
|
54
|
+
@name = "A Shared ExampleGroup"
|
55
|
+
@shared_example_group = @example_group.send method, name, :shared => true do
|
56
|
+
it "should pass" do
|
57
|
+
true.should be_true
|
58
|
+
end
|
58
59
|
end
|
59
60
|
end
|
60
|
-
end
|
61
61
|
|
62
|
-
|
63
|
-
|
64
|
-
|
62
|
+
after do
|
63
|
+
SharedExampleGroup.shared_example_groups.delete_if do |registered_shared_example_group|
|
64
|
+
registered_shared_example_group == shared_example_group
|
65
|
+
end
|
65
66
|
end
|
66
|
-
end
|
67
67
|
|
68
|
-
|
69
|
-
|
68
|
+
it "should create a SharedExampleGroup" do
|
69
|
+
SharedExampleGroup.find_shared_example_group(name).should == shared_example_group
|
70
|
+
end
|
70
71
|
end
|
71
|
-
end
|
72
72
|
|
73
|
+
end
|
73
74
|
end
|
74
|
-
end
|
75
75
|
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
76
|
+
describe "#it" do
|
77
|
+
it "should should create an example instance" do
|
78
|
+
lambda {
|
79
|
+
@example_group.it("")
|
80
|
+
}.should change { @example_group.examples.length }.by(1)
|
81
|
+
end
|
81
82
|
end
|
82
|
-
end
|
83
83
|
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
84
|
+
describe "#xit and #xspecify" do
|
85
|
+
before(:each) do
|
86
|
+
Kernel.stub!(:warn)
|
87
|
+
end
|
88
88
|
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
89
|
+
it "should NOT create an example instance" do
|
90
|
+
lambda {
|
91
|
+
@example_group.xit("")
|
92
|
+
}.should_not change(@example_group.examples, :length)
|
93
93
|
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
94
|
+
lambda {
|
95
|
+
@example_group.xspecify("")
|
96
|
+
}.should_not change(@example_group.examples, :length)
|
97
|
+
end
|
98
98
|
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
99
|
+
it "should warn that it is disabled" do
|
100
|
+
Kernel.should_receive(:warn).with("Example disabled: foo").twice
|
101
|
+
@example_group.xit("foo")
|
102
|
+
@example_group.xspecify("foo")
|
103
|
+
end
|
103
104
|
end
|
104
|
-
end
|
105
105
|
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
106
|
+
describe "#examples" do
|
107
|
+
it "should have Examples" do
|
108
|
+
example_group = Class.new(ExampleGroup) do
|
109
|
+
describe('example')
|
110
|
+
it "should pass" do
|
111
|
+
1.should == 1
|
112
|
+
end
|
112
113
|
end
|
114
|
+
example_group.examples.length.should == 1
|
115
|
+
example_group.examples.first.description.should == "should pass"
|
113
116
|
end
|
114
|
-
example_group.examples.length.should == 1
|
115
|
-
example_group.examples.first.description.should == "should pass"
|
116
|
-
end
|
117
117
|
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
118
|
+
it "should not include methods that begin with test (only when TU interop is loaded)" do
|
119
|
+
example_group = Class.new(ExampleGroup) do
|
120
|
+
describe('example')
|
121
|
+
def test_any_args(*args)
|
122
|
+
true.should be_true
|
123
|
+
end
|
124
|
+
def test_something
|
125
|
+
1.should == 1
|
126
|
+
end
|
127
|
+
def test
|
128
|
+
raise "This is not a real test"
|
129
|
+
end
|
130
|
+
def testify
|
131
|
+
raise "This is not a real test"
|
132
|
+
end
|
133
|
+
def should_something
|
134
|
+
# forces the run
|
135
|
+
end
|
135
136
|
end
|
137
|
+
example_group.examples.length.should == 1
|
138
|
+
example_group.run.should be_true
|
136
139
|
end
|
137
|
-
example_group.examples.length.should == 1
|
138
|
-
example_group.run.should be_true
|
139
|
-
end
|
140
140
|
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
141
|
+
it "should include methods that begin with should and has an arity of 0 in suite" do
|
142
|
+
example_group = Class.new(ExampleGroup) do
|
143
|
+
describe('example')
|
144
|
+
def shouldCamelCase
|
145
|
+
true.should be_true
|
146
|
+
end
|
147
|
+
def should_any_args(*args)
|
148
|
+
true.should be_true
|
149
|
+
end
|
150
|
+
def should_something
|
151
|
+
1.should == 1
|
152
|
+
end
|
153
|
+
def should_not_something
|
154
|
+
1.should_not == 2
|
155
|
+
end
|
156
|
+
def should
|
157
|
+
raise "This is not a real example"
|
158
|
+
end
|
159
|
+
def should_not
|
160
|
+
raise "This is not a real example"
|
161
|
+
end
|
158
162
|
end
|
159
|
-
|
160
|
-
|
163
|
+
example_group = example_group.dup
|
164
|
+
example_group.examples.length.should == 4
|
165
|
+
descriptions = example_group.examples.collect {|example| example.description}.sort
|
166
|
+
descriptions.should include("shouldCamelCase")
|
167
|
+
descriptions.should include("should_any_args")
|
168
|
+
descriptions.should include("should_something")
|
169
|
+
descriptions.should include("should_not_something")
|
170
|
+
descriptions.should_not include("should")
|
171
|
+
descriptions.should_not include("should_not")
|
172
|
+
end
|
173
|
+
|
174
|
+
it "should not include methods that begin with test_ and has an arity > 0 in suite" do
|
175
|
+
example_group = Class.new(ExampleGroup) do
|
176
|
+
describe('example')
|
177
|
+
def test_invalid(foo)
|
178
|
+
1.should == 1
|
179
|
+
end
|
180
|
+
def testInvalidCamelCase(foo)
|
181
|
+
1.should == 1
|
182
|
+
end
|
161
183
|
end
|
184
|
+
example_group.examples.length.should == 0
|
162
185
|
end
|
163
|
-
example_group = example_group.dup
|
164
|
-
example_group.examples.length.should == 4
|
165
|
-
descriptions = example_group.examples.collect {|example| example.description}.sort
|
166
|
-
descriptions.should include("shouldCamelCase")
|
167
|
-
descriptions.should include("should_any_args")
|
168
|
-
descriptions.should include("should_something")
|
169
|
-
descriptions.should include("should_not_something")
|
170
|
-
end
|
171
186
|
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
187
|
+
it "should not include methods that begin with should_ and has an arity > 0 in suite" do
|
188
|
+
example_group = Class.new(ExampleGroup) do
|
189
|
+
describe('example')
|
190
|
+
def should_invalid(foo)
|
191
|
+
1.should == 2
|
192
|
+
end
|
193
|
+
def shouldInvalidCamelCase(foo)
|
194
|
+
1.should == 3
|
195
|
+
end
|
196
|
+
def should_not_invalid(foo)
|
197
|
+
1.should == 4
|
198
|
+
end
|
199
|
+
def should_valid
|
200
|
+
1.should == 1
|
201
|
+
end
|
180
202
|
end
|
203
|
+
example_group.examples.length.should == 1
|
204
|
+
example_group.run.should be_true
|
181
205
|
end
|
182
|
-
example_group.examples.length.should == 0
|
183
|
-
end
|
184
206
|
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
end
|
191
|
-
def shouldInvalidCamelCase(foo)
|
192
|
-
1.should == 3
|
193
|
-
end
|
194
|
-
def should_not_invalid(foo)
|
195
|
-
1.should == 4
|
196
|
-
end
|
197
|
-
def should_valid
|
198
|
-
1.should == 1
|
207
|
+
it "should run should_methods" do
|
208
|
+
example_group = Class.new(ExampleGroup) do
|
209
|
+
def should_valid
|
210
|
+
1.should == 2
|
211
|
+
end
|
199
212
|
end
|
213
|
+
example_group.examples.length.should == 1
|
214
|
+
example_group.run.should be_false
|
200
215
|
end
|
201
|
-
example_group.examples.length.should == 1
|
202
|
-
example_group.run.should be_true
|
203
216
|
end
|
204
217
|
|
205
|
-
|
206
|
-
example_group
|
207
|
-
|
208
|
-
|
218
|
+
describe "#set_description" do
|
219
|
+
attr_reader :example_group
|
220
|
+
before do
|
221
|
+
class << example_group
|
222
|
+
public :set_description
|
209
223
|
end
|
210
224
|
end
|
211
|
-
example_group.examples.length.should == 1
|
212
|
-
example_group.run.should be_false
|
213
|
-
end
|
214
|
-
end
|
215
225
|
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
public :set_description
|
221
|
-
end
|
222
|
-
end
|
226
|
+
describe "#set_description(String)" do
|
227
|
+
before(:each) do
|
228
|
+
example_group.set_description("abc")
|
229
|
+
end
|
223
230
|
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
end
|
231
|
+
specify ".description should return the String passed into .set_description" do
|
232
|
+
example_group.description.should == "abc"
|
233
|
+
end
|
228
234
|
|
229
|
-
|
230
|
-
|
235
|
+
specify ".described_type should provide nil as its type" do
|
236
|
+
example_group.described_type.should be_nil
|
237
|
+
end
|
231
238
|
end
|
232
239
|
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
240
|
+
describe "#set_description(Type)" do
|
241
|
+
before(:each) do
|
242
|
+
example_group.set_description(ExampleGroup)
|
243
|
+
end
|
237
244
|
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
end
|
245
|
+
specify ".description should return a String representation of that type (fully qualified) as its name" do
|
246
|
+
example_group.description.should == "Spec::Example::ExampleGroup"
|
247
|
+
end
|
242
248
|
|
243
|
-
|
244
|
-
|
249
|
+
specify ".described_type should return the passed in type" do
|
250
|
+
example_group.described_type.should == Spec::Example::ExampleGroup
|
251
|
+
end
|
245
252
|
end
|
246
253
|
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
254
|
+
describe "#set_description(String, Type)" do
|
255
|
+
before(:each) do
|
256
|
+
example_group.set_description("behaving", ExampleGroup)
|
257
|
+
end
|
251
258
|
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
end
|
259
|
+
specify ".description should return String then space then Type" do
|
260
|
+
example_group.description.should == "behaving Spec::Example::ExampleGroup"
|
261
|
+
end
|
256
262
|
|
257
|
-
|
258
|
-
|
263
|
+
specify ".described_type should return the passed in type" do
|
264
|
+
example_group.described_type.should == Spec::Example::ExampleGroup
|
265
|
+
end
|
259
266
|
end
|
260
267
|
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
268
|
+
describe "#set_description(Type, String not starting with a space)" do
|
269
|
+
before(:each) do
|
270
|
+
example_group.set_description(ExampleGroup, "behaving")
|
271
|
+
end
|
265
272
|
|
266
|
-
|
267
|
-
|
268
|
-
|
273
|
+
specify ".description should return the Type then space then String" do
|
274
|
+
example_group.description.should == "Spec::Example::ExampleGroup behaving"
|
275
|
+
end
|
269
276
|
end
|
270
277
|
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
278
|
+
describe "#set_description(Type, String starting with .)" do
|
279
|
+
before(:each) do
|
280
|
+
example_group.set_description(ExampleGroup, ".behaving")
|
281
|
+
end
|
275
282
|
|
276
|
-
|
277
|
-
|
278
|
-
|
283
|
+
specify ".description should return the Type then String" do
|
284
|
+
example_group.description.should == "Spec::Example::ExampleGroup.behaving"
|
285
|
+
end
|
279
286
|
end
|
280
287
|
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
288
|
+
describe "#set_description(Type, String containing .)" do
|
289
|
+
before(:each) do
|
290
|
+
example_group.set_description(ExampleGroup, "calling a.b")
|
291
|
+
end
|
285
292
|
|
286
|
-
|
287
|
-
|
288
|
-
|
293
|
+
specify ".description should return the Type then space then String" do
|
294
|
+
example_group.description.should == "Spec::Example::ExampleGroup calling a.b"
|
295
|
+
end
|
289
296
|
end
|
290
297
|
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
298
|
+
describe "#set_description(Type, String starting with .)" do
|
299
|
+
before(:each) do
|
300
|
+
example_group.set_description(ExampleGroup, ".behaving")
|
301
|
+
end
|
295
302
|
|
296
|
-
|
297
|
-
|
298
|
-
|
303
|
+
specify "should return the Type then String" do
|
304
|
+
example_group.description.should == "Spec::Example::ExampleGroup.behaving"
|
305
|
+
end
|
299
306
|
end
|
300
307
|
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
308
|
+
describe "#set_description(Type, String containing .)" do
|
309
|
+
before(:each) do
|
310
|
+
example_group.set_description(ExampleGroup, "is #1")
|
311
|
+
end
|
305
312
|
|
306
|
-
|
307
|
-
|
308
|
-
|
313
|
+
specify ".description should return the Type then space then String" do
|
314
|
+
example_group.description.should == "Spec::Example::ExampleGroup is #1"
|
315
|
+
end
|
309
316
|
end
|
310
317
|
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
318
|
+
describe "#set_description(String, Type, String)" do
|
319
|
+
before(:each) do
|
320
|
+
example_group.set_description("A", Hash, "with one entry")
|
321
|
+
end
|
315
322
|
|
316
|
-
|
317
|
-
|
318
|
-
|
323
|
+
specify ".description should return the first String then space then Type then second String" do
|
324
|
+
example_group.description.should == "A Hash with one entry"
|
325
|
+
end
|
319
326
|
end
|
320
327
|
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
|
328
|
+
describe "#set_description(Hash representing options)" do
|
329
|
+
before(:each) do
|
330
|
+
example_group.set_description(:a => "b", :spec_path => "blah")
|
331
|
+
end
|
325
332
|
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
end
|
333
|
+
it ".spec_path should expand the passed in :spec_path option passed into the constructor" do
|
334
|
+
example_group.spec_path.should == File.expand_path("blah")
|
335
|
+
end
|
330
336
|
|
331
|
-
|
332
|
-
|
333
|
-
|
337
|
+
it ".description_options should return all the options passed in" do
|
338
|
+
example_group.description_options.should == {:a => "b", :spec_path => "blah"}
|
339
|
+
end
|
334
340
|
|
335
|
-
it ".description_options should return all the options passed in" do
|
336
|
-
example_group.description_options.should == {:a => "b", :spec_path => "blah"}
|
337
341
|
end
|
338
|
-
|
339
342
|
end
|
340
|
-
end
|
341
343
|
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
|
344
|
+
describe "#description" do
|
345
|
+
it "should return the same description instance for each call" do
|
346
|
+
example_group.description.should eql(example_group.description)
|
347
|
+
end
|
346
348
|
|
347
|
-
|
348
|
-
|
349
|
-
|
349
|
+
it "should not add a space when description_text begins with #" do
|
350
|
+
child_example_group = Class.new(example_group) do
|
351
|
+
describe("#foobar", "Does something")
|
352
|
+
end
|
353
|
+
child_example_group.description.should == "ExampleGroup#foobar Does something"
|
350
354
|
end
|
351
|
-
child_example_group.description.should == "ExampleGroup#foobar Does something"
|
352
|
-
end
|
353
355
|
|
354
|
-
|
355
|
-
|
356
|
-
|
356
|
+
it "should not add a space when description_text begins with ." do
|
357
|
+
child_example_group = Class.new(example_group) do
|
358
|
+
describe(".foobar", "Does something")
|
359
|
+
end
|
360
|
+
child_example_group.description.should == "ExampleGroup.foobar Does something"
|
357
361
|
end
|
358
|
-
child_example_group.description.should == "ExampleGroup.foobar Does something"
|
359
|
-
end
|
360
362
|
|
361
|
-
|
362
|
-
|
363
|
-
|
364
|
-
|
363
|
+
it "should return the class name if nil" do
|
364
|
+
example_group.set_description(nil)
|
365
|
+
example_group.description.should =~ /Class:/
|
366
|
+
end
|
365
367
|
|
366
|
-
|
367
|
-
|
368
|
-
|
368
|
+
it "should return the class name if nil" do
|
369
|
+
example_group.set_description("")
|
370
|
+
example_group.description.should =~ /Class:/
|
371
|
+
end
|
369
372
|
end
|
370
|
-
end
|
371
373
|
|
372
|
-
|
373
|
-
|
374
|
-
|
375
|
-
|
374
|
+
describe "#description_parts" do
|
375
|
+
it "should return an Array of the current class description args" do
|
376
|
+
example_group.description_parts.should == [example_group.description]
|
377
|
+
end
|
376
378
|
|
377
|
-
|
378
|
-
|
379
|
-
|
380
|
-
|
381
|
-
|
382
|
-
grand_child_example_group = Class.new(child_example_group)
|
383
|
-
grand_child_example_group.describe("GrandChild", ExampleGroup)
|
384
|
-
grand_child_example_group.description.should_not be_empty
|
385
|
-
|
386
|
-
grand_child_example_group.description_parts.should == [
|
387
|
-
"ExampleGroup",
|
388
|
-
"Child",
|
389
|
-
Spec::Example::ExampleGroup,
|
390
|
-
"GrandChild",
|
391
|
-
Spec::Example::ExampleGroup
|
392
|
-
]
|
393
|
-
end
|
394
|
-
end
|
379
|
+
it "should return an Array of the description args from each class in the hierarchy" do
|
380
|
+
child_example_group = Class.new(example_group)
|
381
|
+
child_example_group.describe("Child", ExampleGroup)
|
382
|
+
child_example_group.description.should_not be_empty
|
395
383
|
|
396
|
-
|
397
|
-
|
398
|
-
|
399
|
-
|
384
|
+
grand_child_example_group = Class.new(child_example_group)
|
385
|
+
grand_child_example_group.describe("GrandChild", ExampleGroup)
|
386
|
+
grand_child_example_group.description.should_not be_empty
|
387
|
+
|
388
|
+
grand_child_example_group.description_parts.should == [
|
389
|
+
"ExampleGroup",
|
390
|
+
"Child",
|
391
|
+
Spec::Example::ExampleGroup,
|
392
|
+
"GrandChild",
|
393
|
+
Spec::Example::ExampleGroup
|
394
|
+
]
|
400
395
|
end
|
401
|
-
child_example_group.described_type.should == Object
|
402
396
|
end
|
403
397
|
|
404
|
-
|
405
|
-
|
406
|
-
|
398
|
+
describe "#described_type" do
|
399
|
+
it "should return passed in type" do
|
400
|
+
child_example_group = Class.new(example_group) do
|
401
|
+
describe Object
|
402
|
+
end
|
403
|
+
child_example_group.described_type.should == Object
|
407
404
|
end
|
408
|
-
|
409
|
-
|
405
|
+
|
406
|
+
it "should return #described_type of superclass when no passed in type" do
|
407
|
+
parent_example_group = Class.new(ExampleGroup) do
|
408
|
+
describe Object, "#foobar"
|
409
|
+
end
|
410
|
+
child_example_group = Class.new(parent_example_group) do
|
411
|
+
describe "not a type"
|
412
|
+
end
|
413
|
+
child_example_group.described_type.should == Object
|
410
414
|
end
|
411
|
-
child_example_group.described_type.should == Object
|
412
415
|
end
|
413
|
-
end
|
414
416
|
|
415
|
-
|
416
|
-
|
417
|
-
|
418
|
-
|
419
|
-
|
420
|
-
|
421
|
-
|
422
|
-
|
423
|
-
|
424
|
-
|
425
|
-
|
426
|
-
|
427
|
-
|
417
|
+
describe "#remove_after" do
|
418
|
+
it "should unregister a given after(:each) block" do
|
419
|
+
after_all_ran = false
|
420
|
+
@example_group.it("example") {}
|
421
|
+
proc = Proc.new { after_all_ran = true }
|
422
|
+
ExampleGroup.after(:each, &proc)
|
423
|
+
@example_group.run
|
424
|
+
after_all_ran.should be_true
|
425
|
+
|
426
|
+
after_all_ran = false
|
427
|
+
ExampleGroup.remove_after(:each, &proc)
|
428
|
+
@example_group.run
|
429
|
+
after_all_ran.should be_false
|
430
|
+
end
|
428
431
|
end
|
429
|
-
end
|
430
432
|
|
431
|
-
|
432
|
-
|
433
|
-
|
434
|
-
|
435
|
-
|
436
|
-
|
437
|
-
|
438
|
-
|
433
|
+
describe "#include" do
|
434
|
+
it "should have accessible class methods from included module" do
|
435
|
+
mod1_method_called = false
|
436
|
+
mod1 = Module.new do
|
437
|
+
extend Spec::MetaClass
|
438
|
+
class_methods = Module.new do
|
439
|
+
define_method :mod1_method do
|
440
|
+
mod1_method_called = true
|
441
|
+
end
|
439
442
|
end
|
440
|
-
end
|
441
443
|
|
442
|
-
|
443
|
-
|
444
|
-
|
444
|
+
metaclass.class_eval do
|
445
|
+
define_method(:included) do |receiver|
|
446
|
+
receiver.extend class_methods
|
447
|
+
end
|
445
448
|
end
|
446
449
|
end
|
447
|
-
end
|
448
450
|
|
449
|
-
|
450
|
-
|
451
|
-
|
452
|
-
|
453
|
-
|
454
|
-
|
451
|
+
mod2_method_called = false
|
452
|
+
mod2 = Module.new do
|
453
|
+
extend Spec::MetaClass
|
454
|
+
class_methods = Module.new do
|
455
|
+
define_method :mod2_method do
|
456
|
+
mod2_method_called = true
|
457
|
+
end
|
455
458
|
end
|
456
|
-
end
|
457
459
|
|
458
|
-
|
459
|
-
|
460
|
-
|
460
|
+
metaclass.class_eval do
|
461
|
+
define_method(:included) do |receiver|
|
462
|
+
receiver.extend class_methods
|
463
|
+
end
|
461
464
|
end
|
462
465
|
end
|
463
|
-
end
|
464
466
|
|
465
|
-
|
467
|
+
@example_group.include mod1, mod2
|
466
468
|
|
467
|
-
|
468
|
-
|
469
|
-
|
470
|
-
|
469
|
+
@example_group.mod1_method
|
470
|
+
@example_group.mod2_method
|
471
|
+
mod1_method_called.should be_true
|
472
|
+
mod2_method_called.should be_true
|
473
|
+
end
|
471
474
|
end
|
472
|
-
end
|
473
475
|
|
474
|
-
|
475
|
-
|
476
|
-
|
477
|
-
|
478
|
-
|
479
|
-
|
480
|
-
|
481
|
-
|
476
|
+
describe "#number_of_examples" do
|
477
|
+
it "should count number of specs" do
|
478
|
+
proc do
|
479
|
+
@example_group.it("one") {}
|
480
|
+
@example_group.it("two") {}
|
481
|
+
@example_group.it("three") {}
|
482
|
+
@example_group.it("four") {}
|
483
|
+
end.should change {@example_group.number_of_examples}.by(4)
|
484
|
+
end
|
482
485
|
end
|
483
|
-
end
|
484
486
|
|
485
|
-
|
486
|
-
|
487
|
-
|
488
|
-
|
489
|
-
|
490
|
-
|
491
|
-
|
487
|
+
describe "#class_eval" do
|
488
|
+
it "should allow constants to be defined" do
|
489
|
+
example_group = Class.new(ExampleGroup) do
|
490
|
+
describe('example')
|
491
|
+
FOO = 1
|
492
|
+
it "should reference FOO" do
|
493
|
+
FOO.should == 1
|
494
|
+
end
|
492
495
|
end
|
496
|
+
example_group.run
|
497
|
+
Object.const_defined?(:FOO).should == false
|
493
498
|
end
|
494
|
-
example_group.run
|
495
|
-
Object.const_defined?(:FOO).should == false
|
496
499
|
end
|
497
|
-
end
|
498
500
|
|
499
|
-
|
500
|
-
|
501
|
-
|
502
|
-
|
501
|
+
describe '#register' do
|
502
|
+
it "should add ExampleGroup to set of ExampleGroups to be run" do
|
503
|
+
options.example_groups.delete(example_group)
|
504
|
+
options.example_groups.should_not include(example_group)
|
503
505
|
|
504
|
-
|
505
|
-
|
506
|
+
example_group.register {}
|
507
|
+
options.example_groups.should include(example_group)
|
508
|
+
end
|
506
509
|
end
|
507
|
-
end
|
508
510
|
|
509
|
-
|
510
|
-
|
511
|
-
|
512
|
-
|
511
|
+
describe '#unregister' do
|
512
|
+
before do
|
513
|
+
options.example_groups.should include(example_group)
|
514
|
+
end
|
513
515
|
|
514
|
-
|
515
|
-
|
516
|
-
|
516
|
+
it "should remove ExampleGroup from set of ExampleGroups to be run" do
|
517
|
+
example_group.unregister
|
518
|
+
options.example_groups.should_not include(example_group)
|
519
|
+
end
|
517
520
|
end
|
518
|
-
end
|
519
521
|
|
520
|
-
|
521
|
-
|
522
|
-
|
523
|
-
|
522
|
+
describe "#registration_backtrace" do
|
523
|
+
it "returns the backtrace of where the ExampleGroup was registered" do
|
524
|
+
example_group = Class.new(ExampleGroup)
|
525
|
+
example_group.registration_backtrace.join("\n").should include("#{__FILE__}:#{__LINE__-1}")
|
526
|
+
end
|
524
527
|
end
|
525
|
-
end
|
526
528
|
|
527
|
-
|
528
|
-
|
529
|
-
|
530
|
-
|
529
|
+
describe "#run" do
|
530
|
+
it "should add_example_group if there are any examples to run" do
|
531
|
+
example_group = Class.new(ExampleGroup) do
|
532
|
+
it "should do something" do end
|
533
|
+
end
|
534
|
+
reporter.should_receive(:add_example_group)
|
535
|
+
example_group.run
|
531
536
|
end
|
532
|
-
reporter.should_receive(:add_example_group)
|
533
|
-
example_group.run
|
534
|
-
end
|
535
537
|
|
536
|
-
|
537
|
-
|
538
|
-
|
539
|
-
|
538
|
+
it "should NOT add_example_group if there are no examples to run" do
|
539
|
+
example_group = Class.new(ExampleGroup) do end
|
540
|
+
reporter.should_not_receive(:add_example_group)
|
541
|
+
example_group.run
|
542
|
+
end
|
540
543
|
end
|
541
|
-
end
|
542
544
|
|
543
|
-
|
544
|
-
|
545
|
-
|
546
|
-
|
547
|
-
|
548
|
-
|
549
|
-
|
550
|
-
|
551
|
-
|
552
|
-
|
545
|
+
describe "#matcher_class=" do
|
546
|
+
it "should call new and matches? on the class used for matching examples" do
|
547
|
+
example_group = Class.new(ExampleGroup) do
|
548
|
+
it "should do something" do end
|
549
|
+
class << self
|
550
|
+
def specified_examples
|
551
|
+
["something"]
|
552
|
+
end
|
553
|
+
def to_s
|
554
|
+
"TestMatcher"
|
555
|
+
end
|
553
556
|
end
|
554
557
|
end
|
555
|
-
end
|
556
558
|
|
557
|
-
|
558
|
-
|
559
|
+
matcher = mock("matcher")
|
560
|
+
matcher.should_receive(:matches?).with(["something"]).any_number_of_times
|
559
561
|
|
560
|
-
|
561
|
-
|
562
|
+
matcher_class = Class.new
|
563
|
+
matcher_class.should_receive(:new).with("TestMatcher", "should do something").twice.and_return(matcher)
|
562
564
|
|
563
|
-
|
564
|
-
|
565
|
+
begin
|
566
|
+
ExampleGroupMethods.matcher_class = matcher_class
|
565
567
|
|
566
|
-
|
567
|
-
|
568
|
-
|
568
|
+
example_group.run
|
569
|
+
ensure
|
570
|
+
ExampleGroupMethods.matcher_class = ExampleMatcher
|
571
|
+
end
|
572
|
+
end
|
573
|
+
end
|
574
|
+
|
575
|
+
describe "#options" do
|
576
|
+
it "should expose the options hash" do
|
577
|
+
group = describe("group", :this => 'hash') {}
|
578
|
+
group.options[:this].should == 'hash'
|
569
579
|
end
|
570
580
|
end
|
571
581
|
end
|