jeremyevans / tilt

Generic interface to multiple Ruby template engines

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Missing entry in 2.1 Changelog?

AlexWayfer opened this issue · comments

I have such code: https://github.com/AlexWayfer/flame/blob/69d650a/lib/flame/render.rb

And such unit test: https://github.com/AlexWayfer/flame/blob/e21ba82/spec/flame/render_spec.rb

After upgrading Tilt from 2.0 to 2.1 I've got tests coverage decrease in this place: https://github.com/AlexWayfer/flame/blob/69d650a/lib/flame/render.rb#L102

Simple debugging showed me that now Tilt.[] doesn't cause LoadError, but returns nil (as I wanted, so tests are passing).

But I found no entry in the CHANGELOG about Tilt.[] neither LoadError.

There is no mention in the commit log related to LoadError, and I'm not seeing any related changes in any related method. Which template library are you trying to use? Are you sure the exact same versions of the template libraries are loaded with both Tilt 2.0.11 and 2.1.0? I know of an issue with slim (an external template library) because all recent versions specifically exclude 2.1+.

Can you provide a minimal, self-contained, reproducible example showing the behavior difference between Tilt 2.0.11 and Tilt 2.1.0?

Which template library are you trying to use?

ERB, as you can see. BTW, it seems more general, than engine-related.

Are you sure the exact same versions of the template libraries are loaded with both Tilt 2.0.11 and 2.1.0?

I see no difference in the Gemfile.lock except Tilt. And, as I've written, I'm using ERB usually.

Can you provide a minimal, self-contained, reproducible example showing the behavior difference between Tilt 2.0.11 and Tilt 2.1.0?

Should I? Do you want to? I've provided a lib (with not too large code related to Tilt) and 100% specs-coverage. Just change from ~> 2.0.0 to ~> 2.0 (or ~> 2.1) affects it.

I can try, but… I though you're more familiar with the Tilt. I'm afraid that my investigation will end-up into a new PR. 😅

Which template library are you trying to use?

ERB, as you can see. BTW, it seems more general, than engine-related.

I couldn't see that it was ERB, hence why I asked. Tilt.[] should only return nil if you are trying to pass something that isn't recognized as an engine. The only default engine change between 2.0.11 and 2.1.0 was the removal of opal, which was broken, and that was mentioned the CHANGELOG.

Can you provide a minimal, self-contained, reproducible example showing the behavior difference between Tilt 2.0.11 and Tilt 2.1.0?

Should I? Do you want to? I've provided a lib (with not too large code related to Tilt) and 100% specs-coverage. Just change from ~> 2.0.0 to ~> 2.0 (or ~> 2.1) affects it.

I wouldn't ask for this if I thought it wasn't needed. The test suite for your lib is not minimal, even if it is self-contained and reproducible.

I can try, but… I though you're more familiar with the Tilt. I'm afraid that my investigation will end-up into a new PR. 😅

And if a new PR is warranted, that is fine.

OK, I got this. Do you have good resources for Ruby code reproduction, or should I create a gist or repo or something else?

Posting an inline code example in this issue is best. It should be minimal, in that you cannot remove any part of the example and still get it to show the difference in behavior.

Posting an inline code example in this issue is best. It should be minimal, in that you cannot remove any part of the example and still get it to show the difference in behavior.

It doesn't help… but OK.

I've reproduced.

# Gemfile

# frozen_string_literal: true

source 'https://rubygems.org/'

gem 'tilt', '< 2.1' # change to `<=` for newer behavior

# there is also `rubocop`, but it doesn't affect
# test.rb

# frozen_string_literal: true

require 'tilt'

def find_file(path)
  caller_path = caller_locations(1..1).first.path

  p caller_path, Tilt[caller_path]
end

find_file 'foo'

I think this is enough.

> bundle exec ruby test.rb
<internal:/home/alex/.rbenv/versions/3.2.1/lib/ruby/3.2.0/rubygems/core_ext/kernel_require.rb>:37:in `require': cannot load such file -- opal (LoadError)
	from <internal:/home/alex/.rbenv/versions/3.2.1/lib/ruby/3.2.0/rubygems/core_ext/kernel_require.rb>:37:in `require'
	from /home/alex/.rbenv/versions/3.2.1/lib/ruby/gems/3.2.0/gems/tilt-2.0.11/lib/tilt/mapping.rb:243:in `block in lazy_load'
	from /home/alex/.rbenv/versions/3.2.1/lib/ruby/gems/3.2.0/gems/tilt-2.0.11/lib/tilt/mapping.rb:241:in `each'
	from /home/alex/.rbenv/versions/3.2.1/lib/ruby/gems/3.2.0/gems/tilt-2.0.11/lib/tilt/mapping.rb:241:in `lazy_load'
	from /home/alex/.rbenv/versions/3.2.1/lib/ruby/gems/3.2.0/gems/tilt-2.0.11/lib/tilt/mapping.rb:216:in `lookup'
	from /home/alex/.rbenv/versions/3.2.1/lib/ruby/gems/3.2.0/gems/tilt-2.0.11/lib/tilt/mapping.rb:154:in `[]'
	from /home/alex/.rbenv/versions/3.2.1/lib/ruby/gems/3.2.0/gems/tilt-2.0.11/lib/tilt.rb:48:in `[]'
	from test.rb:8:in `find_file'
	from test.rb:11:in `<main>'

> bundle update
Fetching gem metadata from https://rubygems.org/.........
Resolving dependencies...
Using bundler 2.4.6
Using rainbow 3.1.1
Using parallel 1.22.1
Using regexp_parser 2.7.0
Using ruby-progressbar 1.11.0
Using unicode-display_width 2.4.2
Using ast 2.4.2
Using rexml 3.2.5
Using tilt 2.1.0 (was 2.0.11)
Using json 2.6.3
Using parser 3.2.1.0
Using rubocop-ast 1.26.0
Using rubocop 1.46.0
Bundle updated!

> bundle exec ruby test.rb 
"test.rb"
nil

Thanks for putting together the minimal example, that makes it easy to see what the problem is. In this case, the error message is cannot load such file -- opal. The removal of opal support is mentioned in the CHANGELOG already, and I mentioned opal support removal earlier in this ticket. You got a LoadError previously because Tilt (attempted to) support opal, and treated the .rb extension as using the opal template, and so tried to require opal. You now get nil, the same as you would for any unrecognized template, because tilt no longer recognizes the .rb extension by default.

If you want to get coverage back in flame, update your tests to try to load a template file for a library that tilt supports but that is not installed, instead of loading something with an .rb extension. Alternatively, you could register a new extension for a library that doesn't exist, and try to load that.

If you want to get coverage back in flame, update your tests to try to load a template file for a library that tilt supports but that is not installed, instead of loading something with an .rb extension. Alternatively, you could register a new extension for a library that doesn't exist, and try to load that.

As you can notice from "the minimal example", I had no idea about opal.