ruby-lint 1.1.0 → 2.0.0

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.
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,39 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe 'RubyLint::Report' do
4
- example 'add a message using #add' do
5
- report = RubyLint::Report.new
6
-
7
- report.add(
8
- :level => :info,
9
- :message => 'info message',
10
- :line => 1,
11
- :column => 2,
12
- :file => 'file.rb'
13
- )
14
-
15
- report.entries.length.should == 1
16
-
17
- entry = report.entries[0]
18
-
19
- entry.level.should == :info
20
- entry.message.should == 'info message'
21
- entry.line.should == 1
22
- entry.column.should == 2
23
- entry.file.should == 'file.rb'
24
- end
25
-
26
- example 'ignore invalid reporting levels' do
27
- report = RubyLint::Report.new
28
-
29
- report.add(
30
- :level => :test,
31
- :message => 'invalid message',
32
- :line => 1,
33
- :column => 1,
34
- :file => 'file.rb'
35
- )
36
-
37
- report.entries.empty?.should == true
38
- end
39
- end
@@ -1,74 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe RubyLint::Runner do
4
- before do
5
- @configuration = RubyLint::Configuration.new
6
- @cache_dir = Dir.mktmpdir('ruby-lint')
7
- end
8
-
9
- after do
10
- FileUtils.rm_rf(@cache_dir)
11
- end
12
-
13
- example 'run analysis on a single file' do
14
- files = [fixture_path('invalid.rb')]
15
- runner = RubyLint::Runner.new(@configuration)
16
- output = runner.analyze(files)
17
-
18
- output.should =~ /undefined method foobar on an instance of String/
19
- end
20
-
21
- example 'run analysis on multiple files' do
22
- files = [fixture_path('invalid.rb'), fixture_path('invalid_2.rb')]
23
- runner = RubyLint::Runner.new(@configuration)
24
- output = runner.analyze(files)
25
-
26
- output.should =~ /undefined method foobar on an instance of String/
27
- output.should =~ /undefined method derp on an instance of String/
28
- end
29
-
30
- example 'add syntax errors to the report' do
31
- files = [fixture_path('syntax_error.rb')]
32
- runner = RubyLint::Runner.new(@configuration)
33
- output = runner.analyze(files)
34
-
35
- output.should =~ /unexpected token \$end/
36
- end
37
-
38
- example 'add errors when using externally defined constants' do
39
- files = [fixture_path('uses_external_invalid.rb')]
40
- dirs = [fixture_path('file_scanner/rails')]
41
- config = RubyLint::Configuration.new(:directories => dirs)
42
- runner = RubyLint::Runner.new(config)
43
- output = runner.analyze(files)
44
-
45
- output.should =~ /undefined method foobar on an instance of User/
46
- end
47
-
48
- example 'associating nodes with external definitions' do
49
- files = [fixture_path('associating.rb')]
50
- dirs = [fixture_path('file_scanner/lib/ruby-lint')]
51
- config = RubyLint::Configuration.new(:directories => dirs)
52
- runner = RubyLint::Runner.new(config)
53
- output = runner.analyze(files)
54
-
55
- output.empty?.should == true
56
- end
57
-
58
- example 'conditionally disable analysis classes' do
59
- # This analysis class triggers the "undefined method foobar..." error.
60
- RubyLint::Analysis::UndefinedMethods.stub(:analyze?) do |ast, vm|
61
- # This ensures that the passed arguments are passed in the right order
62
- # and of the right type.
63
- !(ast.is_a?(RubyLint::AST::Node) && vm.is_a?(RubyLint::VirtualMachine))
64
- end
65
-
66
- files = [fixture_path('uses_external_invalid.rb')]
67
- dirs = [fixture_path('file_scanner/rails')]
68
- config = RubyLint::Configuration.new(:directories => dirs)
69
- runner = RubyLint::Runner.new(config)
70
- output = runner.analyze(files)
71
-
72
- output.empty?.should == true
73
- end
74
- end
@@ -1,30 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe RubyLint::VariablePredicates do
4
- before :all do
5
- @array = s(:array)
6
- @hash = s(:hash)
7
- @const = s(:const, nil, :A)
8
- @path = s(:const, s(:const, nil, :A), :B)
9
- end
10
-
11
- example 'check if an object is an array' do
12
- @array.array?.should == true
13
- end
14
-
15
- example 'check if an object is a hash' do
16
- @hash.hash?.should == true
17
- end
18
-
19
- example 'check if an object is a constant' do
20
- @const.constant?.should == true
21
- end
22
-
23
- example 'check if an object is a constant path' do
24
- @path.constant_path?.should == true
25
- end
26
-
27
- example 'return the Ruby class of an object' do
28
- @array.ruby_class.should == 'Array'
29
- end
30
- end
@@ -1,55 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe RubyLint::VirtualMachine do
4
- describe 'alias' do
5
- example 'alias methods' do
6
- code = <<-CODE
7
- def bar
8
- end
9
-
10
- alias foo bar
11
- CODE
12
-
13
- defs = build_definitions(code)
14
-
15
- defs.lookup(:instance_method, 'bar').is_a?(ruby_method).should == true
16
- defs.lookup(:instance_method, 'foo').is_a?(ruby_method).should == true
17
- end
18
-
19
- example 'alias methods using symbols' do
20
- code = <<-CODE
21
- def bar
22
- end
23
-
24
- alias :foo :bar
25
- CODE
26
-
27
- defs = build_definitions(code)
28
-
29
- defs.lookup(:instance_method, 'bar').is_a?(ruby_method).should == true
30
- defs.lookup(:instance_method, 'foo').is_a?(ruby_method).should == true
31
- end
32
-
33
- example 'alias methods using alias_method' do
34
- code = <<-CODE
35
- def bar
36
- end
37
-
38
- alias_method :foo, :bar
39
- CODE
40
-
41
- defs = build_definitions(code)
42
-
43
- defs.lookup(:instance_method, 'bar').is_a?(ruby_method).should == true
44
- defs.lookup(:instance_method, 'foo').is_a?(ruby_method).should == true
45
- end
46
-
47
- example 'alias global variables' do
48
- code = 'alias $ARGV $*'
49
- defs = build_definitions(code)
50
-
51
- defs.lookup(:gvar, '$*').is_a?(ruby_object).should == true
52
- defs.lookup(:gvar, '$ARGV').is_a?(ruby_object).should == true
53
- end
54
- end
55
- end
@@ -1,87 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe RubyLint::VirtualMachine do
4
- describe 'array assignments' do
5
- example 'assign an empty array' do
6
- defs = build_definitions('numbers = []')
7
- value = defs.lookup(:lvar, 'numbers').value
8
-
9
- value.type.should == :array
10
- value.instance?.should == true
11
-
12
- value.has_definition?(:instance_method, 'each').should == true
13
- end
14
-
15
- example 'assign an array with values' do
16
- defs = build_definitions('numbers = [10, 20]')
17
- array = defs.lookup(:lvar, 'numbers').value
18
- members = [10, 20]
19
-
20
- members.each_with_index do |value, index|
21
- index = index.to_s
22
- member = array.lookup(:member, index)
23
-
24
- member.name.should == index
25
- member.value.type.should == :int
26
- member.value.value.should == value
27
- end
28
- end
29
-
30
- example 'process single index assignments' do
31
- code = <<-CODE
32
- numbers = []
33
- numbers[0] = 10
34
- CODE
35
-
36
- defs = build_definitions(code)
37
- numbers = defs.lookup(:lvar, 'numbers')
38
-
39
- numbers.is_a?(ruby_object).should == true
40
- numbers.value.is_a?(ruby_object).should == true
41
- numbers.value.type.should == :array
42
-
43
- first = numbers.value.lookup(:member, '0')
44
-
45
- first.type.should == :member
46
- first.name.should == '0'
47
-
48
- first.value.is_a?(ruby_object).should == true
49
- first.value.type.should == :int
50
- first.value.value.should == 10
51
- end
52
-
53
- example 'process multiple index assignments' do
54
- code = <<-CODE
55
- numbers = []
56
- numbers[0,1] = 10
57
- numbers[2,3] = 20, 30
58
- numbers[4,5,6] = 40, 50
59
- CODE
60
-
61
- defs = build_definitions(code)
62
- numbers = defs.lookup(:lvar, 'numbers').value
63
-
64
- numbers.lookup(:member, '0').value.value.should == 10
65
- numbers.lookup(:member, '1').value.should == nil
66
- numbers.lookup(:member, '2').value.value.should == 20
67
- numbers.lookup(:member, '3').value.value.should == 30
68
- numbers.lookup(:member, '4').value.value.should == 40
69
- numbers.lookup(:member, '5').value.value.should == 50
70
- numbers.lookup(:member, '6').value.should == nil
71
- end
72
-
73
- example 'process index assignments using variables' do
74
- code = <<-CODE
75
- index = 1
76
- numbers = [10]
77
- numbers[index] = 20
78
- CODE
79
-
80
- defs = build_definitions(code)
81
- numbers = defs.lookup(:lvar, 'numbers').value
82
-
83
- numbers.lookup(:member, '0').value.value.should == 10
84
- numbers.lookup(:member, '1').value.value.should == 20
85
- end
86
- end
87
- end
@@ -1,14 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe RubyLint::VirtualMachine do
4
- context 'variable assignments as method arguments' do
5
- example 'assign a local variable in a method argument' do
6
- code = 'puts(number = 10)'
7
- defs = build_definitions(code)
8
- value = defs.lookup(:lvar, 'number').value
9
-
10
- value.type.should == :int
11
- value.value.should == 10
12
- end
13
- end
14
- end
@@ -1,23 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe RubyLint::VirtualMachine do
4
- context 'constants and local variables' do
5
- # https://github.com/YorickPeterse/ruby-lint/issues/60
6
- example 'access a constant path using a local variable' do
7
- code = <<-CODE
8
- module Example
9
- NUMBER = 10
10
- end
11
-
12
- const = Example
13
- string = const::NUMBER
14
- CODE
15
-
16
- defs = build_definitions(code)
17
- value = defs.lookup(:lvar, 'string').value
18
-
19
- value.type.should == :int
20
- value.value.should == 10
21
- end
22
- end
23
- end
@@ -1,52 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe RubyLint::VirtualMachine do
4
- describe 'hash assignments' do
5
- example 'assign an empty hash' do
6
- defs = build_definitions('numbers = {}')
7
- value = defs.lookup(:lvar, 'numbers').value
8
-
9
- value.type.should == :hash
10
- value.instance?.should == true
11
-
12
- value.has_definition?(:instance_method, 'each').should == true
13
- end
14
-
15
- example 'assign a hash with values' do
16
- defs = build_definitions('numbers = {:one => 1, :two => 2}')
17
- hash = defs.lookup(:lvar, 'numbers').value
18
- members = {'one' => 1, 'two' => 2}
19
-
20
- members.each do |name, value|
21
- member = hash.lookup(:member, name)
22
-
23
- member.name.should == name
24
- member.value.type.should == :int
25
- member.value.value.should == value
26
- end
27
- end
28
-
29
- example 'process single key assignments' do
30
- defs = build_definitions('numbers = {}; numbers[:one] = 1')
31
- hash = defs.lookup(:lvar, 'numbers').value
32
- member = hash.lookup(:member, 'one')
33
-
34
- member.value.type.should == :int
35
- member.value.value.should == 1
36
- end
37
-
38
- example 'process key assignments using variables' do
39
- code = <<-CODE
40
- key = :two
41
- numbers = {:one => 1}
42
- numbers[key] = 2
43
- CODE
44
-
45
- defs = build_definitions(code)
46
- hash = defs.lookup(:lvar, 'numbers').value
47
-
48
- hash.lookup(:member, 'one').value.value.should == 1
49
- hash.lookup(:member, 'two').value.value.should == 2
50
- end
51
- end
52
- end
@@ -1,41 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe 'Building variable definitions' do
4
- describe 'OR assignments' do
5
- example 'assign a non existing local variable' do
6
- defs = build_definitions('number ||= 10')
7
-
8
- defs.lookup(:lvar, 'number').value.value.should == 10
9
- end
10
-
11
- example 'not overwrite an existing variable' do
12
- code = <<-CODE
13
- number = 10
14
- number ||= 20
15
- CODE
16
-
17
- defs = build_definitions(code)
18
-
19
- defs.lookup(:lvar, 'number').value.value.should == 10
20
- end
21
- end
22
-
23
- describe 'AND assignments' do
24
- example 'not assign a non existing local variable' do
25
- defs = build_definitions('number &&= 10')
26
-
27
- defs.lookup(:lvar, 'number').nil?.should == true
28
- end
29
-
30
- example 'overwrite an existing variable' do
31
- code = <<-CODE
32
- number = 10
33
- number &&= 20
34
- CODE
35
-
36
- defs = build_definitions(code)
37
-
38
- defs.lookup(:lvar, 'number').value.value.should == 20
39
- end
40
- end
41
- end
@@ -1,28 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe RubyLint::VirtualMachine do
4
- context 'Range definitions' do
5
- example 'assign an inclusive range to a variable' do
6
- defs = build_definitions('numbers = (0..10)')
7
- val = defs.lookup(:lvar, 'numbers').value
8
-
9
- val.type.should == :irange
10
- val.ruby_class.should == 'Range'
11
- end
12
-
13
- example 'assign an exclusive range to a variable' do
14
- defs = build_definitions('numbers = (0...10)')
15
- val = defs.lookup(:lvar, 'numbers').value
16
-
17
- val.type.should == :erange
18
- val.ruby_class.should == 'Range'
19
- end
20
-
21
- example 'associate a Range with the correct built-in definition' do
22
- defs = build_definitions('numbers = (0...10)')
23
- val = defs.lookup(:lvar, 'numbers').value
24
-
25
- val.has_definition?(:instance_method, 'cover?').should == true
26
- end
27
- end
28
- end