est 0.2.1 → 0.3
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.
- data/.rultor.yml +2 -0
- data/assets/est.xsd +1 -1
- data/features/empty_dir.feature +21 -0
- data/lib/est.rb +8 -6
- data/lib/est/estimates.rb +21 -12
- data/lib/est/version.rb +1 -1
- data/test/test_est.rb +30 -0
- metadata +3 -1
data/.rultor.yml
CHANGED
@@ -12,6 +12,8 @@ release:
|
|
12
12
|
rake
|
13
13
|
rm -rf *.gem
|
14
14
|
sed -i "s/1\.0\.snapshot/${tag}/g" lib/est/version.rb
|
15
|
+
git add lib/est/version.rb
|
16
|
+
git commit -m "version set to ${tag}"
|
15
17
|
gem build est.gemspec
|
16
18
|
chmod 0600 ../rubygems.yml
|
17
19
|
gem push *.gem --config-file ../rubygems.yml
|
data/assets/est.xsd
CHANGED
@@ -0,0 +1,21 @@
|
|
1
|
+
Feature: Command Line Processing
|
2
|
+
As an estimator I want to be able to
|
3
|
+
call Est as a command line tool
|
4
|
+
|
5
|
+
Scenario: Estimates empty directory
|
6
|
+
Given I have a "test.txt" file with content:
|
7
|
+
"""
|
8
|
+
hello
|
9
|
+
"""
|
10
|
+
When I run bin/est with "--dir=. --format=text"
|
11
|
+
Then Exit code is zero
|
12
|
+
And Stdout contains "Total: 0"
|
13
|
+
|
14
|
+
Scenario: Estimates absent directory
|
15
|
+
Given I have a "test.txt" file with content:
|
16
|
+
"""
|
17
|
+
hello
|
18
|
+
"""
|
19
|
+
When I run bin/est with "--dir=./absent-dir --format=text"
|
20
|
+
Then Exit code is zero
|
21
|
+
And Stdout contains "Total: 0"
|
data/lib/est.rb
CHANGED
@@ -76,12 +76,14 @@ module Est
|
|
76
76
|
xml << "<?xml-stylesheet type='text/xsl' href='#{xsl}'?>"
|
77
77
|
xml.estimate(attrs) do
|
78
78
|
xml.total estimates.total
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
xml.
|
83
|
-
|
84
|
-
|
79
|
+
unless estimates.iterate.empty?
|
80
|
+
xml.ests do
|
81
|
+
estimates.iterate.each do |est|
|
82
|
+
xml.est do
|
83
|
+
xml.date est.date
|
84
|
+
xml.total est.total
|
85
|
+
xml.author est.author
|
86
|
+
end
|
85
87
|
end
|
86
88
|
end
|
87
89
|
end
|
data/lib/est/estimates.rb
CHANGED
@@ -42,24 +42,33 @@ module Est
|
|
42
42
|
# Get total estimate.
|
43
43
|
def total
|
44
44
|
estimates = iterate
|
45
|
-
estimates.
|
46
|
-
|
47
|
-
|
48
|
-
|
45
|
+
if estimates.empty?
|
46
|
+
total = 0
|
47
|
+
else
|
48
|
+
total = estimates.reduce(0) do |a, e|
|
49
|
+
Est.log.info "#{e.date}/#{e.author}: #{e.total}"
|
50
|
+
a + e.total
|
51
|
+
end / estimates.size
|
52
|
+
end
|
53
|
+
total
|
49
54
|
end
|
50
55
|
|
51
56
|
# Iterate them all
|
52
57
|
def iterate
|
53
58
|
unless @iterate
|
54
|
-
@
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
59
|
+
if File.exist?(@dir) && File.directory?(@dir)
|
60
|
+
@iterate = Dir.entries(@dir)
|
61
|
+
.reject { |f| f.index('.') == 0 }
|
62
|
+
.select { |f| f =~ /^.*\.est$/ }
|
63
|
+
.map { |f| File.join(@dir, f) }
|
64
|
+
.each { |f| Est.log.info "#{f} found" }
|
65
|
+
.map { |f| Estimate.new(f) }
|
66
|
+
.map { |f| Estimate::Const.new(f) }
|
67
|
+
else
|
68
|
+
Est.log.info "#{@dir} is absent or is not a directory"
|
69
|
+
@iterate = []
|
70
|
+
end
|
61
71
|
end
|
62
|
-
fail "no .est files found in #{@dir}" if @iterate.empty?
|
63
72
|
@iterate
|
64
73
|
end
|
65
74
|
|
data/lib/est/version.rb
CHANGED
data/test/test_est.rb
CHANGED
@@ -75,6 +75,36 @@ class TestEst < Minitest::Test
|
|
75
75
|
end
|
76
76
|
end
|
77
77
|
|
78
|
+
def test_empty_dir
|
79
|
+
Dir.mktmpdir 'test' do |dir|
|
80
|
+
opts = opts(['-v', '-d', dir])
|
81
|
+
matches(
|
82
|
+
Nokogiri::XML(Est::Base.new(opts).xml),
|
83
|
+
[
|
84
|
+
'/estimate/@version',
|
85
|
+
'/estimate/@date',
|
86
|
+
'/estimate[total="0"]',
|
87
|
+
'/estimate[not(ests)]'
|
88
|
+
]
|
89
|
+
)
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
def test_empty_dir
|
94
|
+
Dir.mktmpdir 'test' do |dir|
|
95
|
+
opts = opts(['-v', '-d', File.join(dir, 'absent')])
|
96
|
+
matches(
|
97
|
+
Nokogiri::XML(Est::Base.new(opts).xml),
|
98
|
+
[
|
99
|
+
'/estimate/@version',
|
100
|
+
'/estimate/@date',
|
101
|
+
'/estimate[total="0"]',
|
102
|
+
'/estimate[not(ests)]'
|
103
|
+
]
|
104
|
+
)
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
78
108
|
def opts(args)
|
79
109
|
Slop.parse args do
|
80
110
|
on 'v', 'verbose'
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: est
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: '0.3'
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -214,6 +214,7 @@ files:
|
|
214
214
|
- est.gemspec
|
215
215
|
- est/first.est
|
216
216
|
- features/cli.feature
|
217
|
+
- features/empty_dir.feature
|
217
218
|
- features/gem_package.feature
|
218
219
|
- features/step_definitions/steps.rb
|
219
220
|
- features/support/env.rb
|
@@ -255,6 +256,7 @@ specification_version: 2
|
|
255
256
|
summary: Estimates Automated
|
256
257
|
test_files:
|
257
258
|
- features/cli.feature
|
259
|
+
- features/empty_dir.feature
|
258
260
|
- features/gem_package.feature
|
259
261
|
- features/step_definitions/steps.rb
|
260
262
|
- features/support/env.rb
|