leshill / handlebars_assets

Use handlebars.js templates with the Rails asset pipeline.
MIT License
647 stars 159 forks source link

allow using assets from global path instead of relative path in tests #167

Open pravi opened 5 years ago

pravi commented 5 years ago

When using the globally installed handlebars,

gem which handlebars_assets
/usr/share/rubygems-integration/all/gems/handlebars_assets-0.23.2/lib/handlebars_assets.rb

all tests fails to find the assets.

 1) Error:
HandlebarsAssets::CompilingTest#test_patching_handlebars:
Errno::ENOENT: No such file or directory @ rb_sysopen - vendor/assets/javascripts/handlebars.js
    /usr/share/rubygems-integration/all/gems/handlebars_assets-0.23.2/lib/handlebars_assets/handlebars.rb:35:in `read'
    /usr/share/rubygems-integration/all/gems/handlebars_assets-0.23.2/lib/handlebars_assets/handlebars.rb:35:in `read'
    /usr/share/rubygems-integration/all/gems/handlebars_assets-0.23.2/lib/handlebars_assets/handlebars.rb:35:in `source'
    /usr/share/rubygems-integration/all/gems/handlebars_assets-0.23.2/lib/handlebars_assets/handlebars.rb:18:in `append_patch'
    /usr/share/rubygems-integration/all/gems/handlebars_assets-0.23.2/lib/handlebars_assets/handlebars.rb:24:in `block in apply_patches_to_source'
    /usr/share/rubygems-integration/all/gems/handlebars_assets-0.23.2/lib/handlebars_assets/handlebars.rb:23:in `each'
    /usr/share/rubygems-integration/all/gems/handlebars_assets-0.23.2/lib/handlebars_assets/handlebars.rb:23:in `apply_patches_to_source'
    /usr/share/rubygems-integration/all/gems/handlebars_assets-0.23.2/lib/handlebars_assets/handlebars.rb:31:in `context'
    /usr/share/rubygems-integration/all/gems/handlebars_assets-0.23.2/lib/handlebars_assets/handlebars.rb:10:in `precompile'
    /tmp/autopkgtest-lxc.79gm0iv_/downtmp/build.7aH/src/test/handlebars_assets/compiling_test.rb:26:in `test_patching_handlebars'

https://ci.debian.net/data/packages/unstable/amd64/r/ruby-handlebars-assets/latest-autopkgtest/log.gz This works when assets are present locally, but we'd like to test the installed package also in debian. If there is a way to make this look for assets relative the the installed path instead of relative to test file path, that would help.

pravi commented 5 years ago

A crude method is like this, let me try to make it more generic.

--- a/test/test_helper.rb
+++ b/test/test_helper.rb
@@ -80,7 +80,7 @@
       @source = nil
       @patch_path = nil
       @path = nil
-      @assets_path = nil
+      @assets_path = Pathname.new('/usr/share/rubygems-integration/all/gems/handlebars_assets-0.23.2/vendor/assets/javascripts')
     end

   end
pravi commented 5 years ago

This change makes all tests except one to pass

--- a/test/test_helper.rb
+++ b/test/test_helper.rb
@@ -80,7 +80,7 @@
       @source = nil
       @patch_path = nil
       @path = nil
-      @assets_path = nil
+      @assets_path = Pathname.new(HandlebarsAssets::PATH)
     end

   end

 1) Failure:
HandlebarsAssets::CompilingTest#test_custom_handlebars [/<<PKGBUILDDIR>>/test/handlebars_assets/compiling_test.rb:17]:
Expected /PRECOMPILE CALLED/ to match "{\"compiler\":[7,\">= 4.0.0\"],\"main\":function(container,depth0,helpers,partials,data) {\n    var helper;\n\n  return \"This is \"\n    + container.escapeExpression(((helper = (helper = helpers.handlebars || (depth0 != null ? depth0.handlebars : depth0)) != null ? helper : helpers.helperMissing),(typeof helper === \"function\" ? helper.call(depth0 != null ? depth0 : (container.nullContext || {}),{\"name\":\"handlebars\",\"hash\":{},\"data\":data}) : helper)));\n},\"useData\":true}".

28 runs, 50 assertions, 1 failures, 0 errors, 0 skips
pravi commented 5 years ago

Actually this patch also failed the same way in autopkgtest (the earlier test run was during build). For now I have disabled autopkgtest, but it'd be nice to be able to run it.