rails/rails-dom-testing

can't modify frozen String on ruby 2.3.0

masterkain opened this issue ยท 7 comments

On Ruby 2.3.0, when putting the directive # frozen_string_literal: true on top of the spec file, this happens:

     Failure/Error: assert_select '[content=?]', 'meta,description'
     RuntimeError:
       can't modify frozen String
     # /Users/kain/.rvm/gems/ruby-2.3.0/gems/rails-dom-testing-1.0.7/lib/rails/dom/testing/assertions/selector_assertions/substitution_context.rb:8:in `sub!'
     # /Users/kain/.rvm/gems/ruby-2.3.0/gems/rails-dom-testing-1.0.7/lib/rails/dom/testing/assertions/selector_assertions/substitution_context.rb:8:in `substitute!'
     # /Users/kain/.rvm/gems/ruby-2.3.0/gems/rails-dom-testing-1.0.7/lib/rails/dom/testing/assertions/selector_assertions/html_selector.rb:77:in `extract_selector'
     # /Users/kain/.rvm/gems/ruby-2.3.0/gems/rails-dom-testing-1.0.7/lib/rails/dom/testing/assertions/selector_assertions/html_selector.rb:10:in `initialize'
     # /Users/kain/.rvm/gems/ruby-2.3.0/gems/rails-dom-testing-1.0.7/lib/rails/dom/testing/assertions/selector_assertions.rb:167:in `new'
     # /Users/kain/.rvm/gems/ruby-2.3.0/gems/rails-dom-testing-1.0.7/lib/rails/dom/testing/assertions/selector_assertions.rb:167:in `assert_select'
     # ./spec/controllers/products_controller_spec.rb:247:in `block (5 levels) in <top (required)>'

@masterkain Can you check if it's happening on master? I think

should have fixed it.

yeah it looks good, waiting on release, thanks

donv commented

Hi! Could this fix be backported to a 1.x release? Rails < 5 cannot use the 2.x releases.

donv commented

Workaround for rails-dom-testing 1.x:

class SubstitutionContext
  def substitute_with_dup!(selector, *args)
    substitute_without_dup!(selector.dup, *args)
  end
  alias_method_chain :substitute!, :dup
end

Good enough for me.

Sure, open a pull request. I'll be happy have the original fix backported, thanks ๐Ÿ˜„

donv commented

Thanks for the response, @kaspth , but with the workaround, or just not use the substitution feature, I am good without the fix ๐Ÿ˜„ .

Alright, then ๐Ÿ‘