rspec-core 2.0.0.beta.17 → 2.0.0.beta.18

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.
Files changed (70) hide show
  1. data/README.markdown +5 -1
  2. data/Rakefile +4 -1
  3. data/Upgrade.markdown +28 -2
  4. data/VERSION +1 -1
  5. data/autotest/discover.rb +1 -1
  6. data/features/command_line/configure.feature +19 -0
  7. data/features/example_groups/shared_example_group.feature +125 -0
  8. data/features/hooks/around_hooks.feature +11 -2
  9. data/features/pending/pending_examples.feature +18 -6
  10. data/lib/autotest/rspec2.rb +1 -1
  11. data/lib/rspec/core.rb +1 -0
  12. data/lib/rspec/core/command_line_configuration.rb +62 -0
  13. data/lib/rspec/core/configuration.rb +39 -12
  14. data/lib/rspec/core/configuration_options.rb +5 -5
  15. data/lib/rspec/core/deprecation.rb +6 -6
  16. data/lib/rspec/core/errors.rb +1 -1
  17. data/lib/rspec/core/example.rb +25 -25
  18. data/lib/rspec/core/example_group.rb +30 -14
  19. data/lib/rspec/core/formatters/base_formatter.rb +25 -25
  20. data/lib/rspec/core/formatters/base_text_formatter.rb +11 -10
  21. data/lib/rspec/core/formatters/documentation_formatter.rb +2 -2
  22. data/lib/rspec/core/formatters/helpers.rb +6 -6
  23. data/lib/rspec/core/formatters/html_formatter.rb +13 -12
  24. data/lib/rspec/core/formatters/progress_formatter.rb +1 -1
  25. data/lib/rspec/core/formatters/snippet_extractor.rb +5 -5
  26. data/lib/rspec/core/hooks.rb +3 -3
  27. data/lib/rspec/core/kernel_extensions.rb +1 -1
  28. data/lib/rspec/core/let.rb +5 -5
  29. data/lib/rspec/core/metadata.rb +2 -2
  30. data/lib/rspec/core/mocking/with_absolutely_nothing.rb +3 -3
  31. data/lib/rspec/core/mocking/with_mocha.rb +5 -5
  32. data/lib/rspec/core/mocking/with_rr.rb +3 -3
  33. data/lib/rspec/core/mocking/with_rspec.rb +3 -3
  34. data/lib/rspec/core/option_parser.rb +8 -4
  35. data/lib/rspec/core/rake_task.rb +5 -0
  36. data/lib/rspec/core/ruby_project.rb +1 -1
  37. data/lib/rspec/core/shared_example_group.rb +2 -2
  38. data/lib/rspec/core/subject.rb +10 -4
  39. data/lib/rspec/core/world.rb +5 -5
  40. data/rspec-core.gemspec +19 -11
  41. data/spec/autotest/rspec_spec.rb +14 -14
  42. data/spec/rspec/core/command_line_configuration_spec.rb +26 -0
  43. data/spec/rspec/core/command_line_spec.rb +5 -5
  44. data/spec/rspec/core/configuration_options_spec.rb +20 -20
  45. data/spec/rspec/core/configuration_spec.rb +10 -10
  46. data/spec/rspec/core/core_spec.rb +8 -8
  47. data/spec/rspec/core/deprecations_spec.rb +2 -2
  48. data/spec/rspec/core/drb_command_line_spec.rb +10 -10
  49. data/spec/rspec/core/example_group_spec.rb +46 -10
  50. data/spec/rspec/core/example_spec.rb +46 -12
  51. data/spec/rspec/core/formatters/base_formatter_spec.rb +2 -46
  52. data/spec/rspec/core/formatters/base_text_formatter_spec.rb +4 -3
  53. data/spec/rspec/core/formatters/documentation_formatter_spec.rb +1 -1
  54. data/spec/rspec/core/formatters/helpers_spec.rb +2 -2
  55. data/spec/rspec/core/formatters/html_formatted-1.8.7.html +1 -1
  56. data/spec/rspec/core/formatters/html_formatted-1.9.1.html +1 -1
  57. data/spec/rspec/core/formatters/html_formatted-1.9.2.html +1 -1
  58. data/spec/rspec/core/formatters/progress_formatter_spec.rb +10 -9
  59. data/spec/rspec/core/formatters/text_mate_formatted-1.8.7.html +13 -13
  60. data/spec/rspec/core/formatters/text_mate_formatted-1.9.2.html +1 -1
  61. data/spec/rspec/core/let_spec.rb +1 -1
  62. data/spec/rspec/core/metadata_spec.rb +9 -9
  63. data/spec/rspec/core/option_parser_spec.rb +3 -3
  64. data/spec/rspec/core/pending_example_spec.rb +1 -1
  65. data/spec/rspec/core/resources/custom_example_group_runner.rb +1 -1
  66. data/spec/rspec/core/runner_spec.rb +4 -4
  67. data/spec/rspec/core/shared_example_group_spec.rb +66 -162
  68. data/spec/rspec/core/subject_spec.rb +4 -4
  69. data/spec/rspec/core/world_spec.rb +38 -38
  70. metadata +21 -13
@@ -1,5 +1,5 @@
1
1
  <?xml version="1.0" encoding="UTF-8"?>
2
- <!DOCTYPE html
2
+ <!DOCTYPE html
3
3
  PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
4
4
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
5
5
  <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
@@ -212,14 +212,14 @@ a {
212
212
  <span class="failed_spec_name">fails</span>
213
213
  <div class="failure" id="failure_0">
214
214
  <div class="message"><pre>RSpec::Core::PendingExampleFixedError</pre></div>
215
- <div class="backtrace"><pre><a href="txmt://open?url=file:///Users/dchelimsky/projects/ruby/rspec2/repos/rspec-core/spec/rspec/core/resources/formatter_specs.rb&line=19">./spec/rspec/core/resources/formatter_specs.rb:19</a>
216
- <a href="txmt://open?url=file:///Users/dchelimsky/projects/ruby/rspec2/repos/rspec-core/spec/rspec/core/formatters/text_mate_formatter_spec.rb&line=23">./spec/rspec/core/formatters/text_mate_formatter_spec.rb:23</a>
217
- <a href="txmt://open?url=file:///Users/dchelimsky/projects/ruby/rspec2/repos/rspec-core/spec/rspec/core/formatters/text_mate_formatter_spec.rb&line=38">./spec/rspec/core/formatters/text_mate_formatter_spec.rb:38</a>
215
+ <div class="backtrace"><pre><a href="txmt://open?url=file:///Users/dchelimsky/projects/ruby/rspec2/repos/rspec-core/spec/rspec/core/resources/formatter_specs.rb&line=19">./spec/rspec/core/resources/formatter_specs.rb:19</a>
216
+ <a href="txmt://open?url=file:///Users/dchelimsky/projects/ruby/rspec2/repos/rspec-core/spec/rspec/core/formatters/text_mate_formatter_spec.rb&line=23">./spec/rspec/core/formatters/text_mate_formatter_spec.rb:23</a>
217
+ <a href="txmt://open?url=file:///Users/dchelimsky/projects/ruby/rspec2/repos/rspec-core/spec/rspec/core/formatters/text_mate_formatter_spec.rb&line=38">./spec/rspec/core/formatters/text_mate_formatter_spec.rb:38</a>
218
218
  <a href="txmt://open?url=file:///Users/dchelimsky/projects/ruby/rspec2/repos/rspec-core/spec/rspec/core/formatters/text_mate_formatter_spec.rb&line=38">./spec/rspec/core/formatters/text_mate_formatter_spec.rb:38</a> :in `open'
219
- <a href="txmt://open?url=file:///Users/dchelimsky/projects/ruby/rspec2/repos/rspec-core/spec/rspec/core/formatters/text_mate_formatter_spec.rb&line=38">./spec/rspec/core/formatters/text_mate_formatter_spec.rb:38</a>
219
+ <a href="txmt://open?url=file:///Users/dchelimsky/projects/ruby/rspec2/repos/rspec-core/spec/rspec/core/formatters/text_mate_formatter_spec.rb&line=38">./spec/rspec/core/formatters/text_mate_formatter_spec.rb:38</a>
220
220
  <a href="txmt://open?url=file:///Users/dchelimsky/projects/ruby/rspec2/repos/rspec-core/spec/rspec/core/formatters/text_mate_formatter_spec.rb&line=37">./spec/rspec/core/formatters/text_mate_formatter_spec.rb:37</a> :in `chdir'
221
- <a href="txmt://open?url=file:///Users/dchelimsky/projects/ruby/rspec2/repos/rspec-core/spec/rspec/core/formatters/text_mate_formatter_spec.rb&line=37">./spec/rspec/core/formatters/text_mate_formatter_spec.rb:37</a>
222
- <a href="txmt://open?url=file:///Users/dchelimsky/projects/ruby/rspec2/repos/rspec-core/spec/spec_helper.rb&line=73">./spec/spec_helper.rb:73</a>
221
+ <a href="txmt://open?url=file:///Users/dchelimsky/projects/ruby/rspec2/repos/rspec-core/spec/rspec/core/formatters/text_mate_formatter_spec.rb&line=37">./spec/rspec/core/formatters/text_mate_formatter_spec.rb:37</a>
222
+ <a href="txmt://open?url=file:///Users/dchelimsky/projects/ruby/rspec2/repos/rspec-core/spec/spec_helper.rb&line=73">./spec/spec_helper.rb:73</a>
223
223
  <a href="txmt://open?url=file:///Users/dchelimsky/projects/ruby/rspec2/repos/rspec-core/spec/spec_helper.rb&line=49">./spec/spec_helper.rb:49</a> :in `instance_eval'
224
224
  <a href="txmt://open?url=file:///Users/dchelimsky/projects/ruby/rspec2/repos/rspec-core/spec/spec_helper.rb&line=49">./spec/spec_helper.rb:49</a> :in `sandboxed'
225
225
  <a href="txmt://open?url=file:///Users/dchelimsky/projects/ruby/rspec2/repos/rspec-core/spec/spec_helper.rb&line=73">./spec/spec_helper.rb:73</a> </pre></div>
@@ -253,14 +253,14 @@ expected 2
253
253
 
254
254
  (compared using ==)
255
255
  </pre></div>
256
- <div class="backtrace"><pre><a href="txmt://open?url=file:///Users/dchelimsky/projects/ruby/rspec2/repos/rspec-core/spec/rspec/core/resources/formatter_specs.rb&line=34">./spec/rspec/core/resources/formatter_specs.rb:34</a>
257
- <a href="txmt://open?url=file:///Users/dchelimsky/projects/ruby/rspec2/repos/rspec-core/spec/rspec/core/formatters/text_mate_formatter_spec.rb&line=23">./spec/rspec/core/formatters/text_mate_formatter_spec.rb:23</a>
258
- <a href="txmt://open?url=file:///Users/dchelimsky/projects/ruby/rspec2/repos/rspec-core/spec/rspec/core/formatters/text_mate_formatter_spec.rb&line=38">./spec/rspec/core/formatters/text_mate_formatter_spec.rb:38</a>
256
+ <div class="backtrace"><pre><a href="txmt://open?url=file:///Users/dchelimsky/projects/ruby/rspec2/repos/rspec-core/spec/rspec/core/resources/formatter_specs.rb&line=34">./spec/rspec/core/resources/formatter_specs.rb:34</a>
257
+ <a href="txmt://open?url=file:///Users/dchelimsky/projects/ruby/rspec2/repos/rspec-core/spec/rspec/core/formatters/text_mate_formatter_spec.rb&line=23">./spec/rspec/core/formatters/text_mate_formatter_spec.rb:23</a>
258
+ <a href="txmt://open?url=file:///Users/dchelimsky/projects/ruby/rspec2/repos/rspec-core/spec/rspec/core/formatters/text_mate_formatter_spec.rb&line=38">./spec/rspec/core/formatters/text_mate_formatter_spec.rb:38</a>
259
259
  <a href="txmt://open?url=file:///Users/dchelimsky/projects/ruby/rspec2/repos/rspec-core/spec/rspec/core/formatters/text_mate_formatter_spec.rb&line=38">./spec/rspec/core/formatters/text_mate_formatter_spec.rb:38</a> :in `open'
260
- <a href="txmt://open?url=file:///Users/dchelimsky/projects/ruby/rspec2/repos/rspec-core/spec/rspec/core/formatters/text_mate_formatter_spec.rb&line=38">./spec/rspec/core/formatters/text_mate_formatter_spec.rb:38</a>
260
+ <a href="txmt://open?url=file:///Users/dchelimsky/projects/ruby/rspec2/repos/rspec-core/spec/rspec/core/formatters/text_mate_formatter_spec.rb&line=38">./spec/rspec/core/formatters/text_mate_formatter_spec.rb:38</a>
261
261
  <a href="txmt://open?url=file:///Users/dchelimsky/projects/ruby/rspec2/repos/rspec-core/spec/rspec/core/formatters/text_mate_formatter_spec.rb&line=37">./spec/rspec/core/formatters/text_mate_formatter_spec.rb:37</a> :in `chdir'
262
- <a href="txmt://open?url=file:///Users/dchelimsky/projects/ruby/rspec2/repos/rspec-core/spec/rspec/core/formatters/text_mate_formatter_spec.rb&line=37">./spec/rspec/core/formatters/text_mate_formatter_spec.rb:37</a>
263
- <a href="txmt://open?url=file:///Users/dchelimsky/projects/ruby/rspec2/repos/rspec-core/spec/spec_helper.rb&line=73">./spec/spec_helper.rb:73</a>
262
+ <a href="txmt://open?url=file:///Users/dchelimsky/projects/ruby/rspec2/repos/rspec-core/spec/rspec/core/formatters/text_mate_formatter_spec.rb&line=37">./spec/rspec/core/formatters/text_mate_formatter_spec.rb:37</a>
263
+ <a href="txmt://open?url=file:///Users/dchelimsky/projects/ruby/rspec2/repos/rspec-core/spec/spec_helper.rb&line=73">./spec/spec_helper.rb:73</a>
264
264
  <a href="txmt://open?url=file:///Users/dchelimsky/projects/ruby/rspec2/repos/rspec-core/spec/spec_helper.rb&line=49">./spec/spec_helper.rb:49</a> :in `instance_eval'
265
265
  <a href="txmt://open?url=file:///Users/dchelimsky/projects/ruby/rspec2/repos/rspec-core/spec/spec_helper.rb&line=49">./spec/spec_helper.rb:49</a> :in `sandboxed'
266
266
  <a href="txmt://open?url=file:///Users/dchelimsky/projects/ruby/rspec2/repos/rspec-core/spec/spec_helper.rb&line=73">./spec/spec_helper.rb:73</a> </pre></div>
@@ -1,5 +1,5 @@
1
1
  <?xml version="1.0" encoding="UTF-8"?>
2
- <!DOCTYPE html
2
+ <!DOCTYPE html
3
3
  PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
4
4
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
5
5
  <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
@@ -36,7 +36,7 @@ describe "#let!" do
36
36
  lambda { Creator.count }.should_not raise_error
37
37
  end
38
38
 
39
- it "does not interfere between tests" do
39
+ it "does not interfere between tests" do
40
40
  Creator.count.should == 1
41
41
  end
42
42
  end
@@ -112,7 +112,7 @@ module RSpec
112
112
  it "nests the parent's example group metadata" do
113
113
  parent = Metadata.new
114
114
  parent.process(Object, 'parent')
115
-
115
+
116
116
  child = Metadata.new(parent)
117
117
  child.process()
118
118
 
@@ -188,11 +188,11 @@ module RSpec
188
188
  end
189
189
 
190
190
  it "extracts file path from caller" do
191
- mfe[:file_path].should == __FILE__
191
+ mfe[:file_path].should == __FILE__
192
192
  end
193
193
 
194
194
  it "extracts line number from caller" do
195
- mfe[:line_number].should == line_number
195
+ mfe[:line_number].should == line_number
196
196
  end
197
197
 
198
198
  it "extracts location from caller" do
@@ -200,7 +200,7 @@ module RSpec
200
200
  end
201
201
 
202
202
  it "merges arbitrary options" do
203
- mfe[:arbitrary].should == :options
203
+ mfe[:arbitrary].should == :options
204
204
  end
205
205
 
206
206
  it "points :example_group to the same hash object" do
@@ -220,13 +220,13 @@ module RSpec
220
220
  let(:group_line_number) { __LINE__ -1 }
221
221
  let(:example_metadata) { group_metadata.for_example('example', :caller => ["foo_spec.rb:#{__LINE__}"]) }
222
222
  let(:example_line_number) { __LINE__ -1 }
223
- let(:next_example_metadata) {group_metadata.for_example('next_example',
223
+ let(:next_example_metadata) {group_metadata.for_example('next_example',
224
224
  :caller => ["foo_spec.rb:#{example_line_number + 2}"])}
225
225
  let(:world) { RSpec.world }
226
226
 
227
227
  it "matches the group when the line_number is the example group line number" do
228
228
  world.should_receive(:preceding_declaration_line).and_return(group_line_number)
229
- # this call doesn't really make sense since apply_condition is only called
229
+ # this call doesn't really make sense since apply_condition is only called
230
230
  # for example metadata not group metadata
231
231
  group_metadata.apply_condition(:line_number, group_line_number).should be_true
232
232
  end
@@ -245,17 +245,17 @@ module RSpec
245
245
  world.should_receive(:preceding_declaration_line).and_return(example_line_number)
246
246
  example_metadata.apply_condition(:line_number, example_line_number).should be_true
247
247
  end
248
-
248
+
249
249
  it "matches when the line number is between this example and the next" do
250
250
  world.should_receive(:preceding_declaration_line).and_return(example_line_number)
251
251
  example_metadata.apply_condition(:line_number, example_line_number + 1).should be_true
252
252
  end
253
-
253
+
254
254
  it "does not match when the line number matches the next example" do
255
255
  world.should_receive(:preceding_declaration_line).and_return(example_line_number + 2)
256
256
  example_metadata.apply_condition(:line_number, example_line_number + 2).should be_false
257
257
  end
258
-
258
+
259
259
  end
260
260
 
261
261
  end
@@ -5,12 +5,12 @@ module RSpec::Core
5
5
  before do
6
6
  RSpec.stub(:deprecate)
7
7
  end
8
-
8
+
9
9
  it "deprecates the --formatter option" do
10
10
  RSpec.should_receive(:deprecate)
11
- Parser.parse!(%w[--formatter doc])
11
+ Parser.parse!(%w[--formatter doc])
12
12
  end
13
-
13
+
14
14
  it "converts --formatter to --format" do
15
15
  options = Parser.parse!(%w[--formatter doc])
16
16
  options.should eq( {:formatter=>"doc"} )
@@ -14,7 +14,7 @@ describe "an example" do
14
14
  context "with no block" do
15
15
  it "is listed as pending with 'Not Yet Implemented'" do
16
16
  group = RSpec::Core::ExampleGroup.describe('group') do
17
- it "has no block"
17
+ it "has no block"
18
18
  end
19
19
  example = group.examples.first
20
20
  example.run(group.new, stub.as_null_object)
@@ -10,5 +10,5 @@ module Custom
10
10
 
11
11
  def run
12
12
  end
13
- end
13
+ end
14
14
  end
@@ -10,7 +10,7 @@ module RSpec::Core
10
10
  RSpec::Core::Runner.should_receive(:at_exit)
11
11
  RSpec::Core::Runner.autorun
12
12
  end
13
-
13
+
14
14
  it 'does not set the at_exit hook if it is already set' do
15
15
  RSpec::Core::Runner.stub(:installed_at_exit?).and_return(true)
16
16
  RSpec::Core::Runner.stub(:running_in_drb?).and_return(false)
@@ -19,7 +19,7 @@ module RSpec::Core
19
19
  RSpec::Core::Runner.autorun
20
20
  end
21
21
  end
22
-
22
+
23
23
  describe "#run" do
24
24
  context "with --drb or -X" do
25
25
  before(:each) do
@@ -27,11 +27,11 @@ module RSpec::Core
27
27
 
28
28
  @options = RSpec::Core::ConfigurationOptions.new(%w[--drb --drb-port 8181 --color])
29
29
  RSpec::Core::ConfigurationOptions.stub(:new) { @options }
30
-
30
+
31
31
  @drb_proxy = double(RSpec::Core::DRbCommandLine, :run => true)
32
32
  RSpec::Core::DRbCommandLine.stub(:new => @drb_proxy)
33
33
  end
34
-
34
+
35
35
  it "builds a DRbCommandLine" do
36
36
  RSpec::Core::DRbCommandLine.should_receive(:new)
37
37
  RSpec::Core::Runner.run(%w[ --drb ], @err, @out)
@@ -3,107 +3,36 @@ require 'spec_helper'
3
3
  module RSpec::Core
4
4
 
5
5
  describe SharedExampleGroup do
6
- it "should add the 'share_examples_for' method to the global namespace" do
7
- Kernel.should respond_to(:share_examples_for)
8
- end
9
-
10
- it "should add the 'shared_examples_for' method to the global namespace" do
11
- Kernel.should respond_to(:shared_examples_for)
12
- end
13
-
14
- it "should add the 'share_as' method to the global namespace" do
15
- Kernel.should respond_to(:share_as)
16
- end
17
-
18
- it "should raise an ArgumentError when adding a second shared example group with the same name" do
19
- group = ExampleGroup.describe('example group')
20
- group.share_examples_for('really important business value') { }
21
- lambda do
22
- group.share_examples_for('really important business value') { }
23
- end.should raise_error(ArgumentError, "Shared example group 'really important business value' already exists")
24
- end
25
-
26
- describe "share_examples_for" do
27
-
28
- it "should capture the given name and block in the Worlds collection of shared example groups" do
29
- RSpec.world.shared_example_groups.should_receive(:[]=).with(:foo, anything)
30
- share_examples_for(:foo) { }
31
- end
32
6
 
33
- end
34
-
35
- describe "including shared example_groups using #it_should_behave_like" do
36
-
37
- it "should make any shared example_group available at the correct level", :ruby => 1.8 do
38
- group = ExampleGroup.describe('fake group')
39
- block = lambda {
40
- def self.class_helper; end
41
- def extra_helper; end
42
- }
43
- RSpec.world.stub(:shared_example_groups).and_return({ :shared_example_group => block })
44
- group.it_should_behave_like :shared_example_group
45
- group.instance_methods.should include('extra_helper')
46
- group.singleton_methods.should include('class_helper')
47
- end
7
+ %w[share_examples_for shared_examples_for].each do |method_name|
8
+ describe method_name do
48
9
 
49
- it "should make any shared example_group available at the correct level", :ruby => 1.9 do
50
- group = ExampleGroup.describe
51
- shared_examples_for(:shared_example_group) do
52
- def self.class_helper; end
53
- def extra_helper; end
10
+ it "is exposed to the global namespace" do
11
+ Kernel.should respond_to(method_name)
54
12
  end
55
- group.it_should_behave_like :shared_example_group
56
- group.instance_methods.should include(:extra_helper)
57
- group.singleton_methods.should include(:class_helper)
58
- end
59
13
 
60
- it "raises when named shared example_group can not be found" do
61
- group = ExampleGroup.describe("example_group")
62
- lambda do
63
- group.it_should_behave_like("a group that does not exist")
64
- end.should raise_error(/Could not find shared example group named/)
65
- end
66
-
67
- it "adds examples to current example_group using it_should_behave_like" do
68
- group = ExampleGroup.describe("example_group") do
69
- it("i was already here") {}
14
+ it "raises an ArgumentError when adding a second shared example group with the same name" do
15
+ group = ExampleGroup.describe('example group')
16
+ group.send(method_name, 'shared group') {}
17
+ lambda do
18
+ group.send(method_name, 'shared group') {}
19
+ end.should raise_error(ArgumentError, "Shared example group 'shared group' already exists")
70
20
  end
71
21
 
72
- group.examples.size.should == 1
73
-
74
- group.share_examples_for('shared example_group') do
75
- it("shared example") {}
76
- it("shared example 2") {}
22
+ it "captures the given name and block in the Worlds collection of shared example groups" do
23
+ implementation = lambda {}
24
+ RSpec.world.shared_example_groups.should_receive(:[]=).with(:foo, implementation)
25
+ send(method_name, :foo, &implementation)
77
26
  end
78
27
 
79
- group.it_should_behave_like("shared example_group")
80
-
81
- group.examples.size.should == 3
82
28
  end
29
+ end
83
30
 
84
- it "adds examples to from two shared groups" do
85
- group = ExampleGroup.describe("example_group") do
86
- it("i was already here") {}
87
- end
88
-
89
- group.examples.size.should == 1
90
-
91
- group.share_examples_for('test 2 shared groups') do
92
- it("shared example") {}
93
- it("shared example 2") {}
94
- end
95
-
96
- group.share_examples_for('test 2 shared groups 2') do
97
- it("shared example 3") {}
98
- end
99
-
100
- group.it_should_behave_like("test 2 shared groups")
101
- group.it_should_behave_like("test 2 shared groups 2")
102
-
103
- group.examples.size.should == 4
31
+ describe "#share_as" do
32
+ it "is exposed to the global namespace" do
33
+ Kernel.should respond_to("share_as")
104
34
  end
105
35
 
106
-
107
36
  it "adds examples to current example_group using include", :compat => 'rspec-1.2' do
108
37
  share_as('Cornucopia') do
109
38
  it "is plentiful" do
@@ -114,95 +43,70 @@ module RSpec::Core
114
43
  group.examples.length.should == 1
115
44
  group.examples.first.metadata[:description].should == "is plentiful"
116
45
  end
46
+ end
117
47
 
118
- it "adds examples to current example_group using it_should_behave_like with a module" do
119
- group = ExampleGroup.describe("example_group") {}
48
+ describe "#it_should_behave_like" do
49
+ it "creates a nested group" do
50
+ shared_examples_for("thing") {}
51
+ group = ExampleGroup.describe('fake group')
52
+ group.it_should_behave_like("thing")
53
+ group.should have(1).children
54
+ end
120
55
 
121
- shared_foo = group.share_as(:FooShared) do
122
- it("shared example") {}
56
+ it "adds shared examples to nested group" do
57
+ shared_examples_for("thing") do
58
+ it("does something")
123
59
  end
124
-
125
- group.it_should_behave_like(::FooShared)
126
-
127
- group.examples.size.should == 1
60
+ group = ExampleGroup.describe('fake group')
61
+ shared_group = group.it_should_behave_like("thing")
62
+ shared_group.should have(1).examples
128
63
  end
129
64
 
130
- describe "running shared examples" do
131
- module ::RunningSharedExamplesJustForTesting; end
132
-
133
- let(:group) do
134
- ExampleGroup.describe("example group")
65
+ it "adds shared instance methods to nested group" do
66
+ shared_examples_for("thing") do
67
+ def foo; end
135
68
  end
69
+ group = ExampleGroup.describe('fake group')
70
+ shared_group = group.it_should_behave_like("thing")
71
+ shared_group.public_instance_methods.should include("foo")
72
+ end
136
73
 
137
- before(:each) do
138
- group.share_examples_for("it runs shared examples") do
139
- include ::RunningSharedExamplesJustForTesting
140
-
141
- class << self
142
- def magic
143
- $magic ||= {}
144
- end
145
-
146
- def count(scope)
147
- @counters ||= {
148
- :before_all => 0,
149
- :before_each => 0,
150
- :after_each => 0,
151
- :after_all => 0
152
- }
153
- @counters[scope] += 1
154
- end
155
- end
156
-
157
- def magic
158
- $magic ||= {}
159
- end
74
+ it "adds shared class methods to nested group" do
75
+ shared_examples_for("thing") do
76
+ def self.foo; end
77
+ end
78
+ group = ExampleGroup.describe('fake group')
79
+ shared_group = group.it_should_behave_like("thing")
80
+ shared_group.methods.should include("foo")
81
+ end
160
82
 
161
- def count(scope)
162
- self.class.count(scope)
83
+ context "given a block" do
84
+ it "evaluates the block in nested group" do
85
+ scopes = []
86
+ shared_examples_for("thing") do
87
+ it("gets run in the nested group") do
88
+ scopes << self.class
163
89
  end
164
-
165
- before(:all) { magic[:before_all] = "before all #{count(:before_all)}" }
166
- before(:each) { magic[:before_each] = "before each #{count(:before_each)}" }
167
- after(:each) { magic[:after_each] = "after each #{count(:after_each)}" }
168
- after(:all) { magic[:after_all] = "after all #{count(:after_all)}" }
169
90
  end
170
- end
171
-
172
- before do
173
- group.it_should_behave_like "it runs shared examples"
174
- group.it "has one example" do; end
175
- group.it "has another example" do; end
176
- group.it "includes modules, included into shared example_group, into current example_group", :compat => 'rspec-1.2' do
177
- raise "FAIL" unless example.example_group.included_modules.include?(RunningSharedExamplesJustForTesting)
91
+ group = ExampleGroup.describe("group") do
92
+ it_should_behave_like "thing" do
93
+ it("gets run in the same nested group") do
94
+ scopes << self.class
95
+ end
96
+ end
178
97
  end
179
98
  group.run_all
180
- end
181
-
182
- it "runs before(:all) only once from shared example_group", :compat => 'rspec-1.2' do
183
- group.magic[:before_all].should eq("before all 1")
184
- end
185
-
186
- it "runs before(:each) from shared example_group", :compat => 'rspec-1.2' do
187
- group.magic[:before_each].should eq("before each 3")
188
- end
189
-
190
- it "runs after(:each) from shared example_group", :compat => 'rspec-1.2' do
191
- group.magic[:after_each].should eq("after each 3")
192
- end
193
-
194
- it "runs after(:all) only once from shared example_group", :compat => 'rspec-1.2' do
195
- group.magic[:after_all].should eq("after all 1")
196
- end
197
99
 
198
- it "makes methods defined in the shared example_group available in consuming example_group", :compat => 'rspec-1.2' do
199
- group.magic.should be_a(Hash)
100
+ scopes[0].should be(scopes[1])
200
101
  end
201
-
202
102
  end
203
103
 
104
+ it "raises when named shared example_group can not be found" do
105
+ group = ExampleGroup.describe("example_group")
106
+ lambda do
107
+ group.it_should_behave_like("a group that does not exist")
108
+ end.should raise_error(/Could not find shared example group named/)
109
+ end
204
110
  end
205
-
206
111
  end
207
-
208
112
  end