preek 0.1.2 → 0.1.3

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c107d59e998f9ab44c16a25c170e29a28e63e40d
4
- data.tar.gz: 2a1f2fa67d7700bf8b6a900a3ae91543155e8ca5
3
+ metadata.gz: 23aaf624b23cc383b727443a4638f9d8974465ff
4
+ data.tar.gz: ba4e3c93bd89f810a2ff58b8d76373fc39153f19
5
5
  SHA512:
6
- metadata.gz: b383dcbd667dc3937f38311ac46134c3d713da67e3b1e020a350ed5271a5e82549aa111e9eb7f0859467492758b86d930bcb6580a5620461a89ef2cc3b991ab2
7
- data.tar.gz: c3466db14aa8375fdd5a0622ee5c969e1451c7950cccb77e00def184bf70c7ca2fca99cae5c79d00018da66016806fda56d4dd553aa827336616e34022aecd8e
6
+ metadata.gz: f8e069e0498d2879120117dca4c13a4679981bef8757a0fe6293705a0c43d69971b64c3c0d7b30717e628601f8f00962b8b586fd9101c346646056732a9fa2ad
7
+ data.tar.gz: 331ad8be448eb115fc52bc5ef25f719af4a4f71ac4bc670fcd1d75c7e5b022015e6d7339353fa312ee20c7caac37f075ebd14728ffc1755ed7b5dcf8cb8e0b88
data/bin/preek CHANGED
@@ -1,13 +1,14 @@
1
1
  #!/usr/bin/env ruby
2
2
  require "preek"
3
3
 
4
- unless ARGV.empty?
5
- preek = Preek::Preek.new
6
- if preek.respond_to? ARGV[0]
7
- preek.send ARGV.shift.to_sym, ARGV
8
- else
9
- preek.parse ARGV
10
- end
11
- else
12
- Preek::Preek.start
13
- end
4
+ # unless ARGV.empty?
5
+ # preek = Preek::Preek.new
6
+ # if preek.respond_to? ARGV[0]
7
+ # preek.send ARGV.shift.to_sym, ARGV
8
+ # else
9
+ # preek.parse ARGV
10
+ # end
11
+ # else
12
+ # Preek::Preek.start
13
+ # end
14
+ Preek::Preek.start
data/lib/preek.rb CHANGED
@@ -14,17 +14,23 @@ module Preek
14
14
  say VERSION
15
15
  end
16
16
 
17
- desc 'FILE', 'Pretty format Reek output'
18
- def parse(args)
17
+ desc 'smell FILE(S)|DIR', 'Pretty format Reek output'
18
+ method_option :irresponsible,
19
+ type: :boolean,
20
+ aliases: '-i',
21
+ desc: 'include IrresponsibleModule smell in output.'
22
+ def smell(*args)
23
+ args ||= @args
24
+ @includes = options.keys.map {|key| _aliases[key.to_sym] }
19
25
  files, @not_files = args.partition { |file| File.exists? file }
20
- report_smells_for files unless files.empty?
26
+ report_smells_for(files, excludes) unless files.empty?
21
27
  report_not_files
22
28
  end
23
29
 
24
30
  private
25
- def report_smells_for files
31
+ def report_smells_for(files, includes)
26
32
  sources = Reek::Source::SourceLocator.new(files).all_sources
27
- smelly_files = SmellCollector.new(sources).smelly_files
33
+ smelly_files = SmellCollector.new(sources, excludes).smelly_files
28
34
  @reporter = SmellReporter.new(smelly_files)
29
35
  @reporter.print_smells
30
36
  end
@@ -32,5 +38,19 @@ module Preek
32
38
  def report_not_files
33
39
  say_status :error, "No such file(s) - #{@not_files*", "}.", :red unless @not_files.empty?
34
40
  end
41
+
42
+ def _aliases
43
+ {
44
+ irresponsible: 'IrresponsibleModule'
45
+ }
46
+ end
47
+
48
+ def excludes
49
+ (exclude_list - @includes)#.map(&:to_s).map(&:capitalize)
50
+ end
51
+
52
+ def exclude_list
53
+ %w(IrresponsibleModule)
54
+ end
35
55
  end
36
56
  end
@@ -3,8 +3,9 @@ module Preek
3
3
  require 'preek/smell_file'
4
4
  # This is a 'Collector'
5
5
  class SmellCollector
6
- def initialize sources
6
+ def initialize(sources, excludes)
7
7
  @sources = sources
8
+ @excludes = excludes
8
9
  @files = examine_sources
9
10
  end
10
11
 
@@ -16,7 +17,7 @@ module Preek
16
17
  def examine_sources
17
18
  @sources.map do |source|
18
19
  smells = Reek::Examiner.new(source).smells
19
- SmellFile.new smells unless smells.empty?
20
+ SmellFile.new(smells, @excludes) unless smells.empty?
20
21
  end
21
22
  end
22
23
  end
@@ -2,13 +2,14 @@ module Preek
2
2
  require 'preek/klass_collector'
3
3
  # A smelly file
4
4
  class SmellFile
5
- def initialize(smells)
5
+ def initialize(smells, excludes)
6
6
  @smells = smells
7
+ @excludes = excludes
7
8
  @klass_collector = KlassCollector.new
9
+ add_smells_to_klass
8
10
  end
9
11
 
10
12
  def klasses
11
- add_smells_to_klass
12
13
  @klass_collector.get_klasses
13
14
  end
14
15
 
@@ -19,6 +20,7 @@ module Preek
19
20
  private
20
21
  def add_smells_to_klass
21
22
  @smells.each do |smell|
23
+ next if @excludes.include? smell.smell_class
22
24
  @klass_collector.find(smell.klass).add_smell smell
23
25
  end
24
26
  end
@@ -7,6 +7,7 @@ module Preek
7
7
  end
8
8
 
9
9
  def print_smells
10
+ @smelly_files.delete_if {|smell_file| smell_file.klasses.empty? }
10
11
  return say_status 'success!', 'No smells detected.' if @smelly_files.empty?
11
12
  print_line
12
13
  @smelly_files.each do |smell|
data/lib/preek/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Preek
2
- VERSION = "0.1.2"
2
+ VERSION = "0.1.3"
3
3
  end
data/spec/preek_spec.rb CHANGED
@@ -14,7 +14,8 @@ describe Preek::Preek do
14
14
  end
15
15
 
16
16
  describe "#parse" do
17
- let(:output) { capture(:stdout) { subject.parse(args) } }
17
+ let(:output) { capture(:stdout) { subject.parse(*args) } }
18
+ let(:args) { ['i/am/not/a_file'] }
18
19
 
19
20
  context "with non-existing file in ARGS" do
20
21
  let(:args) { ['i/am/not/a_file'] }
@@ -35,16 +36,40 @@ describe Preek::Preek do
35
36
 
36
37
  context "when given file has Irresponsible smell" do
37
38
  let(:args){ [test_file('irresponsible')] }
39
+ it "output contains 'success! No smells'" do
40
+ output.should include("No smells")
41
+ end
42
+ end
43
+
44
+ context "when given file has Irresponsible smell with --irresponsible options" do
45
+ let(:args){ [test_file('irresponsible')] }
46
+
47
+ before :each do
48
+ subject.options = {irresponsible: true}
49
+ end
50
+
38
51
  it "output contains 'Irresponsible'" do
39
52
  output.should include("Irresponsible")
40
53
  end
41
- it "outputs the name of the file" do
42
- output.should include(args[0])
43
- end
54
+
44
55
  end
45
56
 
46
57
  context "when given a file with two smelly classes" do
47
58
  let(:args){ [test_file('two_smelly_classes')] }
59
+ it "output contains one classnames" do
60
+ output.should include('SecondSmelly')
61
+ end
62
+ it "output contains one smell" do
63
+ output.should include('UncommunicativeMethodName')
64
+ end
65
+ end
66
+
67
+ context "when given a file with two smelly classes with --irresponsible options" do
68
+ let(:args){ [test_file('two_smelly_classes')] }
69
+ before :each do
70
+ subject.options = {irresponsible: true}
71
+ end
72
+
48
73
  it "output contains both classnames" do
49
74
  output.should include('FirstSmelly', 'SecondSmelly')
50
75
  end
@@ -53,15 +78,20 @@ describe Preek::Preek do
53
78
  end
54
79
  end
55
80
 
56
- context "when given a file with two different smells" do
81
+ context "when given a file with two different smells with --irresponsible options" do
57
82
  let(:args){ [test_file('irresponsible_and_lazy')] }
58
83
  it "output contains both smells" do
84
+ subject.options = {irresponsible: true}
59
85
  output.should include('IrresponsibleModule', 'UncommunicativeMethodName')
60
86
  end
61
87
  end
62
88
 
63
89
  context "when given two smelly files" do
64
90
  let(:args){ [test_file('too_many_statements'), test_file('two_smelly_classes')] }
91
+ before :each do
92
+ subject.options = {irresponsible: true}
93
+ end
94
+
65
95
  it "output contains all smells" do
66
96
  output.should include('IrresponsibleModule', 'UncommunicativeMethodName', 'TooManyStatements')
67
97
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: preek
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jon Neverland
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-07-17 00:00:00.000000000 Z
11
+ date: 2013-07-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor