rspec-core 2.0.0.a1 → 2.0.0.a2
Sign up to get free protection for your applications and to get access to all the features.
- data/README.markdown +34 -3
- data/Rakefile +32 -17
- data/bin/rspec +5 -7
- data/cucumber.yml +3 -2
- data/features-pending/example_groups/example_group_with_should_methods.feature +3 -1
- data/features/before_and_after_blocks/around.feature +34 -0
- data/features/example_groups/describe_aliases.feature +20 -0
- data/{features-pending → features}/example_groups/nested_groups.feature +6 -8
- data/features/expectations/customized_message.feature +6 -6
- data/{features-pending → features}/matchers/define_matcher.feature +9 -9
- data/features/mock_framework_integration/use_rspec.feature +1 -1
- data/features/mocks/block_local_expectations.feature +68 -0
- data/{features-pending → features}/mocks/mix_stubs_and_mocks.feature +5 -1
- data/features/support/env.rb +6 -18
- data/lib/rspec/core.rb +5 -5
- data/lib/rspec/core/advice.rb +49 -0
- data/lib/rspec/core/command_line_options.rb +4 -11
- data/lib/rspec/core/configuration.rb +20 -32
- data/lib/rspec/core/example.rb +48 -15
- data/lib/rspec/core/example_group.rb +68 -93
- data/lib/rspec/core/extensions/instance_exec.rb +31 -0
- data/lib/rspec/core/kernel_extensions.rb +3 -1
- data/lib/rspec/core/load_path.rb +4 -0
- data/lib/rspec/core/metadata.rb +78 -0
- data/lib/rspec/core/rake_task.rb +3 -4
- data/lib/rspec/core/ruby_project.rb +30 -0
- data/lib/rspec/core/runner.rb +6 -7
- data/lib/rspec/core/version.rb +2 -2
- data/lib/rspec/core/world.rb +6 -4
- data/rspec-core.gemspec +33 -14
- data/spec/rspec/core/command_line_options_spec.rb +10 -10
- data/spec/rspec/core/configuration_spec.rb +26 -21
- data/spec/rspec/core/example_group_spec.rb +243 -173
- data/spec/rspec/core/example_group_subject_spec.rb +1 -1
- data/spec/rspec/core/example_spec.rb +12 -22
- data/spec/rspec/core/formatters/base_formatter_spec.rb +1 -1
- data/spec/rspec/core/formatters/documentation_formatter_spec.rb +1 -1
- data/spec/rspec/core/formatters/progress_formatter_spec.rb +4 -3
- data/spec/rspec/core/kernel_extensions_spec.rb +1 -1
- data/spec/rspec/core/metadata_spec.rb +101 -0
- data/spec/rspec/core/mocha_spec.rb +2 -2
- data/spec/rspec/core/runner_spec.rb +5 -5
- data/spec/rspec/core/shared_behaviour_spec.rb +5 -5
- data/spec/rspec/core/world_spec.rb +8 -8
- data/spec/rspec/core_spec.rb +1 -1
- data/spec/spec_helper.rb +15 -8
- data/specs.watchr +57 -0
- metadata +53 -15
- data/VERSION +0 -1
- data/VERSION.yml +0 -5
@@ -1,33 +1,38 @@
|
|
1
|
-
require '
|
1
|
+
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Rspec::Core::Configuration do
|
4
4
|
|
5
|
-
|
5
|
+
context "setting the mock framework" do
|
6
6
|
|
7
|
-
|
8
|
-
it "requires and includes the mocha adapter when the mock_framework is :mocha" do
|
7
|
+
it "requires and includes the rspec adapter when the mock_framework is :rspec" do
|
9
8
|
config = Rspec::Core::Configuration.new
|
10
|
-
config.
|
11
|
-
Rspec::Core::ExampleGroup.
|
12
|
-
config.mock_framework = :
|
9
|
+
config.should_receive(:require).with('rspec/core/mocking/with_rspec')
|
10
|
+
Rspec::Core::ExampleGroup.should_receive(:send)
|
11
|
+
config.mock_framework = :rspec
|
13
12
|
end
|
14
13
|
|
15
14
|
it "supports mock_with for backward compatibility with rspec-1.x" do
|
16
15
|
config = Rspec::Core::Configuration.new
|
17
|
-
config.
|
18
|
-
Rspec::Core::ExampleGroup.
|
19
|
-
config.mock_with :
|
16
|
+
config.stub!(:require)
|
17
|
+
Rspec::Core::ExampleGroup.stub!(:send)
|
18
|
+
config.mock_with :rspec
|
20
19
|
end
|
21
20
|
|
22
21
|
it "includes the null adapter when the mock_framework is not :rspec, :mocha, or :rr" do
|
23
22
|
config = Rspec::Core::Configuration.new
|
24
|
-
Rspec::Core::ExampleGroup.
|
23
|
+
Rspec::Core::ExampleGroup.should_receive(:send).with(:include, Rspec::Core::Mocking::WithAbsolutelyNothing)
|
25
24
|
config.mock_framework = :crazy_new_mocking_framework_ive_not_yet_heard_of
|
26
25
|
end
|
26
|
+
|
27
|
+
pending "includes the rspec adapter when the mock_framework is not set" do
|
28
|
+
config = Rspec::Core::Configuration.new
|
29
|
+
Rspec::Core::ExampleGroup.stub!(:send)
|
30
|
+
config.mock_framework.should == :rspec
|
31
|
+
end
|
27
32
|
|
28
33
|
end
|
29
34
|
|
30
|
-
|
35
|
+
context "setting the files to run" do
|
31
36
|
|
32
37
|
before do
|
33
38
|
@config = Rspec::Core::Configuration.new
|
@@ -35,7 +40,7 @@ describe Rspec::Core::Configuration do
|
|
35
40
|
|
36
41
|
it "should load files not following pattern if named explicitly" do
|
37
42
|
file = File.expand_path(File.dirname(__FILE__) + "/resources/a_bar.rb")
|
38
|
-
@config.
|
43
|
+
@config.files_or_directories_to_run = file
|
39
44
|
@config.files_to_run.should include(file)
|
40
45
|
end
|
41
46
|
|
@@ -43,7 +48,7 @@ describe Rspec::Core::Configuration do
|
|
43
48
|
|
44
49
|
it "should load files named _spec.rb" do
|
45
50
|
dir = File.expand_path(File.dirname(__FILE__) + "/resources/")
|
46
|
-
@config.
|
51
|
+
@config.files_or_directories_to_run = dir
|
47
52
|
@config.files_to_run.should == ["#{dir}/a_spec.rb"]
|
48
53
|
end
|
49
54
|
|
@@ -57,25 +62,25 @@ describe Rspec::Core::Configuration do
|
|
57
62
|
|
58
63
|
it "should load files following pattern" do
|
59
64
|
file = File.expand_path(File.dirname(__FILE__) + "/resources/a_foo.rb")
|
60
|
-
@config.
|
65
|
+
@config.files_or_directories_to_run = file
|
61
66
|
@config.files_to_run.should include(file)
|
62
67
|
end
|
63
68
|
|
64
69
|
it "should load files in directories following pattern" do
|
65
70
|
dir = File.expand_path(File.dirname(__FILE__) + "/resources")
|
66
|
-
@config.
|
71
|
+
@config.files_or_directories_to_run = dir
|
67
72
|
@config.files_to_run.should include("#{dir}/a_foo.rb")
|
68
73
|
end
|
69
74
|
|
70
75
|
it "should not load files in directories not following pattern" do
|
71
76
|
dir = File.expand_path(File.dirname(__FILE__) + "/resources")
|
72
|
-
@config.
|
77
|
+
@config.files_or_directories_to_run = dir
|
73
78
|
@config.files_to_run.should_not include("#{dir}/a_bar.rb")
|
74
79
|
end
|
75
80
|
|
76
81
|
end
|
77
82
|
|
78
|
-
|
83
|
+
context "with explicit pattern (comma,separated,values)" do
|
79
84
|
|
80
85
|
before do
|
81
86
|
@config.filename_pattern = "**/*_foo.rb,**/*_bar.rb"
|
@@ -83,14 +88,14 @@ describe Rspec::Core::Configuration do
|
|
83
88
|
|
84
89
|
it "should support comma separated values" do
|
85
90
|
dir = File.expand_path(File.dirname(__FILE__) + "/resources")
|
86
|
-
@config.
|
91
|
+
@config.files_or_directories_to_run = dir
|
87
92
|
@config.files_to_run.should include("#{dir}/a_foo.rb")
|
88
93
|
@config.files_to_run.should include("#{dir}/a_bar.rb")
|
89
94
|
end
|
90
95
|
|
91
96
|
it "should support comma separated values with spaces" do
|
92
97
|
dir = File.expand_path(File.dirname(__FILE__) + "/resources")
|
93
|
-
@config.
|
98
|
+
@config.files_or_directories_to_run = dir
|
94
99
|
@config.files_to_run.should include("#{dir}/a_foo.rb")
|
95
100
|
@config.files_to_run.should include("#{dir}/a_bar.rb")
|
96
101
|
end
|
@@ -110,7 +115,7 @@ describe Rspec::Core::Configuration do
|
|
110
115
|
it "should include the given module into each matching behaviour" do
|
111
116
|
Rspec::Core.configuration.include(InstanceLevelMethods, :magic_key => :include)
|
112
117
|
|
113
|
-
|
118
|
+
isolate_example_group do
|
114
119
|
group = Rspec::Core::ExampleGroup.describe(Object, 'does like, stuff and junk', :magic_key => :include) { }
|
115
120
|
group.should_not respond_to(:you_call_this_a_blt?)
|
116
121
|
group.new.you_call_this_a_blt?.should == "egad man, where's the mayo?!?!?"
|
@@ -1,6 +1,6 @@
|
|
1
|
-
require '
|
1
|
+
require 'spec_helper'
|
2
2
|
|
3
|
-
def
|
3
|
+
def empty_example_group(name='Empty ExampleGroup Group')
|
4
4
|
group = Rspec::Core::ExampleGroup.describe(Object, name) {}
|
5
5
|
remove_last_describe_from_world
|
6
6
|
yield group if block_given?
|
@@ -9,33 +9,36 @@ end
|
|
9
9
|
|
10
10
|
describe Rspec::Core::ExampleGroup do
|
11
11
|
|
12
|
-
describe "
|
13
|
-
|
14
|
-
|
12
|
+
describe "#describe" do
|
13
|
+
|
14
|
+
it "raises an ArgumentError if no type or description is given" do
|
15
15
|
lambda { Rspec::Core::ExampleGroup.describe() {} }.should raise_error(ArgumentError, "No arguments given. You must a least supply a type or description")
|
16
16
|
end
|
17
17
|
|
18
|
-
|
18
|
+
it "raises an ArgumentError if no block is given" do
|
19
19
|
lambda { Rspec::Core::ExampleGroup.describe('foo') }.should raise_error(ArgumentError, "You must supply a block when calling describe")
|
20
20
|
end
|
21
21
|
|
22
|
-
|
22
|
+
end
|
23
23
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
24
|
+
describe '#name' do
|
25
|
+
|
26
|
+
it "uses the first parameter as name" do
|
27
|
+
isolate_example_group do
|
28
|
+
Rspec::Core::ExampleGroup.describe("my favorite pony") { }.name.should == 'my favorite pony'
|
28
29
|
end
|
30
|
+
end
|
29
31
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
end
|
32
|
+
it "accepts a constant as the first parameter" do
|
33
|
+
isolate_example_group do
|
34
|
+
Rspec::Core::ExampleGroup.describe(Object) { }.name.should == 'Object'
|
34
35
|
end
|
36
|
+
end
|
35
37
|
|
36
|
-
|
38
|
+
it "concats nested names" do
|
39
|
+
isolate_example_group do
|
37
40
|
behaviour_to_test = nil
|
38
|
-
group =
|
41
|
+
group = empty_example_group('test')
|
39
42
|
group.name.should == 'Object test'
|
40
43
|
|
41
44
|
nested_group_one = group.describe('nested one') { }
|
@@ -44,229 +47,243 @@ describe Rspec::Core::ExampleGroup do
|
|
44
47
|
nested_group_two = nested_group_one.describe('nested two') { }
|
45
48
|
nested_group_two.name.should == 'Object test nested one nested two'
|
46
49
|
end
|
47
|
-
|
48
50
|
end
|
49
51
|
|
50
|
-
|
52
|
+
end
|
53
|
+
|
54
|
+
describe '#describes' do
|
55
|
+
|
56
|
+
context "with a constant as the first parameter" do
|
51
57
|
|
52
|
-
it "
|
53
|
-
|
58
|
+
it "is that constant" do
|
59
|
+
isolate_example_group do
|
54
60
|
Rspec::Core::ExampleGroup.describe(Object) { }.describes.should == Object
|
55
61
|
end
|
56
62
|
end
|
57
63
|
|
58
|
-
|
59
|
-
|
64
|
+
end
|
65
|
+
|
66
|
+
context "with a string as the first parameter" do
|
67
|
+
|
68
|
+
it "is nil" do
|
69
|
+
isolate_example_group do
|
60
70
|
Rspec::Core::ExampleGroup.describe("i'm a computer") { }.describes.should be_nil
|
61
71
|
end
|
62
72
|
end
|
63
73
|
|
64
74
|
end
|
65
75
|
|
66
|
-
|
76
|
+
end
|
67
77
|
|
68
|
-
|
69
|
-
isolate_behaviour do
|
70
|
-
Rspec::Core::ExampleGroup.describe(Object, "my desc") { }.description.should == 'my desc'
|
71
|
-
end
|
72
|
-
end
|
78
|
+
describe '#description' do
|
73
79
|
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
end
|
80
|
+
it "exposes the second parameter as description" do
|
81
|
+
isolate_example_group do
|
82
|
+
Rspec::Core::ExampleGroup.describe(Object, "my desc") { }.description.should == 'my desc'
|
78
83
|
end
|
84
|
+
end
|
79
85
|
|
86
|
+
it "allows the second parameter to be nil" do
|
87
|
+
isolate_example_group do
|
88
|
+
Rspec::Core::ExampleGroup.describe(Object, nil) { }.description.size.should == 0
|
89
|
+
end
|
80
90
|
end
|
81
91
|
|
82
|
-
|
92
|
+
end
|
83
93
|
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
94
|
+
describe '#metadata' do
|
95
|
+
|
96
|
+
it "adds the third parameter to the metadata" do
|
97
|
+
isolate_example_group do
|
98
|
+
Rspec::Core::ExampleGroup.describe(Object, nil, 'foo' => 'bar') { }.metadata.should include({ "foo" => 'bar' })
|
88
99
|
end
|
100
|
+
end
|
89
101
|
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
102
|
+
it "adds the caller to metadata" do
|
103
|
+
isolate_example_group do
|
104
|
+
Rspec::Core::ExampleGroup.describe(Object) { }.metadata[:behaviour][:caller].any? {|f|
|
105
|
+
f =~ /#{__FILE__}/
|
106
|
+
}.should be_true
|
94
107
|
end
|
108
|
+
end
|
95
109
|
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
end
|
110
|
+
it "adds the the file_path to metadata" do
|
111
|
+
isolate_example_group do
|
112
|
+
Rspec::Core::ExampleGroup.describe(Object) { }.metadata[:behaviour][:file_path].should == __FILE__
|
100
113
|
end
|
114
|
+
end
|
101
115
|
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
end
|
116
|
+
it "has a reader for file_path" do
|
117
|
+
isolate_example_group do
|
118
|
+
Rspec::Core::ExampleGroup.describe(Object) { }.file_path.should == __FILE__
|
106
119
|
end
|
120
|
+
end
|
107
121
|
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
end
|
122
|
+
it "adds the line_number to metadata" do
|
123
|
+
isolate_example_group do
|
124
|
+
Rspec::Core::ExampleGroup.describe(Object) { }.metadata[:behaviour][:line_number].should == __LINE__
|
112
125
|
end
|
126
|
+
end
|
113
127
|
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
end
|
128
|
+
it "adds file path and line number metadata for arbitrarily nested describes" do
|
129
|
+
Rspec::Core::ExampleGroup.describe(Object) do
|
130
|
+
Rspec::Core::ExampleGroup.describe("foo") do
|
131
|
+
Rspec::Core::ExampleGroup.describe(Object) { }.metadata[:behaviour][:file_path].should == __FILE__
|
132
|
+
Rspec::Core::ExampleGroup.describe(Object) { }.metadata[:behaviour][:line_number].should == __LINE__
|
120
133
|
end
|
121
|
-
|
122
|
-
4.times { remove_last_describe_from_world }
|
123
134
|
end
|
124
135
|
|
136
|
+
4.times { remove_last_describe_from_world }
|
125
137
|
end
|
126
138
|
|
127
|
-
|
139
|
+
end
|
128
140
|
|
129
|
-
|
130
|
-
group = empty_behaviour_group
|
131
|
-
group.before(:each) { 'foo' }
|
132
|
-
group.should have(1).before_eachs
|
133
|
-
end
|
141
|
+
describe "adding before, after, and around hooks" do
|
134
142
|
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
143
|
+
it "should expose the before each blocks at before_eachs" do
|
144
|
+
group = empty_example_group
|
145
|
+
group.before(:each) { 'foo' }
|
146
|
+
group.should have(1).before_eachs
|
147
|
+
end
|
140
148
|
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
149
|
+
it "should maintain the before each block order" do
|
150
|
+
group = empty_example_group
|
151
|
+
group.before(:each) { 15 }
|
152
|
+
group.before(:each) { 'A' }
|
153
|
+
group.before(:each) { 33.5 }
|
145
154
|
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
end
|
155
|
+
group.before_eachs[0].call.should == 15
|
156
|
+
group.before_eachs[1].call.should == 'A'
|
157
|
+
group.before_eachs[2].call.should == 33.5
|
158
|
+
end
|
151
159
|
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
160
|
+
it "should expose the before all blocks at before_alls" do
|
161
|
+
group = empty_example_group
|
162
|
+
group.before(:all) { 'foo' }
|
163
|
+
group.should have(1).before_alls
|
164
|
+
end
|
157
165
|
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
166
|
+
it "should maintain the before all block order" do
|
167
|
+
group = empty_example_group
|
168
|
+
group.before(:all) { 15 }
|
169
|
+
group.before(:all) { 'A' }
|
170
|
+
group.before(:all) { 33.5 }
|
162
171
|
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
end
|
172
|
+
group.before_alls[0].call.should == 15
|
173
|
+
group.before_alls[1].call.should == 'A'
|
174
|
+
group.before_alls[2].call.should == 33.5
|
175
|
+
end
|
168
176
|
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
177
|
+
it "should expose the after each blocks at after_eachs" do
|
178
|
+
group = empty_example_group
|
179
|
+
group.after(:each) { 'foo' }
|
180
|
+
group.should have(1).after_eachs
|
181
|
+
end
|
174
182
|
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
183
|
+
it "should maintain the after each block order" do
|
184
|
+
group = empty_example_group
|
185
|
+
group.after(:each) { 15 }
|
186
|
+
group.after(:each) { 'A' }
|
187
|
+
group.after(:each) { 33.5 }
|
179
188
|
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
end
|
189
|
+
group.after_eachs[0].call.should == 15
|
190
|
+
group.after_eachs[1].call.should == 'A'
|
191
|
+
group.after_eachs[2].call.should == 33.5
|
192
|
+
end
|
185
193
|
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
194
|
+
it "should expose the after all blocks at after_alls" do
|
195
|
+
group = empty_example_group
|
196
|
+
group.after(:all) { 'foo' }
|
197
|
+
group.should have(1).after_alls
|
198
|
+
end
|
191
199
|
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
200
|
+
it "should maintain the after each block order" do
|
201
|
+
group = empty_example_group
|
202
|
+
group.after(:all) { 15 }
|
203
|
+
group.after(:all) { 'A' }
|
204
|
+
group.after(:all) { 33.5 }
|
196
205
|
|
206
|
+
group.after_alls[0].call.should == 15
|
207
|
+
group.after_alls[1].call.should == 'A'
|
208
|
+
group.after_alls[2].call.should == 33.5
|
197
209
|
end
|
198
210
|
|
199
|
-
|
211
|
+
it "should expose the around each blocks at after_alls" do
|
212
|
+
group = empty_example_group
|
213
|
+
group.around(:each) { 'foo' }
|
214
|
+
group.should have(1).around_eachs
|
215
|
+
end
|
216
|
+
|
217
|
+
end
|
200
218
|
|
201
|
-
|
202
|
-
group = empty_behaviour_group
|
203
|
-
group.it("should do something") { }
|
204
|
-
group.examples.size.should == 1
|
205
|
-
end
|
219
|
+
describe "adding examples" do
|
206
220
|
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
group.examples.size.should == 3
|
213
|
-
end
|
221
|
+
it "should allow adding an example using 'it'" do
|
222
|
+
group = empty_example_group
|
223
|
+
group.it("should do something") { }
|
224
|
+
group.examples.size.should == 1
|
225
|
+
end
|
214
226
|
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
group.examples[2].description.should == 'should 3'
|
223
|
-
end
|
227
|
+
it "should expose all examples at examples" do
|
228
|
+
group = empty_example_group
|
229
|
+
group.it("should do something 1") { }
|
230
|
+
group.it("should do something 2") { }
|
231
|
+
group.it("should do something 3") { }
|
232
|
+
group.examples.size.should == 3
|
233
|
+
end
|
224
234
|
|
235
|
+
it "should maintain the example order" do
|
236
|
+
group = empty_example_group
|
237
|
+
group.it("should 1") { }
|
238
|
+
group.it("should 2") { }
|
239
|
+
group.it("should 3") { }
|
240
|
+
group.examples[0].description.should == 'should 1'
|
241
|
+
group.examples[1].description.should == 'should 2'
|
242
|
+
group.examples[2].description.should == 'should 3'
|
225
243
|
end
|
226
244
|
|
227
245
|
end
|
228
246
|
|
229
|
-
describe Object, "describing nested
|
247
|
+
describe Object, "describing nested example_groups", :little_less_nested => 'yep' do
|
230
248
|
|
231
|
-
describe "A sample nested
|
232
|
-
|
233
|
-
it "should set the described type to the constant Object" do
|
249
|
+
describe "A sample nested group", :nested_describe => "yep" do
|
250
|
+
it "sets the described class to the constant Object" do
|
234
251
|
running_example.behaviour.describes.should == Object
|
235
252
|
end
|
236
253
|
|
237
|
-
it "
|
238
|
-
running_example.behaviour.description.should == 'A sample nested
|
254
|
+
it "sets the description to 'A sample nested describe'" do
|
255
|
+
running_example.behaviour.description.should == 'A sample nested group'
|
239
256
|
end
|
240
257
|
|
241
|
-
it "
|
258
|
+
it "has top level metadata from the behaviour and its ancestors" do
|
242
259
|
running_example.behaviour.metadata.should include(:little_less_nested => 'yep', :nested_describe => 'yep')
|
243
260
|
end
|
244
261
|
|
245
|
-
it "
|
262
|
+
it "exposes the parent metadata to the contained examples" do
|
246
263
|
running_example.metadata.should include(:little_less_nested => 'yep', :nested_describe => 'yep')
|
247
264
|
end
|
248
|
-
|
249
265
|
end
|
250
266
|
|
251
267
|
end
|
252
268
|
|
253
269
|
describe "#run_examples" do
|
254
|
-
|
255
270
|
before do
|
256
271
|
@fake_formatter = Rspec::Core::Formatters::BaseFormatter.new
|
257
272
|
end
|
258
273
|
|
259
274
|
def stub_behaviour
|
260
|
-
|
275
|
+
behaviour = mock('behaviour', :null_object => true)
|
276
|
+
behaviour.stub!(:metadata).and_return(:metadata => { :behaviour => { :name => 'behaviour_name' }})
|
277
|
+
behaviour
|
261
278
|
end
|
262
279
|
|
263
280
|
it "should return true if all examples pass" do
|
264
281
|
use_formatter(@fake_formatter) do
|
265
282
|
passing_example1 = Rspec::Core::Example.new(stub_behaviour, 'description', {}, (lambda { 1.should == 1 }))
|
266
283
|
passing_example2 = Rspec::Core::Example.new(stub_behaviour, 'description', {}, (lambda { 1.should == 1 }))
|
267
|
-
Rspec::Core::ExampleGroup.
|
284
|
+
Rspec::Core::ExampleGroup.stub!(:examples_to_run).and_return([passing_example1, passing_example2])
|
268
285
|
|
269
|
-
Rspec::Core::ExampleGroup.run_examples(stub_behaviour,
|
286
|
+
Rspec::Core::ExampleGroup.run_examples(stub_behaviour, mock('reporter', :null_object => true)).should be_true
|
270
287
|
end
|
271
288
|
end
|
272
289
|
|
@@ -274,9 +291,9 @@ describe Rspec::Core::ExampleGroup do
|
|
274
291
|
use_formatter(@fake_formatter) do
|
275
292
|
failing_example = Rspec::Core::Example.new(stub_behaviour, 'description', {}, (lambda { 1.should == 2 }))
|
276
293
|
passing_example = Rspec::Core::Example.new(stub_behaviour, 'description', {}, (lambda { 1.should == 1 }))
|
277
|
-
Rspec::Core::ExampleGroup.
|
294
|
+
Rspec::Core::ExampleGroup.stub!(:examples_to_run).and_return([failing_example, passing_example])
|
278
295
|
|
279
|
-
Rspec::Core::ExampleGroup.run_examples(stub_behaviour,
|
296
|
+
Rspec::Core::ExampleGroup.run_examples(stub_behaviour, mock('reporter', :null_object => true)).should be_false
|
280
297
|
end
|
281
298
|
end
|
282
299
|
|
@@ -284,18 +301,17 @@ describe Rspec::Core::ExampleGroup do
|
|
284
301
|
use_formatter(@fake_formatter) do
|
285
302
|
failing_example = Rspec::Core::Example.new(stub_behaviour, 'description', {}, (lambda { 1.should == 2 }))
|
286
303
|
passing_example = Rspec::Core::Example.new(stub_behaviour, 'description', {}, (lambda { 1.should == 1 }))
|
287
|
-
Rspec::Core::ExampleGroup.
|
304
|
+
Rspec::Core::ExampleGroup.stub!(:examples_to_run).and_return([failing_example, passing_example])
|
288
305
|
|
289
|
-
passing_example.
|
306
|
+
passing_example.should_receive(:run)
|
290
307
|
|
291
|
-
Rspec::Core::ExampleGroup.run_examples(stub_behaviour,
|
308
|
+
Rspec::Core::ExampleGroup.run_examples(stub_behaviour, mock('reporter', :null_object => true))
|
292
309
|
end
|
293
310
|
end
|
294
311
|
|
295
312
|
end
|
296
|
-
|
313
|
+
|
297
314
|
describe "how instance variables inherit" do
|
298
|
-
|
299
315
|
before(:all) do
|
300
316
|
@before_all_top_level = 'before_all_top_level'
|
301
317
|
end
|
@@ -303,16 +319,15 @@ describe Rspec::Core::ExampleGroup do
|
|
303
319
|
before(:each) do
|
304
320
|
@before_each_top_level = 'before_each_top_level'
|
305
321
|
end
|
306
|
-
|
322
|
+
|
307
323
|
it "should be able to access a before each ivar at the same level" do
|
308
324
|
@before_each_top_level.should == 'before_each_top_level'
|
309
325
|
end
|
310
|
-
|
326
|
+
|
311
327
|
it "should be able to access a before all ivar at the same level" do
|
312
328
|
@before_all_top_level.should == 'before_all_top_level'
|
313
329
|
end
|
314
330
|
|
315
|
-
|
316
331
|
it "should be able to access the before all ivars in the before_all_ivars hash" do
|
317
332
|
with_ruby('1.8') do
|
318
333
|
running_example.behaviour.before_all_ivars.should include('@before_all_top_level' => 'before_all_top_level')
|
@@ -321,13 +336,12 @@ describe Rspec::Core::ExampleGroup do
|
|
321
336
|
running_example.behaviour.before_all_ivars.should include(:@before_all_top_level => 'before_all_top_level')
|
322
337
|
end
|
323
338
|
end
|
324
|
-
|
339
|
+
|
325
340
|
describe "but now I am nested" do
|
326
|
-
|
327
341
|
it "should be able to access a parent behaviours before each ivar at a nested level" do
|
328
342
|
@before_each_top_level.should == 'before_each_top_level'
|
329
343
|
end
|
330
|
-
|
344
|
+
|
331
345
|
it "should be able to access a parent behaviours before all ivar at a nested level" do
|
332
346
|
@before_all_top_level.should == "before_all_top_level"
|
333
347
|
end
|
@@ -337,15 +351,71 @@ describe Rspec::Core::ExampleGroup do
|
|
337
351
|
end
|
338
352
|
|
339
353
|
describe "accessing a before_all ivar that was changed in a parent behaviour" do
|
340
|
-
|
341
|
-
|
342
|
-
@before_all_top_level.should == 'ive been changed'
|
354
|
+
it "does not have access to the modified version" do
|
355
|
+
@before_all_top_level.should == 'before_all_top_level'
|
343
356
|
end
|
344
|
-
|
345
357
|
end
|
346
|
-
|
347
358
|
end
|
348
|
-
|
359
|
+
|
349
360
|
end
|
350
361
|
|
362
|
+
describe "ivars are not shared across examples" do
|
363
|
+
it "(first example)" do
|
364
|
+
@a = 1
|
365
|
+
@b.should be_nil
|
366
|
+
end
|
367
|
+
|
368
|
+
it "(second example)" do
|
369
|
+
@b = 2
|
370
|
+
@a.should be_nil
|
371
|
+
end
|
372
|
+
end
|
373
|
+
|
374
|
+
describe "#let" do
|
375
|
+
let(:counter) do
|
376
|
+
Class.new do
|
377
|
+
def initialize
|
378
|
+
@count = 0
|
379
|
+
end
|
380
|
+
def count
|
381
|
+
@count += 1
|
382
|
+
end
|
383
|
+
end.new
|
384
|
+
end
|
385
|
+
|
386
|
+
it "generates an instance method" do
|
387
|
+
counter.count.should == 1
|
388
|
+
end
|
389
|
+
|
390
|
+
it "caches the value" do
|
391
|
+
counter.count.should == 1
|
392
|
+
counter.count.should == 2
|
393
|
+
end
|
394
|
+
end
|
395
|
+
|
396
|
+
describe "#around" do
|
397
|
+
class Thing
|
398
|
+
def self.cache
|
399
|
+
@cache ||= []
|
400
|
+
end
|
401
|
+
|
402
|
+
def initialize
|
403
|
+
self.class.cache << self
|
404
|
+
end
|
405
|
+
end
|
406
|
+
|
407
|
+
around(:each) do |example|
|
408
|
+
Thing.new
|
409
|
+
example.run
|
410
|
+
Thing.cache.clear
|
411
|
+
end
|
412
|
+
|
413
|
+
it "has 1 Thing (1)" do
|
414
|
+
Thing.cache.length.should == 1
|
415
|
+
end
|
416
|
+
|
417
|
+
it "has 1 Thing (2)" do
|
418
|
+
Thing.cache.length.should == 1
|
419
|
+
end
|
420
|
+
end
|
351
421
|
end
|