Skip to content
This repository
  • 6 commits
  • 10 files changed
  • 0 comments
  • 2 contributors
Jul 18, 2012
Myron Marston Fix ruby warnings.
- lib/rspec/core/shared_example_group.rb:41: warning: `&' interpreted as argument prefix
- spec/rspec/core/configuration_spec.rb:86: warning: ambiguous first argument; put parentheses or even spaces
- spec/rspec/core/configuration_spec.rb:182: warning: ambiguous first argument; put parentheses or even spaces
- spec/rspec/core/option_parser_spec.rb:71: warning: possibly useless use of == in void context

Closes #645.
1f78187
Jo Liss Fix typo
This used to be a multi-line string with "',\n    '" in it.
e75df2c
Myron Marston Fix the way we autoload RSpec::Matchers.
`autoload`, besides being deprecated by Matz, does not work to require files
that are in unactivated gems--it only works with ruby's built in require, for
files that are available relative to a directory on the load path. Instead,
we use `const_missing` to make it work.

Closes #647.
2e32d6e
Myron Marston Update change log. c2ea08c
Myron Marston Ignore mock expectation failures when the example has already failed.
Mock expectation failures have always been ignored in this situation,
but due to my changes in 27059bf it was printing a confusing message.

Closes #651.
30e81b5
Myron Marston 2.11.1 release. b819726
15  Changelog.md
Source Rendered
... ...
@@ -1,3 +1,18 @@
  1
+### 2.11.1 / 2012-07-18
  2
+[full changelog](http://github.com/rspec/rspec-core/compare/v2.11.0...v2.11.1)
  3
+
  4
+Bug fixes
  5
+
  6
+* Fix the way we autoload RSpec::Matchers so that custom matchers can be
  7
+  defined before rspec-core has been configured to definitely use
  8
+  rspec-expectations. (Myron Marston)
  9
+* Fix typo in --help message printed for -e option. (Jo Liss)
  10
+* Fix ruby warnings. (Myron Marston)
  11
+* Ignore mock expectation failures when the example has already failed.
  12
+  Mock expectation failures have always been ignored in this situation,
  13
+  but due to my changes in 27059bf1 it was printing a confusing message.
  14
+  (Myron Marston).
  15
+
1 16
 ### 2.11.0 / 2012-07-07
2 17
 [full changelog](http://github.com/rspec/rspec-core/compare/v2.10.1...v2.11.0)
3 18
 
16  features/expectation_framework_integration/configure_expectation_framework.feature
@@ -13,6 +13,22 @@ Feature: configure expectation framework
13 13
   provide a description to every example.  You cannot rely on the generated
14 14
   descriptions provided by rspec-expectations.
15 15
 
  16
+  Scenario: rspec-expectations can be used by default if nothing is configured
  17
+    Given a file named "example_spec.rb" with:
  18
+      """
  19
+      RSpec::Matchers.define :be_a_multiple_of do |factor|
  20
+        match do |actual|
  21
+          actual % factor == 0
  22
+        end
  23
+      end
  24
+
  25
+      describe 6 do
  26
+        it { should be_a_multiple_of(3) }
  27
+      end
  28
+      """
  29
+    When I run `rspec example_spec.rb`
  30
+    Then the examples should all pass
  31
+
16 32
   Scenario: configure rspec-expectations (explicitly)
17 33
     Given a file named "example_spec.rb" with:
18 34
       """
17  lib/rspec/core.rb
@@ -40,7 +40,6 @@ def require_rspec(path)
40 40
 require_rspec 'core/version'
41 41
 
42 42
 module RSpec
43  
-  autoload :Matchers,      'rspec/matchers'
44 43
   autoload :SharedContext, 'rspec/core/shared_context'
45 44
 
46 45
   # @private
@@ -106,6 +105,22 @@ def self.windows_os?
106 105
 
107 106
   module Core
108 107
   end
  108
+
  109
+  def self.const_missing(name)
  110
+    case name
  111
+      when :Matchers
  112
+        # Load rspec-expectations when RSpec::Matchers is referenced. This allows
  113
+        # people to define custom matchers (using `RSpec::Matchers.define`) before
  114
+        # rspec-core has loaded rspec-expectations (since it delays the loading of
  115
+        # it to allow users to configure a different assertion/expectation
  116
+        # framework). `autoload` can't be used since it works with ruby's built-in
  117
+        # require (e.g. for files that are available relative to a load path dir),
  118
+        # but not with rubygems' extended require.
  119
+        require 'rspec/expectations'
  120
+        ::RSpec::Matchers
  121
+      else super
  122
+    end
  123
+  end
109 124
 end
110 125
 
111 126
 require_rspec 'core/backward_compatibility'
10  lib/rspec/core/example.rb
@@ -205,7 +205,7 @@ def around_each_hooks
205 205
       # Used internally to set an exception in an after hook, which
206 206
       # captures the exception but doesn't raise it.
207 207
       def set_exception(exception, context=nil)
208  
-        if @exception
  208
+        if @exception && context != :dont_print
209 209
           # An error has already been set; we don't want to override it,
210 210
           # but we also don't want silence the error, so let's print it.
211 211
           msg = <<-EOS
@@ -301,13 +301,19 @@ def run_before_each
301 301
 
302 302
       def run_after_each
303 303
         @example_group_class.run_after_each_hooks(self)
304  
-        @example_group_instance.verify_mocks_for_rspec
  304
+        verify_mocks
305 305
       rescue Exception => e
306 306
         set_exception(e, "in an after(:each) hook")
307 307
       ensure
308 308
         @example_group_instance.teardown_mocks_for_rspec
309 309
       end
310 310
 
  311
+      def verify_mocks
  312
+        @example_group_instance.verify_mocks_for_rspec
  313
+      rescue Exception => e
  314
+        set_exception(e, :dont_print)
  315
+      end
  316
+
311 317
       def assign_generated_description
312 318
         return unless RSpec.configuration.expecting_with_rspec?
313 319
         if metadata[:description].empty? and !pending?
4  lib/rspec/core/option_parser.rb
@@ -134,8 +134,8 @@ def parser(options)
134 134
           options[:pattern] = o
135 135
         end
136 136
 
137  
-        parser.on('-e', '--example STRING', "Run examples whose full nested names include STRING (may be',
138  
-                                              '  used more than once)") do |o|
  137
+        parser.on('-e', '--example STRING', "Run examples whose full nested names include STRING (may be",
  138
+                                            "  used more than once)") do |o|
139 139
           (options[:full_description] ||= []) << Regexp.compile(Regexp.escape(o))
140 140
         end
141 141
 
2  lib/rspec/core/shared_example_group.rb
@@ -38,7 +38,7 @@ def shared_examples *args, &block
38 38
         unless args.empty?
39 39
           mod = Module.new
40 40
           (class << mod; self; end).send :define_method, :extended  do |host|
41  
-            host.class_eval &block
  41
+            host.class_eval(&block)
42 42
           end
43 43
           RSpec.configuration.extend mod, *args
44 44
         end
2  lib/rspec/core/version.rb
... ...
@@ -1,7 +1,7 @@
1 1
 module RSpec
2 2
   module Core
3 3
     module Version
4  
-      STRING = '2.11.0'
  4
+      STRING = '2.11.1'
5 5
     end
6 6
   end
7 7
 end
4  spec/rspec/core/configuration_spec.rb
@@ -83,7 +83,7 @@ module RSpec::Core
83 83
         lambda do
84 84
           config.send m, mod do |mod_config|
85 85
           end
86  
-        end.should raise_error /must respond to `configuration`/
  86
+        end.should raise_error(/must respond to `configuration`/)
87 87
       end
88 88
     end
89 89
 
@@ -179,7 +179,7 @@ module RSpec::Core
179 179
         lambda do
180 180
           config.expect_with :rspec, :stdlib do |mod_config|
181 181
           end
182  
-        end.should raise_error /expect_with only accepts/
  182
+        end.should raise_error(/expect_with only accepts/)
183 183
       end
184 184
 
185 185
       it "raises ArgumentError if framework is not supported" do
47  spec/rspec/core/example_spec.rb
@@ -259,37 +259,48 @@ def assert(val)
259 259
       end
260 260
     end
261 261
 
262  
-    context "when the example and an around hook raise errors" do
263  
-      it "prints the around hook error rather than silencing it" do
264  
-        group = RSpec::Core::ExampleGroup.describe do
265  
-          around(:each) { |e| e.run; raise "around" }
266  
-          example("e") { raise "example" }
267  
-        end
268  
-
  262
+    context 'when the example raises an error' do
  263
+      def run_and_capture_reported_message(group)
269 264
         reported_msg = nil
270 265
         # We can't use should_receive(:message).with(/.../) here,
271 266
         # because if that fails, it would fail within our example-under-test,
272 267
         # and since there's already two errors, it would just be reported again.
273 268
         RSpec.configuration.reporter.stub(:message) { |msg| reported_msg = msg }
274 269
         group.run
275  
-        reported_msg.should =~ /An error occurred in an around.* hook/i
  270
+        reported_msg
  271
+      end
  272
+
  273
+      it "prints any around hook errors rather than silencing them" do
  274
+        group = RSpec::Core::ExampleGroup.describe do
  275
+          around(:each) { |e| e.run; raise "around" }
  276
+          example("e") { raise "example" }
  277
+        end
  278
+
  279
+        message = run_and_capture_reported_message(group)
  280
+        message.should =~ /An error occurred in an around.* hook/i
276 281
       end
277  
-    end
278 282
 
279  
-    context "when the example and an after hook raise errors" do
280  
-      it "prints the after hook error rather than silencing it" do
  283
+      it "prints any after hook errors rather than silencing them" do
281 284
         group = RSpec::Core::ExampleGroup.describe do
282 285
           after(:each) { raise "after" }
283 286
           example("e") { raise "example" }
284 287
         end
285 288
 
286  
-        reported_msg = nil
287  
-        # We can't use should_receive(:message).with(/.../) here,
288  
-        # because if that fails, it would fail within our example-under-test,
289  
-        # and since there's already two errors, it would just be reported again.
290  
-        RSpec.configuration.reporter.stub(:message) { |msg| reported_msg = msg }
291  
-        group.run
292  
-        reported_msg.should =~ /An error occurred in an after.* hook/i
  289
+        message = run_and_capture_reported_message(group)
  290
+        message.should =~ /An error occurred in an after.* hook/i
  291
+      end
  292
+
  293
+      it 'does not print mock expectation errors' do
  294
+        group = RSpec::Core::ExampleGroup.describe do
  295
+          example do
  296
+            foo = mock
  297
+            foo.should_receive(:bar)
  298
+            raise "boom"
  299
+          end
  300
+        end
  301
+
  302
+        message = run_and_capture_reported_message(group)
  303
+        message.should be_nil
293 304
       end
294 305
     end
295 306
   end
2  spec/rspec/core/option_parser_spec.rb
@@ -68,7 +68,7 @@ module RSpec::Core
68 68
       describe option do
69 69
         it "escapes the arg" do
70 70
           options = Parser.parse!([option, "this (and that)"])
71  
-          options[:full_description].length.should == 1
  71
+          options[:full_description].length.should eq(1)
72 72
           "this (and that)".should match(options[:full_description].first)
73 73
         end
74 74
       end

No commit comments for this range

Something went wrong with that request. Please try again.