@@ -502,14 +502,20 @@ 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: false' ,
517+ '# -*- frozen_string_literal : true -*-' ,
518+ ] . each { |magic_comment | yield magic_comment }
513519 end
514520
515521 it "should put annotation before class if :position == 'before'" do
@@ -626,17 +632,22 @@ class Foo::User < ActiveRecord::Base
626632 expect ( File . read ( model_file_name ) ) . to eq ( "#{ schema_info } \n #{ file_content } " )
627633 end
628634
629- it "should not touch encoding comments" do
630- encoding_comments_list_each do |encoding_comment |
635+ it "should not touch magic comments" do
636+ magic_comments_list_each do |magic_comment |
631637 write_model "user.rb" , <<-EOS
632- #{ encoding_comment }
638+ #{ magic_comment }
633639class User < ActiveRecord::Base
634640end
635641 EOS
636642
637643 annotate_one_file :position => :before
638644
639- expect ( File . open ( @model_file_name , &:readline ) ) . to eq ( "#{ encoding_comment } \n " )
645+ lines = magic_comment . split ( "\n " )
646+ File . open @model_file_name do |file |
647+ lines . count . times do |index |
648+ expect ( file . readline ) . to eq "#{ lines [ index ] } \n "
649+ end
650+ end
640651 end
641652 end
642653
0 commit comments