Skip to content

Commit 695d0dd

Browse files
committed
add test for multiline magic comments
1 parent b2b1706 commit 695d0dd

File tree

1 file changed

+17
-7
lines changed

1 file changed

+17
-7
lines changed

spec/annotate/annotate_models_spec.rb

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -502,14 +502,19 @@ def annotate_one_file options = {}
502502
Annotate::PATH_OPTIONS.each { |key| ENV[key.to_s] = '' }
503503
end
504504

505-
def encoding_comments_list_each
505+
def magic_comments_list_each
506506
[
507507
'# encoding: UTF-8',
508508
'# coding: UTF-8',
509509
'# -*- coding: UTF-8 -*-',
510510
'#encoding: utf-8',
511-
'# -*- encoding : utf-8 -*-'
512-
].each{|encoding_comment| yield encoding_comment }
511+
'# encoding: utf-8',
512+
'# -*- encoding : utf-8 -*-',
513+
"# encoding: utf-8\n# frozen_string_literal: true",
514+
"# frozen_string_literal: true\n# encoding: utf-8",
515+
'# frozen_string_literal: true',
516+
'#frozen_string_literal: true',
517+
].each{|magic_comment| yield magic_comment }
513518
end
514519

515520
it "should put annotation before class if :position == 'before'" do
@@ -626,17 +631,22 @@ class Foo::User < ActiveRecord::Base
626631
expect(File.read(model_file_name)).to eq("#{schema_info}\n#{file_content}")
627632
end
628633

629-
it "should not touch encoding comments" do
630-
encoding_comments_list_each do |encoding_comment|
634+
it "should not touch magic comments" do
635+
magic_comments_list_each do |magic_comment|
631636
write_model "user.rb", <<-EOS
632-
#{encoding_comment}
637+
#{magic_comment}
633638
class User < ActiveRecord::Base
634639
end
635640
EOS
636641

637642
annotate_one_file :position => :before
638643

639-
expect(File.open(@model_file_name, &:readline)).to eq("#{encoding_comment}\n")
644+
lines= magic_comment.split("\n")
645+
File.open @model_file_name do |file|
646+
lines.count.times do |index|
647+
expect(file.readline).to eq "#{lines[index]}\n"
648+
end
649+
end
640650
end
641651
end
642652

0 commit comments

Comments
 (0)