Class: RuboCop::Cop::Airbnb::RspecEnvironmentModification
- Inherits:
-
Base
- Object
- Base
- RuboCop::Cop::Airbnb::RspecEnvironmentModification
- Defined in:
- lib/rubocop/cop/airbnb/rspec_environment_modification.rb
Overview
This cop checks how the Rails environment is modified in specs. If an individual method on Rails.env is modified multiple environment related branchs could be run down. Rather than modifying a single path or setting Rails.env in a way that could bleed into other specs, use ‘stub_env`
Constant Summary collapse
- MESSAGE =
"Do not stub or set Rails.env in specs. Use the `stub_env` method instead".freeze
Instance Method Summary collapse
Instance Method Details
#is_spec_file?(path) ⇒ Boolean
52 53 54 |
# File 'lib/rubocop/cop/airbnb/rspec_environment_modification.rb', line 52 def is_spec_file?(path) path.end_with?('_spec.rb') end |
#on_send(node) ⇒ Object
44 45 46 47 48 49 50 |
# File 'lib/rubocop/cop/airbnb/rspec_environment_modification.rb', line 44 def on_send(node) path = node.source_range.source_buffer.name return unless is_spec_file?(path) if rails_env_assignment(node) || allow_or_expect_rails_env(node) || stub_rails_env(node) add_offense(node, message: MESSAGE) end end |