To begin with, I had a page "showing working rails" with the name of the project and the records related to the project. When the project name was displayed using the angular $ scope and records using the block in ERB, my tests passed. When I replaced the ERB code with the angular "ng-repeat" directive, only my test scripts started to fail. Interestingly, the application was still running in the browser. And remember, another $ scope variable in my view was and remains passing using an almost identical test.
Working show.html.erb (Entries viewed in 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>
Breaking show.html.erb (Entries presented in 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"}]}
]
, , ERB ng-repeat:
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
- ?