drg 0.14.3 → 0.15.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/drg/ruby/condition.rb +8 -2
- data/lib/drg/spec.rb +7 -3
- data/lib/drg/tasks/log.rb +2 -2
- data/lib/drg/tasks/spec_runner.rb +13 -4
- data/lib/drg/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 237cf5d636b5f61623d98f0de080baf9eee6ec1a
|
4
|
+
data.tar.gz: ef2cff5a52e8a897e2bcc12579c5eb5fcd7217c8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f737cf78ee76ee24f33e365c2d21948253785d34708aeca2bdfb0e66658dab5d4939c9a55e4cf0a1455562c65a56acd013814b4b525f934921350e5fca7f6f67
|
7
|
+
data.tar.gz: 7c1fcda522637511851f0d6a582171bfa30e78b0f57485a1ecebc492ec4b36145f19519dfb2724dfb2a883a548b9c432fad86ef3c00367d9a0af7f2016928459
|
data/lib/drg/ruby/condition.rb
CHANGED
@@ -19,14 +19,20 @@ class DRG::Ruby::Condition
|
|
19
19
|
end
|
20
20
|
|
21
21
|
def return_value
|
22
|
+
edit find_return_value
|
23
|
+
end
|
24
|
+
|
25
|
+
def find_return_value
|
22
26
|
if @statement =~ /\s+\?\s+(.*?)(:|$)/
|
23
27
|
$1.strip
|
28
|
+
elsif @statement[/then\n(.+)\nend/]
|
29
|
+
$1.strip
|
24
30
|
else
|
25
|
-
|
31
|
+
@statement[/(.*?)(unless|if)/, 1].to_s.strip
|
26
32
|
end
|
27
33
|
end
|
28
34
|
|
29
|
-
def
|
35
|
+
def edit(txt)
|
30
36
|
txt.sub! /^return\s*/, 'returns '
|
31
37
|
txt.sub! /^returns\s*$/, 'returns nil'
|
32
38
|
if txt.split(/\s/).length == 1
|
data/lib/drg/spec.rb
CHANGED
@@ -2,6 +2,10 @@ class DRG::Spec < DelegateClass(DRG::Ruby::Const)
|
|
2
2
|
# = Class
|
3
3
|
# generate a rspec file based on existing code
|
4
4
|
|
5
|
+
def self.default_indent_size
|
6
|
+
2
|
7
|
+
end
|
8
|
+
|
5
9
|
def self.generate(file)
|
6
10
|
spec = DRG::Spec.new(file)
|
7
11
|
return if spec.funcs.empty? # nothing to do
|
@@ -44,7 +48,7 @@ class DRG::Spec < DelegateClass(DRG::Ruby::Const)
|
|
44
48
|
end
|
45
49
|
|
46
50
|
def collect_contexts(condition, indent = '', contexts = [])
|
47
|
-
new_indent = indent + '
|
51
|
+
new_indent = indent + (' ' * self.class.default_indent_size)
|
48
52
|
contexts << %Q(#{indent}context #{quote(tr(condition.short_statement))} do) << %Q(#{new_indent}before {})
|
49
53
|
unless condition.return_value.empty?
|
50
54
|
contexts << %Q(#{new_indent}it #{quote(condition.return_value)} do) << %Q(#{new_indent}end)
|
@@ -61,7 +65,7 @@ class DRG::Spec < DelegateClass(DRG::Ruby::Const)
|
|
61
65
|
def quote(txt)
|
62
66
|
txt.strip!
|
63
67
|
if txt =~ /"/
|
64
|
-
"%Q
|
68
|
+
"%Q[#{txt.gsub(/\#\{(.*?)\}/m, '@\1')}]"
|
65
69
|
else
|
66
70
|
%Q("#{txt}")
|
67
71
|
end
|
@@ -79,7 +83,7 @@ class DRG::Spec < DelegateClass(DRG::Ruby::Const)
|
|
79
83
|
phrase.sub! /^if /, 'when '
|
80
84
|
phrase.sub! /^not if /, 'unless '
|
81
85
|
phrase.sub! /^if not /, 'unless '
|
82
|
-
phrase.sub!
|
86
|
+
phrase.sub! /then$/, ''
|
83
87
|
if phrase !~ /^(when|unless|not)/
|
84
88
|
phrase = "when #{phrase}"
|
85
89
|
end
|
data/lib/drg/tasks/log.rb
CHANGED
@@ -18,13 +18,18 @@ module DRG
|
|
18
18
|
file_path = Pathname.new(File.expand_path(ruby_file))
|
19
19
|
spec = DRG::Spec.generate(file_path)
|
20
20
|
unless spec
|
21
|
-
log "
|
21
|
+
log "- #{ruby_file} - no methods", :gray
|
22
22
|
next
|
23
23
|
end
|
24
24
|
rspec_file = Pathname.new(spec_file(ruby_file))
|
25
|
-
|
25
|
+
spec_file_path = rspec_file.to_s[%r|/(spec/.+)|, 1]
|
26
|
+
if rspec_file.exist?
|
27
|
+
log "- #{spec_file_path} - already exists", :gray
|
28
|
+
next
|
29
|
+
end
|
30
|
+
log "+ #{spec_file_path}"
|
26
31
|
FileUtils.mkdir_p(rspec_file.parent)
|
27
|
-
File.open(
|
32
|
+
File.open(rspec_file, 'wb') do |f|
|
28
33
|
f << spec.join("\n")
|
29
34
|
end
|
30
35
|
end
|
@@ -44,7 +49,11 @@ module DRG
|
|
44
49
|
|
45
50
|
# @note subbing out /app/ is Rails specific
|
46
51
|
def spec_file(ruby_file)
|
47
|
-
File.join(spec_path, "#{ruby_file
|
52
|
+
File.join(spec_path, "#{specify(ruby_file)}").sub '/app/', '/'
|
53
|
+
end
|
54
|
+
|
55
|
+
def specify(file_name)
|
56
|
+
file_name.sub('.rb', '_spec.rb')
|
48
57
|
end
|
49
58
|
|
50
59
|
def spec_path
|
data/lib/drg/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: drg
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.15.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ryan Buckley
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-11-
|
11
|
+
date: 2015-11-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: ruby_parser
|