class RuboCop::Cop::Ezcater::RspecRequireFeatureFlagMock
Enforce use of `mock_feature_flag` helper instead of mocking `FeatureFlag.is_active?` directly.
@example
# good mock_feature_flag("MyFeatureFlag", true) mock_feature_flag("MyFeatureFlag", { user: current_user }, true) # bad allow(FeatureFlag).to receive(:is_active?).and_return(true) allow(FeatureFlag).to receive(:is_active?).with("MyFeatureFlag").and_return(true) allow(FeatureFlag).to receive(:is_active?).with("MyFeatureFlag", user: current_user).and_return(true)
Constants
- MSG
Public Instance Methods
on_const(node)
click to toggle source
# File lib/rubocop/cop/ezcater/rspec_require_feature_flag_mock.rb, line 25 def on_const(node) return unless feature_flag_const?(node) # Walk to send node where method = :allow match_node = node match_node = match_node.parent while not_allow_send_node?(match_node.parent) match_node = match_node.parent # Validate send node, method = :allow; could have never been found return unless allow_send_node?(match_node) # Finish tree navigation to full line for highlighting match_node = match_node.parent while match_node.parent add_offense(match_node, location: :expression) end
Private Instance Methods
allow_send_node?(node)
click to toggle source
# File lib/rubocop/cop/ezcater/rspec_require_feature_flag_mock.rb, line 47 def allow_send_node?(node) node&.send_type? && node.method_name == :allow end
not_allow_send_node?(node)
click to toggle source
# File lib/rubocop/cop/ezcater/rspec_require_feature_flag_mock.rb, line 43 def not_allow_send_node?(node) node && !allow_send_node?(node) end