Sha256: 1a31dcc7010922352a87ec5b184ecc1428cce4e738682d559eee6485f75f1c84

Contents?: true

Size: 1.17 KB

Versions: 7

Compression:

Stored size: 1.17 KB

Contents

require 'reek/examiner'
require 'reek/cli/report/report'
require 'reek/cli/report/formatter'
require 'reek/cli/report/strategy'

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
        @warnings = @examiner.smells
        @warnings.length == 1 && @warnings[0].matches?(@klass, @patterns)
      end

      def failure_message
        rpt = Cli::Report::Formatter.format_list(@warnings)
        "Expected #{@examiner.description} to reek only of #{@klass}, but got:\n#{rpt}"
      end

      def failure_message_when_negated
        "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_category, *patterns)
      ShouldReekOnlyOf.new(smell_category, patterns)
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
reek-1.6.6 lib/reek/spec/should_reek_only_of.rb
reek-1.6.5 lib/reek/spec/should_reek_only_of.rb
reek-1.6.4 lib/reek/spec/should_reek_only_of.rb
reek-1.6.3 lib/reek/spec/should_reek_only_of.rb
reek-1.6.2 lib/reek/spec/should_reek_only_of.rb
reek-1.6.1 lib/reek/spec/should_reek_only_of.rb
reek-1.6.0 lib/reek/spec/should_reek_only_of.rb