Module: RuboCop::RSpec::ExpectOffense

Defined in:
lib/rubocop/monkey_patches/allow_invalid_ruby.rb

Instance Method Summary collapse

Instance Method Details

#_parse_invalid_source(source, file = nil) ⇒ Object



23
24
25
# File 'lib/rubocop/monkey_patches/allow_invalid_ruby.rb', line 23

def _parse_invalid_source(source, file = nil)
  parse_source(source, file)
end

#allow_invalid_ruby {|block| ... } ⇒ Object

Yields to a block with ‘parse_processed_source` patched to not raise an exception.

RSpec’s ‘expect_offense` helper calls a method called `parse_processed_source` that parses source code and raises an exception if it is not valid Ruby. Raising an exception prevents RuboCop from calling the cop’s ‘on_other_file` method for checking non-Ruby files.

Yields:

  • (block)


15
16
17
18
19
# File 'lib/rubocop/monkey_patches/allow_invalid_ruby.rb', line 15

def allow_invalid_ruby(&block)
  alias :parse_processed_source :_parse_invalid_source
  yield block
  alias :parse_processed_source :_orig_parse_processed_source
end