twtest 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +1 -0
- data/.travis.yml +6 -0
- data/README.md +4 -2
- data/lib/twtest/testcase.rb +17 -9
- data/lib/twtest/version.rb +1 -1
- data/test/unit/test_commandline.rb +23 -0
- data/test/unit/test_example.rb +13 -0
- metadata +5 -1
data/.gitignore
CHANGED
data/.travis.yml
CHANGED
@@ -3,6 +3,12 @@ language: ruby
|
|
3
3
|
rvm:
|
4
4
|
- 1.9.3
|
5
5
|
|
6
|
+
before_script:
|
7
|
+
- mkdir ~/.task
|
8
|
+
- echo data.location=~/.task > ~/.taskrc
|
9
|
+
- task count
|
10
|
+
|
6
11
|
before_install:
|
12
|
+
- echo | sudo add-apt-repository ppa:ultrafredde/ppa
|
7
13
|
- sudo apt-get update
|
8
14
|
- sudo apt-get install task
|
data/README.md
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
# twtest
|
2
2
|
|
3
|
-
Helpers for writing TaskWarrior tests in Ruby
|
3
|
+
Helpers for writing [TaskWarrior](http://taskwarrior.org/) tests in Ruby. It isolates tests by running TaskWarrior tests in their own data directory, independent from any default data directory you may have on your workstation.
|
4
|
+
|
5
|
+
[![Build Status](https://secure.travis-ci.org/nerab/twtest.png?branch=master)](http://travis-ci.org/nerab/twtest)
|
4
6
|
|
5
7
|
## Installation
|
6
8
|
|
@@ -18,7 +20,7 @@ Or install it yourself as:
|
|
18
20
|
|
19
21
|
## Usage
|
20
22
|
|
21
|
-
|
23
|
+
Have a look at the [example](/nerab/twtest/blob/master/test/unit/test_example.rb).
|
22
24
|
|
23
25
|
## Contributing
|
24
26
|
|
data/lib/twtest/testcase.rb
CHANGED
@@ -3,13 +3,14 @@ require 'test/unit'
|
|
3
3
|
require 'tmpdir'
|
4
4
|
require 'erb'
|
5
5
|
require 'json'
|
6
|
+
require 'shellwords'
|
6
7
|
|
7
8
|
module TaskWarrior
|
8
9
|
module Test
|
9
10
|
module Integration
|
10
11
|
class TestCase < ::Test::Unit::TestCase
|
11
12
|
def setup
|
12
|
-
assert(
|
13
|
+
assert(task('_version') =~ /2\.\d\.\d/, "The TaskWarrior binary '#{TASK}' must be available and at least v2.0.")
|
13
14
|
@data_dir = Dir.mktmpdir
|
14
15
|
@taskrc_file = build_taskrc(:data_dir => @data_dir)
|
15
16
|
end
|
@@ -20,17 +21,24 @@ module TaskWarrior
|
|
20
21
|
end
|
21
22
|
|
22
23
|
protected
|
23
|
-
def
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
def export_tasks
|
28
|
-
JSON[task('export')]
|
24
|
+
def export_tasks(args = {})
|
25
|
+
json = task('export', args)
|
26
|
+
raise "Empty JSON returned by task command" if json.nil? || json.empty?
|
27
|
+
JSON[json]
|
29
28
|
end
|
30
29
|
|
31
|
-
def task(cmd)
|
30
|
+
def task(cmd, args = {})
|
32
31
|
ENV['TASKRC'] = @taskrc_file
|
33
|
-
%x[#{
|
32
|
+
%x[#{build_line(cmd, args)}]
|
33
|
+
end
|
34
|
+
|
35
|
+
def build_line(cmd, args = {})
|
36
|
+
[].tap{|line|
|
37
|
+
line << TASK
|
38
|
+
line << args.map{|k,v| "#{Shellwords.escape(k.strip)}=#{Shellwords.escape(v.strip)}"}.join(' ')
|
39
|
+
line << cmd.strip
|
40
|
+
line.reject!{|part| part.empty?}
|
41
|
+
}.join(' ')
|
34
42
|
end
|
35
43
|
|
36
44
|
def build_taskrc(options = {})
|
data/lib/twtest/version.rb
CHANGED
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class TestCommandLine < TaskWarrior::Test::Integration::TestCase
|
4
|
+
def test_plain
|
5
|
+
assert_equal('task foo', build_line('foo'))
|
6
|
+
end
|
7
|
+
|
8
|
+
def test_args
|
9
|
+
assert_equal('task foo=bar something', build_line('something', 'foo' => 'bar'))
|
10
|
+
end
|
11
|
+
|
12
|
+
def test_args_empty
|
13
|
+
assert_equal('task something', build_line('something', {}))
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_args_with_blanks
|
17
|
+
assert_equal('task foo=bar something', build_line('something', ' foo ' => ' bar '))
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_command_with_blanks
|
21
|
+
assert_equal('task something', build_line(' something '))
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'twtest'
|
2
|
+
|
3
|
+
class ExampleTest < TaskWarrior::Test::Integration::TestCase
|
4
|
+
GTD = "get things done"
|
5
|
+
|
6
|
+
def test_empty
|
7
|
+
task("add #{GTD}")
|
8
|
+
tasks = export_tasks
|
9
|
+
assert_equal(1, tasks.size)
|
10
|
+
assert_equal(GTD, tasks.first['description'])
|
11
|
+
assert_equal('pending', tasks.first['status'])
|
12
|
+
end
|
13
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: twtest
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -78,6 +78,8 @@ files:
|
|
78
78
|
- lib/twtest/version.rb
|
79
79
|
- templates/taskrc.erb
|
80
80
|
- test/test_helper.rb
|
81
|
+
- test/unit/test_commandline.rb
|
82
|
+
- test/unit/test_example.rb
|
81
83
|
- test/unit/test_testcase.rb
|
82
84
|
- twtest.gemspec
|
83
85
|
homepage:
|
@@ -106,4 +108,6 @@ specification_version: 3
|
|
106
108
|
summary: Helpers for writing TaskWarrior tests in Ruby
|
107
109
|
test_files:
|
108
110
|
- test/test_helper.rb
|
111
|
+
- test/unit/test_commandline.rb
|
112
|
+
- test/unit/test_example.rb
|
109
113
|
- test/unit/test_testcase.rb
|