Skip to content

Instantly share code, notes, and snippets.

@sorah
Created December 17, 2012 01:34
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save sorah/4315150 to your computer and use it in GitHub Desktop.
Save sorah/4315150 to your computer and use it in GitHub Desktop.
Show warnings for examples that has no expectations
RSpec.configure do |config|
config.after(:each) do
result = self.example.metadata[:execution_result]
has_mock_expectations = RSpec::Mocks.space.instance_eval{receivers}.empty?
if !result[:exception] && !result[:pending_message] && !RSpec::Matchers.last_should && hasnt_mock_expectations
$stderr.puts "[WARN] No expectations found in example at #{self.example.location}: Maybe you forgot to write `should` in the example?"
end
end
end
@JamesFerguson
Copy link

Thanks for this, it's just what I was looking for.

Should the variable on line 4 be hasnt_mock_expectations though, since that's what you reference on line 5?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment