2016-08-24 12 views
5

JSテストをレール/角形アプリケーションに統合する際に問題があります。特に、私のテスト環境では、このhtmlファイルの{{ハンドルバー}}の8回目と最終的な発生が窒息しています。この現象について何が特別なのか把握できません。ActionView :: Template :: Error: '{{2 + 2}}'の予期しないトークン

問題のエラーが_form.html.erbのライン784で来る:

<textarea class="figures_json col-lg-11 col-md-10 col-xs-9" readonly="readonly" name="dance[figures_json]" id="dance_figures_json"> 
{{2+2}}</textarea> 

とエラーがこれです:あなたは、私が「もののどのバージョンを見ることができるように

[email protected]:~/contra$ rspec ./spec/features/dances/create_spec.rb:7 
Run options: include {:locations=>{"./spec/features/dances/create_spec.rb"=>[7]}} 
F 

Failures: 

    1) Creating dances creates a new dance with non-javascript data 
    Failure/Error: JSON.parse figures_json 

    ActionView::Template::Error: 
     784: unexpected token at '{{2+2}}' 
    # ./app/models/dance.rb:10:in `figures' 
    # ./app/views/dances/_bodyshow.html.erb:6:in `_app_views_dances__bodyshow_html_erb__2235413439078114529_46217560' 
    # /home/dm/.rvm/gems/ruby-2.3.0/gems/actionview-4.2.3/lib/action_view/template.rb:145:in `block in render' 
    # /home/dm/.rvm/gems/ruby-2.3.0/gems/activesupport-4.2.3/lib/active_support/notifications.rb:166:in `instrument' 
    # /home/dm/.rvm/gems/ruby-2.3.0/gems/actionview-4.2.3/lib/action_view/template.rb:333:in `instrument' 
    # /home/dm/.rvm/gems/ruby-2.3.0/gems/actionview-4.2.3/lib/action_view/template.rb:143:in `render' 
    # /home/dm/.rvm/gems/ruby-2.3.0/gems/actionview-4.2.3/lib/action_view/renderer/partial_renderer.rb:339:in `render_partial' 
    # /home/dm/.rvm/gems/ruby-2.3.0/gems/actionview-4.2.3/lib/action_view/renderer/partial_renderer.rb:310:in `block in render' 
    # /home/dm/.rvm/gems/ruby-2.3.0/gems/actionview-4.2.3/lib/action_view/renderer/abstract_renderer.rb:39:in `block in instrument' 
    # /home/dm/.rvm/gems/ruby-2.3.0/gems/activesupport-4.2.3/lib/active_support/notifications.rb:164:in `block in instrument' 
    # /home/dm/.rvm/gems/ruby-2.3.0/gems/activesupport-4.2.3/lib/active_support/notifications/instrumenter.rb:20:in `instrument' 
    # /home/dm/.rvm/gems/ruby-2.3.0/gems/activesupport-4.2.3/lib/active_support/notifications.rb:164:in `instrument' 
    # /home/dm/.rvm/gems/ruby-2.3.0/gems/actionview-4.2.3/lib/action_view/renderer/abstract_renderer.rb:39:in `instrument' 
    # /home/dm/.rvm/gems/ruby-2.3.0/gems/actionview-4.2.3/lib/action_view/renderer/partial_renderer.rb:309:in `render' 
    # /home/dm/.rvm/gems/ruby-2.3.0/gems/actionview-4.2.3/lib/action_view/renderer/renderer.rb:47:in `render_partial' 
    # /home/dm/.rvm/gems/ruby-2.3.0/gems/actionview-4.2.3/lib/action_view/renderer/renderer.rb:21:in `render' 
    # /home/dm/.rvm/gems/ruby-2.3.0/gems/actionview-4.2.3/lib/action_view/helpers/rendering_helper.rb:32:in `render' 
    # ./app/views/dances/show.html.erb:16:in `_app_views_dances_show_html_erb__1493296941766923553_47454680' 
    # /home/dm/.rvm/gems/ruby-2.3.0/gems/actionview-4.2.3/lib/action_view/template.rb:145:in `block in render' 
    # /home/dm/.rvm/gems/ruby-2.3.0/gems/activesupport-4.2.3/lib/active_support/notifications.rb:166:in `instrument' 
    # /home/dm/.rvm/gems/ruby-2.3.0/gems/actionview-4.2.3/lib/action_view/template.rb:333:in `instrument' 
    # /home/dm/.rvm/gems/ruby-2.3.0/gems/actionview-4.2.3/lib/action_view/template.rb:143:in `render' 
    # /home/dm/.rvm/gems/ruby-2.3.0/gems/actionview-4.2.3/lib/action_view/renderer/template_renderer.rb:54:in `block (2 levels) in render_template' 
    # /home/dm/.rvm/gems/ruby-2.3.0/gems/actionview-4.2.3/lib/action_view/renderer/abstract_renderer.rb:39:in `block in instrument' 
    # /home/dm/.rvm/gems/ruby-2.3.0/gems/activesupport-4.2.3/lib/active_support/notifications.rb:164:in `block in instrument' 
    # /home/dm/.rvm/gems/ruby-2.3.0/gems/activesupport-4.2.3/lib/active_support/notifications/instrumenter.rb:20:in `instrument' 
    # /home/dm/.rvm/gems/ruby-2.3.0/gems/activesupport-4.2.3/lib/active_support/notifications.rb:164:in `instrument' 
    # /home/dm/.rvm/gems/ruby-2.3.0/gems/actionview-4.2.3/lib/action_view/renderer/abstract_renderer.rb:39:in `instrument' 
    # /home/dm/.rvm/gems/ruby-2.3.0/gems/actionview-4.2.3/lib/action_view/renderer/template_renderer.rb:53:in `block in render_template' 
    # /home/dm/.rvm/gems/ruby-2.3.0/gems/actionview-4.2.3/lib/action_view/renderer/template_renderer.rb:61:in `render_with_layout' 
    # /home/dm/.rvm/gems/ruby-2.3.0/gems/actionview-4.2.3/lib/action_view/renderer/template_renderer.rb:52:in `render_template' 
    # /home/dm/.rvm/gems/ruby-2.3.0/gems/actionview-4.2.3/lib/action_view/renderer/template_renderer.rb:14:in `render' 
    # /home/dm/.rvm/gems/ruby-2.3.0/gems/actionview-4.2.3/lib/action_view/renderer/renderer.rb:42:in `render_template' 
    # /home/dm/.rvm/gems/ruby-2.3.0/gems/actionview-4.2.3/lib/action_view/renderer/renderer.rb:23:in `render' 
    # /home/dm/.rvm/gems/ruby-2.3.0/gems/actionview-4.2.3/lib/action_view/rendering.rb:100:in `_render_template' 
    # /home/dm/.rvm/gems/ruby-2.3.0/gems/actionpack-4.2.3/lib/action_controller/metal/streaming.rb:217:in `_render_template' 
    # /home/dm/.rvm/gems/ruby-2.3.0/gems/actionview-4.2.3/lib/action_view/rendering.rb:83:in `render_to_body' 
    # /home/dm/.rvm/gems/ruby-2.3.0/gems/actionpack-4.2.3/lib/action_controller/metal/rendering.rb:32:in `render_to_body' 
    # /home/dm/.rvm/gems/ruby-2.3.0/gems/actionpack-4.2.3/lib/action_controller/metal/renderers.rb:37:in `render_to_body' 
    # /home/dm/.rvm/gems/ruby-2.3.0/gems/actionpack-4.2.3/lib/abstract_controller/rendering.rb:25:in `render' 
    # /home/dm/.rvm/gems/ruby-2.3.0/gems/actionpack-4.2.3/lib/action_controller/metal/rendering.rb:16:in `render' 
    # /home/dm/.rvm/gems/ruby-2.3.0/gems/actionpack-4.2.3/lib/action_controller/metal/instrumentation.rb:44:in `block (2 levels) in render' 
    # /home/dm/.rvm/gems/ruby-2.3.0/gems/activesupport-4.2.3/lib/active_support/core_ext/benchmark.rb:12:in `block in ms' 
    # /home/dm/.rvm/gems/ruby-2.3.0/gems/activesupport-4.2.3/lib/active_support/core_ext/benchmark.rb:12:in `ms' 
    # /home/dm/.rvm/gems/ruby-2.3.0/gems/actionpack-4.2.3/lib/action_controller/metal/instrumentation.rb:44:in `block in render' 
    # /home/dm/.rvm/gems/ruby-2.3.0/gems/actionpack-4.2.3/lib/action_controller/metal/instrumentation.rb:87:in `cleanup_view_runtime' 
    # /home/dm/.rvm/gems/ruby-2.3.0/gems/activerecord-4.2.3/lib/active_record/railties/controller_runtime.rb:25:in `cleanup_view_runtime' 
    # /home/dm/.rvm/gems/ruby-2.3.0/gems/actionpack-4.2.3/lib/action_controller/metal/instrumentation.rb:43:in `render' 
    # /home/dm/.rvm/gems/ruby-2.3.0/gems/actionpack-4.2.3/lib/action_controller/metal/implicit_render.rb:10:in `default_render' 
    # /home/dm/.rvm/gems/ruby-2.3.0/gems/actionpack-4.2.3/lib/action_controller/metal/implicit_render.rb:5:in `send_action' 
    # /home/dm/.rvm/gems/ruby-2.3.0/gems/actionpack-4.2.3/lib/abstract_controller/base.rb:198:in `process_action' 
    # /home/dm/.rvm/gems/ruby-2.3.0/gems/actionpack-4.2.3/lib/action_controller/metal/rendering.rb:10:in `process_action' 
    # /home/dm/.rvm/gems/ruby-2.3.0/gems/actionpack-4.2.3/lib/abstract_controller/callbacks.rb:20:in `block in process_action' 
    # /home/dm/.rvm/gems/ruby-2.3.0/gems/activesupport-4.2.3/lib/active_support/callbacks.rb:115:in `call' 
    # /home/dm/.rvm/gems/ruby-2.3.0/gems/activesupport-4.2.3/lib/active_support/callbacks.rb:553:in `block (2 levels) in compile' 
    # /home/dm/.rvm/gems/ruby-2.3.0/gems/activesupport-4.2.3/lib/active_support/callbacks.rb:503:in `call' 
    # /home/dm/.rvm/gems/ruby-2.3.0/gems/activesupport-4.2.3/lib/active_support/callbacks.rb:88:in `run_callbacks' 
    # /home/dm/.rvm/gems/ruby-2.3.0/gems/actionpack-4.2.3/lib/abstract_controller/callbacks.rb:19:in `process_action' 
    # /home/dm/.rvm/gems/ruby-2.3.0/gems/actionpack-4.2.3/lib/action_controller/metal/rescue.rb:29:in `process_action' 
    # /home/dm/.rvm/gems/ruby-2.3.0/gems/actionpack-4.2.3/lib/action_controller/metal/instrumentation.rb:32:in `block in process_action' 
    # /home/dm/.rvm/gems/ruby-2.3.0/gems/activesupport-4.2.3/lib/active_support/notifications.rb:164:in `block in instrument' 
    # /home/dm/.rvm/gems/ruby-2.3.0/gems/activesupport-4.2.3/lib/active_support/notifications/instrumenter.rb:20:in `instrument' 
    # /home/dm/.rvm/gems/ruby-2.3.0/gems/activesupport-4.2.3/lib/active_support/notifications.rb:164:in `instrument' 
    # /home/dm/.rvm/gems/ruby-2.3.0/gems/actionpack-4.2.3/lib/action_controller/metal/instrumentation.rb:30:in `process_action' 
    # /home/dm/.rvm/gems/ruby-2.3.0/gems/actionpack-4.2.3/lib/action_controller/metal/params_wrapper.rb:250:in `process_action' 
    # /home/dm/.rvm/gems/ruby-2.3.0/gems/activerecord-4.2.3/lib/active_record/railties/controller_runtime.rb:18:in `process_action' 
    # /home/dm/.rvm/gems/ruby-2.3.0/gems/actionpack-4.2.3/lib/abstract_controller/base.rb:137:in `process' 
    # /home/dm/.rvm/gems/ruby-2.3.0/gems/actionview-4.2.3/lib/action_view/rendering.rb:30:in `process' 
    # /home/dm/.rvm/gems/ruby-2.3.0/gems/actionpack-4.2.3/lib/action_controller/metal.rb:196:in `dispatch' 
    # /home/dm/.rvm/gems/ruby-2.3.0/gems/actionpack-4.2.3/lib/action_controller/metal/rack_delegation.rb:13:in `dispatch' 
    # /home/dm/.rvm/gems/ruby-2.3.0/gems/actionpack-4.2.3/lib/action_controller/metal.rb:237:in `block in action' 
    # /home/dm/.rvm/gems/ruby-2.3.0/gems/actionpack-4.2.3/lib/action_dispatch/routing/route_set.rb:76:in `dispatch' 
    # /home/dm/.rvm/gems/ruby-2.3.0/gems/actionpack-4.2.3/lib/action_dispatch/routing/route_set.rb:45:in `serve' 
    # /home/dm/.rvm/gems/ruby-2.3.0/gems/actionpack-4.2.3/lib/action_dispatch/journey/router.rb:43:in `block in serve' 
    # /home/dm/.rvm/gems/ruby-2.3.0/gems/actionpack-4.2.3/lib/action_dispatch/journey/router.rb:30:in `each' 
    # /home/dm/.rvm/gems/ruby-2.3.0/gems/actionpack-4.2.3/lib/action_dispatch/journey/router.rb:30:in `serve' 
    # /home/dm/.rvm/gems/ruby-2.3.0/gems/actionpack-4.2.3/lib/action_dispatch/routing/route_set.rb:821:in `call' 
    # /home/dm/.rvm/gems/ruby-2.3.0/gems/warden-1.2.4/lib/warden/manager.rb:35:in `block in call' 
    # /home/dm/.rvm/gems/ruby-2.3.0/gems/warden-1.2.4/lib/warden/manager.rb:34:in `catch' 
    # /home/dm/.rvm/gems/ruby-2.3.0/gems/warden-1.2.4/lib/warden/manager.rb:34:in `call' 
    # /home/dm/.rvm/gems/ruby-2.3.0/gems/rack-1.6.4/lib/rack/etag.rb:24:in `call' 
    # /home/dm/.rvm/gems/ruby-2.3.0/gems/rack-1.6.4/lib/rack/conditionalget.rb:25:in `call' 
    # /home/dm/.rvm/gems/ruby-2.3.0/gems/rack-1.6.4/lib/rack/head.rb:13:in `call' 
    # /home/dm/.rvm/gems/ruby-2.3.0/gems/actionpack-4.2.3/lib/action_dispatch/middleware/params_parser.rb:27:in `call' 
    # /home/dm/.rvm/gems/ruby-2.3.0/gems/actionpack-4.2.3/lib/action_dispatch/middleware/flash.rb:260:in `call' 
    # /home/dm/.rvm/gems/ruby-2.3.0/gems/rack-1.6.4/lib/rack/session/abstract/id.rb:225:in `context' 
    # /home/dm/.rvm/gems/ruby-2.3.0/gems/rack-1.6.4/lib/rack/session/abstract/id.rb:220:in `call' 
    # /home/dm/.rvm/gems/ruby-2.3.0/gems/actionpack-4.2.3/lib/action_dispatch/middleware/cookies.rb:560:in `call' 
    # /home/dm/.rvm/gems/ruby-2.3.0/gems/activerecord-4.2.3/lib/active_record/query_cache.rb:36:in `call' 
    # /home/dm/.rvm/gems/ruby-2.3.0/gems/activerecord-4.2.3/lib/active_record/connection_adapters/abstract/connection_pool.rb:653:in `call' 
    # /home/dm/.rvm/gems/ruby-2.3.0/gems/actionpack-4.2.3/lib/action_dispatch/middleware/callbacks.rb:29:in `block in call' 
    # /home/dm/.rvm/gems/ruby-2.3.0/gems/activesupport-4.2.3/lib/active_support/callbacks.rb:84:in `run_callbacks' 
    # /home/dm/.rvm/gems/ruby-2.3.0/gems/actionpack-4.2.3/lib/action_dispatch/middleware/callbacks.rb:27:in `call' 
    # /home/dm/.rvm/gems/ruby-2.3.0/gems/actionpack-4.2.3/lib/action_dispatch/middleware/remote_ip.rb:78:in `call' 
    # /home/dm/.rvm/gems/ruby-2.3.0/gems/actionpack-4.2.3/lib/action_dispatch/middleware/debug_exceptions.rb:17:in `call' 
    # /home/dm/.rvm/gems/ruby-2.3.0/gems/web-console-2.2.1/lib/web_console/middleware.rb:39:in `call' 
    # /home/dm/.rvm/gems/ruby-2.3.0/gems/actionpack-4.2.3/lib/action_dispatch/middleware/show_exceptions.rb:30:in `call' 
    # /home/dm/.rvm/gems/ruby-2.3.0/gems/railties-4.2.3/lib/rails/rack/logger.rb:38:in `call_app' 
    # /home/dm/.rvm/gems/ruby-2.3.0/gems/railties-4.2.3/lib/rails/rack/logger.rb:20:in `block in call' 
    # /home/dm/.rvm/gems/ruby-2.3.0/gems/activesupport-4.2.3/lib/active_support/tagged_logging.rb:68:in `block in tagged' 
    # /home/dm/.rvm/gems/ruby-2.3.0/gems/activesupport-4.2.3/lib/active_support/tagged_logging.rb:26:in `tagged' 
    # /home/dm/.rvm/gems/ruby-2.3.0/gems/activesupport-4.2.3/lib/active_support/tagged_logging.rb:68:in `tagged' 
    # /home/dm/.rvm/gems/ruby-2.3.0/gems/railties-4.2.3/lib/rails/rack/logger.rb:20:in `call' 
    # /home/dm/.rvm/gems/ruby-2.3.0/gems/actionpack-4.2.3/lib/action_dispatch/middleware/request_id.rb:21:in `call' 
    # /home/dm/.rvm/gems/ruby-2.3.0/gems/rack-1.6.4/lib/rack/methodoverride.rb:22:in `call' 
    # /home/dm/.rvm/gems/ruby-2.3.0/gems/rack-1.6.4/lib/rack/runtime.rb:18:in `call' 
    # /home/dm/.rvm/gems/ruby-2.3.0/gems/activesupport-4.2.3/lib/active_support/cache/strategy/local_cache_middleware.rb:28:in `call' 
    # /home/dm/.rvm/gems/ruby-2.3.0/gems/rack-1.6.4/lib/rack/lock.rb:17:in `call' 
    # /home/dm/.rvm/gems/ruby-2.3.0/gems/actionpack-4.2.3/lib/action_dispatch/middleware/static.rb:116:in `call' 
    # /home/dm/.rvm/gems/ruby-2.3.0/gems/rack-1.6.4/lib/rack/sendfile.rb:113:in `call' 
    # /home/dm/.rvm/gems/ruby-2.3.0/gems/railties-4.2.3/lib/rails/engine.rb:518:in `call' 
    # /home/dm/.rvm/gems/ruby-2.3.0/gems/railties-4.2.3/lib/rails/application.rb:165:in `call' 
    # /home/dm/.rvm/gems/ruby-2.3.0/gems/rack-1.6.4/lib/rack/urlmap.rb:66:in `block in call' 
    # /home/dm/.rvm/gems/ruby-2.3.0/gems/rack-1.6.4/lib/rack/urlmap.rb:50:in `each' 
    # /home/dm/.rvm/gems/ruby-2.3.0/gems/rack-1.6.4/lib/rack/urlmap.rb:50:in `call' 
    # /home/dm/.rvm/gems/ruby-2.3.0/gems/capybara-2.7.1/lib/capybara/server.rb:43:in `call' 
    # /home/dm/.rvm/gems/ruby-2.3.0/gems/rack-1.6.4/lib/rack/handler/webrick.rb:88:in `service' 
    # ------------------ 
    # --- Caused by: --- 
    # Capybara::ExpectationNotMet: 
    # expected to find css "h1" with text "Call Me" but there were no matches. Also found "Internal Server Error", which matched the selector but not all filters. 
    # /home/dm/.rvm/gems/ruby-2.3.0/gems/capybara-2.7.1/lib/capybara/node/matchers.rb:128:in `block in assert_selector' 

Finished in 1.77 seconds (files took 1.59 seconds to load) 
1 example, 1 failure 

Failed examples: 

rspec ./spec/features/dances/create_spec.rb:7 # Creating dances creates a new dance with non-javascript data 

は、ここに私のGemfile.lockへのリンクですを使用しています。

+1

エラーに関連する 'create_spec.rb'にコードを投稿できますか? –

+0

同じエラーが発生したかどうかをブラウザで手動で確認しようとしましたか? –

+0

あなたの問題は、 'figures_json'が' undefined'で 'JSON.parse(undefined)' =が失敗するということです。 – gianlucatursi

答えて

2

問題は、784行目の_form.html.erbから発生していますか?コールスタックでこのファイルが見つかりません! dance.rb#10でチョークする呼び出しスタック状態。figures_jsonには、JSONではない{{2+2}}が含まれています。

UPDATE

私は実際にアプリで何が起こっているか見て&ダウンロードするための予備の分を持っていました。 newアクションを実際にレンダリングするときは、実際にJS経由でcreateアクションを送信し、その_formから{{2+2}}の値を持つDanceを作成します。それは私には奇妙に見えますが(なぜnewアクションで作成するのですか?)角度はtextareaの中の式を評価しないので、ng-modelにバインドする必要があります。したがって、このテキストエリアを次のように書き直したいとします。

<textarea class="figures_json col-lg-11 col-md-10 col-xs-9" readonly="readonly" name="dance[figures_json]" id="dance_figures_json" ng-model="2+2"> 
+0

'{{2 + 2}}'はJSONではありません。 '{{2 + 2}} 'は「4」と評価されるべき角度表現です。角度が正しく働いていないという証拠として挿入されています。 –

+0

@DaveMorseああ、右~~~答えを更新しました – shlajin

+0

Angularがテキストエリアのマッサージをサポートしようとしているという直接的な証拠があります。また、開発中でも動作します。 https://docs.angularjs.org/api/ng/directive/textarea –

関連する問題