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.
Files changed (50) hide show
  1. data/README.markdown +34 -3
  2. data/Rakefile +32 -17
  3. data/bin/rspec +5 -7
  4. data/cucumber.yml +3 -2
  5. data/features-pending/example_groups/example_group_with_should_methods.feature +3 -1
  6. data/features/before_and_after_blocks/around.feature +34 -0
  7. data/features/example_groups/describe_aliases.feature +20 -0
  8. data/{features-pending → features}/example_groups/nested_groups.feature +6 -8
  9. data/features/expectations/customized_message.feature +6 -6
  10. data/{features-pending → features}/matchers/define_matcher.feature +9 -9
  11. data/features/mock_framework_integration/use_rspec.feature +1 -1
  12. data/features/mocks/block_local_expectations.feature +68 -0
  13. data/{features-pending → features}/mocks/mix_stubs_and_mocks.feature +5 -1
  14. data/features/support/env.rb +6 -18
  15. data/lib/rspec/core.rb +5 -5
  16. data/lib/rspec/core/advice.rb +49 -0
  17. data/lib/rspec/core/command_line_options.rb +4 -11
  18. data/lib/rspec/core/configuration.rb +20 -32
  19. data/lib/rspec/core/example.rb +48 -15
  20. data/lib/rspec/core/example_group.rb +68 -93
  21. data/lib/rspec/core/extensions/instance_exec.rb +31 -0
  22. data/lib/rspec/core/kernel_extensions.rb +3 -1
  23. data/lib/rspec/core/load_path.rb +4 -0
  24. data/lib/rspec/core/metadata.rb +78 -0
  25. data/lib/rspec/core/rake_task.rb +3 -4
  26. data/lib/rspec/core/ruby_project.rb +30 -0
  27. data/lib/rspec/core/runner.rb +6 -7
  28. data/lib/rspec/core/version.rb +2 -2
  29. data/lib/rspec/core/world.rb +6 -4
  30. data/rspec-core.gemspec +33 -14
  31. data/spec/rspec/core/command_line_options_spec.rb +10 -10
  32. data/spec/rspec/core/configuration_spec.rb +26 -21
  33. data/spec/rspec/core/example_group_spec.rb +243 -173
  34. data/spec/rspec/core/example_group_subject_spec.rb +1 -1
  35. data/spec/rspec/core/example_spec.rb +12 -22
  36. data/spec/rspec/core/formatters/base_formatter_spec.rb +1 -1
  37. data/spec/rspec/core/formatters/documentation_formatter_spec.rb +1 -1
  38. data/spec/rspec/core/formatters/progress_formatter_spec.rb +4 -3
  39. data/spec/rspec/core/kernel_extensions_spec.rb +1 -1
  40. data/spec/rspec/core/metadata_spec.rb +101 -0
  41. data/spec/rspec/core/mocha_spec.rb +2 -2
  42. data/spec/rspec/core/runner_spec.rb +5 -5
  43. data/spec/rspec/core/shared_behaviour_spec.rb +5 -5
  44. data/spec/rspec/core/world_spec.rb +8 -8
  45. data/spec/rspec/core_spec.rb +1 -1
  46. data/spec/spec_helper.rb +15 -8
  47. data/specs.watchr +57 -0
  48. metadata +53 -15
  49. data/VERSION +0 -1
  50. data/VERSION.yml +0 -5
@@ -1,33 +1,38 @@
1
- require 'spec/spec_helper'
1
+ require 'spec_helper'
2
2
 
3
3
  describe Rspec::Core::Configuration do
4
4
 
5
- describe "setting the mock framework" do
5
+ context "setting the mock framework" do
6
6
 
7
- # TODO: Solution to test rr/rspec/flexmock, possibly cucumber
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.expects(:require).with('rspec/core/mocking/with_mocha')
11
- Rspec::Core::ExampleGroup.expects(:send)
12
- config.mock_framework = :mocha
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.expects(:require).with('rspec/core/mocking/with_mocha')
18
- Rspec::Core::ExampleGroup.expects(:send)
19
- config.mock_with :mocha
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.expects(:send).with(:include, Rspec::Core::Mocking::WithAbsolutelyNothing)
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
- describe "setting the files to run" do
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.files_to_run = file
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.files_to_run = dir
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.files_to_run = file
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.files_to_run = dir
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.files_to_run = dir
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
- describe "with explicit pattern (comma,separated,values)" do
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.files_to_run = dir
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.files_to_run = dir
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
- isolate_behaviour do
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 'spec/spec_helper'
1
+ require 'spec_helper'
2
2
 
3
- def empty_behaviour_group(name='Empty ExampleGroup Group')
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 "describing behaviour with #describe" do
13
-
14
- example "an ArgumentError is raised if no type or description is given" do
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
- example "an ArgumentError is raised if no block is given" do
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
- describe '#name' do
22
+ end
23
23
 
24
- it "should expose the first parameter as name" do
25
- isolate_behaviour do
26
- Rspec::Core::ExampleGroup.describe("my favorite pony") { }.name.should == 'my favorite pony'
27
- end
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
- it "should call to_s on the first parameter in case it is a constant" do
31
- isolate_behaviour do
32
- Rspec::Core::ExampleGroup.describe(Object) { }.name.should == 'Object'
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
- it "should be built correctly when nested" do
38
+ it "concats nested names" do
39
+ isolate_example_group do
37
40
  behaviour_to_test = nil
38
- group = empty_behaviour_group('test')
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
- describe '#describes' do
52
+ end
53
+
54
+ describe '#describes' do
55
+
56
+ context "with a constant as the first parameter" do
51
57
 
52
- it "should be the first parameter when it is a constant" do
53
- isolate_behaviour do
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
- it "should be nil when the first parameter is a string" do
59
- isolate_behaviour do
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
- describe '#description' do
76
+ end
67
77
 
68
- it "should expose the second parameter as description" do
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
- it "should allow the second parameter to be nil" do
75
- isolate_behaviour do
76
- Rspec::Core::ExampleGroup.describe(Object, nil) { }.description.size.should == 0
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
- describe '#metadata' do
92
+ end
83
93
 
84
- it "should add the third parameter to the metadata" do
85
- isolate_behaviour do
86
- Rspec::Core::ExampleGroup.describe(Object, nil, 'foo' => 'bar') { }.metadata.should include({ "foo" => 'bar' })
87
- end
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
- it "should add the caller to metadata" do
91
- isolate_behaviour do
92
- Rspec::Core::ExampleGroup.describe(Object) { }.metadata[:behaviour][:caller][4].should =~ /#{__FILE__}:#{__LINE__}/
93
- end
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
- it "should add the the file_path to metadata" do
97
- isolate_behaviour do
98
- Rspec::Core::ExampleGroup.describe(Object) { }.metadata[:behaviour][:file_path].should == __FILE__
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
- it "should have a reader for file_path" do
103
- isolate_behaviour do
104
- Rspec::Core::ExampleGroup.describe(Object) { }.file_path.should == __FILE__
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
- it "should add the line_number to metadata" do
109
- isolate_behaviour do
110
- Rspec::Core::ExampleGroup.describe(Object) { }.metadata[:behaviour][:line_number].should == __LINE__
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
- it "should add file path and line number metadata for arbitrarily nested describes" do
115
- Rspec::Core::ExampleGroup.describe(Object) do
116
- Rspec::Core::ExampleGroup.describe("foo") do
117
- Rspec::Core::ExampleGroup.describe(Object) { }.metadata[:behaviour][:file_path].should == __FILE__
118
- Rspec::Core::ExampleGroup.describe(Object) { }.metadata[:behaviour][:line_number].should == __LINE__
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
- describe "adding before and after hooks" do
139
+ end
128
140
 
129
- it "should expose the before each blocks at before_eachs" do
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
- it "should maintain the before each block order" do
136
- group = empty_behaviour_group
137
- group.before(:each) { 15 }
138
- group.before(:each) { 'A' }
139
- group.before(:each) { 33.5 }
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
- group.before_eachs[0].call.should == 15
142
- group.before_eachs[1].call.should == 'A'
143
- group.before_eachs[2].call.should == 33.5
144
- end
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
- it "should expose the before all blocks at before_alls" do
147
- group = empty_behaviour_group
148
- group.before(:all) { 'foo' }
149
- group.should have(1).before_alls
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
- it "should maintain the before all block order" do
153
- group = empty_behaviour_group
154
- group.before(:all) { 15 }
155
- group.before(:all) { 'A' }
156
- group.before(:all) { 33.5 }
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
- group.before_alls[0].call.should == 15
159
- group.before_alls[1].call.should == 'A'
160
- group.before_alls[2].call.should == 33.5
161
- end
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
- it "should expose the after each blocks at after_eachs" do
164
- group = empty_behaviour_group
165
- group.after(:each) { 'foo' }
166
- group.should have(1).after_eachs
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
- it "should maintain the after each block order" do
170
- group = empty_behaviour_group
171
- group.after(:each) { 15 }
172
- group.after(:each) { 'A' }
173
- group.after(:each) { 33.5 }
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
- group.after_eachs[0].call.should == 15
176
- group.after_eachs[1].call.should == 'A'
177
- group.after_eachs[2].call.should == 33.5
178
- end
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
- it "should expose the after all blocks at after_alls" do
181
- group = empty_behaviour_group
182
- group.after(:all) { 'foo' }
183
- group.should have(1).after_alls
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
- it "should maintain the after each block order" do
187
- group = empty_behaviour_group
188
- group.after(:all) { 15 }
189
- group.after(:all) { 'A' }
190
- group.after(:all) { 33.5 }
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
- group.after_alls[0].call.should == 15
193
- group.after_alls[1].call.should == 'A'
194
- group.after_alls[2].call.should == 33.5
195
- end
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
- describe "adding examples" do
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
- it "should allow adding an example using 'it'" do
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
- it "should expose all examples at examples" do
208
- group = empty_behaviour_group
209
- group.it("should do something 1") { }
210
- group.it("should do something 2") { }
211
- group.it("should do something 3") { }
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
- it "should maintain the example order" do
216
- group = empty_behaviour_group
217
- group.it("should 1") { }
218
- group.it("should 2") { }
219
- group.it("should 3") { }
220
- group.examples[0].description.should == 'should 1'
221
- group.examples[1].description.should == 'should 2'
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 behaviours", :little_less_nested => 'yep' do
247
+ describe Object, "describing nested example_groups", :little_less_nested => 'yep' do
230
248
 
231
- describe "A sample nested describe", :nested_describe => "yep" do
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 "should set the description to 'A sample nested describe'" do
238
- running_example.behaviour.description.should == 'A sample nested describe'
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 "should have top level metadata from the behaviour and its ancestors" do
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 "should make the parent metadata available on the contained examples" do
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
- stub_everything('behaviour', :metadata => { :behaviour => { :name => 'behaviour_name' }})
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.stubs(:examples_to_run).returns([passing_example1, passing_example2])
284
+ Rspec::Core::ExampleGroup.stub!(:examples_to_run).and_return([passing_example1, passing_example2])
268
285
 
269
- Rspec::Core::ExampleGroup.run_examples(stub_behaviour, stub_everything('reporter')).should be_true
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.stubs(:examples_to_run).returns([failing_example, passing_example])
294
+ Rspec::Core::ExampleGroup.stub!(:examples_to_run).and_return([failing_example, passing_example])
278
295
 
279
- Rspec::Core::ExampleGroup.run_examples(stub_behaviour, stub_everything('reporter')).should be_false
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.stubs(:examples_to_run).returns([failing_example, passing_example])
304
+ Rspec::Core::ExampleGroup.stub!(:examples_to_run).and_return([failing_example, passing_example])
288
305
 
289
- passing_example.expects(:run)
306
+ passing_example.should_receive(:run)
290
307
 
291
- Rspec::Core::ExampleGroup.run_examples(stub_behaviour, stub_everything('reporter'))
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
- it "should have access to the modified version" do
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