reek 1.2.8 → 1.2.9

Sign up to get free protection for your applications and to get access to all the features.
Files changed (52) hide show
  1. data/History.txt +4 -0
  2. data/README.md +40 -25
  3. data/Rakefile +2 -15
  4. data/bin/reek +1 -1
  5. data/features/{options.feature → command_line_interface/options.feature} +1 -3
  6. data/features/{stdin.feature → command_line_interface/stdin.feature} +2 -2
  7. data/features/{masking_smells.feature → configuration_files/masking_smells.feature} +23 -23
  8. data/features/{rake_task.feature → rake_task/rake_task.feature} +9 -9
  9. data/features/{reports.feature → reports/reports.feature} +10 -10
  10. data/features/{yaml.feature → reports/yaml.feature} +2 -2
  11. data/features/{api.feature → ruby_api/api.feature} +6 -6
  12. data/features/samples.feature +239 -247
  13. data/features/step_definitions/reek_steps.rb +15 -1
  14. data/features/support/env.rb +0 -1
  15. data/lib/reek.rb +1 -4
  16. data/lib/reek/cli/command_line.rb +6 -5
  17. data/lib/reek/cli/report.rb +1 -1
  18. data/lib/reek/core/hash_extensions.rb +29 -0
  19. data/lib/reek/core/method_context.rb +3 -16
  20. data/lib/reek/core/object_refs.rb +5 -22
  21. data/lib/reek/core/smell_repository.rb +65 -0
  22. data/lib/reek/core/sniffer.rb +7 -76
  23. data/lib/reek/core/warning_collector.rb +1 -5
  24. data/lib/reek/examiner.rb +3 -13
  25. data/lib/reek/rake/task.rb +10 -2
  26. data/lib/reek/smell_warning.rb +1 -0
  27. data/lib/reek/smells/smell_detector.rb +0 -3
  28. data/lib/reek/smells/uncommunicative_module_name.rb +6 -3
  29. data/lib/reek/smells/uncommunicative_variable_name.rb +1 -1
  30. data/lib/reek/source/config_file.rb +8 -2
  31. data/lib/reek/source/sexp_formatter.rb +1 -1
  32. data/lib/reek/source/source_repository.rb +31 -0
  33. data/lib/reek/source/tree_dresser.rb +1 -1
  34. data/lib/reek/spec/should_reek.rb +5 -2
  35. data/lib/reek/version.rb +3 -0
  36. data/lib/xp.reek +63 -0
  37. data/reek.gemspec +16 -28
  38. data/spec/gem/manifest_spec.rb +22 -0
  39. data/spec/gem/updates_spec.rb +26 -0
  40. data/spec/gem/yard_spec.rb +15 -0
  41. data/spec/matchers/smell_of_matcher.rb +0 -1
  42. data/spec/reek/cli/reek_command_spec.rb +1 -1
  43. data/spec/reek/core/method_context_spec.rb +2 -2
  44. data/spec/reek/core/object_refs_spec.rb +115 -118
  45. data/spec/reek/smell_warning_spec.rb +2 -2
  46. data/spec/reek/smells/uncommunicative_variable_name_spec.rb +3 -0
  47. data/spec/reek/source/sexp_formatter_spec.rb +19 -0
  48. data/spec/reek/spec/should_reek_spec.rb +21 -3
  49. data/tasks/deployment.rake +69 -0
  50. data/tasks/develop.rake +29 -0
  51. data/tasks/test.rake +1 -6
  52. metadata +200 -138
@@ -71,9 +71,6 @@ module Reek
71
71
  end
72
72
  end
73
73
 
74
- def examine_context(context)
75
- end
76
-
77
74
  def exception?(context)
78
75
  context.matches?(value(EXCLUDE_KEY, context, DEFAULT_EXCLUDE_SET))
79
76
  end
@@ -56,15 +56,18 @@ module Reek
56
56
  #
57
57
  # @return [Array<SmellWarning>]
58
58
  #
59
+ # :reek:Duplication { allow_calls: [ to_s ] }
59
60
  def examine_context(ctx)
60
61
  @reject_names = value(REJECT_KEY, ctx, DEFAULT_REJECT_SET)
61
62
  @accept_names = value(ACCEPT_KEY, ctx, DEFAULT_ACCEPT_SET)
62
- name = ctx.exp.simple_name
63
- return [] if @accept_names.include?(ctx.full_name)
63
+ exp = ctx.exp
64
+ full_name = ctx.full_name
65
+ name = exp.simple_name
66
+ return [] if @accept_names.include?(full_name)
64
67
  var = name.to_s.gsub(/^[@\*\&]*/, '')
65
68
  return [] if @accept_names.include?(var)
66
69
  return [] unless @reject_names.detect {|patt| patt === var}
67
- smell = SmellWarning.new(SMELL_CLASS, ctx.full_name, [ctx.exp.line],
70
+ smell = SmellWarning.new(SMELL_CLASS, full_name, [exp.line],
68
71
  "has the name '#{name}'",
69
72
  @source, SMELL_SUBCLASS, {MODULE_NAME_KEY => name.to_s})
70
73
  [smell]
@@ -34,7 +34,7 @@ module Reek
34
34
  # uncommunicative.
35
35
  ACCEPT_KEY = 'accept'
36
36
 
37
- DEFAULT_ACCEPT_SET = []
37
+ DEFAULT_ACCEPT_SET = ['_']
38
38
 
39
39
  def self.default_config
40
40
  super.adopt(
@@ -50,9 +50,15 @@ module Reek
50
50
  def load
51
51
  unless @@bad_config_files.include?(@file_path)
52
52
  begin
53
- return YAML.load_file(@file_path) || {}
53
+ result = YAML.load_file(@file_path) || {}
54
+ if Hash === result
55
+ return result
56
+ else
57
+ @@bad_config_files << @file_path # poop
58
+ problem('Not a hash')
59
+ end
54
60
  rescue Exception => err
55
- @@bad_config_files << @file_path
61
+ @@bad_config_files << @file_path # poop
56
62
  problem(err.to_s)
57
63
  end
58
64
  end
@@ -9,7 +9,7 @@ module Reek
9
9
  class SexpFormatter
10
10
  def self.format(sexp)
11
11
  return sexp.to_s unless Array === sexp
12
- sexp = YAML::load(YAML::dump(sexp))
12
+ sexp = Sexp.from_array(YAML::load(YAML::dump(sexp)))
13
13
  Ruby2Ruby.new.process(sexp)
14
14
  end
15
15
  end
@@ -0,0 +1,31 @@
1
+ require File.join(File.dirname(File.dirname(File.expand_path(__FILE__))), 'source')
2
+
3
+ module Reek
4
+ module Source
5
+ class SourceRepository
6
+ def self.parse source
7
+ case source
8
+ when Array
9
+ new 'dir', Source::SourceLocator.new(source).all_sources
10
+ when Source::SourceCode
11
+ new source.desc, [source]
12
+ else
13
+ src = source.to_reek_source
14
+ new src.desc, [src]
15
+ end
16
+ end
17
+
18
+ include Enumerable
19
+ attr_reader :description
20
+
21
+ def initialize description, sources
22
+ @description = description
23
+ @sources = sources
24
+ end
25
+
26
+ def each &block
27
+ @sources.each &block
28
+ end
29
+ end
30
+ end
31
+ end
@@ -53,7 +53,7 @@ module Reek
53
53
  Ruby2Ruby.new.process(deep_copy)
54
54
  end
55
55
  def deep_copy
56
- YAML::load(YAML::dump(self))
56
+ Sexp.from_array(YAML::load(YAML::dump(self)))
57
57
  end
58
58
  end
59
59
 
@@ -8,8 +8,11 @@ module Reek
8
8
  # An rspec matcher that matches when the +actual+ has code smells.
9
9
  #
10
10
  class ShouldReek # :nodoc:
11
+ def initialize(config_files = [])
12
+ @config_files = config_files
13
+ end
11
14
  def matches?(actual)
12
- @examiner = Examiner.new(actual)
15
+ @examiner = Examiner.new(actual, @config_files)
13
16
  @examiner.smelly?
14
17
  end
15
18
  def failure_message_for_should
@@ -25,7 +28,7 @@ module Reek
25
28
  # Returns +true+ if and only if the target source code contains smells.
26
29
  #
27
30
  def reek
28
- ShouldReek.new
31
+ ShouldReek.new(Dir['config/*.reek'])
29
32
  end
30
33
  end
31
34
  end
@@ -0,0 +1,3 @@
1
+ module Reek
2
+ VERSION = '1.2.9'
3
+ end
data/lib/xp.reek ADDED
@@ -0,0 +1,63 @@
1
+ ---
2
+ LargeClass:
3
+ max_methods: 25
4
+ exclude: []
5
+ enabled: true
6
+ max_instance_variables: 9
7
+ LongParameterList:
8
+ max_params: 3
9
+ exclude: []
10
+ enabled: true
11
+ overrides:
12
+ initialize:
13
+ max_params: 5
14
+ FeatureEnvy:
15
+ exclude:
16
+ - initialize
17
+ enabled: false
18
+ ClassVariable:
19
+ exclude: &id001 []
20
+ enabled: true
21
+ UncommunicativeVariableName:
22
+ accept:
23
+ - Inline::C
24
+ exclude: []
25
+ enabled: true
26
+ reject:
27
+ - !ruby/regexp /^.$/
28
+ - !ruby/regexp /[0-9]$/
29
+ NestedIterators:
30
+ exclude: *id001
31
+ enabled: false
32
+ LongMethod:
33
+ max_statements: 5
34
+ exclude:
35
+ - initialize
36
+ enabled: false
37
+ Duplication:
38
+ exclude: []
39
+ enabled: true
40
+ max_calls: 1
41
+ UtilityFunction:
42
+ max_helper_calls: 1
43
+ exclude: []
44
+ enabled: false
45
+ Attribute:
46
+ exclude: []
47
+ enabled: true
48
+ SimulatedPolymorphism:
49
+ exclude: []
50
+ enabled: true
51
+ max_ifs: 2
52
+ DataClump:
53
+ exclude: []
54
+ enabled: true
55
+ max_copies: 2
56
+ min_clump_size: 2
57
+ LongYieldList:
58
+ max_params: 2
59
+ exclude: []
60
+ enabled: true
61
+ overrides:
62
+ initialize:
63
+ max_params: 5
data/reek.gemspec CHANGED
@@ -1,48 +1,36 @@
1
1
  # -*- encoding: utf-8 -*-
2
+ require File.join(File.dirname(__FILE__), 'lib/reek/version.rb')
2
3
 
3
4
  Gem::Specification.new do |s|
4
5
  s.name = %q{reek}
5
- s.version = "1.2.8"
6
+ s.version = Reek::VERSION
6
7
 
7
- s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
- s.authors = ["Kevin Rutherford"]
8
+ s.authors = ['Kevin Rutherford', 'Timo Roessner', 'Matijs van Zuijlen']
9
9
  s.date = %q{2010-04-26}
10
10
  s.default_executable = %q{reek}
11
11
  s.description = %q{Reek is a tool that examines Ruby classes, modules and methods
12
12
  and reports any code smells it finds.
13
13
  }
14
- s.email = ["kevin@rutherford-software.com"]
14
+ s.email = ["timo.roessner@googlemail.com"]
15
15
  s.executables = ["reek"]
16
16
  s.extra_rdoc_files = ["History.txt", "License.txt"]
17
- s.files = [".yardopts", "History.txt", "License.txt", "README.md", "Rakefile", "bin/reek", "config/defaults.reek", "features/api.feature", "features/masking_smells.feature", "features/options.feature", "features/rake_task.feature", "features/reports.feature", "features/samples.feature", "features/stdin.feature", "features/step_definitions/reek_steps.rb", "features/support/env.rb", "features/yaml.feature", "lib/reek.rb", "lib/reek/cli/application.rb", "lib/reek/cli/command_line.rb", "lib/reek/cli/help_command.rb", "lib/reek/cli/reek_command.rb", "lib/reek/cli/report.rb", "lib/reek/cli/version_command.rb", "lib/reek/cli/yaml_command.rb", "lib/reek/core/code_context.rb", "lib/reek/core/code_parser.rb", "lib/reek/core/method_context.rb", "lib/reek/core/module_context.rb", "lib/reek/core/object_refs.rb", "lib/reek/core/singleton_method_context.rb", "lib/reek/core/smell_configuration.rb", "lib/reek/core/sniffer.rb", "lib/reek/core/stop_context.rb", "lib/reek/core/warning_collector.rb", "lib/reek/examiner.rb", "lib/reek/rake/task.rb", "lib/reek/smell_warning.rb", "lib/reek/smells.rb", "lib/reek/smells/attribute.rb", "lib/reek/smells/boolean_parameter.rb", "lib/reek/smells/class_variable.rb", "lib/reek/smells/control_couple.rb", "lib/reek/smells/data_clump.rb", "lib/reek/smells/duplication.rb", "lib/reek/smells/feature_envy.rb", "lib/reek/smells/irresponsible_module.rb", "lib/reek/smells/large_class.rb", "lib/reek/smells/long_method.rb", "lib/reek/smells/long_parameter_list.rb", "lib/reek/smells/long_yield_list.rb", "lib/reek/smells/nested_iterators.rb", "lib/reek/smells/simulated_polymorphism.rb", "lib/reek/smells/smell_detector.rb", "lib/reek/smells/uncommunicative_method_name.rb", "lib/reek/smells/uncommunicative_module_name.rb", "lib/reek/smells/uncommunicative_parameter_name.rb", "lib/reek/smells/uncommunicative_variable_name.rb", "lib/reek/smells/utility_function.rb", "lib/reek/source.rb", "lib/reek/source/code_comment.rb", "lib/reek/source/config_file.rb", "lib/reek/source/core_extras.rb", "lib/reek/source/reference_collector.rb", "lib/reek/source/sexp_formatter.rb", "lib/reek/source/source_code.rb", "lib/reek/source/source_file.rb", "lib/reek/source/source_locator.rb", "lib/reek/source/tree_dresser.rb", "lib/reek/spec.rb", "lib/reek/spec/should_reek.rb", "lib/reek/spec/should_reek_of.rb", "lib/reek/spec/should_reek_only_of.rb", "reek.gemspec", "spec/matchers/smell_of_matcher.rb", "spec/reek/cli/help_command_spec.rb", "spec/reek/cli/reek_command_spec.rb", "spec/reek/cli/report_spec.rb", "spec/reek/cli/version_command_spec.rb", "spec/reek/cli/yaml_command_spec.rb", "spec/reek/core/code_context_spec.rb", "spec/reek/core/code_parser_spec.rb", "spec/reek/core/config_spec.rb", "spec/reek/core/method_context_spec.rb", "spec/reek/core/module_context_spec.rb", "spec/reek/core/object_refs_spec.rb", "spec/reek/core/singleton_method_context_spec.rb", "spec/reek/core/smell_configuration_spec.rb", "spec/reek/core/stop_context_spec.rb", "spec/reek/core/warning_collector_spec.rb", "spec/reek/examiner_spec.rb", "spec/reek/smell_warning_spec.rb", "spec/reek/smells/attribute_spec.rb", "spec/reek/smells/behaves_like_variable_detector.rb", "spec/reek/smells/boolean_parameter_spec.rb", "spec/reek/smells/class_variable_spec.rb", "spec/reek/smells/control_couple_spec.rb", "spec/reek/smells/data_clump_spec.rb", "spec/reek/smells/duplication_spec.rb", "spec/reek/smells/feature_envy_spec.rb", "spec/reek/smells/irresponsible_module_spec.rb", "spec/reek/smells/large_class_spec.rb", "spec/reek/smells/long_method_spec.rb", "spec/reek/smells/long_parameter_list_spec.rb", "spec/reek/smells/long_yield_list_spec.rb", "spec/reek/smells/nested_iterators_spec.rb", "spec/reek/smells/simulated_polymorphism_spec.rb", "spec/reek/smells/smell_detector_shared.rb", "spec/reek/smells/uncommunicative_method_name_spec.rb", "spec/reek/smells/uncommunicative_module_name_spec.rb", "spec/reek/smells/uncommunicative_parameter_name_spec.rb", "spec/reek/smells/uncommunicative_variable_name_spec.rb", "spec/reek/smells/utility_function_spec.rb", "spec/reek/source/code_comment_spec.rb", "spec/reek/source/object_source_spec.rb", "spec/reek/source/reference_collector_spec.rb", "spec/reek/source/source_code_spec.rb", "spec/reek/source/tree_dresser_spec.rb", "spec/reek/spec/should_reek_of_spec.rb", "spec/reek/spec/should_reek_only_of_spec.rb", "spec/reek/spec/should_reek_spec.rb", "spec/samples/all_but_one_masked/clean_one.rb", "spec/samples/all_but_one_masked/dirty.rb", "spec/samples/all_but_one_masked/masked.reek", "spec/samples/clean_due_to_masking/clean_one.rb", "spec/samples/clean_due_to_masking/clean_three.rb", "spec/samples/clean_due_to_masking/clean_two.rb", "spec/samples/clean_due_to_masking/dirty_one.rb", "spec/samples/clean_due_to_masking/dirty_two.rb", "spec/samples/clean_due_to_masking/masked.reek", "spec/samples/config/allow_duplication.reek", "spec/samples/config/deeper_nested_iterators.reek", "spec/samples/corrupt_config_file/corrupt.reek", "spec/samples/corrupt_config_file/dirty.rb", "spec/samples/demo/demo.rb", "spec/samples/empty_config_file/dirty.rb", "spec/samples/empty_config_file/empty.reek", "spec/samples/exceptions.reek", "spec/samples/inline_config/dirty.rb", "spec/samples/inline_config/masked.reek", "spec/samples/inline.rb", "spec/samples/mask_some/dirty.rb", "spec/samples/mask_some/some.reek", "spec/samples/masked/dirty.rb", "spec/samples/masked/masked.reek", "spec/samples/mixed_results/clean_one.rb", "spec/samples/mixed_results/clean_three.rb", "spec/samples/mixed_results/clean_two.rb", "spec/samples/mixed_results/dirty_one.rb", "spec/samples/mixed_results/dirty_two.rb", "spec/samples/not_quite_masked/dirty.rb", "spec/samples/not_quite_masked/masked.reek", "spec/samples/optparse.rb", "spec/samples/overrides/masked/dirty.rb", "spec/samples/overrides/masked/lower.reek", "spec/samples/overrides/upper.reek", "spec/samples/redcloth.rb", "spec/samples/three_clean_files/clean_one.rb", "spec/samples/three_clean_files/clean_three.rb", "spec/samples/three_clean_files/clean_two.rb", "spec/samples/two_smelly_files/dirty_one.rb", "spec/samples/two_smelly_files/dirty_two.rb", "spec/spec.opts", "spec/spec_helper.rb", "tasks/reek.rake", "tasks/test.rake"]
18
- s.homepage = %q{http://wiki.github.com/kevinrutherford/reek}
19
- s.post_install_message = %q{
20
- Thank you for downloading Reek. For info:
21
- - see the reek wiki http://wiki.github.com/kevinrutherford/reek
22
- - follow @rubyreek on twitter
23
- }
17
+ s.files = Dir[".yardopts", "History.txt", "License.txt", "README.md",
18
+ "Rakefile", "bin/reek", "config/defaults.reek",
19
+ "{features,lib,spec,tasks}/**/*",
20
+ "reek.gemspec" ] & `git ls-files -z`.split("\0")
21
+ s.homepage = %q{http://wiki.github.com/troessner/reek}
22
+ s.post_install_message = %q{Thank you for downloading Reek. For info see the reek wiki http://wiki.github.com/troessner/reek}
24
23
  s.rdoc_options = ["--main", "README.md"]
25
24
  s.require_paths = ["lib"]
26
25
  s.rubyforge_project = %q{reek}
27
26
  s.rubygems_version = %q{1.3.6}
28
27
  s.summary = %q{Code smell detector for Ruby}
29
28
 
30
- if s.respond_to? :specification_version then
31
- current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
32
- s.specification_version = 3
29
+ s.add_runtime_dependency(%q<ruby_parser>, ["~> 2.0"])
30
+ s.add_runtime_dependency(%q<ruby2ruby>, ["~> 1.2.5"])
31
+ s.add_runtime_dependency(%q<sexp_processor>, ["~> 3.0"])
33
32
 
34
- if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
35
- s.add_runtime_dependency(%q<ruby_parser>, ["~> 2.0"])
36
- s.add_runtime_dependency(%q<ruby2ruby>, ["~> 1.2"])
37
- s.add_runtime_dependency(%q<sexp_processor>, ["~> 3.0"])
38
- else
39
- s.add_dependency(%q<ruby_parser>, ["~> 2.0"])
40
- s.add_dependency(%q<ruby2ruby>, ["~> 1.2"])
41
- s.add_dependency(%q<sexp_processor>, ["~> 3.0"])
42
- end
43
- else
44
- s.add_dependency(%q<ruby_parser>, ["~> 2.0"])
45
- s.add_dependency(%q<ruby2ruby>, ["~> 1.2"])
46
- s.add_dependency(%q<sexp_processor>, ["~> 3.0"])
47
- end
33
+ s.add_development_dependency(%q<rake>)
34
+ s.add_development_dependency(%q<cucumber>)
35
+ s.add_development_dependency(%q<rspec>, ["= 1.3.2"])
48
36
  end
@@ -0,0 +1,22 @@
1
+ require File.join(File.dirname(File.dirname(File.expand_path(__FILE__))), 'spec_helper')
2
+ require 'find'
3
+
4
+ describe 'gem manifest' do
5
+ before :each do
6
+ @current_files = []
7
+ Find.find '.' do |path|
8
+ next unless File.file? path
9
+ next if path =~ /\.git|\.idea|build|doc|gem\/|tmp|nbproject|quality|xp.reek|Manifest.txt|develop.rake|deployment.rake/
10
+ @current_files << path[2..-1]
11
+ end
12
+ @current_files.sort!
13
+ @manifest = IO.readlines('Manifest.txt').map {|path| path.chomp}.sort
14
+ end
15
+
16
+ it 'lists every current file' do
17
+ (@current_files - @manifest).should == []
18
+ end
19
+ it 'lists no extra files' do
20
+ (@manifest - @current_files).should == []
21
+ end
22
+ end
@@ -0,0 +1,26 @@
1
+ require File.join(File.dirname(File.dirname(File.expand_path(__FILE__))), 'spec_helper')
2
+ require 'find'
3
+
4
+ release_timestamp_file = 'build/.last-release'
5
+ if test(?f, release_timestamp_file)
6
+ describe 'updates' do
7
+ before :each do
8
+ @release_time = File.stat(release_timestamp_file).mtime
9
+ end
10
+
11
+ context 'version file' do
12
+ it 'has been updated since the last release' do
13
+ version_time = File.stat('lib/reek.rb').mtime
14
+ (version_time > @release_time).should be_true
15
+ end
16
+ end
17
+
18
+ context 'history file' do
19
+ it 'has been updated since the last release' do
20
+ history_time = File.stat('History.txt').mtime
21
+ (history_time > @release_time).should be_true
22
+ end
23
+ end
24
+ end
25
+ end
26
+
@@ -0,0 +1,15 @@
1
+ require File.join(File.dirname(File.dirname(File.expand_path(__FILE__))), 'spec_helper')
2
+ require 'tempfile'
3
+
4
+ describe 'yardoc' do
5
+ before :each do
6
+ stderr_file = Tempfile.new('yardoc')
7
+ stderr_file.close
8
+ @stdout = `yardoc 2> #{stderr_file.path}`
9
+ @stderr = IO.read(stderr_file.path)
10
+ end
11
+ it 'raises no warnings' do
12
+ @stderr.should == ''
13
+ end
14
+ end
15
+
@@ -35,7 +35,6 @@ module SmellOfMatcher
35
35
  expected_smell.each do |(key,value)|
36
36
  if actual_smells[index].smell[key] != value
37
37
  @reason = "#{key} != #{value}"
38
- return false
39
38
  end
40
39
  end
41
40
  end
@@ -18,7 +18,7 @@ describe ReekCommand do
18
18
  end
19
19
 
20
20
  it 'displays the correct text on the view' do
21
- @view.should_receive(:output).with(/UncommunicativeName/)
21
+ @view.should_receive(:output).with(/UncommunicativeMethodName/)
22
22
  @cmd.execute(@view)
23
23
  end
24
24
 
@@ -32,7 +32,7 @@ describe MethodContext do
32
32
 
33
33
  it 'should count calls to self' do
34
34
  mctx = MethodContext.new(StopContext.new, ast(:defn, :equals))
35
- mctx.refs.record_ref([:lvar, :other])
35
+ mctx.refs.record_reference_to([:lvar, :other])
36
36
  mctx.record_call_to(ast(:call, s(:self), :thing))
37
37
  mctx.envious_receivers.should be_empty
38
38
  end
@@ -85,4 +85,4 @@ describe MethodParameters, 'default assignments' do
85
85
  @defaults.length.should == 2
86
86
  end
87
87
  end
88
- end
88
+ end
@@ -3,128 +3,125 @@ require File.join(File.dirname(File.dirname(File.dirname(File.dirname(File.expan
3
3
 
4
4
  include Reek::Core
5
5
 
6
- describe ObjectRefs, 'when empty' do
6
+ describe ObjectRefs do
7
7
  before(:each) do
8
8
  @refs = ObjectRefs.new
9
9
  end
10
10
 
11
- it 'should report no refs to self' do
12
- @refs.refs_to_self.should == 0
11
+ context 'when empty' do
12
+ it 'should report no refs to self' do
13
+ @refs.references_to(:self).should == 0
14
+ end
15
+ end
16
+
17
+ context "with references to a, b, and a" do
18
+ context 'with no refs to self' do
19
+ before(:each) do
20
+ @refs.record_reference_to('a')
21
+ @refs.record_reference_to('b')
22
+ @refs.record_reference_to('a')
23
+ end
24
+
25
+ it 'should report no refs to self' do
26
+ @refs.references_to(:self).should == 0
27
+ end
28
+
29
+ it 'should report :a as the max' do
30
+ @refs.max_keys.should == {'a' => 2}
31
+ end
32
+
33
+ it 'should not report self as the max' do
34
+ @refs.self_is_max?.should == false
35
+ end
36
+
37
+ context "with one reference to self" do
38
+ before(:each) do
39
+ @refs.record_reference_to(:self)
40
+ end
41
+
42
+ it 'should report 1 ref to self' do
43
+ @refs.references_to(:self).should == 1
44
+ end
45
+
46
+ it 'should not report self among the max' do
47
+ @refs.max_keys.should include('a')
48
+ @refs.max_keys.should_not include(:self)
49
+ end
50
+
51
+ it 'should not report self as the max' do
52
+ @refs.self_is_max?.should == false
53
+ end
54
+ end
55
+ end
56
+ end
57
+
58
+ context 'with many refs to self' do
59
+ before(:each) do
60
+ @refs.record_reference_to(:self)
61
+ @refs.record_reference_to(:self)
62
+ @refs.record_reference_to('a')
63
+ @refs.record_reference_to(:self)
64
+ @refs.record_reference_to('b')
65
+ @refs.record_reference_to('a')
66
+ @refs.record_reference_to(:self)
67
+ end
68
+
69
+ it 'should report all refs to self' do
70
+ @refs.references_to(:self).should == 4
71
+ end
72
+
73
+ it 'should report self among the max' do
74
+ @refs.max_keys.should == { :self => 4}
75
+ end
76
+
77
+ it 'should report self as the max' do
78
+ @refs.self_is_max?.should == true
79
+ end
80
+ end
81
+
82
+ context 'when self is not the only max' do
83
+ before(:each) do
84
+ @refs.record_reference_to('a')
85
+ @refs.record_reference_to(:self)
86
+ @refs.record_reference_to(:self)
87
+ @refs.record_reference_to('b')
88
+ @refs.record_reference_to('a')
89
+ end
90
+
91
+ it 'should report all refs to self' do
92
+ @refs.references_to(:self).should == 2
93
+ end
94
+
95
+ it 'should report self among the max' do
96
+ @refs.max_keys.should include('a')
97
+ @refs.max_keys.should include(:self)
98
+ end
99
+
100
+ it 'should report self as the max' do
101
+ @refs.self_is_max?.should == true
102
+ end
103
+ end
104
+
105
+ context 'when self is not among the max' do
106
+ before(:each) do
107
+ @refs.record_reference_to('a')
108
+ @refs.record_reference_to('b')
109
+ @refs.record_reference_to('a')
110
+ @refs.record_reference_to('b')
111
+ end
112
+
113
+ it 'should report all refs to self' do
114
+ @refs.references_to(:self).should == 0
115
+ end
116
+
117
+ it 'should not report self among the max' do
118
+ @refs.max_keys.should include('a')
119
+ @refs.max_keys.should include('b')
120
+ end
121
+
122
+ it 'should not report self as the max' do
123
+ @refs.self_is_max?.should == false
124
+ end
13
125
  end
14
126
  end
15
127
 
16
- describe ObjectRefs, 'with no refs to self' do
17
- before(:each) do
18
- @refs = ObjectRefs.new
19
- @refs.record_ref('a')
20
- @refs.record_ref('b')
21
- @refs.record_ref('a')
22
- end
23
-
24
- it 'should report no refs to self' do
25
- @refs.refs_to_self.should == 0
26
- end
27
-
28
- it 'should report :a as the max' do
29
- @refs.max_keys.should == {'a' => 2}
30
- end
31
-
32
- it 'should not report self as the max' do
33
- @refs.self_is_max?.should == false
34
- end
35
- end
36
-
37
- describe ObjectRefs, 'with one ref to self' do
38
- before(:each) do
39
- @refs = ObjectRefs.new
40
- @refs.record_ref('a')
41
- @refs.record_ref('b')
42
- @refs.record_ref('a')
43
- @refs.record_reference_to_self
44
- end
45
-
46
- it 'should report 1 ref to self' do
47
- @refs.refs_to_self.should == 1
48
- end
49
-
50
- it 'should not report self among the max' do
51
- @refs.max_keys.should be_include('a')
52
- @refs.max_keys.should_not include(Sexp.from_array([:lit, :self]))
53
- end
54
-
55
- it 'should not report self as the max' do
56
- @refs.self_is_max?.should == false
57
- end
58
- end
59
-
60
- describe ObjectRefs, 'with many refs to self' do
61
- before(:each) do
62
- @refs = ObjectRefs.new
63
- @refs.record_reference_to_self
64
- @refs.record_reference_to_self
65
- @refs.record_ref('a')
66
- @refs.record_reference_to_self
67
- @refs.record_ref('b')
68
- @refs.record_ref('a')
69
- @refs.record_reference_to_self
70
- end
71
-
72
- it 'should report all refs to self' do
73
- @refs.refs_to_self.should == 4
74
- end
75
-
76
- it 'should report self among the max' do
77
- @refs.max_keys.should == {Sexp.from_array([:lit, :self]) => 4}
78
- end
79
-
80
- it 'should report self as the max' do
81
- @refs.self_is_max?.should == true
82
- end
83
- end
84
-
85
- describe ObjectRefs, 'when self is not the only max' do
86
- before(:each) do
87
- @refs = ObjectRefs.new
88
- @refs.record_ref('a')
89
- @refs.record_reference_to_self
90
- @refs.record_reference_to_self
91
- @refs.record_ref('b')
92
- @refs.record_ref('a')
93
- end
94
-
95
- it 'should report all refs to self' do
96
- @refs.refs_to_self.should == 2
97
- end
98
-
99
- it 'should report self among the max' do
100
- @refs.max_keys.should be_include('a')
101
- @refs.max_keys.should be_include(Sexp.from_array([:lit, :self]))
102
- end
103
-
104
- it 'should report self as the max' do
105
- @refs.self_is_max?.should == true
106
- end
107
- end
108
-
109
- describe ObjectRefs, 'when self is not among the max' do
110
- before(:each) do
111
- @refs = ObjectRefs.new
112
- @refs.record_ref('a')
113
- @refs.record_ref('b')
114
- @refs.record_ref('a')
115
- @refs.record_ref('b')
116
- end
117
-
118
- it 'should report all refs to self' do
119
- @refs.refs_to_self.should == 0
120
- end
121
-
122
- it 'should not report self among the max' do
123
- @refs.max_keys.should be_include('a')
124
- @refs.max_keys.should be_include('b')
125
- end
126
-
127
- it 'should not report self as the max' do
128
- @refs.self_is_max?.should == false
129
- end
130
- end