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.
- checksums.yaml +4 -4
- data/CONTRIBUTING.md +43 -29
- data/LICENSE +1 -1
- data/README.md +0 -1
- data/bin/ruby-lint +91 -3
- data/checksum/ruby-lint-1.1.0.gem.sha512 +1 -0
- data/doc/changelog.md +30 -0
- data/doc/code_analysis.md +13 -0
- data/doc/configuration.md +5 -24
- data/lib/ruby-lint.rb +7 -10
- data/lib/ruby-lint/analysis/argument_amount.rb +2 -0
- data/lib/ruby-lint/analysis/base.rb +12 -0
- data/lib/ruby-lint/analysis/pedantics.rb +2 -0
- data/lib/ruby-lint/analysis/shadowing_variables.rb +2 -0
- data/lib/ruby-lint/analysis/undefined_methods.rb +5 -2
- data/lib/ruby-lint/analysis/undefined_variables.rb +2 -0
- data/lib/ruby-lint/analysis/unused_variables.rb +2 -0
- data/lib/ruby-lint/analysis/useless_equality_checks.rb +2 -0
- data/lib/ruby-lint/ast/node.rb +0 -15
- data/lib/ruby-lint/command.rb +100 -0
- data/lib/ruby-lint/configuration.rb +35 -66
- data/lib/ruby-lint/constant_path.rb +7 -2
- data/lib/ruby-lint/definition/ruby_object.rb +20 -6
- data/lib/ruby-lint/definitions/core/argf.rb +3 -3
- data/lib/ruby-lint/definitions/gems/minitest.rb +792 -0
- data/lib/ruby-lint/file_list.rb +1 -1
- data/lib/ruby-lint/file_loader.rb +2 -20
- data/lib/ruby-lint/file_scanner.rb +11 -2
- data/lib/ruby-lint/method_evaluation.rb +21 -0
- data/lib/ruby-lint/presenter/base.rb +18 -0
- data/lib/ruby-lint/presenter/json.rb +3 -1
- data/lib/ruby-lint/presenter/syntastic.rb +3 -1
- data/lib/ruby-lint/presenter/text.rb +3 -1
- data/lib/ruby-lint/runner.rb +6 -63
- data/lib/ruby-lint/variable_predicates.rb +3 -3
- data/lib/ruby-lint/version.rb +1 -1
- data/lib/ruby-lint/virtual_machine.rb +4 -1
- data/ruby-lint.gemspec +13 -4
- metadata +12 -187
- data/.editorconfig +0 -15
- data/.gitignore +0 -6
- data/.ruby-version +0 -1
- data/.travis.yml +0 -19
- data/Gemfile +0 -15
- data/MANIFEST +0 -469
- data/Rakefile +0 -25
- data/benchmark/bootup.rb +0 -13
- data/benchmark/virtual_machine.rb +0 -17
- data/checksum/.gitkeep +0 -0
- data/doc/.gitkeep +0 -0
- data/doc/css/.gitkeep +0 -0
- data/doc/images/.gitkeep +0 -0
- data/gen/rails/constants.txt +0 -12
- data/gen/rails/requires.rb +0 -2
- data/gen/stdlib/constants.rb +0 -30
- data/gen/stdlib/constants.txt +0 -214
- data/gen/stdlib/requires.rb +0 -64
- data/lib/ruby-lint/benchmark/average.rb +0 -115
- data/lib/ruby-lint/cache.rb +0 -121
- data/lib/ruby-lint/cache_entry.rb +0 -44
- data/lib/ruby-lint/cli.rb +0 -4
- data/lib/ruby-lint/cli/analyze.rb +0 -209
- data/lib/ruby-lint/cli/base.rb +0 -103
- data/lib/ruby-lint/cli/cache.rb +0 -60
- data/lib/ruby-lint/default_names.rb +0 -19
- data/lib/ruby-lint/definitions/gems/.gitkeep +0 -0
- data/lib/ruby-lint/node_hash.rb +0 -105
- data/misc/stdlib.rb +0 -66
- data/profiling/virtual_machine.rb +0 -20
- data/ruby-lint.yml +0 -7
- data/spec/fixtures/associating.rb +0 -7
- data/spec/fixtures/complex/rails/basic_controller.rb +0 -9
- data/spec/fixtures/complex/rcap.rb +0 -67
- data/spec/fixtures/complex/slop.rb +0 -701
- data/spec/fixtures/config.yml +0 -8
- data/spec/fixtures/deeply/nested/file.rb +0 -1
- data/spec/fixtures/file_scanner/lib/example/recursive/source.rb +0 -6
- data/spec/fixtures/file_scanner/lib/example/recursive/target.rb +0 -8
- data/spec/fixtures/file_scanner/lib/example/user.rb +0 -6
- data/spec/fixtures/file_scanner/lib/ruby-lint/definition/constant_proxy.rb +0 -6
- data/spec/fixtures/file_scanner/lib/ruby-lint/global_scope.rb +0 -6
- data/spec/fixtures/file_scanner/lib/test-dashes/foo.rb +0 -4
- data/spec/fixtures/file_scanner/rails/app/models/example/user.rb +0 -6
- data/spec/fixtures/file_scanner/rails/app/models/user.rb +0 -4
- data/spec/fixtures/invalid.rb +0 -3
- data/spec/fixtures/invalid_2.rb +0 -3
- data/spec/fixtures/syntax_error.rb +0 -1
- data/spec/fixtures/uses_external.rb +0 -1
- data/spec/fixtures/uses_external_invalid.rb +0 -3
- data/spec/fixtures/uses_external_namespace.rb +0 -1
- data/spec/fixtures/valid.rb +0 -3
- data/spec/ruby-lint/analysis/argument_amount_spec.rb +0 -131
- data/spec/ruby-lint/analysis/base_spec.rb +0 -24
- data/spec/ruby-lint/analysis/pedantics_spec.rb +0 -63
- data/spec/ruby-lint/analysis/shadowing_variables_spec.rb +0 -85
- data/spec/ruby-lint/analysis/undefined_methods_spec.rb +0 -337
- data/spec/ruby-lint/analysis/undefined_variables_spec.rb +0 -138
- data/spec/ruby-lint/analysis/unused_variables_spec.rb +0 -270
- data/spec/ruby-lint/analysis/useless_equality_checks_spec.rb +0 -107
- data/spec/ruby-lint/ast/node_spec.rb +0 -39
- data/spec/ruby-lint/cache_entry_spec.rb +0 -25
- data/spec/ruby-lint/cache_spec.rb +0 -53
- data/spec/ruby-lint/cli/analyze_spec.rb +0 -52
- data/spec/ruby-lint/configuration_spec.rb +0 -126
- data/spec/ruby-lint/constant_loader_spec.rb +0 -79
- data/spec/ruby-lint/constant_path.rb +0 -63
- data/spec/ruby-lint/definition/constant_proxy_spec.rb +0 -85
- data/spec/ruby-lint/definition/dsl_spec.rb +0 -135
- data/spec/ruby-lint/definition/registry_spec.rb +0 -106
- data/spec/ruby-lint/definition/ruby_method_spec.rb +0 -106
- data/spec/ruby-lint/definition/ruby_object_spec.rb +0 -264
- data/spec/ruby-lint/definition_builder/primitive_spec.rb +0 -62
- data/spec/ruby-lint/definition_builder/ruby_class_spec.rb +0 -107
- data/spec/ruby-lint/definition_builder/ruby_method_spec.rb +0 -53
- data/spec/ruby-lint/definition_builder/ruby_module_spec.rb +0 -52
- data/spec/ruby-lint/definitions/argv_spec.rb +0 -18
- data/spec/ruby-lint/definitions/env_spec.rb +0 -13
- data/spec/ruby-lint/definitions/file_spec.rb +0 -17
- data/spec/ruby-lint/definitions/fixnum_spec.rb +0 -18
- data/spec/ruby-lint/definitions/io_spec.rb +0 -15
- data/spec/ruby-lint/definitions/kernel_spec.rb +0 -18
- data/spec/ruby-lint/definitions/range_spec.rb +0 -21
- data/spec/ruby-lint/definitions/string_spec.rb +0 -20
- data/spec/ruby-lint/docstring/mapping.rb +0 -27
- data/spec/ruby-lint/docstring/parser_spec.rb +0 -88
- data/spec/ruby-lint/extensions/string_spec.rb +0 -7
- data/spec/ruby-lint/file_list_spec.rb +0 -25
- data/spec/ruby-lint/file_loader_spec.rb +0 -69
- data/spec/ruby-lint/file_scanner_spec.rb +0 -84
- data/spec/ruby-lint/inspector_spec.rb +0 -224
- data/spec/ruby-lint/iterator_spec.rb +0 -151
- data/spec/ruby-lint/method_call/.gitkeep +0 -0
- data/spec/ruby-lint/nested_stack_spec.rb +0 -23
- data/spec/ruby-lint/node_hash_spec.rb +0 -56
- data/spec/ruby-lint/parser_spec.rb +0 -38
- data/spec/ruby-lint/presenter/json_spec.rb +0 -58
- data/spec/ruby-lint/presenter/syntastic_spec.rb +0 -49
- data/spec/ruby-lint/presenter/text_spec.rb +0 -49
- data/spec/ruby-lint/report/entry_spec.rb +0 -58
- data/spec/ruby-lint/report_spec.rb +0 -39
- data/spec/ruby-lint/runner_spec.rb +0 -74
- data/spec/ruby-lint/variable_predicates_spec.rb +0 -30
- data/spec/ruby-lint/virtual_machine/alias_spec.rb +0 -55
- data/spec/ruby-lint/virtual_machine/assignments/arrays_spec.rb +0 -87
- data/spec/ruby-lint/virtual_machine/assignments/assignment_arguments_spec.rb +0 -14
- data/spec/ruby-lint/virtual_machine/assignments/constants_spec.rb +0 -23
- data/spec/ruby-lint/virtual_machine/assignments/hashes_spec.rb +0 -52
- data/spec/ruby-lint/virtual_machine/assignments/optional_spec.rb +0 -41
- data/spec/ruby-lint/virtual_machine/assignments/range_spec.rb +0 -28
- data/spec/ruby-lint/virtual_machine/assignments/return_values_spec.rb +0 -78
- data/spec/ruby-lint/virtual_machine/assignments/variables_spec.rb +0 -130
- data/spec/ruby-lint/virtual_machine/associate_nodes_spec.rb +0 -61
- data/spec/ruby-lint/virtual_machine/autoloading_spec.rb +0 -18
- data/spec/ruby-lint/virtual_machine/blocks_spec.rb +0 -90
- data/spec/ruby-lint/virtual_machine/classes/class_methods_spec.rb +0 -21
- data/spec/ruby-lint/virtual_machine/classes/extending_spec.rb +0 -109
- data/spec/ruby-lint/virtual_machine/classes/redefining_spec.rb +0 -51
- data/spec/ruby-lint/virtual_machine/classes/sclass_spec.rb +0 -96
- data/spec/ruby-lint/virtual_machine/classes/scoping_spec.rb +0 -60
- data/spec/ruby-lint/virtual_machine/complex/rails_spec.rb +0 -21
- data/spec/ruby-lint/virtual_machine/complex/rcap_spec.rb +0 -15
- data/spec/ruby-lint/virtual_machine/complex/slop_spec.rb +0 -16
- data/spec/ruby-lint/virtual_machine/constants_spec.rb +0 -31
- data/spec/ruby-lint/virtual_machine/for_spec.rb +0 -16
- data/spec/ruby-lint/virtual_machine/freeze_spec.rb +0 -13
- data/spec/ruby-lint/virtual_machine/global_variables_spec.rb +0 -15
- data/spec/ruby-lint/virtual_machine/inherit_kernel_spec.rb +0 -15
- data/spec/ruby-lint/virtual_machine/interpolation_spec.rb +0 -12
- data/spec/ruby-lint/virtual_machine/location_spec.rb +0 -64
- data/spec/ruby-lint/virtual_machine/method_call_tracking_spec.rb +0 -57
- data/spec/ruby-lint/virtual_machine/methods/attr_spec.rb +0 -182
- data/spec/ruby-lint/virtual_machine/methods/calls_spec.rb +0 -25
- data/spec/ruby-lint/virtual_machine/methods/define_method_spec.rb +0 -41
- data/spec/ruby-lint/virtual_machine/methods/defining_spec.rb +0 -40
- data/spec/ruby-lint/virtual_machine/methods/docstrings_spec.rb +0 -80
- data/spec/ruby-lint/virtual_machine/methods/exporting_spec.rb +0 -19
- data/spec/ruby-lint/virtual_machine/methods/kernel_spec.rb +0 -25
- data/spec/ruby-lint/virtual_machine/methods/parameters_spec.rb +0 -89
- data/spec/ruby-lint/virtual_machine/methods/patching_spec.rb +0 -20
- data/spec/ruby-lint/virtual_machine/methods/scoping_spec.rb +0 -63
- data/spec/ruby-lint/virtual_machine/methods/square_bracket_spec.rb +0 -32
- data/spec/ruby-lint/virtual_machine/methods/visibility_spec.rb +0 -64
- data/spec/ruby-lint/virtual_machine/modules_spec.rb +0 -205
- data/spec/ruby-lint/virtual_machine/reference_amount_spec.rb +0 -81
- data/spec/ruby-lint/virtual_machine/self_spec.rb +0 -37
- data/spec/ruby-lint/virtual_machine/unused_spec.rb +0 -17
- data/spec/spec_helper.rb +0 -28
- data/spec/support/building.rb +0 -50
- data/spec/support/coveralls.rb +0 -5
- data/spec/support/definitions.rb +0 -39
- data/spec/support/fixtures.rb +0 -20
- data/spec/support/parsing.rb +0 -30
- data/spec/support/simplecov.rb +0 -18
- data/spec/support/versions.rb +0 -9
- data/task/build.rake +0 -4
- data/task/checksum.rake +0 -13
- data/task/coverage.rake +0 -6
- data/task/doc.rake +0 -16
- data/task/generate.rake +0 -77
- data/task/graphviz.rake +0 -12
- data/task/manifest.rake +0 -8
- data/task/tag.rake +0 -6
- data/task/test.rake +0 -4
- data/task/todo.rake +0 -6
- data/task/travis.rake +0 -8
@@ -1,88 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe RubyLint::Docstring::Parser do
|
4
|
-
let(:parser) { RubyLint::Docstring::Parser.new }
|
5
|
-
|
6
|
-
context '@param tags' do
|
7
|
-
example 'parse a tag with just the parameter name' do
|
8
|
-
comments = ['# @param number']
|
9
|
-
tag = parser.parse(comments)[0]
|
10
|
-
|
11
|
-
tag.is_a?(RubyLint::Docstring::ParamTag).should == true
|
12
|
-
|
13
|
-
tag.name.should == 'number'
|
14
|
-
end
|
15
|
-
|
16
|
-
example 'parse a tag with a parameter name and description' do
|
17
|
-
comments = ['# @param number The number.']
|
18
|
-
tag = parser.parse(comments)[0]
|
19
|
-
|
20
|
-
tag.name.should == 'number'
|
21
|
-
tag.description.should == 'The number.'
|
22
|
-
end
|
23
|
-
|
24
|
-
example 'parse a tag with a type' do
|
25
|
-
comments = ['# @param [Numeric] number']
|
26
|
-
tag = parser.parse(comments)[0]
|
27
|
-
|
28
|
-
tag.name.should == 'number'
|
29
|
-
tag.types.should == ['Numeric']
|
30
|
-
end
|
31
|
-
|
32
|
-
example 'parse a tag with a type and description' do
|
33
|
-
comments = ['# @param [Numeric] number The number.']
|
34
|
-
tag = parser.parse(comments)[0]
|
35
|
-
|
36
|
-
tag.name.should == 'number'
|
37
|
-
tag.types.should == ['Numeric']
|
38
|
-
tag.description.should == 'The number.'
|
39
|
-
end
|
40
|
-
|
41
|
-
example 'parse a tag with a compound type' do
|
42
|
-
comments = ['# @param [Array<String>] names The names']
|
43
|
-
tag = parser.parse(comments)[0]
|
44
|
-
|
45
|
-
tag.name.should == 'names'
|
46
|
-
tag.description.should == 'The names'
|
47
|
-
tag.types.should == ['Array']
|
48
|
-
end
|
49
|
-
|
50
|
-
example 'should parse a tag with a namespace in it' do
|
51
|
-
comments = ['# @param [Foo::Bar] baz']
|
52
|
-
tag = parser.parse(comments)[0]
|
53
|
-
|
54
|
-
tag.name.should == 'baz'
|
55
|
-
tag.types.should == ['Foo::Bar']
|
56
|
-
end
|
57
|
-
end
|
58
|
-
|
59
|
-
context '@return tags' do
|
60
|
-
example 'parse a tag with just the type' do
|
61
|
-
comments = ['# @return [Numeric]']
|
62
|
-
tag = parser.parse(comments)[0]
|
63
|
-
|
64
|
-
tag.is_a?(RubyLint::Docstring::ReturnTag).should == true
|
65
|
-
|
66
|
-
tag.description.nil?.should == true
|
67
|
-
tag.types.should == ['Numeric']
|
68
|
-
end
|
69
|
-
|
70
|
-
example 'parse a tag with the type and description' do
|
71
|
-
comments = ['# @return [Numeric] The number.']
|
72
|
-
tag = parser.parse(comments)[0]
|
73
|
-
|
74
|
-
tag.is_a?(RubyLint::Docstring::ReturnTag).should == true
|
75
|
-
|
76
|
-
tag.types.should == ['Numeric']
|
77
|
-
tag.description.should == 'The number.'
|
78
|
-
end
|
79
|
-
|
80
|
-
example 'parse a tag with the description' do
|
81
|
-
comments = ['# @return Hello']
|
82
|
-
tag = parser.parse(comments)[0]
|
83
|
-
|
84
|
-
tag.types.should == []
|
85
|
-
tag.description.should == 'Hello'
|
86
|
-
end
|
87
|
-
end
|
88
|
-
end
|
@@ -1,25 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe RubyLint::FileList do
|
4
|
-
before :all do
|
5
|
-
@list = RubyLint::FileList.new
|
6
|
-
end
|
7
|
-
|
8
|
-
example 'list a set of files' do
|
9
|
-
path = fixture_path('valid.rb')
|
10
|
-
|
11
|
-
@list.process([path]).should == [path]
|
12
|
-
end
|
13
|
-
|
14
|
-
example 'list a set of directories' do
|
15
|
-
@list.process([fixture_path('deeply')]).should == [
|
16
|
-
fixture_path('deeply/nested/file.rb')
|
17
|
-
]
|
18
|
-
end
|
19
|
-
|
20
|
-
example 'raise for non existing files' do
|
21
|
-
block = lambda { @list.process(['yeah-right']) }
|
22
|
-
|
23
|
-
block.should raise_error(Errno::ENOENT)
|
24
|
-
end
|
25
|
-
end
|
@@ -1,69 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe RubyLint::FileLoader do
|
4
|
-
before :all do
|
5
|
-
@rails_dir = fixture_path('file_scanner/rails')
|
6
|
-
@lib_dir = fixture_path('file_scanner/lib')
|
7
|
-
end
|
8
|
-
|
9
|
-
context 'rails projects' do
|
10
|
-
example 'finding a class' do
|
11
|
-
loader = RubyLint::FileLoader.new(:directories => [@rails_dir])
|
12
|
-
ast = parse('User')
|
13
|
-
|
14
|
-
loader.iterate(ast)
|
15
|
-
|
16
|
-
loader.nodes.empty?.should == false
|
17
|
-
|
18
|
-
const = loader.nodes[1][0].children[0]
|
19
|
-
|
20
|
-
const.file
|
21
|
-
.should == fixture_path('file_scanner/rails/app/models/user.rb')
|
22
|
-
end
|
23
|
-
|
24
|
-
example 'finding a namespaced class' do
|
25
|
-
loader = RubyLint::FileLoader.new(:directories => [@rails_dir])
|
26
|
-
ast = parse('Example::User')
|
27
|
-
|
28
|
-
loader.iterate(ast)
|
29
|
-
|
30
|
-
loader.nodes.empty?.should == false
|
31
|
-
|
32
|
-
const = loader.nodes[1][0].children[0]
|
33
|
-
|
34
|
-
const.file
|
35
|
-
.should == fixture_path('file_scanner/rails/app/models/example/user.rb')
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
|
-
context 'regular Ruby projects' do
|
40
|
-
example 'finding a class' do
|
41
|
-
loader = RubyLint::FileLoader.new(:directories => [@lib_dir])
|
42
|
-
ast = parse('Example::User')
|
43
|
-
|
44
|
-
loader.iterate(ast)
|
45
|
-
|
46
|
-
loader.nodes.empty?.should == false
|
47
|
-
|
48
|
-
const = loader.nodes[0][0].children[0]
|
49
|
-
|
50
|
-
const.file.should == fixture_path('file_scanner/lib/example/user.rb')
|
51
|
-
end
|
52
|
-
|
53
|
-
example 'recursively find dependencies' do
|
54
|
-
loader = RubyLint::FileLoader.new(:directories => [@lib_dir])
|
55
|
-
ast = parse('Example::Recursive::Source')
|
56
|
-
|
57
|
-
loader.iterate(ast)
|
58
|
-
|
59
|
-
nodes = loader.nodes.map do |pair|
|
60
|
-
pair[0].children[0]
|
61
|
-
end
|
62
|
-
|
63
|
-
nodes.length.should == 2
|
64
|
-
|
65
|
-
File.basename(nodes[0].file).should == 'target.rb'
|
66
|
-
File.basename(nodes[1].file).should == 'source.rb'
|
67
|
-
end
|
68
|
-
end
|
69
|
-
end
|
@@ -1,84 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe RubyLint::FileScanner do
|
4
|
-
before :all do
|
5
|
-
@rails_dir = fixture_path('file_scanner/rails')
|
6
|
-
@lib_dir = fixture_path('file_scanner/lib')
|
7
|
-
end
|
8
|
-
|
9
|
-
example 'raise when a non enumerable argument is given' do
|
10
|
-
lambda { RubyLint::FileScanner.new(10) }.should raise_error(TypeError)
|
11
|
-
end
|
12
|
-
|
13
|
-
example 'set the default directories' do
|
14
|
-
scanner = RubyLint::FileScanner.new
|
15
|
-
|
16
|
-
scanner.directories.empty?.should == false
|
17
|
-
end
|
18
|
-
|
19
|
-
example 'do not include non existing directories' do
|
20
|
-
app = File.join(Dir.pwd, 'app')
|
21
|
-
scanner = RubyLint::FileScanner.new
|
22
|
-
|
23
|
-
scanner.directories.include?(app).should == false
|
24
|
-
end
|
25
|
-
|
26
|
-
example 'glob Ruby source files in a single directory' do
|
27
|
-
scanner = RubyLint::FileScanner.new([@lib_dir])
|
28
|
-
|
29
|
-
scanner.glob_ruby_files.empty?.should == false
|
30
|
-
end
|
31
|
-
|
32
|
-
example 'glob Ruby source files in multiple directories' do
|
33
|
-
scanner = RubyLint::FileScanner.new([@lib_dir, @rails_dir])
|
34
|
-
|
35
|
-
scanner.glob_ruby_files.empty?.should == false
|
36
|
-
end
|
37
|
-
|
38
|
-
example 'finding a class' do
|
39
|
-
scanner = RubyLint::FileScanner.new([@lib_dir])
|
40
|
-
paths = scanner.scan('Example::User')
|
41
|
-
|
42
|
-
paths.should == [fixture_path('file_scanner/lib/example/user.rb')]
|
43
|
-
end
|
44
|
-
|
45
|
-
example 'finding a class using dashes for the directory names' do
|
46
|
-
scanner = RubyLint::FileScanner.new([@lib_dir])
|
47
|
-
paths = scanner.scan('TestDashes::Foo')
|
48
|
-
|
49
|
-
paths.should == [fixture_path('file_scanner/lib/test-dashes/foo.rb')]
|
50
|
-
end
|
51
|
-
|
52
|
-
example 'finding a class using a Rails structure' do
|
53
|
-
scanner = RubyLint::FileScanner.new([@rails_dir])
|
54
|
-
paths = scanner.scan('User')
|
55
|
-
|
56
|
-
paths.should == [
|
57
|
-
fixture_path('file_scanner/rails/app/models/user.rb'),
|
58
|
-
fixture_path('file_scanner/rails/app/models/example/user.rb')
|
59
|
-
]
|
60
|
-
end
|
61
|
-
|
62
|
-
example 'finding a namespaced class using a Rails structure' do
|
63
|
-
scanner = RubyLint::FileScanner.new([@rails_dir])
|
64
|
-
paths = scanner.scan('Example::User')
|
65
|
-
|
66
|
-
paths.should == [
|
67
|
-
fixture_path('file_scanner/rails/app/models/example/user.rb')
|
68
|
-
]
|
69
|
-
end
|
70
|
-
|
71
|
-
example 'ignoring directories' do
|
72
|
-
scanner = RubyLint::FileScanner.new([@lib_dir], [@lib_dir])
|
73
|
-
|
74
|
-
scanner.scan('Example::User').empty?.should == true
|
75
|
-
end
|
76
|
-
|
77
|
-
example 'do not scan when there are no directories' do
|
78
|
-
scanner = RubyLint::FileScanner.new([])
|
79
|
-
|
80
|
-
scanner.should_not receive(:glob_ruby_files)
|
81
|
-
|
82
|
-
scanner.scan('Foo')
|
83
|
-
end
|
84
|
-
end
|
@@ -1,224 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe RubyLint::Inspector do
|
4
|
-
context 'inspecting constants' do
|
5
|
-
before :all do
|
6
|
-
inspector = RubyLint::Inspector.new(Encoding)
|
7
|
-
@constants = inspector.inspect_constants
|
8
|
-
end
|
9
|
-
|
10
|
-
example 'include the source constant' do
|
11
|
-
@constants.include?('Encoding').should == true
|
12
|
-
end
|
13
|
-
|
14
|
-
example 'include the child constants' do
|
15
|
-
@constants.include?('Encoding::BINARY').should == true
|
16
|
-
@constants.include?('Encoding::ASCII_8BIT').should == true
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
context 'ignoring duplicates' do
|
21
|
-
before :all do
|
22
|
-
inspector = RubyLint::Inspector.new(Encoding)
|
23
|
-
@constants = inspector.inspect_constants(
|
24
|
-
inspector.constant,
|
25
|
-
['Encoding::BINARY']
|
26
|
-
)
|
27
|
-
end
|
28
|
-
|
29
|
-
example 'ignore duplicates' do
|
30
|
-
@constants.include?('Encoding::BINARY').should == false
|
31
|
-
end
|
32
|
-
|
33
|
-
example 'include other constants' do
|
34
|
-
@constants.include?('Encoding::ASCII_8BIT').should == true
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
context 'dealing with recursive constant lists' do
|
39
|
-
before :all do
|
40
|
-
# This ignores all constants except those defined on the right hand side
|
41
|
-
# of the subtraction. This speeds up the tests quite a bit (we don't care
|
42
|
-
# about constants such as CGI and Parser in this case).
|
43
|
-
ignore = Object.constants.map(&:to_s) - %w{Object Class Module Encoding}
|
44
|
-
|
45
|
-
inspector = RubyLint::Inspector.new(Object)
|
46
|
-
@constants = inspector.inspect_constants(inspector.constant, ignore)
|
47
|
-
end
|
48
|
-
|
49
|
-
example 'include Class and Module' do
|
50
|
-
@constants.include?('Class').should == true
|
51
|
-
@constants.include?('Module').should == true
|
52
|
-
end
|
53
|
-
|
54
|
-
example 'exclude recursive constants' do
|
55
|
-
@constants.include?('Class::Object').should == false
|
56
|
-
@constants.include?('Module::Object').should == false
|
57
|
-
end
|
58
|
-
|
59
|
-
example 'include other regular constants' do
|
60
|
-
@constants.include?('Encoding').should == true
|
61
|
-
@constants.include?('Encoding::BINARY').should == true
|
62
|
-
end
|
63
|
-
end
|
64
|
-
|
65
|
-
context 'Ruby implementation shenanigans' do
|
66
|
-
before :all do
|
67
|
-
mod = Module.new { include Enumerable }
|
68
|
-
|
69
|
-
inspector = RubyLint::Inspector.new(mod)
|
70
|
-
@constants = inspector.inspect_constants
|
71
|
-
end
|
72
|
-
|
73
|
-
# This test was added since Rubinius defines `Range::Enumerator` which is
|
74
|
-
# an alias of `Enumerable::Enumerator`.
|
75
|
-
example 'ignore constants from a different root constant' do
|
76
|
-
@constants.include?('Enumerable::Enumerator').should == false
|
77
|
-
end
|
78
|
-
end
|
79
|
-
|
80
|
-
context 'inspecting parent classes' do
|
81
|
-
before :all do
|
82
|
-
@inspector = RubyLint::Inspector.new(Object)
|
83
|
-
end
|
84
|
-
|
85
|
-
example 'return the parent class' do
|
86
|
-
@inspector.inspect_superclass.should == BasicObject
|
87
|
-
end
|
88
|
-
end
|
89
|
-
|
90
|
-
context 'inspecting anonymous parent classes' do
|
91
|
-
before :all do
|
92
|
-
parent = Class.new
|
93
|
-
klass = Class.new(parent)
|
94
|
-
|
95
|
-
@inspector = RubyLint::Inspector.new(klass)
|
96
|
-
end
|
97
|
-
|
98
|
-
example 'ignore anonymous parent classes' do
|
99
|
-
@inspector.inspect_superclass.nil?.should == true
|
100
|
-
end
|
101
|
-
end
|
102
|
-
|
103
|
-
context 'inspecting included modules' do
|
104
|
-
before :all do
|
105
|
-
klass = Class.new { include Enumerable }
|
106
|
-
child = Class.new(klass) { include Enumerable }
|
107
|
-
|
108
|
-
@modules = RubyLint::Inspector.new(klass).inspect_modules
|
109
|
-
@child_modules = RubyLint::Inspector.new(child).inspect_modules
|
110
|
-
end
|
111
|
-
|
112
|
-
example 'include Enumerable' do
|
113
|
-
@modules.include?(Enumerable).should == true
|
114
|
-
end
|
115
|
-
|
116
|
-
example 'ignore modules that are already included in the parent' do
|
117
|
-
@child_modules.empty?.should == true
|
118
|
-
end
|
119
|
-
end
|
120
|
-
|
121
|
-
context 'inspecing included modules with anonymous modules' do
|
122
|
-
before :all do
|
123
|
-
mod = Module.new { def foo; end }
|
124
|
-
klass = Class.new { include mod }
|
125
|
-
|
126
|
-
@modules = RubyLint::Inspector.new(klass).inspect_modules
|
127
|
-
end
|
128
|
-
|
129
|
-
example 'ignore anonymous modules' do
|
130
|
-
@modules.empty?.should == true
|
131
|
-
end
|
132
|
-
end
|
133
|
-
|
134
|
-
context 'inspecting class methods' do
|
135
|
-
before :all do
|
136
|
-
inspector = RubyLint::Inspector.new(Encoding)
|
137
|
-
@methods = inspector.inspect_methods.map(&:name)
|
138
|
-
end
|
139
|
-
|
140
|
-
example 'include a method' do
|
141
|
-
@methods.include?(:find).should == true
|
142
|
-
end
|
143
|
-
end
|
144
|
-
|
145
|
-
context 'inspecting instance methods' do
|
146
|
-
before :all do
|
147
|
-
inspector = RubyLint::Inspector.new(Encoding)
|
148
|
-
@methods = inspector.inspect_instance_methods.map(&:name)
|
149
|
-
end
|
150
|
-
|
151
|
-
example 'include a method' do
|
152
|
-
@methods.include?(:to_s).should == true
|
153
|
-
end
|
154
|
-
end
|
155
|
-
|
156
|
-
context 'exclude methods defined in a parent class' do
|
157
|
-
before :all do
|
158
|
-
parent = Class.new { def foo; end }
|
159
|
-
child = Class.new(parent) { def bar; end }
|
160
|
-
inspector = RubyLint::Inspector.new(child)
|
161
|
-
@methods = inspector.inspect_instance_methods.map(&:name)
|
162
|
-
end
|
163
|
-
|
164
|
-
example 'exclude parent methods' do
|
165
|
-
@methods.include?(:foo).should == false
|
166
|
-
end
|
167
|
-
|
168
|
-
example 'include the instance methods of the source' do
|
169
|
-
@methods.include?(:bar).should == true
|
170
|
-
end
|
171
|
-
end
|
172
|
-
|
173
|
-
context 'exclude methods defined in an included module' do
|
174
|
-
before :all do
|
175
|
-
mod = Module.new { def foo; end }
|
176
|
-
klass = Class.new { include(mod); def bar; end }
|
177
|
-
inspector = RubyLint::Inspector.new(klass)
|
178
|
-
@methods = inspector.inspect_instance_methods.map(&:name)
|
179
|
-
end
|
180
|
-
|
181
|
-
example 'do not include methods from included modules' do
|
182
|
-
@methods.include?(:foo).should == false
|
183
|
-
end
|
184
|
-
|
185
|
-
example 'include methods defined directly in the class' do
|
186
|
-
@methods.include?(:bar).should == true
|
187
|
-
end
|
188
|
-
end
|
189
|
-
|
190
|
-
context 'excluding parent methods when extending Object' do
|
191
|
-
before :all do
|
192
|
-
child = Class.new(Object) { def foo; end }
|
193
|
-
inspector = RubyLint::Inspector.new(child)
|
194
|
-
@methods = inspector.inspect_instance_methods.map(&:name)
|
195
|
-
end
|
196
|
-
|
197
|
-
example 'only include methods of the sub class' do
|
198
|
-
@methods.should == [:foo]
|
199
|
-
end
|
200
|
-
end
|
201
|
-
|
202
|
-
context 'including initialize methods' do
|
203
|
-
before :all do
|
204
|
-
@no_init = Class.new
|
205
|
-
@init = Class.new { def initialize; end }
|
206
|
-
|
207
|
-
@no_init_methods = RubyLint::Inspector.new(@no_init)
|
208
|
-
.inspect_instance_methods
|
209
|
-
.map(&:name)
|
210
|
-
|
211
|
-
@init_methods = RubyLint::Inspector.new(@init)
|
212
|
-
.inspect_instance_methods
|
213
|
-
.map(&:name)
|
214
|
-
end
|
215
|
-
|
216
|
-
example 'exclude initialize if it is not defined directly' do
|
217
|
-
@no_init_methods.include?(:initialize).should == false
|
218
|
-
end
|
219
|
-
|
220
|
-
example 'include initialize if it is defined directly' do
|
221
|
-
@init_methods.include?(:initialize).should == true
|
222
|
-
end
|
223
|
-
end
|
224
|
-
end
|