Sha256: 34b5a760028b29fc5f8363313b9ac6a6ae914df5a953355889cc5597551a2ede

Contents?: true

Size: 1.18 KB

Versions: 2

Compression:

Stored size: 1.18 KB

Contents

require File.join(File.dirname(File.dirname(File.expand_path(__FILE__))), 'examiner')

module Reek
  module Spec

    #
    # An rspec matcher that matches when the +actual+ has the specified
    # code smell and no others.
    #
    class ShouldReekOnlyOf < ShouldReekOf        # :nodoc:
      def matches?(actual)
        matches_examiner?(Examiner.new(actual))
      end
      def matches_examiner?(examiner)
        @examiner = examiner
        @all_smells = @examiner.all_active_smells
        @all_smells.length == 1 and @all_smells[0].matches?(@klass, @patterns)
      end
      def failure_message_for_should
        rpt = @all_smells.map { |smell| "#{smell.report('%c %w (%s)')}" }.join("\n")
        "Expected #{@examiner.description} to reek only of #{@klass}, but got:\n#{rpt}"
      end
      def failure_message_for_should_not
        "Expected #{@examiner.description} not to reek only of #{@klass}, but it did"
      end
    end

    #
    # As for reek_of, but the matched smell warning must be the only warning of
    # any kind in the target source code's Reek report.
    #
    def reek_only_of(smell_class, *patterns)
      ShouldReekOnlyOf.new(smell_class, patterns)
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
reek-1.2.7.1 lib/reek/spec/should_reek_only_of.rb
reek-1.2.7 lib/reek/spec/should_reek_only_of.rb