首先,我有一个工作的 rails 'show' 页面,显示项目名称和属于该项目的条目。当使用 angular $scope 显示项目名称并使用 ERB 中的块显示条目时,我的测试通过了。当我用角度指令“ng-repeat”替换条目 ERB 代码时,只有我的条目测试场景开始失败。有趣的是,该应用程序仍在浏览器中运行。请记住,在我看来,另一个 $scope 变量曾经并且仍然使用几乎相同的测试通过。
工作 show.html.erb(在 ERB 中查看的条目):
<div ng-controller="ProjectCtrl">
<h1>This is {{ project.details.name }}</h1>
<h2>Entries</h2>
<% @entries.each do |e| %>
<ul>
<li>
<%= e.title %>
</li>
<li>
<%= e.summary %>
</li>
</ul>
<% end %>
</div>
破坏 show.html.erb(在 Angular 中查看的条目):
<div ng-controller="ProjectCtrl">
<h1>This is {{ project.details.name }}</h1>
<h2>Entries</h2>
<ul ng-repeat=" e in project.entries ">
<li>
{{ e.title }}
</li>
<li>
{{ e.summary }}
</li>
</ul>
</div>
Angular 控制器,数据已替换为返回的 JSON。
@ProjectCtrl = ["$scope", "$http", ($scope, $http) ->
$http.get().success (data) ->
$scope.project = {"details":{"name":"Project1","author":"brian"},"updated_at":"2013-04-13T16:48:46.406Z","entries":[{"title":"Test Title","summary":"Summary Test"},{"title":"The Third Entry","summary":"Summary of Third Entry"}]}
]
这是一个示例测试,之前有效,但在用 ng-repeat 替换 ERB 后失败:
scenario "Displays Entries Summary" do
project = Project.create!(details: {name: "aproject"})
Entry.create!(data: {summary: "Should Be Displayed"}, project_id: project.id)
Entry.create!(data: {summary: "Should Not Be Displayed"})
visit project_path(project.id)
page.must_have_content "Should Be Displayed"
page.wont_have_content "Should Not Be Displayed"
end
我是否遗漏了什么,或者我是否必须改变我进行功能测试的方式?