Error compiling ERB code from string

后端 未结 1 1814
独厮守ぢ
独厮守ぢ 2021-01-14 09:36

I\'m writing some tests for my view helper (Rails 4.0) and trying to compile ERB code in a string that executes it. However, for the sake of simplicity, I am using a common

相关标签:
1条回答
  • 2021-01-14 09:43

    “Normal” Eruby doesn’t allow for expressions using <%= to have blocks the way Rails uses them. Rails extends the Erubis Eruby handler to add support for them. Your test is just tring to use Erb directly, so this support isn’t available.

    You need to make sure this support is loaded for this to work. I can get get it working with this:

    ActionView::Template::Handlers::Erubis.new(template).evaluate(ActionView::Base.new)
    

    I don’t know if this is the best way though. Check the RSpec docs, there may be a better way for testing parts of views like this.

    0 讨论(0)
提交回复
热议问题