Skip to content

Commit

Permalink
Improve RSpec/InstanceVariable offence message
Browse files Browse the repository at this point in the history
  • Loading branch information
pirj authored and kellysutton committed Oct 28, 2019
1 parent 41c6ce3 commit 36bc49c
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
3 changes: 2 additions & 1 deletion lib/rubocop/cop/rspec/instance_variable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ module RSpec
# end
#
class InstanceVariable < Cop
MSG = 'Replace instance variable with local variable or `let`.'
MSG = 'Avoid instance variables – use let, ' \
'a method call, or a local variable (if possible).'

EXAMPLE_GROUP_METHODS = ExampleGroups::ALL + SharedGroups::ALL

Expand Down
10 changes: 5 additions & 5 deletions spec/rubocop/cop/rspec/instance_variable_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
RSpec.describe RuboCop::Cop::RSpec::InstanceVariable do
subject(:cop) { described_class.new }

it 'finds an instance variable inside a describe' do
it 'flags an instance variable inside a describe' do
expect_offense(<<-RUBY)
describe MyClass do
before { @foo = [] }
it { expect(@foo).to be_empty }
^^^^ Replace instance variable with local variable or `let`.
^^^^ Avoid instance variables – use let, a method call, or a local variable (if possible).
end
RUBY
end
Expand All @@ -22,11 +22,11 @@
RUBY
end

it 'finds an instance variable inside a shared example' do
it 'flags an instance variable inside a shared example' do
expect_offense(<<-RUBY)
shared_examples 'shared example' do
it { expect(@foo).to be_empty }
^^^^ Replace instance variable with local variable or `let`.
^^^^ Avoid instance variables – use let, a method call, or a local variable (if possible).
end
RUBY
end
Expand Down Expand Up @@ -79,7 +79,7 @@ def serialize
describe MyClass do
before { @foo = [] }
it { expect(@foo).to be_empty }
^^^^ Replace instance variable with local variable or `let`.
^^^^ Avoid instance variables – use let, a method call, or a local variable (if possible).
end
RUBY
end
Expand Down

0 comments on commit 36bc49c

Please sign in to comment.