rspec 1.0.5 → 1.0.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (87) hide show
  1. data/CHANGES +78 -1
  2. data/EXAMPLES.rd +8 -5
  3. data/README +1 -0
  4. data/Rakefile +1 -1
  5. data/examples/pending_example.rb +20 -0
  6. data/lib/autotest/rspec.rb +46 -18
  7. data/lib/spec/dsl.rb +1 -0
  8. data/lib/spec/dsl/behaviour.rb +37 -27
  9. data/lib/spec/dsl/behaviour_callbacks.rb +4 -0
  10. data/lib/spec/dsl/behaviour_eval.rb +27 -16
  11. data/lib/spec/dsl/behaviour_factory.rb +2 -2
  12. data/lib/spec/dsl/composite_proc_builder.rb +9 -4
  13. data/lib/spec/dsl/configuration.rb +20 -4
  14. data/lib/spec/dsl/description.rb +7 -0
  15. data/lib/spec/dsl/errors.rb +9 -0
  16. data/lib/spec/dsl/example.rb +18 -10
  17. data/lib/spec/matchers/have.rb +10 -13
  18. data/lib/spec/matchers/operator_matcher.rb +3 -3
  19. data/lib/spec/matchers/raise_error.rb +8 -3
  20. data/lib/spec/mocks/error_generator.rb +1 -1
  21. data/lib/spec/mocks/message_expectation.rb +11 -0
  22. data/lib/spec/mocks/methods.rb +9 -5
  23. data/lib/spec/mocks/proxy.rb +13 -9
  24. data/lib/spec/rake/spectask.rb +80 -38
  25. data/lib/spec/runner/backtrace_tweaker.rb +2 -1
  26. data/lib/spec/runner/behaviour_runner.rb +37 -16
  27. data/lib/spec/runner/formatter/base_formatter.rb +23 -15
  28. data/lib/spec/runner/formatter/base_text_formatter.rb +39 -11
  29. data/lib/spec/runner/formatter/failing_behaviours_formatter.rb +7 -3
  30. data/lib/spec/runner/formatter/failing_examples_formatter.rb +3 -3
  31. data/lib/spec/runner/formatter/html_formatter.rb +32 -25
  32. data/lib/spec/runner/formatter/progress_bar_formatter.rb +6 -5
  33. data/lib/spec/runner/formatter/rdoc_formatter.rb +6 -6
  34. data/lib/spec/runner/formatter/specdoc_formatter.rb +7 -6
  35. data/lib/spec/runner/option_parser.rb +6 -5
  36. data/lib/spec/runner/options.rb +60 -43
  37. data/lib/spec/runner/reporter.rb +17 -6
  38. data/lib/spec/runner/spec_parser.rb +1 -1
  39. data/lib/spec/translator.rb +8 -0
  40. data/lib/spec/version.rb +3 -3
  41. data/plugins/mock_frameworks/flexmock.rb +14 -18
  42. data/plugins/mock_frameworks/mocha.rb +0 -2
  43. data/plugins/mock_frameworks/rr.rb +21 -0
  44. data/spec/autotest/discover_spec.rb +19 -0
  45. data/spec/autotest/rspec_spec.rb +257 -0
  46. data/spec/autotest_helper.rb +4 -0
  47. data/spec/spec/dsl/behaviour_eval_spec.rb +30 -0
  48. data/spec/spec/dsl/behaviour_factory_spec.rb +18 -0
  49. data/spec/spec/dsl/behaviour_spec.rb +95 -58
  50. data/spec/spec/dsl/composite_proc_builder_spec.rb +0 -13
  51. data/spec/spec/dsl/configuration_spec.rb +6 -1
  52. data/spec/spec/dsl/description_spec.rb +9 -1
  53. data/spec/spec/dsl/example_class_spec.rb +3 -3
  54. data/spec/spec/dsl/example_instance_spec.rb +26 -28
  55. data/spec/spec/dsl/example_matcher_spec.rb +91 -0
  56. data/spec/spec/dsl/shared_behaviour_spec.rb +24 -0
  57. data/spec/spec/expectations/extensions/object_spec.rb +2 -2
  58. data/spec/spec/expectations/fail_with_spec.rb +2 -2
  59. data/spec/spec/matchers/have_spec.rb +1 -1
  60. data/spec/spec/matchers/operator_matcher_spec.rb +10 -10
  61. data/spec/spec/matchers/raise_error_spec.rb +38 -0
  62. data/spec/spec/mocks/argument_expectation_spec.rb +18 -14
  63. data/spec/spec/mocks/at_most_spec.rb +1 -1
  64. data/spec/spec/mocks/bug_report_11545_spec.rb +31 -0
  65. data/spec/spec/mocks/partial_mock_spec.rb +33 -1
  66. data/spec/spec/runner/behaviour_runner_spec.rb +72 -49
  67. data/spec/spec/runner/command_line_spec.rb +1 -1
  68. data/spec/spec/runner/context_matching_spec.rb +10 -10
  69. data/spec/spec/runner/drb_command_line_spec.rb +62 -59
  70. data/spec/spec/runner/extensions/bug_report_10577_spec.rb +35 -0
  71. data/spec/spec/runner/formatter/failing_behaviours_formatter_spec.rb +15 -2
  72. data/spec/spec/runner/formatter/failing_examples_formatter_spec.rb +3 -3
  73. data/spec/spec/runner/formatter/html_formatter_spec.rb +1 -1
  74. data/spec/spec/runner/formatter/progress_bar_formatter_dry_run_spec.rb +14 -15
  75. data/spec/spec/runner/formatter/progress_bar_formatter_failure_dump_spec.rb +1 -1
  76. data/spec/spec/runner/formatter/progress_bar_formatter_spec.rb +42 -9
  77. data/spec/spec/runner/formatter/rdoc_formatter_spec.rb +40 -40
  78. data/spec/spec/runner/formatter/specdoc_formatter_spec.rb +55 -49
  79. data/spec/spec/runner/option_parser_spec.rb +16 -15
  80. data/spec/spec/runner/options_spec.rb +64 -31
  81. data/spec/spec/runner/reporter_spec.rb +67 -15
  82. data/spec/spec/spec_classes.rb +9 -1
  83. data/spec/spec/translator_spec.rb +48 -0
  84. data/spec/spec_helper.rb +5 -2
  85. metadata +13 -6
  86. data/examples/not_yet_implemented_spec.rb +0 -12
  87. data/spec/spec/runner/example_matcher_spec.rb +0 -127
data/CHANGES CHANGED
@@ -1,7 +1,84 @@
1
+ == Version 1.0.6
2
+
3
+ The "holy cow, batman, it's been a long time since we released and there are a ton of bug
4
+ fixes, patches and even new features" release.
5
+
6
+ Warning: Spec::Rails users: In fixing 11508, we've removed the raise_controller_errors method. As long as you
7
+ follow the upgrade instructions and run 'script/generate rspec' you'll be fine, but if you skip this
8
+ step you need to manually go into spec_helper.rb and remove the call to that method (if present - it
9
+ might not be if you haven't upgraded in a while).
10
+
11
+ Warning: Implementors of custom formatters. Formatters will now be sent an Example object instead of just a
12
+ String for #example_started, #example_passed and #example_failed. In certain scenarios
13
+ (Spec::Ui with Spec::Distributed), the formatter must ask the Example for its sequence number instead of
14
+ keeping track of a sequence number internal to the formatter. Most of you shouldn't need to upgrade
15
+ your formatters though - the Example#to_s method returns the example name/description, so you should be
16
+ able to use the passed Example instance as if it were a String.
17
+
18
+ * Applied [#12986] Autotest Specs + Refactoring (Patch from Scott Tayler)
19
+ * Added a #close method to formatters, which allows them to gracefully close streams.
20
+ * Applied [#12935] Remove requirement that mocha must be installed as a gem when used as mocking framework. (Patch from Ryan Kinderman).
21
+ * Fixed [#12893] RSpec's Autotest should work with rspec's trunk
22
+ * Fixed [#12865] Partial mock error when object has an @options instance var
23
+ * Applied [#12701] Allow checking of content captured with content_for in view specs (Patch from Jens Kr�mer)
24
+ * Applied [#12817] Cannot include same shared behaviour when required with absolute paths (Patch from Ian Leitch)
25
+ * Applied [#12719] rspec_on_rails should not include pagination helper (Patch from Matthijs Langenberg)
26
+ * Fixed [#12714] helper spec not finding rails core helpers
27
+ * Applied [#12611] should_not redirect_to implementation (Patch from Yurii Rashkovskii)
28
+ * Applied [#12682] Not correctly aliasing original 'stub!' and 'should_receive' methods for ApplicationController (Patch from Matthijs Langenberg)
29
+ * Disabled controller.should_receive(:render) and controller.stub!(:render). Use expect_render or stub_render instead.
30
+ * Applied [#12484] Allow a Behaviour's Description to flow through to the Formatter (Patch from Bob Cotton)
31
+ * Fixed [#12448] The spec:plugins rake task from rspec_on_rails should ignore specs from the rspec_on_rails plugin
32
+ * Applied [#12300] rr integration (patch from Kyle Hargraves)
33
+ * Implemented [#12284] mock_with :rr (integration with RR mock framework: http://rubyforge.org/projects/pivotalrb/)
34
+ * Applied [#12237] (tiny) added full path to mate in switch_command (Patch from Carl Porth)
35
+ * Formatters will now be sent an Example object instead of just a String for certain methods
36
+ * All Spec::Rake::SpecTask attributes can now be procs, which allows for lazy evaluation.
37
+ * Changed the Spec::Ui interfaces slightly. See examples.
38
+ * Applied [#12174] mishandling of paths with spaces in spec_mate switch_command (Patch from Carl Porth)
39
+ * Implemented [#8315] File "Go to..." functionality
40
+ * Applied [#11917] Cleaner Spec::Ui error for failed Selenium connection (Patch from Ian Dees)
41
+ * Applied [#11888] rspec_on_rails spews out warnings when assert_select is used with an XML response (Patch from Ian Leitch)
42
+ * Applied [#12010] Nicer failure message formatting (Patch from Wincent Colaiuta)
43
+ * Applied [#12156] smooth open mate patch (Patch from Ienaga Eiji)
44
+ * Applied [#10577] Rails with Oracle breaks 0.9.2. (Patch from Sinclair Bain)
45
+ * Fixed [#12079] auto-generated example name incomplete: should have 1 error on ....]
46
+ * Applied [#12066] Docfix for mocks/mocks.page (Patch from Kyle Hargraves)
47
+ * Fixed [#11891] script/generate rspec_controller fails to create appropriate views (from templates) on edge rails
48
+ * Applied [#11921] Adds the correct controller_name from derived_controller_name() to the ViewExampleController (Patch from Eloy Duran)
49
+ * Fixed [#11903] config.include with behaviour_type 'hash' does not work
50
+ * Examples without blocks and pending is now reported with a P instead of a *
51
+ * Pending blocks that now pass are rendered blue
52
+ * New behaviour for after: If an after block raises an error, the other ones will still run instead of bailing at the first.
53
+ * Made it possible to run spec from RSpec.tmbundle with --drb against a Rails spec_server.
54
+ * Applied [#11868] Add ability for pending to optionally hold a failing block and to fail when it passes (Patch from Bob Cotton)
55
+ * Fixed [#11843] watir_behaviour missing from spec_ui gem
56
+ * Added 'switch between source and spec file' command in Spec::Mate (based on code from Ruy Asan)
57
+ * Applied [#11509] Documentation - RSpec requires hpricot
58
+ * Applied [#11807] Daemonize spec_server and rake tasks to manage them. (patch from Kyosuke MOROHASHI)
59
+ * Added pending(message) method
60
+ * Fixed [#11777] should render_template doesn't check paths correctly
61
+ * Fixed [#11749] Use of 'rescue => e' does not catch all exceptions
62
+ * Fixed [#11793] should raise_error('with a message') does not work correctly
63
+ * Fixed [#11774] Mocks should respond to :kind_of? in the same way they respond to :is_a?
64
+ * Fixed [#11508] Exceptions are not raised for Controller Specs (removed experimental raise_controller_errors)
65
+ * Applied [#11615] Partial mock methods give ambiguous failures when given a method name as a String (Patch from Jay Phillips)
66
+ * Fixed [#11545] Rspec doesn't handle should_receive on ActiveRecord associations (Patch from Ian White)
67
+ * Fixed [#11514] configuration.use_transactional_fixtures is ALWAYS true, regardless of assignment
68
+ * Improved generated RESTful controller examples to cover both successful and unsuccessful POST and PUT
69
+ * Changed TextMate snippets for controllers to pass controller class names to #describe rather than controller_name.
70
+ * Changed TextMate snippets for mocks to use no_args() and any_args() instead of the deprecated Symbols.
71
+ * Applied [#11500] Documentation: no rails integration specs in 1.0
72
+ * Renamed SpecMate's shortcuts for running all examples and focused examples to avoid conflicts (CMD-d and CMD-i)
73
+ * Added a TextMate snippet for custom matchers, lifted from Geoffrey Grosenbach's RSpec peepcode show.
74
+ * The translator translates mock constraints to the new matchers that were introduced in 1.0.4
75
+ * Documented environment variables for Spec::Rake::SpecTask. Renamed SPECOPTS and RCOVOPTS to SPEC_OPTS and RCOV_OPTS.
76
+ * Fixed [#10534] Windows: undefined method 'controller_name'
77
+
1
78
  == Version 1.0.5
2
79
  Bug fixes. Autotest plugin tweaks.
3
80
 
4
- * Fixed [#11378] fix to 10814 broke drb
81
+ * Fixed [#11378] fix to 10814 broke drb (re-opened #10814)
5
82
  * Fixed [#11223] Unable to access flash from rails helper specs
6
83
  * Fixed [#11337] autotest runs specs redundantly
7
84
  * Fixed [#11258] windows: autotest won't run
data/EXAMPLES.rd CHANGED
@@ -43,13 +43,16 @@
43
43
  # a mock
44
44
  # * should be able to mock the same message twice w/ different args
45
45
  # * should be able to mock the same message twice w/ different args in reverse order
46
- # Stack (not implemented features)
47
- # * should transform to xml using #to_xml [NOT IMPLEMENTED]
48
- # * should convert from xml using #from_xml [NOT IMPLEMENTED]
49
46
  # A partial mock
50
47
  # * should work at the class level
51
48
  # * should revert to the original after each spec
52
49
  # * can be mocked w/ ordering
50
+ # pending example (using pending method)
51
+ # * pending example (using pending method) should be reported as "PENDING: for some reason" [PENDING: for some reason]
52
+ # pending example (with no block)
53
+ # * pending example (with no block) should be reported as "PENDING: Not Yet Implemented" [PENDING: Not Yet Implemented]
54
+ # pending example (with block for pending)
55
+ # * pending example (with block for pending) should have a failing block, passed to pending, reported as "PENDING: for some reason" [PENDING: for some reason]
53
56
  # BDD framework
54
57
  # * should be adopted quickly
55
58
  # * should be intuitive
@@ -103,6 +106,6 @@
103
106
  # * RSpec should be able to access TestCase methods
104
107
  # * RSpec should be able to accept included modules
105
108
 
106
- Finished in 0.024612 seconds
109
+ Finished in 0.030625 seconds
107
110
 
108
- 77 examples, 0 failures, 2 not implemented
111
+ 78 examples, 0 failures, 3 pending
data/README CHANGED
@@ -46,6 +46,7 @@ In order to run RSpec's full suite of specs (rake pre_commit) you must install t
46
46
  * win32console # Required by the --colour switch if you're on Windows
47
47
  * meta_project # Required in order to make releases at RubyForge
48
48
  * heckle # Required if you use the --heckle switch
49
+ * hpricot # Used for parsing HTML from the HTML output formatter in RSpec's own specs
49
50
 
50
51
  Once those are all installed, you should be able to run the suite with the following steps:
51
52
 
data/Rakefile CHANGED
@@ -107,7 +107,7 @@ spec = Gem::Specification.new do |s|
107
107
  s.bindir = 'bin'
108
108
  s.executables = ['spec', 'spec_translator']
109
109
  s.default_executable = 'spec'
110
- s.author = ["RSpec Development Team"]
110
+ s.author = "RSpec Development Team"
111
111
  s.email = "rspec-devel@rubyforge.org"
112
112
  s.homepage = "http://rspec.rubyforge.org"
113
113
  s.rubyforge_project = "rspec"
@@ -0,0 +1,20 @@
1
+ require File.dirname(__FILE__) + '/spec_helper'
2
+
3
+ describe "pending example (using pending method)" do
4
+ it %Q|should be reported as "PENDING: for some reason"| do
5
+ pending("for some reason")
6
+ end
7
+ end
8
+
9
+ describe "pending example (with no block)" do
10
+ it %Q|should be reported as "PENDING: Not Yet Implemented"|
11
+ end
12
+
13
+ describe "pending example (with block for pending)" do
14
+ it %Q|should have a failing block, passed to pending, reported as "PENDING: for some reason"| do
15
+ pending("for some reason") do
16
+ raise "some reason"
17
+ end
18
+ end
19
+ end
20
+
@@ -1,30 +1,42 @@
1
1
  require 'autotest'
2
2
 
3
+ class RspecCommandError < StandardError; end
4
+
3
5
  class Autotest::Rspec < Autotest
6
+
7
+ def initialize(kernel=Kernel, separator=File::SEPARATOR, alt_separator=File::ALT_SEPARATOR) # :nodoc:
8
+ super()
9
+ @kernel, @separator, @alt_separator = kernel, separator, alt_separator
10
+ @spec_command = spec_command
4
11
 
5
- def initialize # :nodoc:
6
- super
7
- @spec_command = "spec"
12
+ # watch out: Ruby bug (1.8.6):
13
+ # %r(/) != /\//
14
+ # since Ruby compares the REGEXP source, not the resulting pattern
8
15
  @test_mappings = {
9
- %r%^spec/.*\.rb$% => proc { |filename, _|
10
- filename
11
- },
12
- %r%^lib/(.*)\.rb$% => proc { |_, m|
13
- ["spec/#{m[1]}_spec.rb"]
16
+ %r%^spec/.*\.rb$% => kernel.proc { |filename, _|
17
+ filename
14
18
  },
15
- %r%^spec/(spec_helper|shared/.*)\.rb$% => proc {
16
- files_matching %r%^spec/.*_spec\.rb$%
19
+ %r%^lib/(.*)\.rb$% => kernel.proc { |_, m|
20
+ ["spec/#{m[1]}_spec.rb"]
17
21
  },
22
+ %r%^spec/(spec_helper|shared/.*)\.rb$% => kernel.proc {
23
+ files_matching %r%^spec/.*_spec\.rb$%
24
+ }
18
25
  }
19
26
  end
20
27
 
21
28
  def tests_for_file(filename)
22
29
  super.select { |f| @files.has_key? f }
23
30
  end
31
+
32
+ alias :specs_for_file :tests_for_file
33
+
34
+ def failed_results(results)
35
+ results.scan(/^\d+\)\n(?:\e\[\d*m)?(?:.*?Error in )?'([^\n]*)'(?: FAILED)?(?:\e\[\d*m)?\n(.*?)\n\n/m)
36
+ end
24
37
 
25
38
  def handle_results(results)
26
- failed = results.scan(/^\d+\)\n(?:\e\[\d*m)?(?:.*?Error in )?'([^\n]*)'(?: FAILED)?(?:\e\[\d*m)?\n(.*?)\n\n/m)
27
- @files_to_test = consolidate_failures failed
39
+ @files_to_test = consolidate_failures failed_results(results)
28
40
  unless @files_to_test.empty? then
29
41
  hook :red
30
42
  else
@@ -54,14 +66,30 @@ class Autotest::Rspec < Autotest
54
66
  File.exist?("spec/spec.opts") ? "-O spec/spec.opts " : ""
55
67
  end
56
68
 
69
+ # Finds the proper spec command to use. Precendence
70
+ # is set in the lazily-evaluated method spec_commands. Alias + Override
71
+ # that in ~/.autotest to provide a different spec command
72
+ # then the default paths provided.
57
73
  def spec_command
58
- spec = File.join(Config::CONFIG['bindir'], 'spec')
59
-
60
- unless File::ALT_SEPARATOR.nil? then
61
- spec.gsub! File::SEPARATOR, File::ALT_SEPARATOR
74
+ spec_commands.each do |command|
75
+ if File.exists?(command)
76
+ return @alt_separator ? (command.gsub @separator, @alt_separator) : command
77
+ end
62
78
  end
63
-
64
- return spec
79
+
80
+ raise RspecCommandError, "No spec command could be found!"
81
+ end
82
+
83
+ # Autotest will look for spec commands in the following
84
+ # locations, in this order:
85
+ #
86
+ # * bin/spec
87
+ # * default spec bin/loader installed in Rubygems
88
+ def spec_commands
89
+ [
90
+ File.join('bin', 'spec'),
91
+ File.join(Config::CONFIG['bindir'], 'spec')
92
+ ]
65
93
  end
66
94
 
67
95
  end
data/lib/spec/dsl.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  require 'spec/dsl/description'
2
+ require 'spec/dsl/errors'
2
3
  require 'spec/dsl/configuration'
3
4
  require 'spec/dsl/behaviour_callbacks'
4
5
  require 'spec/dsl/behaviour'
@@ -7,7 +7,7 @@ module Spec
7
7
  class << self
8
8
  def add_shared_behaviour(behaviour)
9
9
  return if behaviour.equal?(found_behaviour = find_shared_behaviour(behaviour.description))
10
- return if found_behaviour and behaviour.description[:spec_path] == found_behaviour.description[:spec_path]
10
+ return if found_behaviour and File.expand_path(behaviour.description[:spec_path]) == File.expand_path(found_behaviour.description[:spec_path])
11
11
  raise ArgumentError.new("Shared Behaviour '#{behaviour.description}' already exists") if found_behaviour
12
12
  shared_behaviours << behaviour
13
13
  end
@@ -63,18 +63,22 @@ module Spec
63
63
 
64
64
  def run(reporter, dry_run=false, reverse=false, timeout=nil)
65
65
  raise "shared behaviours should never run" if shared?
66
- reporter.add_behaviour(description)
66
+ # TODO - change add_behaviour to add_description ??????
67
+ reporter.add_behaviour(@description)
67
68
  prepare_execution_context_class
68
- errors = run_before_all(reporter, dry_run)
69
+ before_all_errors = run_before_all(reporter, dry_run)
69
70
 
70
- specs = reverse ? examples.reverse : examples
71
+ exs = reverse ? examples.reverse : examples
71
72
  example_execution_context = nil
72
73
 
73
- if errors.empty?
74
- specs.each do |example|
74
+ if before_all_errors.empty?
75
+ exs.each do |example|
75
76
  example_execution_context = execution_context(example)
76
77
  example_execution_context.copy_instance_variables_from(@before_and_after_all_context_instance) unless before_all_proc(behaviour_type).nil?
77
- example.run(reporter, before_each_proc(behaviour_type), after_each_proc(behaviour_type), dry_run, example_execution_context, timeout)
78
+
79
+ befores = before_each_proc(behaviour_type) {|e| raise e}
80
+ afters = after_each_proc(behaviour_type)
81
+ example.run(reporter, befores, afters, dry_run, example_execution_context, timeout)
78
82
  end
79
83
  end
80
84
 
@@ -115,20 +119,25 @@ module Spec
115
119
 
116
120
  # Includes modules in the Behaviour (the <tt>describe</tt> block).
117
121
  def include(*args)
118
- args << {} unless Hash === args.last
119
- modules, options = args_and_options(*args)
120
- required_behaviour_type = options[:behaviour_type]
121
- if required_behaviour_type.nil? || required_behaviour_type.to_sym == behaviour_type.to_sym
122
- @eval_module.include(*modules)
123
- end
122
+ @eval_module.include(*args)
124
123
  end
125
124
 
126
125
  def behaviour_type #:nodoc:
127
126
  @description[:behaviour_type]
128
127
  end
128
+
129
+ # Sets the #number on each Example and returns the next number
130
+ def set_sequence_numbers(number, reverse) #:nodoc:
131
+ exs = reverse ? examples.reverse : examples
132
+ exs.each do |example|
133
+ example.number = number
134
+ number += 1
135
+ end
136
+ number
137
+ end
129
138
 
130
139
  protected
131
-
140
+
132
141
  # Messages that this class does not understand
133
142
  # are passed directly to the @eval_module.
134
143
  def method_missing(sym, *args, &block)
@@ -143,16 +152,15 @@ module Spec
143
152
  end
144
153
 
145
154
  def weave_in_included_modules
146
- mods = included_modules
147
- eval_module = @eval_module
155
+ mods = [@eval_module]
156
+ mods << included_modules.dup
157
+ mods << Spec::Runner.configuration.modules_for(behaviour_type)
148
158
  execution_context_class.class_eval do
149
- include eval_module
150
- Spec::Runner.configuration.included_modules.each do |mod|
151
- include mod
152
- end
153
- mods.each do |mod|
154
- include mod
155
- end
159
+ # WARNING - the following can be executed in the context of any
160
+ # class, and should never pass more than one module to include
161
+ # even though we redefine include in this class. This is NOT
162
+ # tested anywhere, hence this comment.
163
+ mods.flatten.each {|mod| include mod}
156
164
  end
157
165
  end
158
166
 
@@ -166,10 +174,12 @@ module Spec
166
174
  begin
167
175
  @before_and_after_all_context_instance = execution_context(nil)
168
176
  @before_and_after_all_context_instance.instance_eval(&before_all_proc(behaviour_type))
169
- rescue => e
177
+ rescue Exception => e
170
178
  errors << e
171
179
  location = "before(:all)"
172
- reporter.example_finished(location, e, location) if reporter
180
+ # The easiest is to report this as an example failure. We don't have an Example
181
+ # at this point, so we'll just create a placeholder.
182
+ reporter.example_finished(Example.new(location), e, location) if reporter
173
183
  end
174
184
  end
175
185
  errors
@@ -180,9 +190,9 @@ module Spec
180
190
  begin
181
191
  @before_and_after_all_context_instance ||= execution_context(nil)
182
192
  @before_and_after_all_context_instance.instance_eval(&after_all_proc(behaviour_type))
183
- rescue => e
193
+ rescue Exception => e
184
194
  location = "after(:all)"
185
- reporter.example_finished(location, e, location) if reporter
195
+ reporter.example_finished(Example.new(location), e, location) if reporter
186
196
  end
187
197
  end
188
198
  end
@@ -36,6 +36,10 @@ module Spec
36
36
  when :all; self.__send__("#{where}_all_parts", behaviour_type).__send__(how, block)
37
37
  end
38
38
  end
39
+
40
+ def remove_after(scope, &block)
41
+ after_each_parts.delete(block)
42
+ end
39
43
 
40
44
  # Deprecated. Use before(:each)
41
45
  def setup(&block)
@@ -137,6 +137,15 @@ module Spec
137
137
  super
138
138
  end
139
139
 
140
+ def before_each_proc(behaviour_type, &error_handler)
141
+ parts = []
142
+ parts.push(*Behaviour.before_each_parts(nil))
143
+ parts.push(*Behaviour.before_each_parts(behaviour_type)) unless behaviour_type.nil?
144
+ parts.push(*before_each_parts(nil))
145
+ parts.push(*before_each_parts(behaviour_type)) unless behaviour_type.nil?
146
+ CompositeProcBuilder.new(parts).proc(&error_handler)
147
+ end
148
+
140
149
  def before_all_proc(behaviour_type, &error_handler)
141
150
  parts = []
142
151
  parts.push(*Behaviour.before_all_parts(nil))
@@ -146,31 +155,22 @@ module Spec
146
155
  CompositeProcBuilder.new(parts).proc(&error_handler)
147
156
  end
148
157
 
149
- def after_all_proc(behaviour_type, &error_handler)
158
+ def after_all_proc(behaviour_type)
150
159
  parts = []
151
160
  parts.push(*after_all_parts(behaviour_type)) unless behaviour_type.nil?
152
161
  parts.push(*after_all_parts(nil))
153
162
  parts.push(*Behaviour.after_all_parts(behaviour_type)) unless behaviour_type.nil?
154
163
  parts.push(*Behaviour.after_all_parts(nil))
155
- CompositeProcBuilder.new(parts).proc(&error_handler)
164
+ CompositeProcBuilder.new(parts).proc
156
165
  end
157
166
 
158
- def before_each_proc(behaviour_type, &error_handler)
159
- parts = []
160
- parts.push(*Behaviour.before_each_parts(nil))
161
- parts.push(*Behaviour.before_each_parts(behaviour_type)) unless behaviour_type.nil?
162
- parts.push(*before_each_parts(nil))
163
- parts.push(*before_each_parts(behaviour_type)) unless behaviour_type.nil?
164
- CompositeProcBuilder.new(parts).proc(&error_handler)
165
- end
166
-
167
- def after_each_proc(behaviour_type, &error_handler)
167
+ def after_each_proc(behaviour_type)
168
168
  parts = []
169
169
  parts.push(*after_each_parts(behaviour_type)) unless behaviour_type.nil?
170
170
  parts.push(*after_each_parts(nil))
171
171
  parts.push(*Behaviour.after_each_parts(behaviour_type)) unless behaviour_type.nil?
172
172
  parts.push(*Behaviour.after_each_parts(nil))
173
- CompositeProcBuilder.new(parts).proc(&error_handler)
173
+ CompositeProcBuilder.new(parts).proc
174
174
  end
175
175
 
176
176
  private
@@ -210,11 +210,22 @@ module Spec
210
210
  end
211
211
 
212
212
  def inspect
213
- "[Dynamically generated class for RSpec example]"
213
+ "[RSpec example]"
214
+ end
215
+
216
+ def pending(message)
217
+ if block_given?
218
+ begin
219
+ yield
220
+ rescue Exception => e
221
+ raise Spec::DSL::ExamplePendingError.new(message)
222
+ end
223
+ raise Spec::DSL::PendingFixedError.new("Expected pending '#{message}' to fail. No Error was raised.")
224
+ else
225
+ raise Spec::DSL::ExamplePendingError.new(message)
226
+ end
214
227
  end
215
-
216
228
  end
217
-
218
229
  end
219
230
  end
220
231
  end