class RSpec::Expectations::BlockSnippetExtractor
rubocop:disable Metrics/ClassLength
@private
def self.try_extracting_single_line_body_of(proc, method_name)
def self.try_extracting_single_line_body_of(proc, method_name) lines = new(proc, method_name).body_content_lines return nil unless lines.count == 1 lines.first rescue Error nil end
def beginning_line_number
def beginning_line_number source_location.last end
def block_token_extractor
def block_token_extractor @block_token_extractor ||= BlockTokenExtractor.new(method_name, source, beginning_line_number) end
def body_content_lines
but it's not implemented yet since because we use result of this method only when it's a
Ideally we should properly handle indentations of multiline snippet,
def body_content_lines raw_body_lines.map(&:strip).reject(&:empty?) end
def file_path
def file_path source_location.first end
def initialize(proc, method_name)
def initialize(proc, method_name) @proc = proc @method_name = method_name.to_s.freeze end
def raw_body_lines
def raw_body_lines raw_body_snippet.split("\n") end
def raw_body_snippet
def raw_body_snippet block_token_extractor.body_tokens.map(&:string).join end
def source
def source raise TargetNotFoundError unless File.exist?(file_path) RSpec.world.source_from_file(file_path) end
def source
def source raise TargetNotFoundError unless File.exist?(file_path) @source ||= RSpec::Support::Source.from_file(file_path) end
def source_location
def source_location proc.source_location || raise(TargetNotFoundError) end