ruby-lint 1.1.0 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (205) hide show
  1. checksums.yaml +4 -4
  2. data/CONTRIBUTING.md +43 -29
  3. data/LICENSE +1 -1
  4. data/README.md +0 -1
  5. data/bin/ruby-lint +91 -3
  6. data/checksum/ruby-lint-1.1.0.gem.sha512 +1 -0
  7. data/doc/changelog.md +30 -0
  8. data/doc/code_analysis.md +13 -0
  9. data/doc/configuration.md +5 -24
  10. data/lib/ruby-lint.rb +7 -10
  11. data/lib/ruby-lint/analysis/argument_amount.rb +2 -0
  12. data/lib/ruby-lint/analysis/base.rb +12 -0
  13. data/lib/ruby-lint/analysis/pedantics.rb +2 -0
  14. data/lib/ruby-lint/analysis/shadowing_variables.rb +2 -0
  15. data/lib/ruby-lint/analysis/undefined_methods.rb +5 -2
  16. data/lib/ruby-lint/analysis/undefined_variables.rb +2 -0
  17. data/lib/ruby-lint/analysis/unused_variables.rb +2 -0
  18. data/lib/ruby-lint/analysis/useless_equality_checks.rb +2 -0
  19. data/lib/ruby-lint/ast/node.rb +0 -15
  20. data/lib/ruby-lint/command.rb +100 -0
  21. data/lib/ruby-lint/configuration.rb +35 -66
  22. data/lib/ruby-lint/constant_path.rb +7 -2
  23. data/lib/ruby-lint/definition/ruby_object.rb +20 -6
  24. data/lib/ruby-lint/definitions/core/argf.rb +3 -3
  25. data/lib/ruby-lint/definitions/gems/minitest.rb +792 -0
  26. data/lib/ruby-lint/file_list.rb +1 -1
  27. data/lib/ruby-lint/file_loader.rb +2 -20
  28. data/lib/ruby-lint/file_scanner.rb +11 -2
  29. data/lib/ruby-lint/method_evaluation.rb +21 -0
  30. data/lib/ruby-lint/presenter/base.rb +18 -0
  31. data/lib/ruby-lint/presenter/json.rb +3 -1
  32. data/lib/ruby-lint/presenter/syntastic.rb +3 -1
  33. data/lib/ruby-lint/presenter/text.rb +3 -1
  34. data/lib/ruby-lint/runner.rb +6 -63
  35. data/lib/ruby-lint/variable_predicates.rb +3 -3
  36. data/lib/ruby-lint/version.rb +1 -1
  37. data/lib/ruby-lint/virtual_machine.rb +4 -1
  38. data/ruby-lint.gemspec +13 -4
  39. metadata +12 -187
  40. data/.editorconfig +0 -15
  41. data/.gitignore +0 -6
  42. data/.ruby-version +0 -1
  43. data/.travis.yml +0 -19
  44. data/Gemfile +0 -15
  45. data/MANIFEST +0 -469
  46. data/Rakefile +0 -25
  47. data/benchmark/bootup.rb +0 -13
  48. data/benchmark/virtual_machine.rb +0 -17
  49. data/checksum/.gitkeep +0 -0
  50. data/doc/.gitkeep +0 -0
  51. data/doc/css/.gitkeep +0 -0
  52. data/doc/images/.gitkeep +0 -0
  53. data/gen/rails/constants.txt +0 -12
  54. data/gen/rails/requires.rb +0 -2
  55. data/gen/stdlib/constants.rb +0 -30
  56. data/gen/stdlib/constants.txt +0 -214
  57. data/gen/stdlib/requires.rb +0 -64
  58. data/lib/ruby-lint/benchmark/average.rb +0 -115
  59. data/lib/ruby-lint/cache.rb +0 -121
  60. data/lib/ruby-lint/cache_entry.rb +0 -44
  61. data/lib/ruby-lint/cli.rb +0 -4
  62. data/lib/ruby-lint/cli/analyze.rb +0 -209
  63. data/lib/ruby-lint/cli/base.rb +0 -103
  64. data/lib/ruby-lint/cli/cache.rb +0 -60
  65. data/lib/ruby-lint/default_names.rb +0 -19
  66. data/lib/ruby-lint/definitions/gems/.gitkeep +0 -0
  67. data/lib/ruby-lint/node_hash.rb +0 -105
  68. data/misc/stdlib.rb +0 -66
  69. data/profiling/virtual_machine.rb +0 -20
  70. data/ruby-lint.yml +0 -7
  71. data/spec/fixtures/associating.rb +0 -7
  72. data/spec/fixtures/complex/rails/basic_controller.rb +0 -9
  73. data/spec/fixtures/complex/rcap.rb +0 -67
  74. data/spec/fixtures/complex/slop.rb +0 -701
  75. data/spec/fixtures/config.yml +0 -8
  76. data/spec/fixtures/deeply/nested/file.rb +0 -1
  77. data/spec/fixtures/file_scanner/lib/example/recursive/source.rb +0 -6
  78. data/spec/fixtures/file_scanner/lib/example/recursive/target.rb +0 -8
  79. data/spec/fixtures/file_scanner/lib/example/user.rb +0 -6
  80. data/spec/fixtures/file_scanner/lib/ruby-lint/definition/constant_proxy.rb +0 -6
  81. data/spec/fixtures/file_scanner/lib/ruby-lint/global_scope.rb +0 -6
  82. data/spec/fixtures/file_scanner/lib/test-dashes/foo.rb +0 -4
  83. data/spec/fixtures/file_scanner/rails/app/models/example/user.rb +0 -6
  84. data/spec/fixtures/file_scanner/rails/app/models/user.rb +0 -4
  85. data/spec/fixtures/invalid.rb +0 -3
  86. data/spec/fixtures/invalid_2.rb +0 -3
  87. data/spec/fixtures/syntax_error.rb +0 -1
  88. data/spec/fixtures/uses_external.rb +0 -1
  89. data/spec/fixtures/uses_external_invalid.rb +0 -3
  90. data/spec/fixtures/uses_external_namespace.rb +0 -1
  91. data/spec/fixtures/valid.rb +0 -3
  92. data/spec/ruby-lint/analysis/argument_amount_spec.rb +0 -131
  93. data/spec/ruby-lint/analysis/base_spec.rb +0 -24
  94. data/spec/ruby-lint/analysis/pedantics_spec.rb +0 -63
  95. data/spec/ruby-lint/analysis/shadowing_variables_spec.rb +0 -85
  96. data/spec/ruby-lint/analysis/undefined_methods_spec.rb +0 -337
  97. data/spec/ruby-lint/analysis/undefined_variables_spec.rb +0 -138
  98. data/spec/ruby-lint/analysis/unused_variables_spec.rb +0 -270
  99. data/spec/ruby-lint/analysis/useless_equality_checks_spec.rb +0 -107
  100. data/spec/ruby-lint/ast/node_spec.rb +0 -39
  101. data/spec/ruby-lint/cache_entry_spec.rb +0 -25
  102. data/spec/ruby-lint/cache_spec.rb +0 -53
  103. data/spec/ruby-lint/cli/analyze_spec.rb +0 -52
  104. data/spec/ruby-lint/configuration_spec.rb +0 -126
  105. data/spec/ruby-lint/constant_loader_spec.rb +0 -79
  106. data/spec/ruby-lint/constant_path.rb +0 -63
  107. data/spec/ruby-lint/definition/constant_proxy_spec.rb +0 -85
  108. data/spec/ruby-lint/definition/dsl_spec.rb +0 -135
  109. data/spec/ruby-lint/definition/registry_spec.rb +0 -106
  110. data/spec/ruby-lint/definition/ruby_method_spec.rb +0 -106
  111. data/spec/ruby-lint/definition/ruby_object_spec.rb +0 -264
  112. data/spec/ruby-lint/definition_builder/primitive_spec.rb +0 -62
  113. data/spec/ruby-lint/definition_builder/ruby_class_spec.rb +0 -107
  114. data/spec/ruby-lint/definition_builder/ruby_method_spec.rb +0 -53
  115. data/spec/ruby-lint/definition_builder/ruby_module_spec.rb +0 -52
  116. data/spec/ruby-lint/definitions/argv_spec.rb +0 -18
  117. data/spec/ruby-lint/definitions/env_spec.rb +0 -13
  118. data/spec/ruby-lint/definitions/file_spec.rb +0 -17
  119. data/spec/ruby-lint/definitions/fixnum_spec.rb +0 -18
  120. data/spec/ruby-lint/definitions/io_spec.rb +0 -15
  121. data/spec/ruby-lint/definitions/kernel_spec.rb +0 -18
  122. data/spec/ruby-lint/definitions/range_spec.rb +0 -21
  123. data/spec/ruby-lint/definitions/string_spec.rb +0 -20
  124. data/spec/ruby-lint/docstring/mapping.rb +0 -27
  125. data/spec/ruby-lint/docstring/parser_spec.rb +0 -88
  126. data/spec/ruby-lint/extensions/string_spec.rb +0 -7
  127. data/spec/ruby-lint/file_list_spec.rb +0 -25
  128. data/spec/ruby-lint/file_loader_spec.rb +0 -69
  129. data/spec/ruby-lint/file_scanner_spec.rb +0 -84
  130. data/spec/ruby-lint/inspector_spec.rb +0 -224
  131. data/spec/ruby-lint/iterator_spec.rb +0 -151
  132. data/spec/ruby-lint/method_call/.gitkeep +0 -0
  133. data/spec/ruby-lint/nested_stack_spec.rb +0 -23
  134. data/spec/ruby-lint/node_hash_spec.rb +0 -56
  135. data/spec/ruby-lint/parser_spec.rb +0 -38
  136. data/spec/ruby-lint/presenter/json_spec.rb +0 -58
  137. data/spec/ruby-lint/presenter/syntastic_spec.rb +0 -49
  138. data/spec/ruby-lint/presenter/text_spec.rb +0 -49
  139. data/spec/ruby-lint/report/entry_spec.rb +0 -58
  140. data/spec/ruby-lint/report_spec.rb +0 -39
  141. data/spec/ruby-lint/runner_spec.rb +0 -74
  142. data/spec/ruby-lint/variable_predicates_spec.rb +0 -30
  143. data/spec/ruby-lint/virtual_machine/alias_spec.rb +0 -55
  144. data/spec/ruby-lint/virtual_machine/assignments/arrays_spec.rb +0 -87
  145. data/spec/ruby-lint/virtual_machine/assignments/assignment_arguments_spec.rb +0 -14
  146. data/spec/ruby-lint/virtual_machine/assignments/constants_spec.rb +0 -23
  147. data/spec/ruby-lint/virtual_machine/assignments/hashes_spec.rb +0 -52
  148. data/spec/ruby-lint/virtual_machine/assignments/optional_spec.rb +0 -41
  149. data/spec/ruby-lint/virtual_machine/assignments/range_spec.rb +0 -28
  150. data/spec/ruby-lint/virtual_machine/assignments/return_values_spec.rb +0 -78
  151. data/spec/ruby-lint/virtual_machine/assignments/variables_spec.rb +0 -130
  152. data/spec/ruby-lint/virtual_machine/associate_nodes_spec.rb +0 -61
  153. data/spec/ruby-lint/virtual_machine/autoloading_spec.rb +0 -18
  154. data/spec/ruby-lint/virtual_machine/blocks_spec.rb +0 -90
  155. data/spec/ruby-lint/virtual_machine/classes/class_methods_spec.rb +0 -21
  156. data/spec/ruby-lint/virtual_machine/classes/extending_spec.rb +0 -109
  157. data/spec/ruby-lint/virtual_machine/classes/redefining_spec.rb +0 -51
  158. data/spec/ruby-lint/virtual_machine/classes/sclass_spec.rb +0 -96
  159. data/spec/ruby-lint/virtual_machine/classes/scoping_spec.rb +0 -60
  160. data/spec/ruby-lint/virtual_machine/complex/rails_spec.rb +0 -21
  161. data/spec/ruby-lint/virtual_machine/complex/rcap_spec.rb +0 -15
  162. data/spec/ruby-lint/virtual_machine/complex/slop_spec.rb +0 -16
  163. data/spec/ruby-lint/virtual_machine/constants_spec.rb +0 -31
  164. data/spec/ruby-lint/virtual_machine/for_spec.rb +0 -16
  165. data/spec/ruby-lint/virtual_machine/freeze_spec.rb +0 -13
  166. data/spec/ruby-lint/virtual_machine/global_variables_spec.rb +0 -15
  167. data/spec/ruby-lint/virtual_machine/inherit_kernel_spec.rb +0 -15
  168. data/spec/ruby-lint/virtual_machine/interpolation_spec.rb +0 -12
  169. data/spec/ruby-lint/virtual_machine/location_spec.rb +0 -64
  170. data/spec/ruby-lint/virtual_machine/method_call_tracking_spec.rb +0 -57
  171. data/spec/ruby-lint/virtual_machine/methods/attr_spec.rb +0 -182
  172. data/spec/ruby-lint/virtual_machine/methods/calls_spec.rb +0 -25
  173. data/spec/ruby-lint/virtual_machine/methods/define_method_spec.rb +0 -41
  174. data/spec/ruby-lint/virtual_machine/methods/defining_spec.rb +0 -40
  175. data/spec/ruby-lint/virtual_machine/methods/docstrings_spec.rb +0 -80
  176. data/spec/ruby-lint/virtual_machine/methods/exporting_spec.rb +0 -19
  177. data/spec/ruby-lint/virtual_machine/methods/kernel_spec.rb +0 -25
  178. data/spec/ruby-lint/virtual_machine/methods/parameters_spec.rb +0 -89
  179. data/spec/ruby-lint/virtual_machine/methods/patching_spec.rb +0 -20
  180. data/spec/ruby-lint/virtual_machine/methods/scoping_spec.rb +0 -63
  181. data/spec/ruby-lint/virtual_machine/methods/square_bracket_spec.rb +0 -32
  182. data/spec/ruby-lint/virtual_machine/methods/visibility_spec.rb +0 -64
  183. data/spec/ruby-lint/virtual_machine/modules_spec.rb +0 -205
  184. data/spec/ruby-lint/virtual_machine/reference_amount_spec.rb +0 -81
  185. data/spec/ruby-lint/virtual_machine/self_spec.rb +0 -37
  186. data/spec/ruby-lint/virtual_machine/unused_spec.rb +0 -17
  187. data/spec/spec_helper.rb +0 -28
  188. data/spec/support/building.rb +0 -50
  189. data/spec/support/coveralls.rb +0 -5
  190. data/spec/support/definitions.rb +0 -39
  191. data/spec/support/fixtures.rb +0 -20
  192. data/spec/support/parsing.rb +0 -30
  193. data/spec/support/simplecov.rb +0 -18
  194. data/spec/support/versions.rb +0 -9
  195. data/task/build.rake +0 -4
  196. data/task/checksum.rake +0 -13
  197. data/task/coverage.rake +0 -6
  198. data/task/doc.rake +0 -16
  199. data/task/generate.rake +0 -77
  200. data/task/graphviz.rake +0 -12
  201. data/task/manifest.rake +0 -8
  202. data/task/tag.rake +0 -6
  203. data/task/test.rake +0 -4
  204. data/task/todo.rake +0 -6
  205. data/task/travis.rake +0 -8
@@ -1,78 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe 'Using return values in assignments' do
4
- example 'assign a return value' do
5
- code = 'word = String.new'
6
- defs = build_definitions(code)
7
- value = defs.lookup(:lvar, 'word').value
8
-
9
- value.is_a?(ruby_object).should == true
10
-
11
- value.type.should == :const
12
- value.name.should == 'String'
13
- value.instance?.should == true
14
- end
15
-
16
- example 'assign a nil value for a missing return value' do
17
- code = <<-CODE
18
- def example
19
- end
20
-
21
- number = example
22
- CODE
23
-
24
- defs = build_definitions(code)
25
-
26
- defs.lookup(:lvar, 'number').value.type.should == :unknown
27
- end
28
-
29
- example 'assign return values when chaining method calls' do
30
- code = 'word = String.new.initialize.initialize'
31
- defs = build_definitions(code)
32
- value = defs.lookup(:lvar, 'word').value
33
-
34
- value.is_a?(ruby_object).should == true
35
-
36
- value.type.should == :const
37
- value.name.should == 'String'
38
- value.instance?.should == true
39
- end
40
-
41
- describe 'setting instance types for core Ruby types' do
42
- example 'create a new String instance' do
43
- defs = build_definitions('number = "10"')
44
-
45
- defs.lookup(:lvar, 'number').value.instance?.should == true
46
- end
47
-
48
- example 'create a new Symbol instance' do
49
- defs = build_definitions('number = :"10"')
50
-
51
- defs.lookup(:lvar, 'number').value.instance?.should == true
52
- end
53
-
54
- example 'create a new Fixnum instance' do
55
- defs = build_definitions('number = 10')
56
-
57
- defs.lookup(:lvar, 'number').value.instance?.should == true
58
- end
59
-
60
- example 'create a new Float instance' do
61
- defs = build_definitions('number = 10.0')
62
-
63
- defs.lookup(:lvar, 'number').value.instance?.should == true
64
- end
65
-
66
- example 'create a new Array instance' do
67
- defs = build_definitions('number = [10]')
68
-
69
- defs.lookup(:lvar, 'number').value.instance?.should == true
70
- end
71
-
72
- example 'create a new Hash instance' do
73
- defs = build_definitions('number = {:a => 10}')
74
-
75
- defs.lookup(:lvar, 'number').value.instance?.should == true
76
- end
77
- end
78
- end
@@ -1,130 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe RubyLint::VirtualMachine do
4
- context 'variable assignments' do
5
- example 'assign different types of variables' do
6
- types = {
7
- 'number' => :lvar,
8
- '@number' => :ivar,
9
- '@@number' => :cvar,
10
- '$number' => :gvar,
11
- 'NUMBER' => :const
12
- }
13
-
14
- types.each do |name, type|
15
- number = build_definitions("#{name} = 10").lookup(type, name)
16
-
17
- number.name.should == name
18
- number.value.value.should == 10
19
- end
20
- end
21
-
22
- example 'assign multiple values to multiple variables' do
23
- defs = build_definitions('number, numberx = 10, 20')
24
- number = defs.lookup(:lvar, 'number')
25
- numberx = defs.lookup(:lvar, 'numberx')
26
-
27
- number.is_a?(ruby_object).should == true
28
-
29
- number.name.should == 'number'
30
- number.value.value.should == 10
31
-
32
- numberx.is_a?(ruby_object).should == true
33
-
34
- numberx.name.should == 'numberx'
35
- numberx.value.value.should == 20
36
- end
37
-
38
- example 'assign a value to a constant path' do
39
- defs = build_definitions('module Foo; end; Foo::FOO = 10')
40
- foo = defs.lookup(:const, 'Foo').lookup(:const, 'FOO')
41
-
42
- foo.is_a?(ruby_object).should == true
43
-
44
- foo.name.should == 'FOO'
45
- foo.value.value.should == 10
46
- end
47
-
48
- example 'assign a single value to multiple variables' do
49
- code = 'first = second = third = 10'
50
- defs = build_definitions(code)
51
-
52
- %w{first second third}.each do |name|
53
- variable = defs.lookup(:lvar, name)
54
-
55
- variable.is_a?(ruby_object).should == true
56
-
57
- variable.value.type.should == :int
58
- variable.value.value.should == 10
59
- end
60
- end
61
-
62
- example 'resolve variables in assignments' do
63
- code = <<-CODE
64
- a = 1
65
- b = a
66
-
67
- foo = 100 # to ensure this code doesn't use the last assigned values.
68
-
69
- c = b
70
- d = c
71
- CODE
72
-
73
- defs = build_definitions(code)
74
-
75
- %w{a b c d}.each do |name|
76
- var = defs.lookup(:lvar, name)
77
-
78
- var.value.type.should == :int
79
- var.value.value.should == 1
80
- end
81
-
82
- defs.lookup(:lvar, 'foo').value.value.should == 100
83
- end
84
-
85
- example 'assign nil to a value' do
86
- defs = build_definitions('variable = nil')
87
- value = defs.lookup(:lvar, 'variable').value
88
-
89
- value.type.should == :nil
90
- value.parents[0].name.should == 'NilClass'
91
- end
92
-
93
- example 'assign true to a value' do
94
- defs = build_definitions('variable = true')
95
- value = defs.lookup(:lvar, 'variable').value
96
-
97
- value.type.should == :true
98
- value.parents[0].name.should == 'TrueClass'
99
- end
100
-
101
- example 'assign false to a value' do
102
- defs = build_definitions('variable = false')
103
- value = defs.lookup(:lvar, 'variable').value
104
-
105
- value.type.should == :false
106
- value.parents[0].name.should == 'FalseClass'
107
- end
108
-
109
- example 'assigning a magic global variable to a variable' do
110
- defs = build_definitions('variable = $1')
111
- value = defs.lookup(:lvar, 'variable').value
112
-
113
- value.type.should == :unknown
114
- end
115
-
116
- example 'global variables should be assigned in the global scope' do
117
- code = <<-CODE
118
- class Foo
119
- def foo
120
- $bar = 10
121
- end
122
- end
123
- CODE
124
-
125
- defs = build_definitions(code)
126
-
127
- defs.lookup(:gvar, '$bar').value.value.should == 10
128
- end
129
- end
130
- end
@@ -1,61 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe RubyLint::VirtualMachine do
4
- example 'associate AST nodes and their definitions' do
5
- tokens = parse('def foobar; end', false)
6
- vm = RubyLint::VirtualMachine.new
7
-
8
- vm.iterate(tokens)
9
-
10
- defs = vm.definitions
11
- assoc = vm.associations
12
- method = tokens.children[0]
13
-
14
- assoc.key?(method).should == true
15
- assoc[method].should == defs.lookup(:instance_method, 'foobar')
16
- end
17
-
18
- describe 'method calls' do
19
- example 'should not add associations' do
20
- associations = build_associations('foo')
21
- nodes = associations.keys
22
-
23
- nodes.length.should == 1
24
- nodes[0].type.should == :root
25
- end
26
-
27
- example 'should not add associations for methods with arguments' do
28
- associations = build_associations('foo(:bar)')
29
- nodes = associations.keys
30
-
31
- nodes.length.should == 2
32
- nodes[0].type.should == :root
33
- end
34
-
35
- example 'should not add associations for methods called on methods' do
36
- associations = build_associations('foo.bar')
37
- nodes = associations.keys
38
- values = associations.values
39
-
40
- nodes.length.should == 2
41
- nodes[0].type.should == :root
42
- nodes[1].type.should == :send
43
-
44
- values[1].type.should == :unknown
45
- end
46
-
47
- example 'should not add associations for stacked methods with arguments' do
48
- associations = build_associations('foo.bar(:baz)')
49
- nodes = associations.keys
50
- values = associations.values
51
-
52
- nodes.length.should == 3
53
- nodes[0].type.should == :root
54
- nodes[1].type.should == :sym
55
- nodes[2].type.should == :send
56
-
57
- values[1].type.should == :sym
58
- values[2].type.should == :unknown
59
- end
60
- end
61
- end
@@ -1,18 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe RubyLint::VirtualMachine do
4
- example 'automatically load constants' do
5
- definitions = build_definitions('ERB')
6
-
7
- definitions.lookup(:const, 'ERB').is_a?(ruby_object).should == true
8
- end
9
-
10
- example 'automatically load constant paths' do
11
- definitions = build_definitions('Encoding::BINARY')
12
-
13
- definitions.lookup(:const, 'Encoding') \
14
- .lookup(:const, 'BINARY') \
15
- .is_a?(ruby_object) \
16
- .should == true
17
- end
18
- end
@@ -1,90 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe RubyLint::VirtualMachine do
4
- example 'make variables available in a block' do
5
- code = <<-CODE
6
- number = 10
7
-
8
- example do
9
- end
10
- CODE
11
-
12
- definition = build_associations(code).to_a.last.last
13
-
14
- number = definition.lookup(:lvar, 'number')
15
-
16
- number.is_a?(ruby_object).should == true
17
- number.value.value.should == 10
18
- end
19
-
20
- example 'make block arguments available as variables inside the block only' do
21
- code = <<-CODE
22
- example do
23
- number = 10
24
- end
25
- CODE
26
-
27
- associations = build_associations(code).to_a
28
-
29
- root_def = associations.first.last
30
- block_def = associations.last.last
31
-
32
- root_def.lookup(:lvar, 'number').nil?.should == true
33
- block_def.lookup(:lvar, 'number').value.value.should == 10
34
- end
35
-
36
- example 'blocks should be instances by default' do
37
- code = <<-CODE
38
- example do
39
- end
40
- CODE
41
-
42
- block = build_associations(code).to_a.last.last
43
-
44
- block.type.should == :block
45
- block.instance_type.should == :instance
46
- end
47
-
48
- example 'blocks should inherit the instance type from the outer scope' do
49
- code = <<-CODE
50
- class A
51
- example do
52
- end
53
- end
54
- CODE
55
-
56
- block = build_associations(code).to_a.last.last
57
-
58
- block.type.should == :block
59
- block.instance_type.should == :class
60
- end
61
-
62
- example 'update outer variables modified in the block' do
63
- code = <<-CODE
64
- number = 10
65
- @number = 10
66
- @@number = 10
67
- $number = 10
68
-
69
- example do
70
- number = 20
71
- @number = 20
72
- @@number = 20
73
- $number = 20
74
- end
75
- CODE
76
-
77
- defs = build_definitions(code)
78
-
79
- variables = {
80
- :lvar => 'number',
81
- :ivar => '@number',
82
- :cvar => '@@number',
83
- :gvar => '$number'
84
- }
85
-
86
- variables.each do |type, name|
87
- defs.lookup(type, name).value.value.should == 20
88
- end
89
- end
90
- end
@@ -1,21 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe RubyLint::VirtualMachine do
4
- describe 'defining class methods' do
5
- example 'define a single class method using `self`' do
6
- code = <<-CODE
7
- class Example
8
- def self.class_method
9
- end
10
- end
11
- CODE
12
-
13
- defs = build_definitions(code)
14
-
15
- defs.lookup(:const, 'Example') \
16
- .lookup(:method, 'class_method') \
17
- .is_a?(ruby_method) \
18
- .should == true
19
- end
20
- end
21
- end
@@ -1,109 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe RubyLint::VirtualMachine do
4
- describe 'extending classes' do
5
- example 'set the default parent class' do
6
- defs = build_definitions('class First; end')
7
-
8
- defs.lookup(:const, 'First') \
9
- .lookup(:method, 'new') \
10
- .is_a?(ruby_method) \
11
- .should == true
12
- end
13
-
14
- example 'extend a class using a parent' do
15
- code = <<-CODE
16
- class First
17
- def example
18
- end
19
- end
20
-
21
- class Second < First
22
- end
23
- CODE
24
-
25
- defs = build_definitions(code)
26
-
27
- defs.lookup(:const, 'Second') \
28
- .parents \
29
- .map(&:name) \
30
- .should == ['First', 'root']
31
-
32
- defs.lookup(:const, 'Second') \
33
- .lookup(:instance_method, 'example') \
34
- .is_a?(ruby_method) \
35
- .should == true
36
- end
37
-
38
- example 'extend a class using a constant path as the parent class' do
39
- code = <<-CODE
40
- class First
41
- class Second
42
- def example
43
- end
44
- end
45
- end
46
-
47
- class Third < First::Second
48
- end
49
- CODE
50
-
51
- defs = build_definitions(code)
52
-
53
- defs.lookup(:const, 'Third') \
54
- .parents \
55
- .map(&:name) \
56
- .should == ['Second', 'root']
57
-
58
- defs.lookup(:const, 'Third') \
59
- .lookup(:instance_method, 'example') \
60
- .is_a?(ruby_method) \
61
- .should == true
62
- end
63
-
64
- example 'extend a class using a variable' do
65
- code = <<-CODE
66
- parent = String
67
-
68
- class MyString < parent
69
- end
70
- CODE
71
-
72
- defs = build_definitions(code)
73
-
74
- parents = defs.lookup(:const, 'MyString').parents
75
-
76
- parents.length.should == 2
77
- parents.include?(defs.lookup(:const, 'String')).should == true
78
- end
79
-
80
- # This is to ensure that ruby-lint doesn't blow itself up when trying to
81
- # use a constant as a parent class that can't be found (e.g. a user defined
82
- # class).
83
- #
84
- # See https://github.com/YorickPeterse/ruby-lint/issues/32 for the
85
- # motivation behind this fix/test.
86
- example 'inherit Object as a fallback when the parent can not be found' do
87
- code = <<-CODE
88
- class Foo < Bar
89
- end
90
- CODE
91
-
92
- defs = build_definitions(code)
93
- parents = defs.lookup(:const, 'Foo').parents
94
-
95
- parents.length.should == 2
96
-
97
- parents.include?(defs.lookup(:const, 'Object')).should == true
98
- end
99
-
100
- example 'inherit from Object when importing String' do
101
- defs = build_definitions('String')
102
-
103
- defs.lookup(:const, 'String') \
104
- .lookup(:method, 'new') \
105
- .is_a?(ruby_method) \
106
- .should == true
107
- end
108
- end
109
- end