pelusa 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (46) hide show
  1. data/.gitignore +5 -0
  2. data/.rvmrc +1 -0
  3. data/.travis.yml +4 -0
  4. data/Gemfile +4 -0
  5. data/Rakefile +10 -0
  6. data/Readme.md +74 -0
  7. data/bin/pelusa +7 -0
  8. data/lib/pelusa.rb +22 -0
  9. data/lib/pelusa/analysis.rb +88 -0
  10. data/lib/pelusa/analyzer.rb +48 -0
  11. data/lib/pelusa/class_analyzer.rb +28 -0
  12. data/lib/pelusa/cli.rb +27 -0
  13. data/lib/pelusa/iterator.rb +39 -0
  14. data/lib/pelusa/lint.rb +29 -0
  15. data/lib/pelusa/lint/collection_wrappers.rb +50 -0
  16. data/lib/pelusa/lint/demeter_law.rb +35 -0
  17. data/lib/pelusa/lint/else_clauses.rb +40 -0
  18. data/lib/pelusa/lint/indentation_level.rb +94 -0
  19. data/lib/pelusa/lint/instance_variables.rb +39 -0
  20. data/lib/pelusa/lint/line_restriction.rb +41 -0
  21. data/lib/pelusa/lint/properties.rb +37 -0
  22. data/lib/pelusa/lint/short_identifiers.rb +54 -0
  23. data/lib/pelusa/report.rb +27 -0
  24. data/lib/pelusa/reporters/reporter.rb +22 -0
  25. data/lib/pelusa/reporters/ruby_reporter.rb +29 -0
  26. data/lib/pelusa/reporters/stdout_reporter.rb +50 -0
  27. data/lib/pelusa/runner.rb +53 -0
  28. data/lib/pelusa/version.rb +3 -0
  29. data/pelusa.gemspec +22 -0
  30. data/test/pelusa/analysis_test.rb +38 -0
  31. data/test/pelusa/analyzer_test.rb +33 -0
  32. data/test/pelusa/class_analyzer_test.rb +26 -0
  33. data/test/pelusa/iterator_test.rb +28 -0
  34. data/test/pelusa/lint/collection_wrappers_test.rb +42 -0
  35. data/test/pelusa/lint/demeter_law_test.rb +42 -0
  36. data/test/pelusa/lint/else_clauses_test.rb +50 -0
  37. data/test/pelusa/lint/indentation_level_test.rb +47 -0
  38. data/test/pelusa/lint/instance_variables_test.rb +44 -0
  39. data/test/pelusa/lint/line_restriction_test.rb +40 -0
  40. data/test/pelusa/lint/properties_test.rb +44 -0
  41. data/test/pelusa/lint/short_identifiers_test.rb +41 -0
  42. data/test/pelusa/reporters/ruby_reporter_test.rb +42 -0
  43. data/test/pelusa/runner_test.rb +27 -0
  44. data/test/pelusa_test.rb +19 -0
  45. data/test/test_helper.rb +5 -0
  46. metadata +118 -0
@@ -0,0 +1,44 @@
1
+ require 'test_helper'
2
+
3
+ module Pelusa
4
+ module Lint
5
+ describe Properties do
6
+ before do
7
+ @lint = Properties.new
8
+ end
9
+
10
+ describe '#check' do
11
+ describe 'when the class does not use getters, setters or properties' do
12
+ it 'returns a SuccessAnalysis' do
13
+ klass = """
14
+ class Foo
15
+ def initialize
16
+ @name = 'john'
17
+ end
18
+
19
+ def name
20
+ @name
21
+ end
22
+ end""".to_ast
23
+
24
+ analysis = @lint.check(klass)
25
+ analysis.successful?.must_equal true
26
+ end
27
+ end
28
+
29
+ describe 'when the class uses getters, setters or properties' do
30
+ it 'returns a FailureAnalysis' do
31
+ klass = """
32
+ class Foo
33
+ attr_accessor :name
34
+ attr_reader :foo
35
+ end""".to_ast
36
+
37
+ analysis = @lint.check(klass)
38
+ analysis.failed?.must_equal true
39
+ end
40
+ end
41
+ end
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,41 @@
1
+ require 'test_helper'
2
+
3
+ module Pelusa
4
+ module Lint
5
+ describe ShortIdentifiers do
6
+ before do
7
+ @lint = ShortIdentifiers.new
8
+ end
9
+
10
+ describe '#check' do
11
+ describe 'when the class contains no short identifiers' do
12
+ it 'returns a SuccessAnalysis' do
13
+ klass = """
14
+ class Foo
15
+ def initialize
16
+ foo = 3
17
+ end
18
+ end""".to_ast
19
+
20
+ analysis = @lint.check(klass)
21
+ analysis.successful?.must_equal true
22
+ end
23
+ end
24
+
25
+ describe 'when the class contains a short identifier' do
26
+ it 'returns a FailureAnalysis' do
27
+ klass = """
28
+ class Foo
29
+ def initialize
30
+ x = 2
31
+ end
32
+ end""".to_ast
33
+
34
+ analysis = @lint.check(klass)
35
+ analysis.failed?.must_equal true
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,42 @@
1
+ require 'test_helper'
2
+
3
+ module Pelusa
4
+ describe RubyReporter do
5
+ describe '#report' do
6
+ before do
7
+ too_many_lines = FailedAnalysis.new("Is below 50 lines", 200) do |lines|
8
+ "There are #{lines} lines."
9
+ end
10
+ okay = SuccessfulAnalysis.new("Is below 50 lines")
11
+
12
+ @reports = [
13
+ Report.new("Foo", [ too_many_lines ]),
14
+ Report.new("Bar", [ okay ])
15
+ ]
16
+
17
+ @reporter = RubyReporter.new('foo.rb')
18
+ @reporter.reports = @reports
19
+ end
20
+
21
+ it 'returns a hashified version of the reports' do
22
+ @reporter.report.must_equal({
23
+ "Foo" => {
24
+ "Is below 50 lines" => {
25
+ status: "failed",
26
+ message: "There are 200 lines."
27
+ }
28
+ },
29
+
30
+ "Bar" => {
31
+ "Is below 50 lines" => {
32
+ status: "successful",
33
+ message: ""
34
+ }
35
+ },
36
+
37
+ :filename => "foo.rb"
38
+ })
39
+ end
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,27 @@
1
+ require 'test_helper'
2
+
3
+ module Pelusa
4
+ describe Runner do
5
+ describe '#run' do
6
+ before do
7
+ @report = stub(empty?: false, report: true)
8
+ analyzer = stub(:analyze => @report)
9
+ Analyzer.stubs(:new).returns analyzer
10
+ end
11
+
12
+ describe 'when the reports are successful' do
13
+ it 'returns 0' do
14
+ @report.stubs(successful?: true)
15
+ Pelusa.run(__FILE__).must_equal 0
16
+ end
17
+ end
18
+
19
+ describe 'when the reports have failed' do
20
+ it 'returns 1' do
21
+ @report.stubs(successful?: false)
22
+ Pelusa.run(__FILE__).must_equal 1
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,19 @@
1
+ require 'test_helper'
2
+
3
+ module Pelusa
4
+ describe '.run' do
5
+ describe 'without arguments' do
6
+ before do
7
+ @runner = mock
8
+ @output = mock
9
+ end
10
+
11
+ it 'invokes a new Runner on all Ruby files' do
12
+ Runner.expects(:new).with(Lint.all, StdoutReporter).returns @runner
13
+ @runner.expects(:run).with([]).returns @output
14
+
15
+ Pelusa.run.must_equal @output
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,5 @@
1
+ require 'minitest/autorun'
2
+ require 'minitest/spec'
3
+ require 'mocha'
4
+
5
+ require 'pelusa'
metadata ADDED
@@ -0,0 +1,118 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: pelusa
3
+ version: !ruby/object:Gem::Version
4
+ prerelease:
5
+ version: 0.0.1
6
+ platform: ruby
7
+ authors:
8
+ - Josep M. Bach
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-02-14 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ version_requirements: &4468 !ruby/object:Gem::Requirement
16
+ none: false
17
+ requirements:
18
+ - - ! '>='
19
+ - !ruby/object:Gem::Version
20
+ version: '0'
21
+ prerelease: false
22
+ requirement: *4468
23
+ name: mocha
24
+ type: :development
25
+ description: Static analysis Lint-type tool to improve your OO Ruby code
26
+ email:
27
+ - josep.m.bach@gmail.com
28
+ executables:
29
+ - pelusa
30
+ extensions: []
31
+ extra_rdoc_files: []
32
+ files:
33
+ - .gitignore
34
+ - .rvmrc
35
+ - .travis.yml
36
+ - Gemfile
37
+ - Rakefile
38
+ - Readme.md
39
+ - bin/pelusa
40
+ - lib/pelusa.rb
41
+ - lib/pelusa/analysis.rb
42
+ - lib/pelusa/analyzer.rb
43
+ - lib/pelusa/class_analyzer.rb
44
+ - lib/pelusa/cli.rb
45
+ - lib/pelusa/iterator.rb
46
+ - lib/pelusa/lint.rb
47
+ - lib/pelusa/lint/collection_wrappers.rb
48
+ - lib/pelusa/lint/demeter_law.rb
49
+ - lib/pelusa/lint/else_clauses.rb
50
+ - lib/pelusa/lint/indentation_level.rb
51
+ - lib/pelusa/lint/instance_variables.rb
52
+ - lib/pelusa/lint/line_restriction.rb
53
+ - lib/pelusa/lint/properties.rb
54
+ - lib/pelusa/lint/short_identifiers.rb
55
+ - lib/pelusa/report.rb
56
+ - lib/pelusa/reporters/reporter.rb
57
+ - lib/pelusa/reporters/ruby_reporter.rb
58
+ - lib/pelusa/reporters/stdout_reporter.rb
59
+ - lib/pelusa/runner.rb
60
+ - lib/pelusa/version.rb
61
+ - pelusa.gemspec
62
+ - test/pelusa/analysis_test.rb
63
+ - test/pelusa/analyzer_test.rb
64
+ - test/pelusa/class_analyzer_test.rb
65
+ - test/pelusa/iterator_test.rb
66
+ - test/pelusa/lint/collection_wrappers_test.rb
67
+ - test/pelusa/lint/demeter_law_test.rb
68
+ - test/pelusa/lint/else_clauses_test.rb
69
+ - test/pelusa/lint/indentation_level_test.rb
70
+ - test/pelusa/lint/instance_variables_test.rb
71
+ - test/pelusa/lint/line_restriction_test.rb
72
+ - test/pelusa/lint/properties_test.rb
73
+ - test/pelusa/lint/short_identifiers_test.rb
74
+ - test/pelusa/reporters/ruby_reporter_test.rb
75
+ - test/pelusa/runner_test.rb
76
+ - test/pelusa_test.rb
77
+ - test/test_helper.rb
78
+ homepage: http://github.com/codegram/pelusa
79
+ licenses: []
80
+ post_install_message:
81
+ rdoc_options: []
82
+ require_paths:
83
+ - lib
84
+ required_ruby_version: !ruby/object:Gem::Requirement
85
+ none: false
86
+ requirements:
87
+ - - ! '>='
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ required_rubygems_version: !ruby/object:Gem::Requirement
91
+ none: false
92
+ requirements:
93
+ - - ! '>='
94
+ - !ruby/object:Gem::Version
95
+ version: '0'
96
+ requirements: []
97
+ rubyforge_project: pelusa
98
+ rubygems_version: 1.8.12
99
+ signing_key:
100
+ specification_version: 3
101
+ summary: Static analysis Lint-type tool to improve your OO Ruby code
102
+ test_files:
103
+ - test/pelusa_test.rb
104
+ - test/test_helper.rb
105
+ - test/pelusa/analysis_test.rb
106
+ - test/pelusa/analyzer_test.rb
107
+ - test/pelusa/class_analyzer_test.rb
108
+ - test/pelusa/iterator_test.rb
109
+ - test/pelusa/runner_test.rb
110
+ - test/pelusa/lint/collection_wrappers_test.rb
111
+ - test/pelusa/lint/demeter_law_test.rb
112
+ - test/pelusa/lint/else_clauses_test.rb
113
+ - test/pelusa/lint/indentation_level_test.rb
114
+ - test/pelusa/lint/instance_variables_test.rb
115
+ - test/pelusa/lint/line_restriction_test.rb
116
+ - test/pelusa/lint/properties_test.rb
117
+ - test/pelusa/lint/short_identifiers_test.rb
118
+ - test/pelusa/reporters/ruby_reporter_test.rb