{"action":"created","issue":{"url":"https://api.github.com/repos/rspec/rspec-mocks/issues/203","labels_url":"https://api.github.com/repos/rspec/rspec-mocks/issues/203/labels{/name}","comments_url":"https://api.github.com/repos/rspec/rspec-mocks/issues/203/comments","events_url":"https://api.github.com/repos/rspec/rspec-mocks/issues/203/events","html_url":"https://github.com/rspec/rspec-mocks/issues/203","id":9151373,"number":203,"title":"broken should_receive expectations with do blocks don't cause the test to go red on classes which handle exceptions","user":{"login":"froodian","id":1547435,"avatar_url":"https://avatars.githubusercontent.com/u/1547435?v=3","gravatar_id":"","url":"https://api.github.com/users/froodian","html_url":"https://github.com/froodian","followers_url":"https://api.github.com/users/froodian/followers","following_url":"https://api.github.com/users/froodian/following{/other_user}","gists_url":"https://api.github.com/users/froodian/gists{/gist_id}","starred_url":"https://api.github.com/users/froodian/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/froodian/subscriptions","organizations_url":"https://api.github.com/users/froodian/orgs","repos_url":"https://api.github.com/users/froodian/repos","events_url":"https://api.github.com/users/froodian/events{/privacy}","received_events_url":"https://api.github.com/users/froodian/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":{"url":"https://api.github.com/repos/rspec/rspec-mocks/milestones/6","html_url":"https://github.com/rspec/rspec-mocks/milestones/RSpec%203","labels_url":"https://api.github.com/repos/rspec/rspec-mocks/milestones/6/labels","id":434856,"number":6,"title":"RSpec 3","description":"http://myronmars.to/n/dev-blog/2013/07/the-plan-for-rspec-3","creator":{"login":"myronmarston","id":49391,"avatar_url":"https://avatars.githubusercontent.com/u/49391?v=3","gravatar_id":"","url":"https://api.github.com/users/myronmarston","html_url":"https://github.com/myronmarston","followers_url":"https://api.github.com/users/myronmarston/followers","following_url":"https://api.github.com/users/myronmarston/following{/other_user}","gists_url":"https://api.github.com/users/myronmarston/gists{/gist_id}","starred_url":"https://api.github.com/users/myronmarston/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/myronmarston/subscriptions","organizations_url":"https://api.github.com/users/myronmarston/orgs","repos_url":"https://api.github.com/users/myronmarston/repos","events_url":"https://api.github.com/users/myronmarston/events{/privacy}","received_events_url":"https://api.github.com/users/myronmarston/received_events","type":"User","site_admin":false},"open_issues":3,"closed_issues":38,"state":"closed","created_at":"2013-09-23T19:00:02Z","updated_at":"2014-07-29T06:01:10Z","due_on":null,"closed_at":"2014-07-29T06:01:10Z"},"comments":37,"created_at":"2012-12-10T17:17:36Z","updated_at":"2015-06-09T17:17:49Z","closed_at":"2014-01-15T16:04:26Z","body":"If you have some code which rescues from exceptions, and you use the ```should_receive(:foo) do |arg|``` syntax to expect that class to make a call to a mock, if the assertions inside the do block fail, the test doesn't go red as expected.\n\nTest-case which demonstrates the bug:\n\n```ruby\nrequire 'spec_helper'\n\nmodule BugReport203\n  describe \"an expectation on a class with a rescue block\" do\n    class TestClass\n      def test_dependency\n        @dependency ||= TestDependency.new()\n      end\n\n      def test_method\n        begin\n          self.test_dependency.some_call(\"I'm calling this method with unexpected arguments - THIS SHOULD CAUSE THE TEST TO GO RED!  But doesn't.\")\n        rescue\n          # Exception-handling logic here\n        end\n      end\n    end\n\n    class TestDependency\n      def some_call(arguments)\n\n      end\n    end\n\n    # This test should be red!\n    it \"should know the method was called with wrong arguments\" do\n      mock_dependency = mock(TestDependency)\n\n      test_object = TestClass.new()\n      test_object.stub(:test_dependency).and_return(mock_dependency)\n\n      # Obviously in this trivial case of checking string equality, I could use\n      #\n      # mock_dependency.should_receive(:some_call).with(\"expected arguments\")\n      #\n      # which will go red as expected.\n      # This bug applies to the more complex case where I actually need the do block to make my assertions\n      mock_dependency.should_receive(:some_call) do |arg|\n        arg.should == \"expected arguments\"\n      end\n\n      test_object.test_method()\n    end\n  end\nend\n```"},"comment":{"url":"https://api.github.com/repos/rspec/rspec-mocks/issues/comments/110438005","html_url":"https://github.com/rspec/rspec-mocks/issues/203#issuecomment-110438005","issue_url":"https://api.github.com/repos/rspec/rspec-mocks/issues/203","id":110438005,"user":{"login":"myronmarston","id":49391,"avatar_url":"https://avatars.githubusercontent.com/u/49391?v=3","gravatar_id":"","url":"https://api.github.com/users/myronmarston","html_url":"https://github.com/myronmarston","followers_url":"https://api.github.com/users/myronmarston/followers","following_url":"https://api.github.com/users/myronmarston/following{/other_user}","gists_url":"https://api.github.com/users/myronmarston/gists{/gist_id}","starred_url":"https://api.github.com/users/myronmarston/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/myronmarston/subscriptions","organizations_url":"https://api.github.com/users/myronmarston/orgs","repos_url":"https://api.github.com/users/myronmarston/repos","events_url":"https://api.github.com/users/myronmarston/events{/privacy}","received_events_url":"https://api.github.com/users/myronmarston/received_events","type":"User","site_admin":false},"created_at":"2015-06-09T17:17:49Z","updated_at":"2015-06-09T17:17:49Z","body":"@jarmo -- changing to `throw/catch` would be a breaking change to the API, and rspec-mocks and rspec-expectations are both usable with other test frameworks (e.g. cucumber and minitest) which expect the current behavior (raising an exception).  The best we can do for now is make it configurable.\r\n\r\n...which, as of RSpec 3.3 it is :).  It's not a documented public API (and therefore may have breaking changes in later 3.x releases) but there's now this:\r\n\r\n``` ruby\r\nRSpec::Support.failure_notifier = lambda do |error, options|\r\n  # do something with the error\r\nend\r\n```\r\n\r\nSo I believe you could do this:\r\n\r\n``` ruby\r\nRSpec::Support.failure_notifier = lambda do |error, options|\r\n  throw :rspec_failure, error\r\nend\r\n\r\nRSpec.configure do |c|\r\n  c.around do |ex|\r\n    error = catch(:rspec_failure) do\r\n      ex.run\r\n      nil\r\n    end\r\n\r\n    raise error if error\r\n  end\r\nend\r\n\r\nRSpec.describe \"Rescuing exception failures\" do\r\n  it \"does not prevent it from failing\" do\r\n    begin\r\n      expect(1).to eq(2)\r\n    rescue Exception\r\n    end\r\n  end\r\n\r\n  it 'allows passing examples to pass' do\r\n    expect(1).to eq(1)\r\n  end\r\nend\r\n```"}}