Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/annotate/annotate_routes/helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def strip_annotations(content)
header_position = 0

content.split(/\n/, -1).each_with_index do |line, line_number|
if mode == :header && line !~ /\s*#/
if mode == :header && !line.include?('#')
mode = :content
real_content << line unless line.blank?
elsif mode == :content
Expand Down
30 changes: 30 additions & 0 deletions spec/lib/annotate/annotate_routes/helpers_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
require_relative '../../../spec_helper'
require 'annotate/annotate_routes'

RSpec.describe AnnotateRoutes::Helpers do
describe '.strip_annotations' do
it 'removes the route annotation block and keeps the content after it' do
content = "# == Route Map\n#\n# root GET / home#index\n\nRails.application.routes.draw do\nend\n"

real_content, header_position = described_class.strip_annotations(content)

expect(real_content).to eq(['Rails.application.routes.draw do', 'end', ''])
expect(header_position).to eq(:before)
end

it 'handles a long whitespace-only line in the annotation block in linear time' do
content = "# == Route Map\n#{' ' * 100_000}\nRails.application.routes.draw do\nend\n"

(real_content,), elapsed = timed { described_class.strip_annotations(content) }

expect(real_content).to eq(['Rails.application.routes.draw do', 'end', ''])
expect(elapsed).to be < 1
end

def timed
started = Process.clock_gettime(Process::CLOCK_MONOTONIC)
result = yield
[result, Process.clock_gettime(Process::CLOCK_MONOTONIC) - started]
end
end
end
Loading