Skip to content

Instantly share code, notes, and snippets.

@jferris
Created August 23, 2012 14:14
Show Gist options
  • Select an option

  • Save jferris/3437037 to your computer and use it in GitHub Desktop.

Select an option

Save jferris/3437037 to your computer and use it in GitHub Desktop.
Testing views without helpers or decorators
<li class='<%= 'complete' if todo.complete? %>' id='<%= dom_id todo %>'>
<%= todo.description %>
<% if todo.completed_at? -%>
<%= link_to 'Incomplete', todo_completion_path(todo), method: :delete %>
<% else -%>
<%= link_to 'Complete', todo_completion_path(todo), method: :post %>
<% end -%>
</li>
<ul id='my-todos'>
<%= render @todos %>
</ul>
describe 'todos/_todo.html.erb' do
it 'generates a link to complete the todo when incomplete' do
todo = build_stubbed(:todo)
page = render_todo(todo)
page.should have_css(
"a[data-method='post'][href='#{todo_completion_path(todo)}']",
text: 'Complete'
)
end
it 'generates a link to mark the todo as incomplete when complete' do
todo = build_stubbed(:todo, :completed)
page = render_todo(todo)
page.should have_css(
"a[data-method='delete'][href='#{todo_completion_path(todo)}']",
text: 'Incomplete'
)
end
def render_todo(todo)
render partial: 'todos/todo', locals: { todo: todo }
Capybara.string(rendered)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment