我可以使用一些帮助来弄清楚发生了什么。检查下面的日志输出——为什么 rails 会以不同的方式处理这两个渲染?为什么一个成功,没有任何相关的 SQL 调用,而第二个失败 - 使用 SQL 访问。(它不是 ActiveRecord 模型,此渲染中不应涉及 SQL。)
背景
我有一个黄瓜功能,有两个场景,每个场景都依赖 Webrat 来解决步骤“当我转到文章列表时”。文章模型不是 ActiveRecord 模型,不应该依赖 SQL 进行访问。
如果我在文件中订购场景#1、#2,则第一个场景通过所有测试,而第二个场景如预期的那样在稍后的不同步骤中失败。
如果我在文件中订购场景#2、#1,则在通过相关步骤后,#2 场景会按预期失败。但是#1场景现在使“当我转到文章列表时”步骤失败:
找不到资源 (ActionView::TemplateError) features/article.feature:23:in `当我转到文章列表时'
test.log 内容
-------- webrat 测试成功 - 非 db 支持的模型 --------------
Processing ArticlesController#index (for 127.0.0.1 at 2009-08-12 13:22:37) [GET]
Parameters: {"action"=>"index", "controller"=>"articles"}
Rendering template within layouts/application
Rendering articles/index
Completed in 9ms (View: 6, DB: 0) | 200 OK [http://www.example.com/ccc/articles]
REQUESTING PAGE: GET /ccc/articles/new with {} and HTTP headers {"HTTP_REFERER"=>"/ccc/articles"}
-------- webrat 测试失败 ---------
Processing ArticlesController#index (for 127.0.0.1 at 2009-08-12 13:22:37) [GET]
Parameters: {"action"=>"index", "controller"=>"articles"}
Rendering template within layouts/application
Rendering articles/index
Processing ApplicationController#index (for 127.0.0.1 at 2009-08-12 13:22:37) [GET]
Parameters: {"action"=>"index", "controller"=>"articles"}
^[[4;35;1mSQL (0.1ms)^[[0m ^[[0mROLLBACK^[[0m