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,135 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe RubyLint::Definition::RubyObject do
4
- before do
5
- @first = ruby_object.new(:name => 'First', :type => :const)
6
- end
7
-
8
- describe 'definining constants using a DSL' do
9
- example 'define a constant' do
10
- @first.define_constant('B')
11
-
12
- @first.lookup(:const, 'B').is_a?(ruby_object).should == true
13
- end
14
-
15
- example 'define a constant using a block' do
16
- @first.define_constant('B') do |b|
17
- b.define_constant('C')
18
- end
19
-
20
- @first.lookup(:const, 'B') \
21
- .lookup(:const, 'C') \
22
- .is_a?(ruby_object) \
23
- .should == true
24
- end
25
-
26
- example 'inherit from another object' do
27
- @first.define_constant('B') do |b|
28
- b.define_constant('C')
29
- end
30
-
31
- @first.define_constant('D') do |d|
32
- d.inherits(@first.lookup(:const, 'B'))
33
- end
34
-
35
- @first.lookup(:const, 'D') \
36
- .lookup(:const, 'C') \
37
- .is_a?(ruby_object) \
38
- .should == true
39
- end
40
-
41
- example 'define a constant using a constant path' do
42
- @first.define_constant('A')
43
- @first.define_constant('A::B')
44
-
45
- @first.lookup(:const, 'A') \
46
- .lookup(:const, 'B') \
47
- .is_a?(ruby_object) \
48
- .should == true
49
- end
50
- end
51
-
52
- describe 'defining methods using a DSL' do
53
- example 'define a method' do
54
- @first.define_method('example')
55
-
56
- @first.lookup(:method, 'example').is_a?(ruby_method).should == true
57
- end
58
-
59
- example 'define an instance method' do
60
- @first.define_instance_method('example')
61
-
62
- @first.lookup(:instance_method, 'example') \
63
- .is_a?(ruby_method) \
64
- .should == true
65
- end
66
-
67
- example 'define a method\'s return value' do
68
- string = ruby_object.new(:type => :str, :value => 'hello')
69
-
70
- @first.define_method('example') do |example|
71
- example.returns(string)
72
- end
73
-
74
- @first.lookup(:method, 'example') \
75
- .return_value \
76
- .is_a?(ruby_object) \
77
- .should == true
78
- end
79
-
80
- example 'add a required argument' do
81
- arg = method_with_argument(@first, :argument).arguments.first
82
-
83
- arg.is_a?(ruby_object).should == true
84
- arg.name.should == 'number'
85
- end
86
-
87
- example 'add a optional argument' do
88
- arg = method_with_argument(@first, :optional_argument) \
89
- .optional_arguments \
90
- .first
91
-
92
- arg.is_a?(ruby_object).should == true
93
- arg.name.should == 'number'
94
- end
95
-
96
- example 'add a rest argument' do
97
- arg = method_with_argument(@first, :rest_argument).rest_argument
98
-
99
- arg.is_a?(ruby_object).should == true
100
- arg.name.should == 'number'
101
- end
102
-
103
- example 'add a block argument' do
104
- arg = method_with_argument(@first, :block_argument).block_argument
105
-
106
- arg.is_a?(ruby_object).should == true
107
- arg.name.should == 'number'
108
- end
109
-
110
- example 'easily define constructor methods' do
111
- @first.define_constructors do |method|
112
- method.define_argument('name')
113
- end
114
-
115
- @first.lookup(:method, 'new').arguments[0].name.should == 'name'
116
-
117
- @first.lookup(:instance_method, 'initialize') \
118
- .arguments[0] \
119
- .name \
120
- .should == 'name'
121
- end
122
- end
123
-
124
- describe 'defining global variables using a DSL' do
125
- example 'define a global variable' do
126
- @first.define_global_variable('$number', '10')
127
-
128
- found = @first.lookup(:gvar, '$number')
129
-
130
- found.is_a?(ruby_object).should == true
131
- found.type.should == :gvar
132
- found.name.should == '$number'
133
- end
134
- end
135
- end
@@ -1,106 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe RubyLint::Definition::Registry do
4
- before do
5
- @registry = RubyLint::Definition::Registry.new
6
- end
7
-
8
- context 'registering definitions' do
9
- example 'no definitions should be registered by default' do
10
- @registry.registered.empty?.should == true
11
- end
12
-
13
- example 'register a definition' do
14
- @registry.register('String') { }
15
-
16
- @registry.registered.key?('String').should == true
17
- end
18
- end
19
-
20
- context 'checking if definitions exist' do
21
- example 'check for a non existing definition' do
22
- @registry.include?('Foo').should == false
23
- end
24
-
25
- example 'check for an existing definition' do
26
- @registry.register('Foo') { }
27
-
28
- @registry.include?('Foo').should == true
29
- end
30
- end
31
-
32
- context 'retrieving definitions' do
33
- example 'raise when the constant does not exist' do
34
- lambda { @registry.get('Foo') }.should raise_error(ArgumentError)
35
- end
36
-
37
- example 'return the definition when it exists' do
38
- @registry.register('Foo') { }
39
-
40
- @registry.get('Foo').is_a?(Proc).should == true
41
- end
42
- end
43
-
44
- context 'applying definitions' do
45
- before do
46
- @root = ruby_object.new
47
-
48
- @registry.register('Foo') do |defs|
49
- defs.define_constant('Foo') do |foo|
50
- foo.define_method('bar')
51
- end
52
- end
53
-
54
- @registry.apply('Foo', @root)
55
- end
56
-
57
- example 'define the constant' do
58
- @root.has_definition?(:const, 'Foo').should == true
59
- end
60
-
61
- example 'define sub definitions correctly' do
62
- @root.lookup(:const, 'Foo')
63
- .has_definition?(:method, 'bar')
64
- .should == true
65
- end
66
-
67
- example 'do not overwrite existing definitions' do
68
- foo = @root.lookup(:const, 'Foo')
69
-
70
- @registry.apply('Foo', @root)
71
-
72
- @root.lookup(:const, 'Foo').should == foo
73
- end
74
- end
75
-
76
- context 'managing load paths' do
77
- before do
78
- @registry = RubyLint::Definition::Registry.new
79
- end
80
-
81
- example 'use the default load path' do
82
- @registry.load_path
83
- .should == RubyLint::Definition::Registry::DEFAULT_LOAD_PATH
84
- end
85
-
86
- example 'add a path to the load path' do
87
- @registry.load_path << 'foo'
88
-
89
- @registry.load_path.include?('foo').should == true
90
- end
91
- end
92
-
93
- context 'loading constant definitions from the load path' do
94
- before do
95
- RubyLint.registry.load('Rational')
96
- end
97
-
98
- example 'load the String constant' do
99
- RubyLint.registry.loaded_constants.include?('Rational').should == true
100
- end
101
-
102
- example 'register the String definition' do
103
- RubyLint.registry.include?('Rational').should == true
104
- end
105
- end
106
- end
@@ -1,106 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe RubyLint::Definition::RubyObject do
4
- context 'method definition DSL' do
5
- before do
6
- @method = ruby_method.new(:name => 'example', :type => :instance_method)
7
- end
8
-
9
- context 'return values' do
10
- example 'return a static value' do
11
- @method.returns(10)
12
-
13
- @method.return_value.should == 10
14
- end
15
-
16
- example 'return a value using a block' do
17
- @method.returns do
18
- 20
19
- end
20
-
21
- @method.return_value.is_a?(Proc).should == true
22
- @method.return_value.call.should == 20
23
- end
24
- end
25
-
26
- context 'calling methods' do
27
- before do
28
- @method.returns(10)
29
- end
30
-
31
- example 'call the method directly' do
32
- @method.call.should == 10
33
- end
34
-
35
- example 'call the method by name' do
36
- container = ruby_object.new(
37
- :name => 'String',
38
- :type => :const,
39
- :instance_type => :instance
40
- )
41
-
42
- container.add_definition(@method)
43
-
44
- container.call_method('example').should == 10
45
- end
46
-
47
- example 'raise for calling an undefined method' do
48
- container = ruby_object.new(
49
- :name => 'String',
50
- :type => :const,
51
- :instance_type => :instance
52
- )
53
-
54
- lambda { container.call_method('derp') }
55
- .should raise_error(NoMethodError, /undefined method derp for/i)
56
- end
57
- end
58
-
59
- context 'defining arguments' do
60
- example 'define an argument' do
61
- @method.define_argument('number')
62
-
63
- @method.lookup(:arg, 'number').is_a?(ruby_object).should == true
64
- @method.lookup(:lvar, 'number').is_a?(ruby_object).should == true
65
-
66
- @method.arguments[0].is_a?(ruby_object).should == true
67
- end
68
-
69
- example 'define an optional argument' do
70
- @method.define_optional_argument('number')
71
-
72
- @method.lookup(:optarg, 'number').is_a?(ruby_object).should == true
73
- @method.lookup(:lvar, 'number').is_a?(ruby_object).should == true
74
-
75
- @method.optional_arguments[0].is_a?(ruby_object).should == true
76
- end
77
-
78
- example 'define a rest argument' do
79
- @method.define_rest_argument('number')
80
-
81
- @method.lookup(:restarg, 'number').is_a?(ruby_object).should == true
82
- @method.lookup(:lvar, 'number').is_a?(ruby_object).should == true
83
-
84
- @method.rest_argument.is_a?(ruby_object).should == true
85
- end
86
-
87
- example 'define a block argument' do
88
- @method.define_block_argument('number')
89
-
90
- @method.lookup(:blockarg, 'number').is_a?(ruby_object).should == true
91
- @method.lookup(:lvar, 'number').is_a?(ruby_object).should == true
92
-
93
- @method.block_argument.is_a?(ruby_object).should == true
94
- end
95
-
96
- example 'define a keyword argument' do
97
- @method.define_keyword_argument('number')
98
-
99
- @method.lookup(:kwoptarg, 'number').is_a?(ruby_object).should == true
100
- @method.lookup(:lvar, 'number').is_a?(ruby_object).should == true
101
-
102
- @method.keyword_arguments[0].is_a?(ruby_object).should == true
103
- end
104
- end
105
- end
106
- end
@@ -1,264 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe ruby_object do
4
- before do
5
- value = ruby_object.new(
6
- :type => :int,
7
- :value => '10'
8
- )
9
-
10
- @object = ruby_object.new(
11
- :type => :lvar,
12
- :name => 'hello',
13
- :value => value
14
- )
15
- end
16
-
17
- example 'return the name of the object' do
18
- @object.name.should == 'hello'
19
- end
20
-
21
- example 'return the object type' do
22
- @object.type.should == :lvar
23
- end
24
-
25
- example 'return the value of the node' do
26
- @object.value.value.should == '10'
27
- end
28
-
29
- example 'only store RubyObject objects' do
30
- obj = ruby_object.new(
31
- :type => :lvar,
32
- :name => 'foo'
33
- )
34
-
35
- lambda { @object.add(:lvar, 'foo', 10) }.should raise_error(TypeError)
36
- lambda { @object.add(:lvar, 'foo', obj) }.should_not raise_error
37
- end
38
-
39
- example 'only add valid collection types' do
40
- obj = ruby_object.new(:name => 'Foo', :type => :test)
41
-
42
- lambda { @object.add_definition(obj) }.should raise_error(ArgumentError)
43
- end
44
-
45
- example 'look up a constant path' do
46
- first = ruby_object.new(:name => 'A', :type => :const)
47
- second = ruby_object.new(:name => 'B', :type => :const)
48
- third = ruby_object.new(:name => 'C', :type => :const)
49
-
50
- second.add_definition(third)
51
- first.add_definition(second)
52
-
53
- first.lookup_constant_path('B::C').should == third
54
- end
55
-
56
- example 'store a variable' do
57
- var = ruby_object.new(
58
- :type => :lvar,
59
- :name => 'number'
60
- )
61
-
62
- @object.add(:lvar, var.name, var)
63
-
64
- found = @object.lookup(:lvar, var.name)
65
-
66
- found.is_a?(ruby_object).should == true
67
-
68
- found.name.should == 'number'
69
- found.type.should == :lvar
70
- end
71
-
72
- example 'set the parent definitions' do
73
- var1 = ruby_object.new(
74
- :type => :lvar,
75
- :name => 'numberx',
76
- :value => '10'
77
- )
78
-
79
- var2 = ruby_object.new(
80
- :type => :lvar,
81
- :name => 'number',
82
- :value => '10',
83
- :parents => [var1]
84
- )
85
-
86
- var2.parents.length.should == 1
87
- end
88
-
89
- example 'retrieve parent definitions' do
90
- method = ruby_object.new(
91
- :type => :lvar,
92
- :name => 'example'
93
- )
94
-
95
- @object.add(:method, 'example', method)
96
-
97
- child = ruby_object.new(
98
- :type => :class,
99
- :name => 'Example',
100
- :parents => [@object]
101
- )
102
-
103
- found = child.lookup(:method, 'example')
104
-
105
- found.is_a?(ruby_object).should == true
106
-
107
- found.name.should == 'example'
108
- end
109
-
110
- example 'create a shim of a definition' do
111
- object = ruby_object.new(:type => :const, :name => 'Foo')
112
- shim = object.shim
113
-
114
- shim.name.should == object.name
115
- shim.parents.should == [object]
116
- end
117
-
118
- example 'create a RubyObject that represents an instance' do
119
- object = ruby_object.new(:type => :const, :name => 'String')
120
-
121
- object.instance_type.should == :class
122
-
123
- instance = object.instance
124
-
125
- instance.type.should == object.type
126
- instance.name.should == object.name
127
- instance.instance_type.should == :instance
128
- end
129
-
130
- example 'add data to a parent definition' do
131
- initial = ruby_object.new(
132
- :type => :lvar,
133
- :name => 'test',
134
- :value => '10'
135
- )
136
-
137
- copy = ruby_object.new(
138
- :type => :lvar,
139
- :name => 'test',
140
- :value => '20'
141
- )
142
-
143
- child_only = ruby_object.new(
144
- :type => :lvar,
145
- :name => 'child_only',
146
- :value => '30'
147
- )
148
-
149
- parent = ruby_object.new(:name => 'parent')
150
- child = ruby_object.new(
151
- :name => 'child',
152
- :update_parents => [:lvar],
153
- :parents => [parent]
154
- )
155
-
156
- parent.add(initial.type, initial.name, initial)
157
-
158
- child.add(initial.type, initial.name, initial)
159
- child.add(copy.type, copy.name, copy)
160
- child.add(child_only.type, child_only.name, child_only)
161
-
162
- child.lookup(initial.type, initial.name).should == copy
163
- parent.lookup(initial.type, initial.name).should == copy
164
-
165
- parent.lookup(child_only.type, child_only.name).nil?.should == true
166
- end
167
-
168
- example 'return the members as the definition value' do
169
- array = ruby_object.new(:type => :array, :members_as_value => true)
170
- values = [10, 20]
171
-
172
- values.each_with_index do |value, index|
173
- value = ruby_object.new(:type => :int, :value => value)
174
- member = ruby_object.new(
175
- :type => :member,
176
- :name => index.to_s,
177
- :value => value
178
- )
179
-
180
- array.add(member.type, member.name, member)
181
- end
182
-
183
- array.value.is_a?(Array).should == true
184
- array.value.length.should == 2
185
-
186
- values.each_with_index do |value, index|
187
- array.value[index].name.should == index.to_s
188
-
189
- array.value[index].value.type.should == :int
190
- array.value[index].value.value.should == value
191
- end
192
- end
193
-
194
- example 'merging two definitions' do
195
- source = ruby_object.new(:type => :const, :name => 'Source')
196
- target = ruby_object.new(:type => :const, :name => 'Target')
197
- const = ruby_object.new(:type => :const, :name => 'Foo')
198
-
199
- source.add_definition(const)
200
-
201
- target.merge(source)
202
-
203
- target.lookup(:const, 'Foo').should == const
204
- end
205
-
206
- example 'storing location information in a definition' do
207
- obj = ruby_object.new(:line => 10, :column => 3, :file => '(ruby-lint)')
208
-
209
- obj.line.should == 10
210
- obj.column.should == 3
211
- obj.file.should == '(ruby-lint)'
212
- end
213
-
214
- context 'defining self' do
215
- before do
216
- @class = ruby_object.new(:instance_type => :class)
217
- @instance = ruby_object.new(:instance_type => :instance)
218
-
219
- @class.define_self
220
- @instance.define_self
221
- end
222
-
223
- example 'define instance level self for an instance' do
224
- @instance.lookup(:instance_method, 'self')
225
- .return_value
226
- .should == @instance
227
- end
228
-
229
- example 'define class level self for an instance' do
230
- @instance.lookup(:method, 'self')
231
- .return_value
232
- .parents
233
- .should == [@instance]
234
- end
235
-
236
- example 'define instance level self for a class' do
237
- @class.lookup(:instance_method, 'self')
238
- .return_value
239
- .parents
240
- .should == [@class]
241
- end
242
-
243
- example 'define class level self for a class' do
244
- @class.lookup(:method, 'self').return_value.should == @class
245
- end
246
- end
247
-
248
- context 'constant proxies' do
249
- before do
250
- @root = ruby_object.new(:type => :const, :name => 'Foo')
251
- @proxy = @root.constant_proxy('Bar')
252
- end
253
-
254
- example 'create a constant proxy' do
255
- @proxy.is_a?(RubyLint::Definition::ConstantProxy).should == true
256
- end
257
-
258
- example 'point to the definition when it exists' do
259
- baz = @root.define_constant('Bar').define_constant('Baz')
260
-
261
- @proxy.lookup(:const, 'Baz').should == baz
262
- end
263
- end
264
- end