todotxt 0.1.0 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,3 +1,3 @@
1
1
  module Todotxt
2
- VERSION = "0.1.0"
2
+ VERSION = '0.2.0'.freeze
3
3
  end
data/spec/config_spec.rb CHANGED
@@ -1,52 +1,72 @@
1
- require "spec_helper"
2
- require "todotxt/config"
1
+ require 'spec_helper'
2
+ require 'todotxt/config'
3
3
 
4
4
  describe Todotxt::Config do
5
5
  before(:each) do
6
- ENV["HOME"] = File.join "/", "tmp"
7
- @config_file = File.join ENV["HOME"], ".todotxt.cfg"
6
+ ENV['HOME'] = File.join '/', 'tmp'
7
+ @config_file = File.join ENV['HOME'], '.todotxt.cfg'
8
8
  end
9
9
 
10
- context "valid config" do
10
+ context 'valid config' do
11
11
  before(:each) do
12
- @cfg = Todotxt::Config.new "spec/fixtures/config_new.cfg"
12
+ @cfg = Todotxt::Config.new(config_file: 'spec/fixtures/config_new.cfg')
13
13
  end
14
14
 
15
15
  it 'should have a "files"' do
16
- @cfg.files.keys.should include "todo"
16
+ expect(@cfg.files.keys).to include('todo')
17
17
  end
18
18
 
19
19
  it 'should not be deprecated' do
20
- @cfg.should_not be_deprecated
20
+ expect(@cfg).not_to be_deprecated
21
+ end
22
+
23
+ describe '#files' do
24
+ it 'should return a list of TodoFile objects as configured in config' do
25
+ expect(@cfg.files).to be_kind_of(Hash)
26
+ expect(@cfg.files).to match('todo' => Todotxt::TodoFile.new('/tmp/todo.txt'))
27
+ end
28
+ end
29
+ describe '#file' do
30
+ it "should return the 'todo' file from the 'files' hash" do
31
+ expect(@cfg.file).to match(@cfg.files['todo'])
32
+ end
33
+ end
34
+ end
35
+
36
+ context 'invalid config' do
37
+ it 'not allow both "files" and "todo_txt_path"' do
38
+ expect do
39
+ Todotxt::Config.new(config_file: 'spec/fixtures/config_both.cfg')
40
+ end.to raise_error 'Bad configuration file: use either files or todo_txt_path'
41
+ end
42
+
43
+ it 'should complain when there is no "todo" in files and no file is requested' do
44
+ expect do
45
+ Todotxt::Config.new(config_file: 'spec/fixtures/config_no_todo.cfg').file
46
+ end.to raise_error "Bad configuration file: 'todo' is a required file."
21
47
  end
22
48
  end
23
49
 
24
- context "old style config" do
50
+ context 'old style config' do
25
51
  before(:each) do
26
- @cfg = Todotxt::Config.new "spec/fixtures/config_old.cfg"
52
+ @cfg = Todotxt::Config.new(config_file: 'spec/fixtures/config_old.cfg')
27
53
  end
28
54
 
29
55
  it 'should place "todo_txt_path" under files' do
30
- @cfg.files.keys.should include "todo"
56
+ expect(@cfg.files.keys).to include('todo')
31
57
  end
32
58
 
33
59
  it 'should be deprecated' do
34
- @cfg.should be_deprecated
60
+ expect(@cfg).to be_deprecated
35
61
  end
36
62
  end
37
63
 
38
- it 'not allow both "files" and "todo_txt_path"' do
39
- expect do
40
- Todotxt::Config.new "spec/fixtures/config_both.cfg"
41
- end.to raise_error "Bad configuration file: use either files or todo_txt_path"
42
- end
43
-
44
- context "#generate!" do
64
+ context '#generate!' do
45
65
  it 'should create a template' do
46
- File.delete @config_file if File.exists? @config_file
66
+ File.delete @config_file if File.exist? @config_file
47
67
  todo = Todotxt::Config.new
48
68
  todo.generate!
49
- File.exists?(@config_file).should be_true
69
+ expect(File.exist?(@config_file)).to be_truthy
50
70
  end
51
71
  end
52
72
  end
@@ -0,0 +1,2 @@
1
+ [files]
2
+ done = "/tmp/done.txt"
data/spec/todo_spec.rb CHANGED
@@ -1,141 +1,128 @@
1
- require "spec_helper"
2
- require "todotxt/todo"
1
+ require 'spec_helper'
2
+ require 'todotxt/todo'
3
3
 
4
4
  describe Todotxt::Todo do
5
-
6
- it "creates a todo item string" do
7
- todo = Todotxt::Todo.new "an item"
8
- todo.to_s.should eql("an item")
5
+ it 'creates a todo item string' do
6
+ todo = Todotxt::Todo.new 'an item'
7
+ expect(todo.to_s).to match('an item')
9
8
  end
10
9
 
11
- it "parses metadata when creating a simple item" do
12
- todo = Todotxt::Todo.new "x an item +project1 +project2 @context1 @context2"
13
-
14
- todo.to_s.should eql "x an item +project1 +project2 @context1 @context2"
15
- todo.priority.should eql nil
16
- todo.projects.should eql ["+project1", "+project2"]
17
- todo.contexts.should eql ["@context1", "@context2"]
18
- todo.done.should eql true
10
+ it 'parses metadata when creating a simple item' do
11
+ todo = Todotxt::Todo.new 'x an item +project1 +project2 @context1 @context2'
12
+ expect(todo.to_s).to match('x an item +project1 +project2 @context1 @context2')
13
+ expect(todo.priority).to be_nil
14
+ expect(todo.projects).to contain_exactly('+project1', '+project2')
15
+ expect(todo.contexts).to contain_exactly('@context1', '@context2')
16
+ expect(todo.done).to be_truthy
19
17
  end
20
18
 
21
- it "parses metadata when creating an item with priority" do
22
- todo = Todotxt::Todo.new "(A) x an item +project1 +project2 @context1 @context2"
23
-
24
- todo.to_s.should eql "(A) x an item +project1 +project2 @context1 @context2"
25
- todo.priority.should eql "A"
26
- todo.projects.should eql ["+project1", "+project2"]
27
- todo.contexts.should eql ["@context1", "@context2"]
28
- todo.done.should eql true
19
+ it 'parses metadata when creating an item with priority' do
20
+ todo = Todotxt::Todo.new '(A) x an item +project1 +project2 @context1 @context2'
21
+ expect(todo.to_s).to match('(A) x an item +project1 +project2 @context1 @context2')
22
+ expect(todo.priority).to match('A')
23
+ expect(todo.projects).to contain_exactly('+project1', '+project2')
24
+ expect(todo.contexts).to contain_exactly('@context1', '@context2')
25
+ expect(todo.done).to be_truthy
29
26
  end
30
27
 
31
- it "parses a due date" do
32
- todo = Todotxt::Todo.new "(A) x 2012-12-12 an item +project1 +project2 @context1 @context2"
33
- todo.due.should eql Chronic.parse("12 December 2012").to_date
28
+ it 'parses a due date' do
29
+ todo = Todotxt::Todo.new '(A) x 2012-12-12 an item +project1 +project2 @context1 @context2'
30
+ expect(todo.due).to eql(Chronic.parse('12 December 2012').to_date)
34
31
 
35
- todo = Todotxt::Todo.new "2012-1-2 an item +project1 +project2 @context1 @context2"
36
- todo.due.should eql Chronic.parse("2 January 2012").to_date
32
+ todo = Todotxt::Todo.new '2012-1-2 an item +project1 +project2 @context1 @context2'
33
+ expect(todo.due).to eql(Chronic.parse('2 January 2012').to_date)
37
34
 
38
- todo = Todotxt::Todo.new "42 folders"
39
- todo.due.should be_nil
35
+ todo = Todotxt::Todo.new '42 folders'
36
+ expect(todo.due).to be_nil
40
37
  end
41
38
 
42
- it "stores line number when creating an item" do
43
- todo = Todotxt::Todo.new "an item", "2"
44
-
45
- todo.line.should eql "2"
39
+ it 'stores line number when creating an item' do
40
+ todo = Todotxt::Todo.new 'an item', '2'
41
+ expect(todo.line).to match('2')
46
42
  end
47
43
 
48
- it "sets an item as done" do
49
- todo = Todotxt::Todo.new "an item"
50
-
44
+ it 'sets an item as done' do
45
+ todo = Todotxt::Todo.new 'an item'
51
46
  todo.do
52
47
 
53
- todo.to_s.should eql "x an item"
54
- todo.done.should eql true
48
+ expect(todo.to_s).to match 'x an item'
49
+ expect(todo.done).to be_truthy
55
50
  end
56
51
 
57
- it "sets an item as not done" do
58
- todo = Todotxt::Todo.new "x an item"
52
+ it 'sets an item as not done' do
53
+ todo = Todotxt::Todo.new 'x an item'
59
54
 
60
55
  todo.undo
61
56
 
62
- todo.to_s.should eql "an item"
63
- todo.done.should eql false
57
+ expect(todo.to_s).to match('an item')
58
+ expect(todo.done).to be_falsy
64
59
  end
65
60
 
66
- it "adds priority to an item" do
67
- todo = Todotxt::Todo.new "an item"
68
-
69
- todo.prioritize "a"
61
+ it 'adds priority to an item' do
62
+ todo = Todotxt::Todo.new 'an item'
63
+ todo.prioritize 'a'
70
64
 
71
- todo.to_s.should eql "(A) an item"
72
- todo.priority.should eql "A"
65
+ expect(todo.to_s).to match('(A) an item')
66
+ expect(todo.priority).to match('A')
73
67
  end
74
68
 
75
- it "changes priority of an item" do
76
- todo = Todotxt::Todo.new "(A) an item"
77
-
78
- todo.prioritize "z"
69
+ it 'changes priority of an item' do
70
+ todo = Todotxt::Todo.new '(A) an item'
71
+ todo.prioritize 'z'
79
72
 
80
- todo.to_s.should eql "(Z) an item"
81
- todo.priority.should eql "Z"
73
+ expect(todo.to_s).to match('(Z) an item')
74
+ expect(todo.priority).to match('Z')
82
75
  end
83
76
 
84
- it "removes priority from an item" do
85
- todo = Todotxt::Todo.new "(A) an item"
86
-
77
+ it 'removes priority from an item' do
78
+ todo = Todotxt::Todo.new '(A) an item'
87
79
  todo.prioritize
88
80
 
89
- todo.to_s.should eql "an item"
90
- todo.priority.should eql nil
81
+ expect(todo.to_s).to match('an item')
82
+ expect(todo.priority).to be_nil
91
83
  end
92
84
 
93
- it "appends text to an item" do
94
- todo = Todotxt::Todo.new "an item"
95
-
96
- todo.append "more text"
85
+ it 'appends text to an item' do
86
+ todo = Todotxt::Todo.new 'an item'
87
+ todo.append 'more text'
97
88
 
98
- todo.to_s.should eql "an item more text"
89
+ expect(todo.to_s).to match('an item more text')
99
90
  end
100
91
 
101
- it "prepends text to an item" do
102
- todo = Todotxt::Todo.new "an item"
103
-
104
- todo.prepend "more text"
92
+ it 'prepends text to an item' do
93
+ todo = Todotxt::Todo.new 'an item'
94
+ todo.prepend 'more text'
105
95
 
106
- todo.to_s.should eql "more text an item"
96
+ expect(todo.to_s).to match('more text an item')
107
97
  end
108
98
 
109
- it "preserves priority when prepending text to an item" do
110
- todo = Todotxt::Todo.new "(A) an item"
99
+ it 'preserves priority when prepending text to an item' do
100
+ todo = Todotxt::Todo.new '(A) an item'
101
+ todo.prepend 'more text'
111
102
 
112
- todo.prepend "more text"
113
-
114
- todo.to_s.should eql "(A) more text an item"
115
- todo.priority.should eql "A"
103
+ expect(todo.to_s).to match('(A) more text an item')
104
+ expect(todo.priority).to match('A')
116
105
  end
117
106
 
118
- it "replaces an item with new text" do
119
- todo = Todotxt::Todo.new "an item"
120
-
121
- todo.replace "(A) a replacement item"
107
+ it 'replaces an item with new text' do
108
+ todo = Todotxt::Todo.new 'an item'
109
+ todo.replace '(A) a replacement item'
122
110
 
123
- todo.to_s.should eql "(A) a replacement item"
124
- todo.priority.should eql "A"
111
+ expect(todo.to_s).to match('(A) a replacement item')
112
+ expect(todo.priority).to match('A')
125
113
  end
126
114
 
127
- it "sorts based on line number" do
128
- todo1 = Todotxt::Todo.new "an item 1", 1
129
- todo2 = Todotxt::Todo.new "an item 2", 2
115
+ it 'sorts based on line number' do
116
+ todo1 = Todotxt::Todo.new 'an item 1', 1
117
+ todo2 = Todotxt::Todo.new 'an item 2', 2
130
118
 
131
- (todo1 <=> todo2).should eql -1
119
+ expect(todo1 <=> todo2).to eql -1
132
120
  end
133
121
 
134
- it "values items with priority higher when sorting" do
135
- todo1 = Todotxt::Todo.new "an item 1", 1
136
- todo2 = Todotxt::Todo.new "(A) an item 2", 2
122
+ it 'values items with priority higher when sorting' do
123
+ todo1 = Todotxt::Todo.new 'an item 1', 1
124
+ todo2 = Todotxt::Todo.new '(A) an item 2', 2
137
125
 
138
- (todo1 <=> todo2).should eql 1
126
+ expect(todo1 <=> todo2).to eql 1
139
127
  end
140
-
141
128
  end
@@ -1,31 +1,36 @@
1
- require "spec_helper"
2
- require "todotxt/config"
3
- require "todotxt/todofile"
1
+ require 'spec_helper'
2
+ require 'todotxt/config'
3
+ require 'todotxt/todofile'
4
4
 
5
5
  describe Todotxt::TodoFile do
6
6
  before(:each) do
7
- @todo_path = "/tmp/todo.txt"
8
- Todotxt::Config.any_instance.stub(:files) do
9
- {todo:@todo_path}
10
- end
7
+ @todo_path = '/tmp/todo.txt'
8
+ allow_any_instance_of(Todotxt::Config).to receive(:files).and_return(todo: @todo_path)
11
9
  end
12
10
  after(:each) do
13
- File.delete @todo_path if File.exists? @todo_path
11
+ File.delete @todo_path if File.exist? @todo_path
14
12
  end
15
13
 
16
14
  it 'should create a new file when initializing' do
17
15
  file = Todotxt::TodoFile.new(@todo_path)
18
- file.class.should == Todotxt::TodoFile
16
+ expect(file).to be_kind_of(Todotxt::TodoFile)
19
17
  end
20
18
 
21
19
  it 'should create a new file via the key in config' do
22
20
  file = Todotxt::TodoFile.from_key(:todo)
23
- file.class.should == Todotxt::TodoFile
21
+ expect(file).to be_kind_of(Todotxt::TodoFile)
24
22
  end
25
23
 
26
24
  it 'should throw an error for undefined keys' do
27
- expect {
25
+ expect do
28
26
  Todotxt::TodoFile.from_key(:does_not_exist)
29
- }.to raise_error "Key not found in config"
27
+ end.to raise_error 'Key not found in config'
28
+ end
29
+
30
+ describe '#==' do
31
+ it 'should compare using paths' do
32
+ expect(Todotxt::TodoFile.new(@todo_path)).to eq(Todotxt::TodoFile.new(@todo_path))
33
+ expect(Todotxt::TodoFile.new(@todo_path)).not_to eq(Todotxt::TodoFile.new('/other/path'))
34
+ end
30
35
  end
31
36
  end
@@ -1,117 +1,116 @@
1
- require "spec_helper"
2
- require "todotxt/todolist"
3
- require "todotxt/todofile"
1
+ require 'spec_helper'
2
+ require 'todotxt/todolist'
3
+ require 'todotxt/todofile'
4
4
 
5
5
  describe Todotxt::TodoList do
6
-
7
- describe "with simple list" do
6
+ describe 'with simple list' do
8
7
  before :each do
9
- @file = Todotxt::TodoFile.new File.join(File.dirname(__FILE__), "fixtures", "simple_todo.txt")
8
+ @file = Todotxt::TodoFile.new File.join(File.dirname(__FILE__), 'fixtures', 'simple_todo.txt')
10
9
  @list = Todotxt::TodoList.new @file
11
10
  end
12
11
 
13
- it "parses a file on creation" do
14
- @list.todos[0].to_s.should eql "First item"
15
- @list.todos[1].to_s.should eql "Second item"
16
- @list.todos[2].to_s.should eql "Third item"
17
- @list.todos[3].to_s.should eql "x First done item"
12
+ it 'parses a file on creation' do
13
+ expect(@list.todos[0].to_s).to match('First item')
14
+ expect(@list.todos[1].to_s).to match('Second item')
15
+ expect(@list.todos[2].to_s).to match('Third item')
16
+ expect(@list.todos[3].to_s).to match('x First done item')
18
17
 
19
- @list.todos[0].line.should eql 1
20
- @list.todos[1].line.should eql 2
21
- @list.todos[2].line.should eql 3
22
- @list.todos[3].line.should eql 4
18
+ expect(@list.todos[0].line).to eql 1
19
+ expect(@list.todos[1].line).to eql 2
20
+ expect(@list.todos[2].line).to eql 3
21
+ expect(@list.todos[3].line).to eql 4
23
22
  end
24
23
 
25
- it "adds a new item" do
26
- @list.add "Fourth item"
27
-
28
- @list.todos[4].to_s.should eql "Fourth item"
29
- @list.todos[4].line.should eql 5
24
+ it 'adds a new item' do
25
+ @list.add 'Fourth item'
26
+ expect(@list.todos[4].to_s).to match('Fourth item')
27
+ expect(@list.todos[4].line).to eql 5
30
28
  end
31
29
 
32
- it "removes an item" do
30
+ it 'removes an item' do
33
31
  @list.remove 1
34
-
35
- @list.todos[0].to_s.should eql "Second item"
32
+ expect(@list.todos[0].to_s).to match('Second item')
36
33
  end
37
34
 
38
- it "finds item by line" do
35
+ it 'finds item by line' do
39
36
  todo = @list.find_by_line 3
40
-
41
- todo.to_s.should eql "Third item"
37
+ expect(todo.to_s).to match('Third item')
42
38
  end
43
39
 
44
- it "filters list when searching" do
45
- @list.filter "First"
46
-
47
- @list.todos.count.should eql 1
40
+ it 'filters list when searching' do
41
+ @list.filter 'First'
42
+ expect(@list.todos.count).to eql 1
48
43
  end
49
44
 
50
- it "filters list when searching case-sensitive" do
51
- @list.filter "first"
52
-
53
- @list.todos.count.should eql 1
45
+ it 'filters list when searching case-sensitive' do
46
+ @list.filter 'first'
47
+ expect(@list.todos.count).to eql 1
54
48
  end
55
49
 
56
- it "fetches items for a certain date" do
57
- @list.add "2012-12-12 item"
58
- date = DateTime.parse("2012-12-12")
59
- @list.on_date(date).count.should eql 1
60
- @list.on_date(date).should eql [@list.todos.last]
50
+ it 'fetches items for a certain date' do
51
+ @list.add '2012-12-12 item'
52
+ date = DateTime.parse('2012-12-12')
53
+ expect(@list.on_date(date).count).to eql 1
54
+ expect(@list.on_date(date)).to match([@list.todos.last])
61
55
  end
62
56
 
63
- it "fetchs items before a cereain date" do
64
- @list.add "2012-11-11 item"
65
- @list.add "2012-12-12 item"
66
- date = DateTime.parse("2012-12-12")
67
- @list.before_date(date).count.should eql 1
57
+ it 'fetchs items before a cereain date' do
58
+ @list.add '2012-11-11 item'
59
+ @list.add '2012-12-12 item'
60
+ date = DateTime.parse('2012-12-12')
61
+ expect(@list.before_date(date).count).to eql 1
68
62
  end
69
63
 
70
- it "includes done items in search when told to do so" do
71
- @list.filter "first", :with_done => true
72
-
73
- @list.todos.count.should eql 2
64
+ it 'includes done items in search when told to do so' do
65
+ @list.filter 'first', with_done: true
66
+ expect(@list.todos.count).to eql 2
74
67
  end
75
68
 
76
- it "only includes done items in search when told to do so" do
77
- @list.filter "first", :only_done => true
78
-
79
- @list.todos.count.should eql 1
69
+ it 'only includes done items in search when told to do so' do
70
+ @list.filter 'first', only_done: true
71
+ expect(@list.todos.count).to eql 1
80
72
  end
81
73
 
82
- it "renders plain text" do
74
+ it 'renders plain text' do
83
75
  comparison_string = <<EOF
84
76
  First item
85
77
  Second item
86
78
  Third item
87
79
  x First done item
88
80
  EOF
89
- @list.to_txt.should eql comparison_string.strip
81
+ expect(@list.to_txt).to match(comparison_string.strip)
90
82
  end
91
83
  end
92
84
 
93
- describe "with complex list" do
85
+ describe 'with complex list' do
94
86
  before :each do
95
- @file = Todotxt::TodoFile.new File.join(File.dirname(__FILE__), "fixtures", "complex_todo.txt")
87
+ @file = Todotxt::TodoFile.new File.join(File.dirname(__FILE__), 'fixtures', 'complex_todo.txt')
96
88
  @list = Todotxt::TodoList.new @file
97
89
  end
98
90
 
99
- it "sorts itself automatically on parse" do
100
- @list.todos[0].to_s.should eql "(A) an item"
101
- @list.todos[0].line.should eql 3
91
+ it 'sorts itself automatically on parse' do
92
+ expect(@list.todos[0].to_s).to match('(A) an item')
93
+ expect(@list.todos[0].line).to eql(3)
102
94
  end
103
95
 
104
- it "re-sorts itself after adding a new item" do
105
- @list.add "(B) A new item"
96
+ it 're-sorts itself after adding a new item' do
97
+ @list.add '(B) A new item'
106
98
 
107
- @list.todos[1].to_s.should eql "(B) A new item"
108
- @list.todos[1].line.should eql 4
99
+ expect(@list.todos[1].to_s).to match('(B) A new item')
100
+ expect(@list.todos[1].line).to eql(4)
109
101
  end
110
102
 
111
- it "lists all projects and contexts in the list" do
112
- @list.projects.should eql ["+project1", "+project2"]
113
- @list.contexts.should eql ["@context1", "@context2"]
103
+ it 'lists all projects and contexts in the list' do
104
+ expect(@list.projects).to contain_exactly('+project1', '+project2')
105
+ expect(@list.contexts).to contain_exactly('@context1', '@context2')
114
106
  end
115
107
  end
116
108
 
109
+ describe 'with line-number provided' do
110
+ it 'starts counting at the number' do
111
+ @file = Todotxt::TodoFile.new File.join(File.dirname(__FILE__), 'fixtures', 'simple_todo.txt')
112
+ @list = Todotxt::TodoList.new @file, 42
113
+ expect(@list.todos[0].line).to eql 43
114
+ end
115
+ end
117
116
  end