est 0.2.1 → 0.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -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
@@ -33,7 +33,7 @@
33
33
  <xs:complexType>
34
34
  <xs:all>
35
35
  <xs:element name="total" type="xs:int"/>
36
- <xs:element name="ests">
36
+ <xs:element name="ests" minOccurs="0">
37
37
  <xs:complexType>
38
38
  <xs:sequence>
39
39
  <xs:element name="est" type="est" minOccurs="1" maxOccurs="unbounded" />
@@ -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
- xml.ests do
80
- estimates.iterate.each do |est|
81
- xml.est do
82
- xml.date est.date
83
- xml.total est.total
84
- xml.author est.author
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
@@ -42,24 +42,33 @@ module Est
42
42
  # Get total estimate.
43
43
  def total
44
44
  estimates = iterate
45
- estimates.reduce(0) do |a, e|
46
- Est.log.info "#{e.date}/#{e.author}: #{e.total}"
47
- a + e.total
48
- end / estimates.size
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
- @iterate = Dir.entries(@dir)
55
- .reject { |f| f.index('.') == 0 }
56
- .select { |f| f =~ /^.*\.est$/ }
57
- .map { |f| File.join(@dir, f) }
58
- .each { |f| Est.log.info "#{f} found" }
59
- .map { |f| Estimate.new(f) }
60
- .map { |f| Estimate::Const.new(f) }
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
 
@@ -26,5 +26,5 @@
26
26
  # Copyright:: Copyright (c) 2014 Yegor Bugayenko
27
27
  # License:: MIT
28
28
  module Est
29
- VERSION = '0.2.1'
29
+ VERSION = '0.3'
30
30
  end
@@ -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.2.1
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