Class: RuboCop::Cop::Obsession::Rspec::DescribePublicMethod
- Inherits:
-
Base
- Object
- Base
- RuboCop::Cop::Obsession::Rspec::DescribePublicMethod
- Defined in:
- lib/rubocop/cop/obsession/rspec/describe_public_method.rb
Overview
This cop checks for ‘describe` blocks that test private methods.
If you are doing black box unit testing, it means that you are only interested in testing external behavior, a.k.a public interface, a.k.a public methods. Private methods are considered implementation details and are not directly tested.
If you need to test a Rails callback, test it indirectly through its corresponding Rails public method, e.g. #create, #save, etc.
Constant Summary collapse
- MSG =
'Only test public methods.'
Instance Method Summary collapse
Instance Method Details
#on_block(node) ⇒ Object
55 56 57 58 59 60 |
# File 'lib/rubocop/cop/obsession/rspec/describe_public_method.rb', line 55 def on_block(node) on_context_method(node) do |method_name| method_name = method_name.sub('#', '').to_sym add_offense(node) if private_methods.include?(method_name) end end |