开发者

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

开发者 https://www.devze.com 2023-03-30 17:51 出处:网络
I\'m using the latest edition (3?) of the Pragmatic Ruby book to help me learn Ruby, and just did a tutorial about sending emails. I ran the tests that I just constructed and am seeing some errors. I\

I'm using the latest edition (3?) of the Pragmatic Ruby book to help me learn Ruby, and just did a tutorial about sending emails. I ran the tests that I just constructed and am seeing some errors. I'm trying to debug them without simply re-doing all the code I just did. Unfortunately, I'm not good enough at understanding the Rails setup to understand what these errors mean and what I should look for:

  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 ;@out开发者_如何学Cput_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>'

UPDATED to add the code for 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.


The important lines are these:

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

That semicolon before the = shouldn't be there, or perhaps the = itself shouldn't be there :)

Edit: here's the problem:

<% = @order.name %>

should be

<%= @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....

Generally, the most useful part of an error is at the top, Everything below that goes further into the backtrace. in this example, the error says you are missing an end keyword, but I'd suggest removing the semi-colons.

0

精彩评论

暂无评论...
验证码 换一张
取 消