Sha256: 07247f109396e1264e5c140e9f06b1af7d7a40f2575c3aa751d3bb9d1aec3b88
Contents?: true
Size: 1.66 KB
Versions: 3
Compression:
Stored size: 1.66 KB
Contents
module SmellOfMatcher class SmellOf def initialize(klass, *expected_smells) @klass = klass @expected_smells = expected_smells @config = {} end def failure_message_for_should "Expected #{@source.desc} to smell of #{@klass}, but it didn't: #{@reason}" end def failure_message_for_should_not "Expected #{@source.desc} not to smell of #{@klass}, but it did" end def matches?(src) @source = src.to_reek_source ctx = MethodContext.new(nil, @source.syntax_tree) detector = @klass.new(@source.desc, @klass.default_config.merge(@config)) detector.examine(ctx) actual_smells = detector.smells_found.to_a if actual_smells.empty? @reason = 'no smells found by detector' return false end return false if actual_smells.any? do |expected_smell| @reason = "Found #{expected_smell.smell_class}/#{expected_smell.subclass}" && expected_smell.smell_class != @klass::SMELL_CLASS && expected_smell.subclass != @klass::SMELL_SUBCLASS end return actual_smells.length == 1 if @expected_smells.empty? return false unless @expected_smells.length == actual_smells.length @expected_smells.each_with_index do |expected_smell,index| expected_smell.each do |(key,value)| if actual_smells[index].smell[key] != value @reason = "#{key} != #{value}" end end end true end def with_config(options) @config = options self end end def smell_of(klass, *smells) SmellOf.new(klass, *smells) end end RSpec.configure do |config| config.include(SmellOfMatcher) end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
reek-1.3.1 | spec/matchers/smell_of_matcher.rb |
reek-1.3 | spec/matchers/smell_of_matcher.rb |
reek-1.2.13 | spec/matchers/smell_of_matcher.rb |