`
jbf034
  • 浏览: 152347 次
  • 性别: Icon_minigender_1
  • 来自: 杭州
社区版块
存档分类
最新评论

Debugging Hints

阅读更多
首先想到的和广泛使用的是,写测试代码!rails 使得写unit test 和functional test
变得容易。使用了它们,你将发现bug 的出现率会显著减少。测试是廉价的保单。
测试会告诉你哪些东西起作用,哪些不起作用,有助于你隔离有问题的代码。但有时,
出现问题的原因不是非常明显。
如果问题出现在一个model 中,你可能想在web 程序外来跟踪相关的类。script/console
把你的rails 程序带到irb 的会话中,让你有机会测试方法。下面是当我们使用控制台来更新
一个产品的单价时的会话。
depot> ruby script/console
Loading development environment.
irb(main):001:0> pr = Product.find(:first)
=> #<Product:0x248acd0 @attributes={"image_url"=>"/images/sk..."
irb(main):002:0> pr.price
=> 29.95
irb(main):003:0> pr.price = 34.95
=> 34.95
irb(main):004:0> pr.save
=> true
日志和跟踪是动态理解复杂的应用程序的最好方式。你会发现development 的日志文件
中有很多信息。当不希望的事情发生时,它或许是你想看第一个地方。它也写入web 服务日
志。如果你在开发环境中使用了WEBric 的话,这将在使用script/server 命令的窗口滚动。
你也可以添加你自已的信息到前面描述的Logger 对象中。有时候日志文件很忙,它很难
找到你添加信息。在这些情况下,如果你使用WEBrick,的话将你出现WEBrick 控制台上信
息写入到STDERR 中。
如果一个页面显示警告信息,你可能想转储对象。Debug() helper 方法可用于这种情况。
它格式化对象并确保其内容是有效的HTML。
<h3>Your Order</h3>
<%= debug(@order) %>
<div id="ordersummary">
. . .
</div>
最后,所有问题都似乎得不到修正,你可以在你运行应用程序时,使用调试器。通常这
只能在开发环境下有效。
要使用断点:
1、在你想停下之处插入方法breakpoint( )。你可以像这个方法传递一个字符串—想区
别的信息。
2、在控制台上,导航你应用程序的基本目录和命令入口。
depot> ruby script/breakpointer
No connection to breakpoint service at
druby://localhost:42531 (DRb::DRbConnError)
Tries to connect will be made every 2 seconds...
不要为没有连接消息烦恼—它只意味着你的断言并没有被击中。
分享到:
评论

相关推荐

    DSV Editor 3.00

    DSV PHP Editor is a program for creating, editing and debugging PHP scripts, HTML, CSS, Java Script and SQL pages. Editor is designed specifically for PHP development; it is comfortable both for ...

    微软Visual Studio 2017社区版安装文件

    •Python projects support type hints in IntelliSense, and a Run MyPy command has been added to look for typing errors in your code. •Conda environments are supported in Python projects. •We added a ...

    Java2核心技术卷I+卷2:基础知识(第8版) 代码

    Chapter 11: Exceptions, Logging, Assertions, and Debugging 551 Dealing with Errors 552 Catching Exceptions 559 Tips for Using Exceptions 568 Using Assertions 571 Logging 575 Debugging Tips 591 ...

    Bloodshed Dev-C++

    * Added the possibility to modify the value of a variable during debugging (right click on a watch variable and select "Modify value") * During Dev-C++ First Time COnfiguration window, users can now ...

    java.核心技术.第八版 卷1

    Chapter 11: Exceptions, Logging, Assertions, and Debugging 551 Dealing with Errors 552 Catching Exceptions 559 Tips for Using Exceptions 568 Using Assertions 571 Logging 575 Debugging Tips 591 ...

    Delphi编译指令说明

    - **Show Hints**:显示提示信息,帮助改进代码质量。 - **Show Warnings**:显示警告,提醒潜在的问题。 此外,还可以使用编译指令直接影响编译过程。例如,`{$B+}` 开启完全布尔量检查,而 `{$Q-}` 关闭溢出...

    CUDA11.0-C-Programming-Guide.pdf

    - A breakpoint function has been added, allowing developers to set breakpoints for debugging purposes. This function helps in identifying and resolving issues during program execution. 18. **Trap ...

    Delphi 编译指令说明

    - **Show Hints**: 显示提示信息。 - **Show Warnings**: 显示警告信息。 #### 三、编译指令的使用 除了通过 IDE 的图形界面进行配置外,Delphi 还支持通过源代码中的编译指令来控制编译选项。这些编译指令可以...

    HPL: Vol. IV: Functional and Logic Programming Languages

    4.6. Hints for Using Guile 4.7. Related Work 4.8. Obtaining Guile and Other Packages Part IV—CLOS Chapter 5—A History and Description of CLOS 5.1. A Quick History of CLOS 5.2. An ...

    完全剖析Microsoft SQL Server 7.0

    鎖定提示(Hints)與追蹤旗標(Trace Flags) . 總結 第四部分 效能與調整篇 14. 查詢效能最佳化 [加入我的離線書架] . 開發小組 . 應用程式與資料庫設計 . 規劃尖峰使用量 . 了解互動系統的回應時間 . ...

    Itanium Architecture For Programmers

    Preface Acknowledgments Trademarks Chapter 1. Architecture and Implementation Section 1.1.... Answers and Hints for Selected Exercises Chapter 1 Chapter 2 Chapter 3 Chapter 4 ...

    delphi编译指令

    - **Show Hints**: 显示提示信息,这些信息通常是关于代码风格或潜在问题的建议。 - **Show Warnings**: 显示警告信息,警告通常表示可能存在潜在的问题,但不会阻止编译成功。 #### A.2 使用编译指令 除了通过...

    最完整的Toad For Oracle使用手册

    ### Toad for Oracle 使用手册关键知识点总结 #### 一、简介与新特性 - **Toad for Oracle**:是一款强大的数据库开发与管理工具,适用于Oracle数据库环境。 - **新版本特性**:概述了Toad for Oracle最新版本的...

    微软内部资料-SQL性能优化2

    Contents Module Overview 1 Lesson 1: Memory 3 Lesson 2: I/O 73 Lesson 3: CPU 111 Module 3: Troubleshooting Server Performance ...Troubleshooting server performance-based support calls requires ...

    python3.6.5参考手册 chm

    PEP 484 - Type Hints PEP 471 - os.scandir() function – a better and faster directory iterator PEP 475: Retry system calls failing with EINTR PEP 479: Change StopIteration handling inside ...

Global site tag (gtag.js) - Google Analytics