Dmitry Matveyev
Dmitry Matveyev

Reputation: 481

ActionView::Template::Error: 785: unexpected token at ''

This error happens randomly during testing (standard Rails testing toolkit) after running rails test. Failed test can be any test in any file.

This error happens usually in testing environment during CI/CD process. Locally it occurs very rarely.

Here is a full stack trace:

Error:
SitePositionsControllerTest#test_should_create_position_link:
ActionView::Template::Error: 785: unexpected token at ''
    app/views/layouts/site/application.html.erb:10
    test/controllers/site_positions_controller_test.rb:28:in `block (2 levels) in <class:SitePositionsControllerTest>'
    test/controllers/site_positions_controller_test.rb:27:in `block in <class:SitePositionsControllerTest>'
    test/test_helper.rb:64:in `block (3 levels) in run'
    test/test_helper.rb:63:in `block (2 levels) in run'
    test/test_helper.rb:62:in `block in run'
    test/test_helper.rb:54:in `run'

rails test test/controllers/site_positions_controller_test.rb:18

Upvotes: 12

Views: 1462

Answers (2)

Todd
Todd

Reputation: 3508

Like @jellymann I was having this issue on calls to javascript_pack_tag.

I added bin/rails webpacker:compile before rails test and it seems to have resolved the issue.

This was happening pretty regularly. In the two days since I made that change, at least a dozen or so builds have gone off without this error.

Upvotes: 2

duleorlovic
duleorlovic

Reputation: 452

I had the same problem when I used with webmock and VCR.

Solved adding this initializer (some hints)

# config/initializers/webmock.rb
if Rails.env.test?
  require 'webmock'
  WebMock.disable_net_connect!(allow_localhost: true)
end

Upvotes: 0

Related Questions