Skip to content

Instantly share code, notes, and snippets.

@iorionda
Created March 5, 2013 06:34
Show Gist options
  • Select an option

  • Save iorionda/5088454 to your computer and use it in GitHub Desktop.

Select an option

Save iorionda/5088454 to your computer and use it in GitHub Desktop.
diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb
index 41392c5..d9d4595 100644
--- a/spec/spec_helper.rb
+++ b/spec/spec_helper.rb
@@ -29,6 +29,13 @@ WebMock.allow_net_connect! #スタブ未設定URLへのアクセスを許可す
# in spec/support/ and its subdirectories.
Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f}
+class String
+ def colorize(color_code); "\e[#{color_code}m#{self}\e[0m"; end
+ def red; colorize(31); end
+ def yellow; colorize(33); end
+ def pink; colorize(35); end
+end
+
RSpec.configure do |config|
config.filter_run :focus => true
#config.filter_run_excluding :slow => true
@@ -84,6 +91,13 @@ RSpec.configure do |config|
config.after(:each) do
DatabaseCleaner.clean
+
+ result = self.example.metadata[:execution_result]
+ hasnt_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?".yellow
+ end
end
config.after(:all) do
@iorionda
Copy link
Copy Markdown
Author

iorionda commented Mar 5, 2013

rspec 実行時に should がなかった場合に yellow でWARNを出力する。

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