簡體   English   中英

學習如何閱讀錯誤和調試Ruby - 從實用Ruby運行代碼時測試錯誤

[英]Learning how to Read Errors and Debug Ruby - Test Errors while Running Code from Pragmatic Ruby

我正在使用Pragmatic Ruby書的最新版本(3?)來幫助我學習Ruby,並且只是做了一個關於發送電子郵件的教程。 我運行了剛剛構建的測試並看到了一些錯誤。 我正在嘗試調試它們,而不是簡單地重新執行我剛才所做的所有代碼。 不幸的是,我不太了解Rails設置以了解這些錯誤的含義以及我應該尋找的內容:

  1) Error:
test_order_received(NotifierTest):
ActionView::Template::Error: /PATH_BASE/agileRails/depot/app/views/notifier/order_received.text.erb:1: syntax error, unexpected '=', expecting keyword_end
..._buffer.safe_concat('Dear '); = @order.name ;@output_buffer....
...                               ^
    /PATH_BASE/.rvm/gems/ruby-1.9.2-p290/gems/actionpack-3.0.9/lib/action_view/template.rb:258:in `module_eval'
    /PATH_BASE/.rvm/gems/ruby-1.9.2-p290/gems/actionpack-3.0.9/lib/action_view/template.rb:258:in `compile'
    /PATH_BASE/.rvm/gems/ruby-1.9.2-p290/gems/actionpack-3.0.9/lib/action_view/template.rb:134:in `block in render'
    /PATH_BASE/.rvm/gems/ruby-1.9.2-p290/gems/activesupport-3.0.9/lib/active_support/notifications.rb:54:in `instrument'
    /PATH_BASE/.rvm/gems/ruby-1.9.2-p290/gems/actionpack-3.0.9/lib/action_view/template.rb:127:in `render'
    /PATH_BASE/.rvm/gems/ruby-1.9.2-p290/gems/actionpack-3.0.9/lib/action_view/render/rendering.rb:59:in `block in _render_template'
    /PATH_BASE/.rvm/gems/ruby-1.9.2-p290/gems/activesupport-3.0.9/lib/active_support/notifications.rb:54:in `instrument'
    /PATH_BASE/.rvm/gems/ruby-1.9.2-p290/gems/actionpack-3.0.9/lib/action_view/render/rendering.rb:56:in `_render_template'
    /PATH_BASE/.rvm/gems/ruby-1.9.2-p290/gems/actionpack-3.0.9/lib/action_view/render/rendering.rb:26:in `render'
    /PATH_BASE/.rvm/gems/ruby-1.9.2-p290/gems/actionpack-3.0.9/lib/abstract_controller/rendering.rb:115:in `_render_template'
    /PATH_BASE/.rvm/gems/ruby-1.9.2-p290/gems/actionpack-3.0.9/lib/abstract_controller/rendering.rb:109:in `render_to_body'
    /PATH_BASE/.rvm/gems/ruby-1.9.2-p290/gems/actionpack-3.0.9/lib/abstract_controller/rendering.rb:102:in `render_to_string'
    /PATH_BASE/.rvm/gems/ruby-1.9.2-p290/gems/actionpack-3.0.9/lib/abstract_controller/rendering.rb:93:in `render'
    /PATH_BASE/.rvm/gems/ruby-1.9.2-p290/gems/actionmailer-3.0.9/lib/action_mailer/deprecated_api.rb:111:in `render'
    /PATH_BASE/.rvm/gems/ruby-1.9.2-p290/gems/actionmailer-3.0.9/lib/action_mailer/base.rb:735:in `block in collect_responses_and_parts_order'
    /PATH_BASE/.rvm/gems/ruby-1.9.2-p290/gems/actionmailer-3.0.9/lib/action_mailer/base.rb:750:in `each'
    /PATH_BASE/.rvm/gems/ruby-1.9.2-p290/gems/actionmailer-3.0.9/lib/action_mailer/base.rb:750:in `block in each_template'
    /PATH_BASE/.rvm/gems/ruby-1.9.2-p290/gems/actionmailer-3.0.9/lib/action_mailer/base.rb:745:in `each'
    /PATH_BASE/.rvm/gems/ruby-1.9.2-p290/gems/actionmailer-3.0.9/lib/action_mailer/base.rb:745:in `each_template'
    /PATH_BASE/.rvm/gems/ruby-1.9.2-p290/gems/actionmailer-3.0.9/lib/action_mailer/base.rb:731:in `collect_responses_and_parts_order'
    /PATH_BASE/.rvm/gems/ruby-1.9.2-p290/gems/actionmailer-3.0.9/lib/action_mailer/base.rb:673:in `mail'
    /PATH_BASE/Dropbox/Development/instruction/agileRails/depot/app/mailers/notifier.rb:12:in `order_received'
    /PATH_BASE/.rvm/gems/ruby-1.9.2-p290/gems/actionpack-3.0.9/lib/abstract_controller/base.rb:150:in `process_action'
    /PATH_BASE/.rvm/gems/ruby-1.9.2-p290/gems/actionpack-3.0.9/lib/abstract_controller/base.rb:119:in `process'
    /PATH_BASE/.rvm/gems/ruby-1.9.2-p290/gems/actionpack-3.0.9/lib/abstract_controller/rendering.rb:41:in `process'
    /PATH_BASE/.rvm/gems/ruby-1.9.2-p290/gems/actionmailer-3.0.9/lib/action_mailer/old_api.rb:75:in `process'
    /PATH_BASE/.rvm/gems/ruby-1.9.2-p290/gems/actionmailer-3.0.9/lib/action_mailer/base.rb:471:in `process'
    /PATH_BASE/.rvm/gems/ruby-1.9.2-p290/gems/actionmailer-3.0.9/lib/action_mailer/base.rb:466:in `initialize'
    /PATH_BASE/.rvm/gems/ruby-1.9.2-p290/gems/actionmailer-3.0.9/lib/action_mailer/base.rb:450:in `new'
    /PATH_BASE/.rvm/gems/ruby-1.9.2-p290/gems/actionmailer-3.0.9/lib/action_mailer/base.rb:450:in `method_missing'
    test/functional/notifier_test.rb:5:in `block in <class:NotifierTest>'

  2) Error:
test_order_shipped(NotifierTest):
ArgumentError: wrong number of arguments (1 for 0)
    /PATH_BASE/agileRails/depot/app/mailers/notifier.rb:20:in `order_shipped'
    /PATH_BASE/.rvm/gems/ruby-1.9.2-p290/gems/actionpack-3.0.9/lib/abstract_controller/base.rb:150:in `process_action'
    /PATH_BASE/.rvm/gems/ruby-1.9.2-p290/gems/actionpack-3.0.9/lib/abstract_controller/base.rb:119:in `process'
    /PATH_BASE/.rvm/gems/ruby-1.9.2-p290/gems/actionpack-3.0.9/lib/abstract_controller/rendering.rb:41:in `process'
    /PATH_BASE/.rvm/gems/ruby-1.9.2-p290/gems/actionmailer-3.0.9/lib/action_mailer/old_api.rb:75:in `process'
    /PATH_BASE/.rvm/gems/ruby-1.9.2-p290/gems/actionmailer-3.0.9/lib/action_mailer/base.rb:471:in `process'
    /PATH_BASE/.rvm/gems/ruby-1.9.2-p290/gems/actionmailer-3.0.9/lib/action_mailer/base.rb:466:in `initialize'
    /PATH_BASE/.rvm/gems/ruby-1.9.2-p290/gems/actionmailer-3.0.9/lib/action_mailer/base.rb:450:in `new'
    /PATH_BASE/.rvm/gems/ruby-1.9.2-p290/gems/actionmailer-3.0.9/lib/action_mailer/base.rb:450:in `method_missing'
    test/functional/notifier_test.rb:13:in `block in <class:NotifierTest>'

更新為order_received.text.erb添加代碼

Dear <% = @order.name %>

Thank you for your recent order from The Pragmatic Store.

You ordered the following items:
<%= render @order.line_items %>

We'll send you a separate e-mail when your order ships.

重要的是這些:

syntax error, unexpected '=', expecting keyword_end
..._buffer.safe_concat('Dear '); = @order.name ;@output_buffer....
...                               ^

=之前的那個分號不應該在那里,或者也許=本身不應該在那里:)

編輯:這是問題所在:

<% = @order.name %>

應該

<%= @order.name %>
ActionView::Template::Error: /PATH_BASE/agileRails/depot/app/views/notifier/order_received.text.erb:1: syntax error, unexpected '=', expecting keyword_end
..._buffer.safe_concat('Dear '); = @order.name ;@output_buffer....

通常,錯誤中最有用的部分位於頂部,下面的所有內容都會進一步進入回溯。 在此示例中,錯誤表示您缺少end關鍵字,但我建議刪除分號。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM