reek 3.4.0 → 3.4.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (75) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +9 -0
  3. data/features/step_definitions/reek_steps.rb +19 -16
  4. data/lib/reek/ast/sexp_extensions.rb +17 -8
  5. data/lib/reek/cli/application.rb +21 -12
  6. data/lib/reek/cli/option_interpreter.rb +1 -6
  7. data/lib/reek/cli/options.rb +32 -22
  8. data/lib/reek/report/location_formatter.rb +11 -5
  9. data/lib/reek/smells/smell_warning.rb +10 -2
  10. data/lib/reek/smells/uncommunicative_method_name.rb +25 -21
  11. data/lib/reek/smells/uncommunicative_parameter_name.rb +14 -15
  12. data/lib/reek/spec/should_reek_of.rb +44 -9
  13. data/lib/reek/version.rb +1 -1
  14. data/reek.gemspec +2 -2
  15. data/spec/reek/ast/node_spec.rb +1 -1
  16. data/spec/reek/ast/object_refs_spec.rb +1 -1
  17. data/spec/reek/ast/reference_collector_spec.rb +1 -1
  18. data/spec/reek/ast/sexp_extensions_spec.rb +49 -2
  19. data/spec/reek/ast/sexp_formatter_spec.rb +1 -1
  20. data/spec/reek/cli/option_interpreter_spec.rb +7 -7
  21. data/spec/reek/cli/options_spec.rb +27 -19
  22. data/spec/reek/cli/warning_collector_spec.rb +2 -2
  23. data/spec/reek/code_comment_spec.rb +1 -1
  24. data/spec/reek/configuration/app_configuration_spec.rb +4 -4
  25. data/spec/reek/configuration/default_directive_spec.rb +1 -1
  26. data/spec/reek/configuration/directory_directives_spec.rb +1 -1
  27. data/spec/reek/configuration/excluded_paths_spec.rb +1 -1
  28. data/spec/reek/context/code_context_spec.rb +2 -2
  29. data/spec/reek/context/method_context_spec.rb +1 -1
  30. data/spec/reek/context/module_context_spec.rb +2 -2
  31. data/spec/reek/context/root_context_spec.rb +1 -1
  32. data/spec/reek/context/singleton_method_context_spec.rb +1 -1
  33. data/spec/reek/examiner_spec.rb +1 -1
  34. data/spec/reek/report/html_report_spec.rb +2 -2
  35. data/spec/reek/report/json_report_spec.rb +3 -3
  36. data/spec/reek/report/location_formatter_spec.rb +30 -0
  37. data/spec/reek/report/text_report_spec.rb +4 -4
  38. data/spec/reek/report/xml_report_spec.rb +2 -2
  39. data/spec/reek/report/yaml_report_spec.rb +3 -3
  40. data/spec/reek/smells/attribute_spec.rb +1 -1
  41. data/spec/reek/smells/boolean_parameter_spec.rb +1 -1
  42. data/spec/reek/smells/class_variable_spec.rb +2 -2
  43. data/spec/reek/smells/control_parameter_spec.rb +1 -1
  44. data/spec/reek/smells/data_clump_spec.rb +1 -1
  45. data/spec/reek/smells/duplicate_method_call_spec.rb +3 -3
  46. data/spec/reek/smells/feature_envy_spec.rb +2 -2
  47. data/spec/reek/smells/irresponsible_module_spec.rb +2 -2
  48. data/spec/reek/smells/long_parameter_list_spec.rb +2 -2
  49. data/spec/reek/smells/long_yield_list_spec.rb +2 -2
  50. data/spec/reek/smells/module_initialize_spec.rb +1 -1
  51. data/spec/reek/smells/nested_iterators_spec.rb +1 -1
  52. data/spec/reek/smells/nil_check_spec.rb +2 -2
  53. data/spec/reek/smells/prima_donna_method_spec.rb +1 -1
  54. data/spec/reek/smells/repeated_conditional_spec.rb +3 -3
  55. data/spec/reek/smells/smell_configuration_spec.rb +1 -1
  56. data/spec/reek/smells/smell_repository_spec.rb +2 -2
  57. data/spec/reek/smells/smell_warning_spec.rb +1 -1
  58. data/spec/reek/smells/too_many_instance_variables_spec.rb +1 -1
  59. data/spec/reek/smells/too_many_methods_spec.rb +1 -1
  60. data/spec/reek/smells/too_many_statements_spec.rb +1 -1
  61. data/spec/reek/smells/uncommunicative_method_name_spec.rb +2 -2
  62. data/spec/reek/smells/uncommunicative_module_name_spec.rb +2 -2
  63. data/spec/reek/smells/uncommunicative_parameter_name_spec.rb +2 -2
  64. data/spec/reek/smells/uncommunicative_variable_name_spec.rb +1 -1
  65. data/spec/reek/smells/unused_parameters_spec.rb +1 -1
  66. data/spec/reek/smells/utility_function_spec.rb +2 -2
  67. data/spec/reek/source/source_code_spec.rb +1 -1
  68. data/spec/reek/source/source_locator_spec.rb +2 -2
  69. data/spec/reek/spec/should_reek_of_spec.rb +90 -37
  70. data/spec/reek/spec/should_reek_only_of_spec.rb +1 -1
  71. data/spec/reek/spec/should_reek_spec.rb +1 -1
  72. data/spec/reek/tree_dresser_spec.rb +2 -2
  73. data/spec/reek/tree_walker_spec.rb +2 -2
  74. data/spec/spec_helper.rb +6 -0
  75. metadata +7 -6
@@ -1,5 +1,5 @@
1
1
  require_relative '../spec_helper'
2
- require_relative '../../lib/reek/examiner'
2
+ require_lib 'reek/examiner'
3
3
 
4
4
  RSpec.shared_examples_for 'no smells found' do
5
5
  it 'is not smelly' do
@@ -1,7 +1,7 @@
1
1
  require 'tempfile'
2
2
  require_relative '../../spec_helper'
3
- require_relative '../../../lib/reek/examiner'
4
- require_relative '../../../lib/reek/report/report'
3
+ require_lib 'reek/examiner'
4
+ require_lib 'reek/report/report'
5
5
 
6
6
  RSpec.describe Reek::Report::HTMLReport do
7
7
  let(:instance) { Reek::Report::HTMLReport.new }
@@ -1,7 +1,7 @@
1
1
  require_relative '../../spec_helper'
2
- require_relative '../../../lib/reek/examiner'
3
- require_relative '../../../lib/reek/report/report'
4
- require_relative '../../../lib/reek/report/formatter'
2
+ require_lib 'reek/examiner'
3
+ require_lib 'reek/report/report'
4
+ require_lib 'reek/report/formatter'
5
5
 
6
6
  require 'json'
7
7
  require 'stringio'
@@ -0,0 +1,30 @@
1
+ require_relative '../../spec_helper'
2
+ require_lib 'reek/report/formatter'
3
+
4
+ RSpec.describe 'location formatters' do
5
+ let(:warning) { build(:smell_warning, lines: [11, 9, 250, 100]) }
6
+
7
+ describe Reek::Report::BlankLocationFormatter do
8
+ describe '.format' do
9
+ it 'returns a blank String regardless of the warning' do
10
+ expect(described_class.format(warning)).to eq('')
11
+ end
12
+ end
13
+ end
14
+
15
+ describe Reek::Report::DefaultLocationFormatter do
16
+ describe '.format' do
17
+ it 'returns a prefix with sorted line numbers' do
18
+ expect(described_class.format(warning)).to eq('[9, 11, 100, 250]:')
19
+ end
20
+ end
21
+ end
22
+
23
+ describe Reek::Report::SingleLineLocationFormatter do
24
+ describe '.format' do
25
+ it 'returns the first line where the smell was found' do
26
+ expect(described_class.format(warning)).to eq('dummy_file:9: ')
27
+ end
28
+ end
29
+ end
30
+ end
@@ -1,8 +1,8 @@
1
1
  require_relative '../../spec_helper'
2
- require_relative '../../../lib/reek/examiner'
3
- require_relative '../../../lib/reek/report/report'
4
- require_relative '../../../lib/reek/report/formatter'
5
- require_relative '../../../lib/reek/report/heading_formatter'
2
+ require_lib 'reek/examiner'
3
+ require_lib 'reek/report/report'
4
+ require_lib 'reek/report/formatter'
5
+ require_lib 'reek/report/heading_formatter'
6
6
  require 'rainbow'
7
7
 
8
8
  RSpec.describe Reek::Report::TextReport do
@@ -1,6 +1,6 @@
1
1
  require_relative '../../spec_helper'
2
- require_relative '../../../lib/reek/examiner'
3
- require_relative '../../../lib/reek/report/report'
2
+ require_lib 'reek/examiner'
3
+ require_lib 'reek/report/report'
4
4
 
5
5
  RSpec.describe Reek::Report::XMLReport do
6
6
  let(:xml_report) { Reek::Report::XMLReport.new }
@@ -1,7 +1,7 @@
1
1
  require_relative '../../spec_helper'
2
- require_relative '../../../lib/reek/examiner'
3
- require_relative '../../../lib/reek/report/report'
4
- require_relative '../../../lib/reek/report/formatter'
2
+ require_lib 'reek/examiner'
3
+ require_lib 'reek/report/report'
4
+ require_lib 'reek/report/formatter'
5
5
 
6
6
  require 'yaml'
7
7
  require 'stringio'
@@ -1,5 +1,5 @@
1
1
  require_relative '../../spec_helper'
2
- require_relative '../../../lib/reek/smells/attribute'
2
+ require_lib 'reek/smells/attribute'
3
3
  require_relative 'smell_detector_shared'
4
4
 
5
5
  RSpec.describe Reek::Smells::Attribute do
@@ -1,5 +1,5 @@
1
1
  require_relative '../../spec_helper'
2
- require_relative '../../../lib/reek/smells/boolean_parameter'
2
+ require_lib 'reek/smells/boolean_parameter'
3
3
  require_relative 'smell_detector_shared'
4
4
 
5
5
  RSpec.describe Reek::Smells::BooleanParameter do
@@ -1,6 +1,6 @@
1
1
  require_relative '../../spec_helper'
2
- require_relative '../../../lib/reek/smells/class_variable'
3
- require_relative '../../../lib/reek/context/module_context'
2
+ require_lib 'reek/smells/class_variable'
3
+ require_lib 'reek/context/module_context'
4
4
  require_relative 'smell_detector_shared'
5
5
 
6
6
  RSpec.describe Reek::Smells::ClassVariable do
@@ -1,5 +1,5 @@
1
1
  require_relative '../../spec_helper'
2
- require_relative '../../../lib/reek/smells/control_parameter'
2
+ require_lib 'reek/smells/control_parameter'
3
3
  require_relative 'smell_detector_shared'
4
4
 
5
5
  RSpec.describe Reek::Smells::ControlParameter do
@@ -1,5 +1,5 @@
1
1
  require_relative '../../spec_helper'
2
- require_relative '../../../lib/reek/smells/data_clump'
2
+ require_lib 'reek/smells/data_clump'
3
3
  require_relative 'smell_detector_shared'
4
4
 
5
5
  RSpec.shared_examples_for 'a data clump detector' do
@@ -1,7 +1,7 @@
1
1
  require_relative '../../spec_helper'
2
- require_relative '../../../lib/reek/smells/duplicate_method_call'
3
- require_relative '../../../lib/reek/context/code_context'
4
- require_relative '../../../lib/reek/tree_walker'
2
+ require_lib 'reek/smells/duplicate_method_call'
3
+ require_lib 'reek/context/code_context'
4
+ require_lib 'reek/tree_walker'
5
5
  require_relative 'smell_detector_shared'
6
6
 
7
7
  RSpec.describe Reek::Smells::DuplicateMethodCall do
@@ -1,6 +1,6 @@
1
1
  require_relative '../../spec_helper'
2
- require_relative '../../../lib/reek/smells/feature_envy'
3
- require_relative '../../../lib/reek/examiner'
2
+ require_lib 'reek/smells/feature_envy'
3
+ require_lib 'reek/examiner'
4
4
  require_relative 'smell_detector_shared'
5
5
 
6
6
  # TODO: Bring specs in line with specs for other detectors
@@ -1,6 +1,6 @@
1
1
  require_relative '../../spec_helper'
2
- require_relative '../../../lib/reek/context/code_context'
3
- require_relative '../../../lib/reek/smells/irresponsible_module'
2
+ require_lib 'reek/context/code_context'
3
+ require_lib 'reek/smells/irresponsible_module'
4
4
  require_relative 'smell_detector_shared'
5
5
 
6
6
  RSpec.describe Reek::Smells::IrresponsibleModule do
@@ -1,6 +1,6 @@
1
1
  require_relative '../../spec_helper'
2
- require_relative '../../../lib/reek/context/code_context'
3
- require_relative '../../../lib/reek/smells/long_parameter_list'
2
+ require_lib 'reek/context/code_context'
3
+ require_lib 'reek/smells/long_parameter_list'
4
4
  require_relative 'smell_detector_shared'
5
5
 
6
6
  RSpec.describe Reek::Smells::LongParameterList do
@@ -1,6 +1,6 @@
1
1
  require_relative '../../spec_helper'
2
- require_relative '../../../lib/reek/context/code_context'
3
- require_relative '../../../lib/reek/smells/long_yield_list'
2
+ require_lib 'reek/context/code_context'
3
+ require_lib 'reek/smells/long_yield_list'
4
4
  require_relative 'smell_detector_shared'
5
5
 
6
6
  RSpec.describe Reek::Smells::LongYieldList do
@@ -1,5 +1,5 @@
1
1
  require_relative '../../spec_helper'
2
- require_relative '../../../lib/reek/smells/module_initialize'
2
+ require_lib 'reek/smells/module_initialize'
3
3
  require_relative 'smell_detector_shared'
4
4
 
5
5
  RSpec.describe Reek::Smells::ModuleInitialize do
@@ -1,5 +1,5 @@
1
1
  require_relative '../../spec_helper'
2
- require_relative '../../../lib/reek/smells/nested_iterators'
2
+ require_lib 'reek/smells/nested_iterators'
3
3
  require_relative 'smell_detector_shared'
4
4
 
5
5
  RSpec.describe Reek::Smells::NestedIterators do
@@ -1,6 +1,6 @@
1
1
  require_relative '../../spec_helper'
2
- require_relative '../../../lib/reek/context/code_context'
3
- require_relative '../../../lib/reek/smells/nil_check'
2
+ require_lib 'reek/context/code_context'
3
+ require_lib 'reek/smells/nil_check'
4
4
  require_relative 'smell_detector_shared'
5
5
 
6
6
  RSpec.describe Reek::Smells::NilCheck do
@@ -1,5 +1,5 @@
1
1
  require_relative '../../spec_helper'
2
- require_relative '../../../lib/reek/context/module_context'
2
+ require_lib 'reek/context/module_context'
3
3
  require_relative 'smell_detector_shared'
4
4
 
5
5
  RSpec.describe Reek::Smells::PrimaDonnaMethod do
@@ -1,8 +1,8 @@
1
1
  require_relative '../../spec_helper'
2
- require_relative '../../../lib/reek/smells/repeated_conditional'
3
- require_relative '../../../lib/reek/context/code_context'
2
+ require_lib 'reek/smells/repeated_conditional'
3
+ require_lib 'reek/context/code_context'
4
4
  require_relative 'smell_detector_shared'
5
- require_relative '../../../lib/reek/source/source_code'
5
+ require_lib 'reek/source/source_code'
6
6
 
7
7
  RSpec.describe Reek::Smells::RepeatedConditional do
8
8
  let(:detector) { build(:smell_detector, smell_type: :RepeatedConditional, source: source_name) }
@@ -1,5 +1,5 @@
1
1
  require_relative '../../spec_helper'
2
- require_relative '../../../lib/reek/smells/smell_configuration'
2
+ require_lib 'reek/smells/smell_configuration'
3
3
 
4
4
  RSpec.describe Reek::Smells::SmellConfiguration do
5
5
  it 'returns the default value when key not found' do
@@ -1,6 +1,6 @@
1
1
  require_relative '../../spec_helper'
2
- require_relative '../../../lib/reek/smells/smell_detector'
3
- require_relative '../../../lib/reek/smells/smell_repository'
2
+ require_lib 'reek/smells/smell_detector'
3
+ require_lib 'reek/smells/smell_repository'
4
4
 
5
5
  RSpec.describe Reek::Smells::SmellRepository do
6
6
  describe '.smell_types' do
@@ -1,5 +1,5 @@
1
1
  require_relative '../../spec_helper'
2
- require_relative '../../../lib/reek/smells/smell_warning'
2
+ require_lib 'reek/smells/smell_warning'
3
3
 
4
4
  RSpec.describe Reek::Smells::SmellWarning do
5
5
  let(:duplication_detector) { build(:smell_detector, smell_type: 'DuplicateMethodCall') }
@@ -1,5 +1,5 @@
1
1
  require_relative '../../spec_helper'
2
- require_relative '../../../lib/reek/smells/too_many_instance_variables'
2
+ require_lib 'reek/smells/too_many_instance_variables'
3
3
  require_relative 'smell_detector_shared'
4
4
 
5
5
  RSpec.describe Reek::Smells::TooManyInstanceVariables do
@@ -1,5 +1,5 @@
1
1
  require_relative '../../spec_helper'
2
- require_relative '../../../lib/reek/smells/too_many_methods'
2
+ require_lib 'reek/smells/too_many_methods'
3
3
  require_relative 'smell_detector_shared'
4
4
 
5
5
  RSpec.describe Reek::Smells::TooManyMethods do
@@ -1,5 +1,5 @@
1
1
  require_relative '../../spec_helper'
2
- require_relative '../../../lib/reek/smells/too_many_statements'
2
+ require_lib 'reek/smells/too_many_statements'
3
3
  require_relative 'smell_detector_shared'
4
4
 
5
5
  RSpec.describe Reek::Smells::TooManyStatements do
@@ -1,5 +1,5 @@
1
1
  require_relative '../../spec_helper'
2
- require_relative '../../../lib/reek/smells/uncommunicative_method_name'
2
+ require_lib 'reek/smells/uncommunicative_method_name'
3
3
  require_relative 'smell_detector_shared'
4
4
 
5
5
  RSpec.describe Reek::Smells::UncommunicativeMethodName do
@@ -12,7 +12,7 @@ RSpec.describe Reek::Smells::UncommunicativeMethodName do
12
12
 
13
13
  ['help', '+', '-', '/', '*'].each do |method_name|
14
14
  it "accepts the method name '#{method_name}'" do
15
- src = "def #{method_name}(fred) basics(17) end"
15
+ src = "def #{method_name}(arg) basics(17) end"
16
16
  expect(src).not_to reek_of(:UncommunicativeMethodName)
17
17
  end
18
18
  end
@@ -1,7 +1,7 @@
1
1
  require_relative '../../spec_helper'
2
- require_relative '../../../lib/reek/smells/uncommunicative_module_name'
2
+ require_lib 'reek/smells/uncommunicative_module_name'
3
3
  require_relative 'smell_detector_shared'
4
- require_relative '../../../lib/reek/context/code_context'
4
+ require_lib 'reek/context/code_context'
5
5
 
6
6
  RSpec.describe Reek::Smells::UncommunicativeModuleName do
7
7
  let(:source_name) { 'string' }
@@ -1,7 +1,7 @@
1
1
  require_relative '../../spec_helper'
2
- require_relative '../../../lib/reek/smells/uncommunicative_parameter_name'
2
+ require_lib 'reek/smells/uncommunicative_parameter_name'
3
3
  require_relative 'smell_detector_shared'
4
- require_relative '../../../lib/reek/context/method_context'
4
+ require_lib 'reek/context/method_context'
5
5
 
6
6
  RSpec.describe Reek::Smells::UncommunicativeParameterName do
7
7
  let(:detector) do
@@ -1,5 +1,5 @@
1
1
  require_relative '../../spec_helper'
2
- require_relative '../../../lib/reek/smells/uncommunicative_variable_name'
2
+ require_lib 'reek/smells/uncommunicative_variable_name'
3
3
  require_relative 'smell_detector_shared'
4
4
 
5
5
  RSpec.describe Reek::Smells::UncommunicativeVariableName do
@@ -1,5 +1,5 @@
1
1
  require_relative '../../spec_helper'
2
- require_relative '../../../lib/reek/smells/unused_parameters'
2
+ require_lib 'reek/smells/unused_parameters'
3
3
  require_relative 'smell_detector_shared'
4
4
 
5
5
  RSpec.describe Reek::Smells::UnusedParameters do
@@ -1,6 +1,6 @@
1
1
  require_relative '../../spec_helper'
2
- require_relative '../../../lib/reek/smells/utility_function'
3
- require_relative '../../../lib/reek/examiner'
2
+ require_lib 'reek/smells/utility_function'
3
+ require_lib 'reek/examiner'
4
4
  require_relative 'smell_detector_shared'
5
5
 
6
6
  # TODO: Bring specs in line with specs for other detectors
@@ -1,6 +1,6 @@
1
1
  require_relative '../../spec_helper'
2
2
  require 'stringio'
3
- require_relative '../../../lib/reek/source/source_code'
3
+ require_lib 'reek/source/source_code'
4
4
 
5
5
  RSpec.describe Reek::Source::SourceCode do
6
6
  describe '#syntax_tree' do
@@ -1,7 +1,7 @@
1
1
  require 'pathname'
2
2
  require_relative '../../spec_helper'
3
- require_relative '../../../lib/reek/configuration/app_configuration'
4
- require_relative '../../../lib/reek/source/source_locator'
3
+ require_lib 'reek/configuration/app_configuration'
4
+ require_lib 'reek/source/source_locator'
5
5
 
6
6
  RSpec.describe Reek::Source::SourceLocator do
7
7
  describe '#sources' do
@@ -1,63 +1,116 @@
1
1
  require 'pathname'
2
2
  require_relative '../../spec_helper'
3
- require_relative '../../../lib/reek/spec'
3
+ require_lib 'reek/spec'
4
4
 
5
5
  RSpec.describe Reek::Spec::ShouldReekOf do
6
- context 'rdoc demo example' do
7
- let(:ruby) { 'def double_thing() @other.thing.foo + @other.thing.foo end' }
6
+ describe 'smell type check' do
7
+ let(:src) { 'def double_thing() @other.thing.foo + @other.thing.foo end' }
8
8
 
9
- it 'reports duplicate calls to @other.thing' do
10
- expect(ruby).to reek_of(:Duplication, name: '@other.thing')
9
+ it 'reports duplicate calls' do
10
+ expect(src).to reek_of(:Duplication)
11
11
  end
12
12
 
13
- it 'reports duplicate calls to @other.thing.foo' do
14
- expect(ruby).to reek_of(:Duplication, name: '@other.thing.foo')
15
- end
16
-
17
- it 'does not report any feature envy' do
18
- expect(ruby).not_to reek_of(:FeatureEnvy)
13
+ it 'does not report any other smell types' do
14
+ expect(src).not_to reek_of(:FeatureEnvy)
19
15
  end
20
16
  end
21
17
 
22
- context 'checking code in a string' do
23
- let(:clean_code) { 'def good() true; end' }
24
- let(:matcher) { Reek::Spec::ShouldReekOf.new(:UncommunicativeVariableName, name: 'y') }
25
- let(:smelly_code) { 'def x() y = 4; end' }
18
+ describe 'different sources of input' do
19
+ context 'checking code in a string' do
20
+ let(:clean_code) { 'def good() true; end' }
21
+ let(:matcher) { Reek::Spec::ShouldReekOf.new(:UncommunicativeVariableName, name: 'y') }
22
+ let(:smelly_code) { 'def x() y = 4; end' }
26
23
 
27
- it 'matches a smelly String' do
28
- expect(matcher.matches?(smelly_code)).to be_truthy
29
- end
24
+ it 'matches a smelly String' do
25
+ expect(matcher.matches?(smelly_code)).to be_truthy
26
+ end
30
27
 
31
- it 'doesnt match a fragrant String' do
32
- expect(matcher.matches?(clean_code)).to be_falsey
28
+ it 'doesnt match a fragrant String' do
29
+ expect(matcher.matches?(clean_code)).to be_falsey
30
+ end
33
31
  end
34
32
 
35
- it 'reports the smells when should_not fails' do
36
- expect(matcher.matches?(smelly_code)).to be_truthy
37
- expect(matcher.failure_message_when_negated).to match('UncommunicativeVariableName')
33
+ context 'checking code in a File' do
34
+ let(:clean_file) { Pathname.glob("#{SAMPLES_PATH}/three_clean_files/*.rb").first }
35
+ let(:matcher) { Reek::Spec::ShouldReekOf.new(:UncommunicativeVariableName, name: '@s') }
36
+ let(:smelly_file) { Pathname.glob("#{SAMPLES_PATH}/two_smelly_files/*.rb").first }
37
+
38
+ it 'matches a smelly file' do
39
+ expect(matcher.matches?(smelly_file)).to be_truthy
40
+ end
41
+
42
+ it 'doesnt match a fragrant file' do
43
+ expect(matcher.matches?(clean_file)).to be_falsey
44
+ end
38
45
  end
39
46
  end
40
47
 
41
- context 'passing in smell_details with unknown parameter name' do
42
- let(:matcher) { Reek::Spec::ShouldReekOf.new(:UncommunicativeVariableName, foo: 'y') }
43
- let(:smelly_code) { 'def x() y = 4; end' }
48
+ describe 'smell types and smell details' do
49
+ context 'passing in smell_details with unknown parameter name' do
50
+ let(:matcher) { Reek::Spec::ShouldReekOf.new(:UncommunicativeVariableName, foo: 'y') }
51
+ let(:smelly_code) { 'def x() y = 4; end' }
44
52
 
45
- it 'raises ArgumentError' do
46
- expect { matcher.matches?(smelly_code) }.to raise_error(ArgumentError)
53
+ it 'raises ArgumentError' do
54
+ expect { matcher.matches?(smelly_code) }.to raise_error(ArgumentError)
55
+ end
56
+ end
57
+
58
+ context 'both are matching' do
59
+ let(:smelly_code) { 'def x() y = 4; end' }
60
+ let(:matcher) { Reek::Spec::ShouldReekOf.new(:UncommunicativeVariableName, name: 'y') }
61
+
62
+ it 'is truthy' do
63
+ expect(matcher.matches?(smelly_code)).to be_truthy
64
+ end
47
65
  end
48
- end
49
66
 
50
- context 'checking code in a File' do
51
- let(:clean_file) { Pathname.glob("#{SAMPLES_PATH}/three_clean_files/*.rb").first }
52
- let(:matcher) { Reek::Spec::ShouldReekOf.new(:UncommunicativeVariableName, name: '@s') }
53
- let(:smelly_file) { Pathname.glob("#{SAMPLES_PATH}/two_smelly_files/*.rb").first }
67
+ context 'no smell_type is matching' do
68
+ let(:smelly_code) { 'def dummy() y = 4; end' }
69
+ let(:falsey_matcher) { Reek::Spec::ShouldReekOf.new(:FeatureEnvy, name: 'y') }
70
+ let(:truthy_matcher) { Reek::Spec::ShouldReekOf.new(:UncommunicativeVariableName, name: 'y') }
54
71
 
55
- it 'matches a smelly String' do
56
- expect(matcher.matches?(smelly_file)).to be_truthy
72
+ it 'is falsey' do
73
+ expect(falsey_matcher.matches?(smelly_code)).to be_falsey
74
+ end
75
+
76
+ it 'sets the proper error message' do
77
+ falsey_matcher.matches?(smelly_code)
78
+
79
+ expect(falsey_matcher.failure_message).to\
80
+ match('Expected string to reek of FeatureEnvy, but it didn\'t')
81
+ end
82
+
83
+ it 'sets the proper error message when negated' do
84
+ truthy_matcher.matches?(smelly_code)
85
+
86
+ expect(truthy_matcher.failure_message_when_negated).to\
87
+ match('Expected string not to reek of UncommunicativeVariableName, but it did')
88
+ end
57
89
  end
58
90
 
59
- it 'doesnt match a fragrant String' do
60
- expect(matcher.matches?(clean_file)).to be_falsey
91
+ context 'smell type is matching but smell details are not' do
92
+ let(:smelly_code) { 'def dummy() y = 4; end' }
93
+ let(:matcher) { Reek::Spec::ShouldReekOf.new(:UncommunicativeVariableName, name: 'x') }
94
+
95
+ it 'is falsey' do
96
+ expect(matcher.matches?(smelly_code)).to be_falsey
97
+ end
98
+
99
+ it 'sets the proper error message' do
100
+ matcher.matches?(smelly_code)
101
+
102
+ expect(matcher.failure_message).to\
103
+ match('Expected string to reek of UncommunicativeVariableName (which it did) with '\
104
+ 'smell details {:name=>"x"}, which it didn\'t')
105
+ end
106
+
107
+ it 'sets the proper error message when negated' do
108
+ matcher.matches?(smelly_code)
109
+
110
+ expect(matcher.failure_message_when_negated).to\
111
+ match('Expected string not to reek of UncommunicativeVariableName with smell '\
112
+ 'details {:name=>"x"}, but it did')
113
+ end
61
114
  end
62
115
  end
63
116
  end