drg 0.15.4 → 0.15.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0d1cc344f3f40558e3ff0b5b1b4e8cb121b28f33
4
- data.tar.gz: 725395f9526ee8371ccd781be7062aab12415342
3
+ metadata.gz: 63f814a01fc0fbe0162746f51d58f4fd4f761b74
4
+ data.tar.gz: 51c609488f4b8f9fc82f8e71898da822f71c0f36
5
5
  SHA512:
6
- metadata.gz: ecd79de1e5d14e24502a38492bd154140c7beebcfbab0210152aa0ea4b47662ba03533c044ba10e6ce65bf5fbc130a4e1091326bd0487cf4f3bd9a11a7f396b5
7
- data.tar.gz: d7670cfd5996e9cc0314088d8d09f89b9aeb006173b7f670f3e80361673062b445f5e8401188963fc087d2318170e945ab2dcb5f25bce768971b791920dd54bf
6
+ metadata.gz: 4f95bdc5018996bcec997689a04b9d42e550007512858b5c895ee0078fe2c92a0bd21af92dcb21a22423eb83cf93f88ad7a8778a0a9427ca20ada802f4634cb4
7
+ data.tar.gz: 7790f3fc153247b4e3426452ff2d180d8651fdaef949fd1764aa34e5370c0db97a2e592e315380bc069d62d125637d2f9cc25a9976fdd9d8767b97455e6d9cde
@@ -0,0 +1,25 @@
1
+ module DRG
2
+ class Ruby
3
+ class Assignment
4
+ attr_reader :sexp
5
+
6
+ def initialize(sexp)
7
+ @sexp = sexp
8
+ end
9
+
10
+ def to_s
11
+ "assigns #{ivar_name}"
12
+ end
13
+
14
+ # @example s(:iasgn, :@duder, s(:if, ...)
15
+ # @example s(:op_asgn_or, s(:ivar, :@report), ...)
16
+ def ivar_name
17
+ if sexp.first == :iasgn
18
+ sexp[1]
19
+ elsif sexp.first == :op_asgn_or
20
+ sexp[1][1]
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
data/lib/drg/ruby/func.rb CHANGED
@@ -2,12 +2,24 @@ class DRG::Ruby::Func < Struct.new(:sexp, :_private)
2
2
  alias private? _private
3
3
 
4
4
  def conditions
5
- DRG::Decorators::SexpDecorator.new(sexp).each_sexp_condition.map do |exp|
6
- DRG::Ruby::Condition.new(exp)
5
+ DRG::Decorators::SexpDecorator.new(sexp).each_sexp_condition.map &DRG::Ruby::Condition.method(:new)
6
+ end
7
+
8
+ def assignments
9
+ nodes = find_assignments(sexp)
10
+ sexp.find_nodes(:rescue).each do |node|
11
+ node = node[1] if node[1].first == :block
12
+ nodes.concat find_assignments(node)
7
13
  end
14
+ nodes.map &DRG::Ruby::Assignment.method(:new)
15
+ end
16
+
17
+ def find_assignments(s_expression)
18
+ s_expression.find_nodes(:op_asgn_or) + s_expression.find_nodes(:iasgn)
8
19
  end
9
20
 
10
21
  # @note we drop(1) to get rid of :args (which should be the first item in the sexp)
22
+ # @note called from subclasses
11
23
  def map_args(_sexp = sexp, list = [])
12
24
  val = _sexp.first
13
25
  return list.drop(1) unless val
data/lib/drg/ruby.rb CHANGED
@@ -8,6 +8,7 @@ module DRG
8
8
  autoload :Func, 'drg/ruby/func'
9
9
  autoload :ClassFunc, 'drg/ruby/class_func'
10
10
  autoload :InstanceFunc, 'drg/ruby/instance_func'
11
+ autoload :Assignment, 'drg/ruby/assignment'
11
12
 
12
13
  attr_reader :sexp, :const
13
14
 
data/lib/drg/spec.rb CHANGED
@@ -7,7 +7,7 @@ class DRG::Spec < DelegateClass(DRG::Ruby::Const)
7
7
  end
8
8
 
9
9
  def self.generate(file)
10
- spec = DRG::Spec.new(file)
10
+ spec = new(file)
11
11
  return if spec.funcs.empty? # nothing to do
12
12
  lines = [%Q(require "spec_helper"), %Q(), %Q(describe #{spec.const} do)]
13
13
  if spec.class?
@@ -22,6 +22,9 @@ class DRG::Spec < DelegateClass(DRG::Ruby::Const)
22
22
  lines << %Q()
23
23
  spec.funcs.reject(&:private?).each do |func|
24
24
  lines << %Q( describe #{spec.quote("#{func.class? ? '.' : '#'}#{func.name}")} do)
25
+ func.assignments.each do |assignment|
26
+ lines << %Q( it #{spec.quote(assignment)} do) << %Q( end)
27
+ end
25
28
  func.conditions.each do |condition|
26
29
  lines.concat spec.collect_contexts(condition, ' ')
27
30
  end
@@ -49,7 +52,7 @@ class DRG::Spec < DelegateClass(DRG::Ruby::Const)
49
52
  def collect_contexts(condition, indent = '', contexts = [])
50
53
  new_indent = indent + (' ' * self.class.default_indent_size)
51
54
  contexts << %Q(#{indent}context #{quote(tr(condition.short_statement))} do) << %Q(#{new_indent}before {})
52
- unless condition.return_value.empty?
55
+ if should_print? condition.return_value
53
56
  contexts << %Q(#{new_indent}it #{quote(condition.return_value)} do) << %Q(#{new_indent}end)
54
57
  end
55
58
  if condition.nested_conditions.any?
@@ -58,7 +61,7 @@ class DRG::Spec < DelegateClass(DRG::Ruby::Const)
58
61
  contexts << %Q(#{indent}end) << %Q() # /context
59
62
  if condition.parts.empty?
60
63
  contexts << %Q(#{indent}context #{quote(tr(negate(condition.short_statement)))} do) << %Q(#{new_indent}before {})
61
- unless condition.else_return_value.empty?
64
+ if should_print? condition.else_return_value
62
65
  contexts << %Q(#{new_indent}it #{quote(condition.else_return_value)} do) << %Q(#{new_indent}end)
63
66
  end
64
67
  contexts << %Q(#{indent}end)
@@ -67,7 +70,7 @@ class DRG::Spec < DelegateClass(DRG::Ruby::Const)
67
70
  contexts << %Q(#{indent}context #{quote(tr(condition_part.short_statement))} do) << %Q(#{new_indent}before {})
68
71
  contexts << %Q(#{new_indent}it #{quote(condition_part.return_value)} do) << %Q(#{new_indent}end)
69
72
  contexts << %Q(#{indent}end)
70
- unless condition_part.else_return_value.empty?
73
+ if should_print? condition_part.else_return_value
71
74
  contexts << %Q(#{indent}context #{quote(tr(negate(condition_part.short_statement)))} do) << %Q(#{new_indent}before {})
72
75
  contexts << %Q(#{new_indent}it #{quote(condition_part.else_return_value)} do) << %Q(#{new_indent}end)
73
76
  contexts << %Q(#{indent}end)
@@ -77,6 +80,7 @@ class DRG::Spec < DelegateClass(DRG::Ruby::Const)
77
80
  end
78
81
 
79
82
  def quote(txt)
83
+ txt = txt.to_s
80
84
  txt.strip!
81
85
  if txt =~ /"/
82
86
  "%Q[#{txt.gsub(/\#\{(.*?)\}/m, '\#{\1}')}]"
@@ -103,4 +107,9 @@ class DRG::Spec < DelegateClass(DRG::Ruby::Const)
103
107
  end
104
108
  phrase
105
109
  end
110
+
111
+ # @description reject multiline statements, which means we messed up somewhere else, so let's hide that
112
+ def should_print?(txt)
113
+ !txt.empty? and txt !~ /\n/
114
+ end
106
115
  end
data/lib/drg/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module DRG
2
- VERSION = '0.15.4'.freeze
2
+ VERSION = '0.15.5'.freeze
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: drg
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.15.4
4
+ version: 0.15.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryan Buckley
@@ -148,6 +148,7 @@ files:
148
148
  - lib/drg/decorators.rb
149
149
  - lib/drg/decorators/sexp_decorator.rb
150
150
  - lib/drg/ruby.rb
151
+ - lib/drg/ruby/assignment.rb
151
152
  - lib/drg/ruby/class_func.rb
152
153
  - lib/drg/ruby/condition.rb
153
154
  - lib/drg/ruby/const.rb