rspec 1.1.8 → 1.1.9

Sign up to get free protection for your applications and to get access to all the features.
Files changed (57) hide show
  1. data/History.txt +30 -3
  2. data/License.txt +22 -0
  3. data/Manifest.txt +3 -3
  4. data/README.txt +1 -25
  5. data/Rakefile +4 -2
  6. data/TODO.txt +5 -4
  7. data/bin/autospec +1 -1
  8. data/examples/pure/shared_example_group_example.rb +2 -2
  9. data/lib/autotest/rspec.rb +1 -1
  10. data/lib/spec.rb +5 -1
  11. data/lib/spec/example.rb +1 -1
  12. data/lib/spec/example/before_and_after_hooks.rb +93 -0
  13. data/lib/spec/example/configuration.rb +10 -1
  14. data/lib/spec/example/example_group.rb +2 -1
  15. data/lib/spec/example/example_group_factory.rb +18 -1
  16. data/lib/spec/example/example_group_methods.rb +45 -123
  17. data/lib/spec/example/example_methods.rb +9 -6
  18. data/lib/spec/example/shared_example_group.rb +6 -12
  19. data/lib/spec/extensions/main.rb +1 -1
  20. data/lib/spec/interop/test/unit/testcase.rb +1 -1
  21. data/lib/spec/mocks/error_generator.rb +1 -1
  22. data/lib/spec/mocks/message_expectation.rb +19 -4
  23. data/lib/spec/mocks/methods.rb +2 -2
  24. data/lib/spec/mocks/proxy.rb +4 -5
  25. data/lib/spec/runner.rb +3 -4
  26. data/lib/spec/runner/formatter/nested_text_formatter.rb +3 -3
  27. data/lib/spec/runner/option_parser.rb +23 -22
  28. data/lib/spec/version.rb +1 -1
  29. data/rspec.gemspec +19 -8
  30. data/spec/autotest/rspec_spec.rb +5 -1
  31. data/spec/spec/example/configuration_spec.rb +229 -215
  32. data/spec/spec/example/example_group_class_definition_spec.rb +9 -9
  33. data/spec/spec/example/example_group_factory_spec.rb +48 -27
  34. data/spec/spec/example/example_group_methods_spec.rb +436 -426
  35. data/spec/spec/example/example_group_spec.rb +459 -500
  36. data/spec/spec/example/example_methods_spec.rb +92 -86
  37. data/spec/spec/example/shared_example_group_spec.rb +219 -203
  38. data/spec/spec/extensions/main_spec.rb +23 -23
  39. data/spec/spec/interop/test/unit/resources/spec_with_options_hash.rb +13 -0
  40. data/spec/spec/interop/test/unit/spec_spec.rb +15 -8
  41. data/spec/spec/mocks/mock_spec.rb +12 -2
  42. data/spec/spec/mocks/nil_expectation_warning_spec.rb +0 -1
  43. data/spec/spec/mocks/partial_mock_spec.rb +10 -5
  44. data/spec/spec/package/bin_spec_spec.rb +8 -0
  45. data/spec/spec/runner/command_line_spec.rb +101 -100
  46. data/spec/spec/runner/drb_command_line_spec.rb +0 -2
  47. data/spec/spec/runner/formatter/html_formatter_spec.rb +1 -4
  48. data/spec/spec/runner/formatter/nested_text_formatter_spec.rb +230 -245
  49. data/spec/spec/runner/formatter/spec_mate_formatter_spec.rb +2 -3
  50. data/spec/spec/runner/formatter/specdoc_formatter_spec.rb +110 -109
  51. data/spec/spec/runner/option_parser_spec.rb +18 -6
  52. data/spec/spec_helper.rb +26 -5
  53. data/stories/mock_framework_integration/use_flexmock.story +1 -1
  54. metadata +38 -7
  55. data/lib/spec/example/module_inclusion_warnings.rb +0 -38
  56. data/spec/spec/example/example_group/described_module_spec.rb +0 -20
  57. data/spec/spec/example/example_group/warning_messages_spec.rb +0 -76
@@ -1,3 +1,30 @@
1
+ === Version 1.1.9 / 2008-10-20
2
+
3
+ WARNING: This release removes implicit inclusion of modules in example groups.
4
+ This means that if you have 'describe MyModule do', MyModule will not be
5
+ included in the group.
6
+
7
+ * 2 major enhancements
8
+
9
+ * Add extend to configuration (thanks to advice from Chad Fowler)
10
+ * Modules are no longer implicitly included in example groups
11
+
12
+ * 4 minor enhancements
13
+
14
+ * mingw indicates windows too (thanks to Luis Lavena for the tip)
15
+ * improved output for partial mock expecation failures
16
+ * it_should_behave_like now accepts n names of shared groups
17
+ * eliminated redundant inclusion/extension of ExampleGroupMethods
18
+
19
+ * 6 bug fixes
20
+
21
+ * spec command with no arguments prints help
22
+ * fixed typo in help. Fixes #73.
23
+ * fixed bug where should_receive..and_yield after similar stub added the args_to_yield to the stub's original args_to_yield (Pat Maddox)
24
+ * fixed bug where rspec-autotest (autospec) was loading non-spec files in spec directory. Fixes #559.
25
+ * fixed bug where should_not_receive was reporting twice
26
+ * fixed bug where rspec tries to run examples just because it is required (even if there are no examples loaded). Fixes #575.
27
+
1
28
  === Version 1.1.8 / 2008-10-03
2
29
 
3
30
  * 2 bug fixes
@@ -13,12 +40,12 @@
13
40
 
14
41
  * 2 bug fixes
15
42
 
16
- * fixed bug where negative message expectations following stubs resulted in false (negative) positives (Pat Maddox). Closes #548.
17
- * fixed bug where Not Yet Implemented examples report incorrect caller (Scott Taylor). Closes #547.
43
+ * fixed bug where negative message expectations following stubs resulted in false (negative) positives (Mathias Meyer). Closes #548.
44
+ * fixed bug where Not Yet Implemented examples report incorrect caller (Scott Taylor). Closes #547.
18
45
 
19
46
  * 1 minor enhancement
20
47
 
21
- * removed deprecated mock argument constraint symbols
48
+ * removed deprecated mock argument constraint symbols
22
49
 
23
50
  === Version 1.1.5 / 2008-09-28
24
51
 
@@ -0,0 +1,22 @@
1
+ (The MIT License)
2
+
3
+ Copyright (c) 2005-2008 The RSpec Development Team
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
20
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
21
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
22
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -1,4 +1,5 @@
1
1
  History.txt
2
+ License.txt
2
3
  Manifest.txt
3
4
  README.txt
4
5
  Rakefile
@@ -85,6 +86,7 @@ lib/spec/adapters/ruby_engine.rb
85
86
  lib/spec/adapters/ruby_engine/mri.rb
86
87
  lib/spec/adapters/ruby_engine/rubinius.rb
87
88
  lib/spec/example.rb
89
+ lib/spec/example/before_and_after_hooks.rb
88
90
  lib/spec/example/configuration.rb
89
91
  lib/spec/example/errors.rb
90
92
  lib/spec/example/example_group.rb
@@ -92,7 +94,6 @@ lib/spec/example/example_group_factory.rb
92
94
  lib/spec/example/example_group_methods.rb
93
95
  lib/spec/example/example_matcher.rb
94
96
  lib/spec/example/example_methods.rb
95
- lib/spec/example/module_inclusion_warnings.rb
96
97
  lib/spec/example/module_reopening_fix.rb
97
98
  lib/spec/example/pending.rb
98
99
  lib/spec/example/shared_example_group.rb
@@ -213,8 +214,6 @@ spec/ruby_forker.rb
213
214
  spec/spec.opts
214
215
  spec/spec/adapters/ruby_engine_spec.rb
215
216
  spec/spec/example/configuration_spec.rb
216
- spec/spec/example/example_group/described_module_spec.rb
217
- spec/spec/example/example_group/warning_messages_spec.rb
218
217
  spec/spec/example/example_group_class_definition_spec.rb
219
218
  spec/spec/example/example_group_factory_spec.rb
220
219
  spec/spec/example/example_group_methods_spec.rb
@@ -234,6 +233,7 @@ spec/spec/extensions/main_spec.rb
234
233
  spec/spec/interop/test/unit/resources/spec_that_fails.rb
235
234
  spec/spec/interop/test/unit/resources/spec_that_passes.rb
236
235
  spec/spec/interop/test/unit/resources/spec_with_errors.rb
236
+ spec/spec/interop/test/unit/resources/spec_with_options_hash.rb
237
237
  spec/spec/interop/test/unit/resources/test_case_that_fails.rb
238
238
  spec/spec/interop/test/unit/resources/test_case_that_passes.rb
239
239
  spec/spec/interop/test/unit/resources/test_case_with_errors.rb
data/README.txt CHANGED
@@ -2,6 +2,7 @@
2
2
 
3
3
  * http://rspec.info
4
4
  * http://rspec.info/rdoc/
5
+ * http://rubyforge.org/projects/rspec
5
6
  * http://github.com/dchelimsky/rspec/wikis
6
7
  * mailto:rspec-devel@rubyforge.org
7
8
 
@@ -36,28 +37,3 @@ behaviour to your existing objects.
36
37
  cd rspec
37
38
  rake gem
38
39
  rake install_gem
39
-
40
- == LICENSE:
41
-
42
- (The MIT License)
43
-
44
- Copyright (c) 2005-2008 The RSpec Development Team
45
-
46
- Permission is hereby granted, free of charge, to any person obtaining
47
- a copy of this software and associated documentation files (the
48
- "Software"), to deal in the Software without restriction, including
49
- without limitation the rights to use, copy, modify, merge, publish,
50
- distribute, sublicense, and/or sell copies of the Software, and to
51
- permit persons to whom the Software is furnished to do so, subject to
52
- the following conditions:
53
-
54
- The above copyright notice and this permission notice shall be
55
- included in all copies or substantial portions of the Software.
56
-
57
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
58
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
59
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
60
- IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
61
- CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
62
- TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
63
- SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Rakefile CHANGED
@@ -18,10 +18,12 @@ Hoe.new('rspec', Spec::VERSION::STRING) do |p|
18
18
  p.url = 'http://rspec.info/'
19
19
  p.description = "Behaviour Driven Development for Ruby."
20
20
  p.rubyforge_name = 'rspec'
21
+ p.extra_dev_deps = ['diff-lcs',['spicycode-rcov','>= 0.8.1.3'],'syntax']
21
22
  p.developer('RSpec Development Team', 'rspec-devel@rubyforge.org')
23
+ p.remote_rdoc_dir = "rspec/#{Spec::VERSION::STRING}"
22
24
  end
23
25
 
24
- ['audit','test','test_deps','default','publish_docs','post_blog'].each do |task|
26
+ ['audit','test','test_deps','default','post_blog'].each do |task|
25
27
  Rake.application.instance_variable_get('@tasks').delete(task)
26
28
  end
27
29
 
@@ -41,7 +43,7 @@ Spec::Rake::SpecTask.new do |t|
41
43
  unless ENV['NO_RCOV']
42
44
  t.rcov = true
43
45
  t.rcov_dir = 'coverage'
44
- t.rcov_opts = ['--exclude', "lib/spec.rb,lib/spec/runner.rb,spec\/spec,bin\/spec,examples,\/var\/lib\/gems,\/Library\/Ruby,\.autotest,#{ENV['GEM_HOME']}"]
46
+ t.rcov_opts = ['--text-report', '--exclude', "lib/spec.rb,lib/spec/runner.rb,spec\/spec,bin\/spec,examples,\/var\/lib\/gems,\/Library\/Ruby,\.autotest,#{ENV['GEM_HOME']}"]
45
47
  end
46
48
  end
47
49
 
data/TODO.txt CHANGED
@@ -1,9 +1,10 @@
1
- == 1.1.6
2
-
3
- * resolve windows tty/colorization issue
4
-
5
1
  == Future
6
2
 
7
3
  * do SOMETHING with the website
8
4
  * extract spec/story to rspec-stories (new gem)
9
5
  * remove the ruby engine adapter unless Rubinius team plans to use it
6
+ * rename top level namespace to Rspec and commands to 'rspec' and 'autorspec'
7
+ * continue to support Spec 'spec' and 'autospec' as aliases for a reasonable time
8
+ * separate the underlying framework from the DSL
9
+ * be able to do everything with classes and methods
10
+ * tweak raise_error rdoc to show only one arg
@@ -1,4 +1,4 @@
1
1
  #!/usr/bin/env ruby
2
2
  ENV['RSPEC'] = 'true' # allows autotest to discover rspec
3
3
  ENV['AUTOTEST'] = 'true' # allows autotest to run w/ color on linux
4
- system (RUBY_PLATFORM =~ /mswin/ ? 'autotest.bat' : 'autotest'), *ARGV
4
+ system (RUBY_PLATFORM =~ /mswin|mingw/ ? 'autotest.bat' : 'autotest'), *ARGV
@@ -31,8 +31,8 @@ module SharedExampleGroupExample
31
31
  end
32
32
  end
33
33
 
34
- # A SharedExampleGroup is also module. If you create one like this
35
- # it gets assigned to the constant AllThings
34
+ # A SharedExampleGroup is also a module. If you create one like this it gets
35
+ # assigned to the constant MostThings
36
36
  share_as :MostThings do
37
37
  def helper_method
38
38
  "helper method"
@@ -4,7 +4,7 @@ Autotest.add_hook :initialize do |at|
4
4
  at.clear_mappings
5
5
  # watch out: Ruby bug (1.8.6):
6
6
  # %r(/) != /\//
7
- at.add_mapping(%r%^spec/.*\.rb$%) { |filename, _|
7
+ at.add_mapping(%r%^spec/.*_spec.rb$%) { |filename, _|
8
8
  filename
9
9
  }
10
10
  at.add_mapping(%r%^lib/(.*)\.rb$%) { |_, m|
@@ -24,5 +24,9 @@ module Spec
24
24
  def exit?
25
25
  !Object.const_defined?(:Test) || Test::Unit.run?
26
26
  end
27
+
28
+ def spec_command?
29
+ $0.split('/').last == 'spec'
30
+ end
27
31
  end
28
- end
32
+ end
@@ -1,7 +1,7 @@
1
1
  require 'timeout'
2
+ require 'spec/example/before_and_after_hooks'
2
3
  require 'spec/example/pending'
3
4
  require 'spec/example/module_reopening_fix'
4
- require 'spec/example/module_inclusion_warnings'
5
5
  require 'spec/example/example_group_methods'
6
6
  require 'spec/example/example_methods'
7
7
  require 'spec/example/example_group'
@@ -0,0 +1,93 @@
1
+ module Spec
2
+ module Example
3
+ module BeforeAndAfterHooks
4
+ # Registers a block to be executed before each example.
5
+ # This method prepends +block+ to existing before blocks.
6
+ def prepend_before(*args, &block)
7
+ scope, options = scope_and_options(*args)
8
+ parts = before_parts_from_scope(scope)
9
+ parts.unshift(block)
10
+ end
11
+
12
+ # Registers a block to be executed before each example.
13
+ # This method appends +block+ to existing before blocks.
14
+ def append_before(*args, &block)
15
+ scope, options = scope_and_options(*args)
16
+ parts = before_parts_from_scope(scope)
17
+ parts << block
18
+ end
19
+ alias_method :before, :append_before
20
+
21
+ # Registers a block to be executed after each example.
22
+ # This method prepends +block+ to existing after blocks.
23
+ def prepend_after(*args, &block)
24
+ scope, options = scope_and_options(*args)
25
+ parts = after_parts_from_scope(scope)
26
+ parts.unshift(block)
27
+ end
28
+ alias_method :after, :prepend_after
29
+
30
+ # Registers a block to be executed after each example.
31
+ # This method appends +block+ to existing after blocks.
32
+ def append_after(*args, &block)
33
+ scope, options = scope_and_options(*args)
34
+ parts = after_parts_from_scope(scope)
35
+ parts << block
36
+ end
37
+
38
+ def remove_after(scope, &block)
39
+ after_each_parts.delete(block)
40
+ end
41
+
42
+ # Deprecated. Use before(:each)
43
+ def setup(&block)
44
+ before(:each, &block)
45
+ end
46
+
47
+ # Deprecated. Use after(:each)
48
+ def teardown(&block)
49
+ after(:each, &block)
50
+ end
51
+
52
+ def before_all_parts # :nodoc:
53
+ @before_all_parts ||= []
54
+ end
55
+
56
+ def after_all_parts # :nodoc:
57
+ @after_all_parts ||= []
58
+ end
59
+
60
+ def before_each_parts # :nodoc:
61
+ @before_each_parts ||= []
62
+ end
63
+
64
+ def after_each_parts # :nodoc:
65
+ @after_each_parts ||= []
66
+ end
67
+
68
+ private
69
+
70
+ def scope_and_options(*args)
71
+ args, options = args_and_options(*args)
72
+ scope = (args[0] || :each), options
73
+ end
74
+
75
+ def before_parts_from_scope(scope)
76
+ case scope
77
+ when :each; before_each_parts
78
+ when :all; before_all_parts
79
+ when :suite; Spec::Runner.options.before_suite_parts
80
+ end
81
+ end
82
+
83
+ def after_parts_from_scope(scope)
84
+ case scope
85
+ when :each; after_each_parts
86
+ when :all; after_all_parts
87
+ when :suite; Spec::Runner.options.after_suite_parts
88
+ end
89
+ end
90
+
91
+ end
92
+ end
93
+ end
@@ -67,12 +67,21 @@ module Spec
67
67
  # end
68
68
  #
69
69
  def include(*args)
70
+ include_or_extend(:include, *args)
71
+ end
72
+
73
+ def extend(*args)
74
+ include_or_extend(:extend, *args)
75
+ end
76
+
77
+ def include_or_extend(*args)
78
+ action = args.shift
70
79
  args << {} unless Hash === args.last
71
80
  modules, options = args_and_options(*args)
72
81
  required_example_group = get_type_from_options(options)
73
82
  required_example_group = required_example_group.to_sym if required_example_group
74
83
  modules.each do |mod|
75
- ExampleGroupFactory.get(required_example_group).send(:include, mod)
84
+ ExampleGroupFactory.get(required_example_group).send(action, mod)
76
85
  end
77
86
  end
78
87
 
@@ -6,7 +6,8 @@ module Spec
6
6
  extend Spec::Example::ExampleGroupMethods
7
7
  include Spec::Example::ExampleMethods
8
8
 
9
- def initialize(defined_description, &implementation)
9
+ def initialize(defined_description, options={}, &implementation)
10
+ @_options = options
10
11
  @_defined_description = defined_description
11
12
  @_implementation = implementation || pending_implementation
12
13
  end
@@ -7,6 +7,13 @@ module Spec
7
7
  default(ExampleGroup)
8
8
  end
9
9
 
10
+ def all_registered?(example_group_classes)
11
+ example_group_classes.each do |example_group_class|
12
+ return false unless registered_or_ancestor_of_registered? example_group_class
13
+ end
14
+ return true
15
+ end
16
+
10
17
  # Registers an example group class +klass+ with the symbol +type+. For
11
18
  # example:
12
19
  #
@@ -46,7 +53,7 @@ module Spec
46
53
  superclass.describe(*args, &block)
47
54
  end
48
55
 
49
- protected
56
+ protected
50
57
 
51
58
  def determine_superclass(opts)
52
59
  key = if opts[:type]
@@ -56,6 +63,16 @@ module Spec
56
63
  end
57
64
  get(key)
58
65
  end
66
+
67
+ private
68
+
69
+ def registered_or_ancestor_of_registered? example_group_class
70
+ registered_types.any? {|registered_type| registered_type.ancestors.include? example_group_class}
71
+ end
72
+
73
+ def registered_types
74
+ @example_group_types.values
75
+ end
59
76
 
60
77
  end
61
78
  self.reset
@@ -2,6 +2,8 @@ module Spec
2
2
  module Example
3
3
 
4
4
  module ExampleGroupMethods
5
+ include Spec::Example::BeforeAndAfterHooks
6
+
5
7
  class << self
6
8
  attr_accessor :matcher_class
7
9
 
@@ -13,7 +15,12 @@ module Spec
13
15
  end
14
16
  end
15
17
 
16
- attr_reader :description_text, :description_args, :description_options, :spec_path, :registration_binding_block
18
+ attr_reader :description_text, :description_options, :spec_path
19
+ alias :options :description_options
20
+
21
+ def description_args
22
+ @description_args ||= []
23
+ end
17
24
 
18
25
  def inherited(klass)
19
26
  super
@@ -64,19 +71,12 @@ module Spec
64
71
 
65
72
  # Use this to pull in examples from shared example groups.
66
73
  # See Spec::Runner for information about shared example groups.
67
- def it_should_behave_like(shared_example_group)
68
- case shared_example_group
69
- when SharedExampleGroup
70
- include shared_example_group
71
- else
72
- example_group = SharedExampleGroup.find_shared_example_group(shared_example_group)
73
- unless example_group
74
- raise RuntimeError.new("Shared Example Group '#{shared_example_group}' can not be found")
75
- end
76
- include(example_group)
74
+ def it_should_behave_like(*shared_example_groups)
75
+ shared_example_groups.each do |group|
76
+ include_shared_example_group(group)
77
77
  end
78
78
  end
79
-
79
+
80
80
  # :call-seq:
81
81
  # predicate_matchers[matcher_name] = method_on_object
82
82
  # predicate_matchers[matcher_name] = [method1_on_object, method2_on_object]
@@ -111,8 +111,8 @@ module Spec
111
111
 
112
112
  # Creates an instance of the current example group class and adds it to
113
113
  # a collection of examples of the current example group.
114
- def example(description=nil, &implementation)
115
- e = new(description, &implementation)
114
+ def example(description=nil, options={}, &implementation)
115
+ e = new(description, options, &implementation)
116
116
  example_objects << e
117
117
  e
118
118
  end
@@ -157,8 +157,8 @@ module Spec
157
157
 
158
158
  def description_parts #:nodoc:
159
159
  parts = []
160
- execute_in_class_hierarchy do |example_group|
161
- parts << example_group.description_args
160
+ each_ancestor_example_group_class do |example_group_class|
161
+ parts << example_group_class.description_args
162
162
  end
163
163
  parts.flatten.compact
164
164
  end
@@ -169,14 +169,9 @@ module Spec
169
169
  @description_options = options
170
170
  @description_text = ExampleGroupMethods.description_text(*args)
171
171
  @spec_path = File.expand_path(options[:spec_path]) if options[:spec_path]
172
- if described_type.class == Module
173
- @described_module = described_type
174
- end
175
172
  self
176
173
  end
177
174
 
178
- attr_reader :described_module
179
-
180
175
  def examples #:nodoc:
181
176
  examples = example_objects.dup
182
177
  add_method_examples(examples)
@@ -187,70 +182,6 @@ module Spec
187
182
  examples.length
188
183
  end
189
184
 
190
- # Registers a block to be executed before each example.
191
- # This method prepends +block+ to existing before blocks.
192
- def prepend_before(*args, &block)
193
- scope, options = scope_and_options(*args)
194
- parts = before_parts_from_scope(scope)
195
- parts.unshift(block)
196
- end
197
-
198
- # Registers a block to be executed before each example.
199
- # This method appends +block+ to existing before blocks.
200
- def append_before(*args, &block)
201
- scope, options = scope_and_options(*args)
202
- parts = before_parts_from_scope(scope)
203
- parts << block
204
- end
205
- alias_method :before, :append_before
206
-
207
- # Registers a block to be executed after each example.
208
- # This method prepends +block+ to existing after blocks.
209
- def prepend_after(*args, &block)
210
- scope, options = scope_and_options(*args)
211
- parts = after_parts_from_scope(scope)
212
- parts.unshift(block)
213
- end
214
- alias_method :after, :prepend_after
215
-
216
- # Registers a block to be executed after each example.
217
- # This method appends +block+ to existing after blocks.
218
- def append_after(*args, &block)
219
- scope, options = scope_and_options(*args)
220
- parts = after_parts_from_scope(scope)
221
- parts << block
222
- end
223
-
224
- def remove_after(scope, &block)
225
- after_each_parts.delete(block)
226
- end
227
-
228
- # Deprecated. Use before(:each)
229
- def setup(&block)
230
- before(:each, &block)
231
- end
232
-
233
- # Deprecated. Use after(:each)
234
- def teardown(&block)
235
- after(:each, &block)
236
- end
237
-
238
- def before_all_parts # :nodoc:
239
- @before_all_parts ||= []
240
- end
241
-
242
- def after_all_parts # :nodoc:
243
- @after_all_parts ||= []
244
- end
245
-
246
- def before_each_parts # :nodoc:
247
- @before_each_parts ||= []
248
- end
249
-
250
- def after_each_parts # :nodoc:
251
- @after_each_parts ||= []
252
- end
253
-
254
185
  # Only used from RSpec's own examples
255
186
  def reset # :nodoc:
256
187
  @before_all_parts = nil
@@ -269,18 +200,18 @@ module Spec
269
200
  end
270
201
 
271
202
  def registration_backtrace
272
- eval("caller", registration_binding_block)
203
+ eval("caller", @registration_binding_block)
273
204
  end
274
205
 
275
206
  def run_before_each(example)
276
- execute_in_class_hierarchy do |example_group|
277
- example.eval_each_fail_fast(example_group.before_each_parts)
207
+ each_ancestor_example_group_class do |example_group_class|
208
+ example.eval_each_fail_fast(example_group_class.before_each_parts)
278
209
  end
279
210
  end
280
211
 
281
212
  def run_after_each(example)
282
- execute_in_class_hierarchy(:superclass_first) do |example_group|
283
- example.eval_each_fail_slow(example_group.after_each_parts)
213
+ each_ancestor_example_group_class(:superclass_first) do |example_group_class|
214
+ example.eval_each_fail_slow(example_group_class.after_each_parts)
284
215
  end
285
216
  end
286
217
 
@@ -296,8 +227,8 @@ module Spec
296
227
  def run_before_all
297
228
  before_all = new("before(:all)")
298
229
  begin
299
- execute_in_class_hierarchy do |example_group|
300
- before_all.eval_each_fail_fast(example_group.before_all_parts)
230
+ each_ancestor_example_group_class do |example_group_class|
231
+ before_all.eval_each_fail_fast(example_group_class.before_all_parts)
301
232
  end
302
233
  return [true, before_all.instance_variable_hash]
303
234
  rescue Exception => e
@@ -320,8 +251,8 @@ module Spec
320
251
  def run_after_all(success, instance_variables)
321
252
  after_all = new("after(:all)")
322
253
  after_all.set_instance_variables_from_hash(instance_variables)
323
- execute_in_class_hierarchy(:superclass_first) do |example_group|
324
- after_all.eval_each_fail_slow(example_group.after_all_parts)
254
+ each_ancestor_example_group_class(:superclass_first) do |example_group_class|
255
+ after_all.eval_each_fail_slow(example_group_class.after_all_parts)
325
256
  end
326
257
  return success
327
258
  rescue Exception => e
@@ -359,22 +290,21 @@ module Spec
359
290
  @example_objects ||= []
360
291
  end
361
292
 
362
- def execute_in_class_hierarchy(superclass_last=false)
293
+ def each_ancestor_example_group_class(superclass_last=false)
363
294
  classes = []
364
295
  current_class = self
365
- while is_example_group?(current_class)
296
+ while is_example_group_class?(current_class)
366
297
  superclass_last ? classes << current_class : classes.unshift(current_class)
367
298
  current_class = current_class.superclass
368
299
  end
369
- superclass_last ? classes << ExampleMethods : classes.unshift(ExampleMethods)
370
-
300
+
371
301
  classes.each do |example_group|
372
302
  yield example_group
373
303
  end
374
304
  end
375
305
 
376
- def is_example_group?(klass)
377
- Module === klass && klass.kind_of?(ExampleGroupMethods)
306
+ def is_example_group_class?(klass)
307
+ klass.kind_of?(ExampleGroupMethods) && klass.included_modules.include?(ExampleMethods)
378
308
  end
379
309
 
380
310
  def plugin_mock_framework
@@ -398,27 +328,6 @@ module Spec
398
328
  end
399
329
  end
400
330
 
401
- def scope_and_options(*args)
402
- args, options = args_and_options(*args)
403
- scope = (args[0] || :each), options
404
- end
405
-
406
- def before_parts_from_scope(scope)
407
- case scope
408
- when :each; before_each_parts
409
- when :all; before_all_parts
410
- when :suite; Spec::Runner.options.before_suite_parts
411
- end
412
- end
413
-
414
- def after_parts_from_scope(scope)
415
- case scope
416
- when :each; after_each_parts
417
- when :all; after_all_parts
418
- when :suite; Spec::Runner.options.after_suite_parts
419
- end
420
- end
421
-
422
331
  def add_method_examples(examples)
423
332
  instance_methods.sort.each do |method_name|
424
333
  if example_method?(method_name)
@@ -436,10 +345,23 @@ module Spec
436
345
  def should_method?(method_name)
437
346
  !(method_name =~ /^should(_not)?$/) &&
438
347
  method_name =~ /^should/ && (
439
- instance_method(method_name).arity == 0 ||
440
- instance_method(method_name).arity == -1
348
+ [-1,0].include?(instance_method(method_name).arity)
441
349
  )
442
350
  end
351
+
352
+ def include_shared_example_group(shared_example_group)
353
+ case shared_example_group
354
+ when SharedExampleGroup
355
+ include shared_example_group
356
+ else
357
+ example_group = SharedExampleGroup.find_shared_example_group(shared_example_group)
358
+ unless example_group
359
+ raise RuntimeError.new("Shared Example Group '#{shared_example_group}' can not be found")
360
+ end
361
+ include(example_group)
362
+ end
363
+ end
364
+
443
365
  end
444
366
 
445
367
  end