liquid
liquid copied to clipboard
Liquid::Template.parse(text) error in rspec after ver 5.6~
only in rspec, the method has error. works fine in application env, or rails console.
rspec result:
Failure/Error: template = Liquid::Template.parse(text.to_s)
NoMethodError:
undefined method `peek_byte' for #<StringScanner 0/26 @ "Hello...">
# /usr/local/bundle/gems/liquid-5.6.4/lib/liquid/tokenizer.rb:74:in `next_token'
# /usr/local/bundle/gems/liquid-5.6.4/lib/liquid/tokenizer.rb:65:in `shift_normal'
# /usr/local/bundle/gems/liquid-5.6.4/lib/liquid/tokenizer.rb:57:in `tokenize'
# /usr/local/bundle/gems/liquid-5.6.4/lib/liquid/tokenizer.rb:33:in `initialize'
# /usr/local/bundle/gems/liquid-5.6.4/lib/liquid/parse_context.rb:45:in `new'
# /usr/local/bundle/gems/liquid-5.6.4/lib/liquid/parse_context.rb:45:in `new_tokenizer'
# /usr/local/bundle/gems/liquid-5.6.4/lib/liquid/template.rb:105:in `parse'
# /usr/local/bundle/gems/liquid-5.6.4/lib/liquid/template.rb:85:in `parse'
...
downgrading to 5.5~, error has gone.
I can confirm this too.
I used rspec-rails 8.0.2 which is the latest version at the time of writing this.
I had to downgrade to liquid v 5.5.1
It looks like you are using the old version of strscan 🤔
The gemspec should force the gem users from using a gem version that is >= 3.1.1.
https://github.com/Shopify/liquid/blob/1c1e7119065b0fa915149b9e2bdc303490a0dfff/liquid.gemspec#L31
Also, upgrading ruby to "3.4.x" should fix this issue too