Sha256: bd8d4f972702833b121386011ec53840eb2aa88f13d779faa8df740b07a861bb

Contents?: true

Size: 1.09 KB

Versions: 28

Compression:

Stored size: 1.09 KB

Contents

# frozen_string_literal: true

require_relative '../examiner'
require_relative '../report/simple_warning_formatter'
require_relative 'should_reek_of'
require_relative 'smell_matcher'

module Reek
  module Spec
    #
    # An rspec matcher that matches when the +actual+ has the specified
    # code smell and no others.
    #
    class ShouldReekOnlyOf < ShouldReekOf
      def matches?(source)
        matches_examiner?(Examiner.new(source, configuration: configuration))
      end

      def matches_examiner?(examiner)
        self.examiner = examiner
        self.warnings = examiner.smells
        return false if warnings.empty?

        warnings.all? { |warning| SmellMatcher.new(warning).matches?(smell_type) }
      end

      def failure_message
        rpt = Report::SimpleWarningFormatter.new.format_list(warnings)
        "Expected #{examiner.origin} to reek only of #{smell_type}, but got:\n#{rpt}"
      end

      def failure_message_when_negated
        "Expected #{examiner.origin} not to reek only of #{smell_type}, but it did"
      end

      private

      attr_accessor :warnings
    end
  end
end

Version data entries

28 entries across 26 versions & 2 rubygems

Version Path
reek-6.4.0 lib/reek/spec/should_reek_only_of.rb
reek-6.3.0 lib/reek/spec/should_reek_only_of.rb
reek-6.2.0 lib/reek/spec/should_reek_only_of.rb
reek-6.1.4 lib/reek/spec/should_reek_only_of.rb
reek-6.1.3 lib/reek/spec/should_reek_only_of.rb
reek-6.1.2 lib/reek/spec/should_reek_only_of.rb
reek-6.1.1 lib/reek/spec/should_reek_only_of.rb
reek-6.1.0 lib/reek/spec/should_reek_only_of.rb
reek-6.0.6 lib/reek/spec/should_reek_only_of.rb
reek-6.0.5 lib/reek/spec/should_reek_only_of.rb
reek-6.0.4 lib/reek/spec/should_reek_only_of.rb
reek-6.0.3 lib/reek/spec/should_reek_only_of.rb
reek-6.0.2 lib/reek/spec/should_reek_only_of.rb
reek-6.0.1 lib/reek/spec/should_reek_only_of.rb
reek-6.0.0 lib/reek/spec/should_reek_only_of.rb
reek-5.6.0 lib/reek/spec/should_reek_only_of.rb
reek-5.5.0 lib/reek/spec/should_reek_only_of.rb
reek-5.4.1 lib/reek/spec/should_reek_only_of.rb
reek-5.4.0 lib/reek/spec/should_reek_only_of.rb
reek-5.3.2 lib/reek/spec/should_reek_only_of.rb