Don’t count tasks that are not defined as list items correctly

This commit is contained in:
Jarka Kadlecova 2017-01-25 08:24:14 +01:00
parent 94715834ce
commit 816fad3530
3 changed files with 27 additions and 4 deletions

View File

@ -11,10 +11,10 @@ module Taskable
INCOMPLETE = 'incomplete'.freeze
ITEM_PATTERN = /
^
\s*(?:[-+*]|(?:\d+\.))? # optional list prefix
\s* # optional whitespace prefix
(\[\s\]|\[[xX]\]) # checkbox
(\s.+) # followed by whitespace and some text.
\s*(?:[-+*]|(?:\d+\.)) # list prefix required - task item has to be always in a list
\s+ # whitespace prefix has to be always presented for a list item
(\[\s\]|\[[xX]\]) # checkbox
(\s.+) # followed by whitespace and some text.
/x
def self.get_tasks(content)

View File

@ -0,0 +1,4 @@
---
title: Dont count tasks that are not defined as list items correctly
merge_request: 8526
author:

View File

@ -72,6 +72,25 @@ shared_examples 'a Taskable' do
end
end
describe 'with tasks that are not formatted correctly' do
before do
subject.description = <<-EOT.strip_heredoc
[ ] task 1
[ ] task 2
- [ ]task 1
-[ ] task 2
EOT
end
it 'returns the correct task status' do
expect(subject.task_status).to match('0 of')
expect(subject.task_status).to match('0 tasks completed')
expect(subject.task_status_short).to match('0/')
expect(subject.task_status_short).to match('0 task')
end
end
describe 'with a complete task' do
before do
subject.description = <<-EOT.strip_heredoc