@@ -502,14 +502,19 @@ def annotate_one_file options = {}
502
502
Annotate ::PATH_OPTIONS . each { |key | ENV [ key . to_s ] = '' }
503
503
end
504
504
505
- def encoding_comments_list_each
505
+ def magic_comments_list_each
506
506
[
507
507
'# encoding: UTF-8' ,
508
508
'# coding: UTF-8' ,
509
509
'# -*- coding: UTF-8 -*-' ,
510
510
'#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 }
513
518
end
514
519
515
520
it "should put annotation before class if :position == 'before'" do
@@ -626,17 +631,22 @@ class Foo::User < ActiveRecord::Base
626
631
expect ( File . read ( model_file_name ) ) . to eq ( "#{ schema_info } \n #{ file_content } " )
627
632
end
628
633
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 |
631
636
write_model "user.rb" , <<-EOS
632
- #{ encoding_comment }
637
+ #{ magic_comment }
633
638
class User < ActiveRecord::Base
634
639
end
635
640
EOS
636
641
637
642
annotate_one_file :position => :before
638
643
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
640
650
end
641
651
end
642
652
0 commit comments