Sha256: 3d88d612d9273ac067e96b52a0cd7e6ae125d45f9ba14a4a4e48fcd744ec6f54

Contents?: true

Size: 1.01 KB

Versions: 3

Compression:

Stored size: 1.01 KB

Contents

require 'reek/examiner'

module Reek
  module Spec
    #
    # An rspec matcher that matches when the +actual+ has the specified
    # code smell.
    #
    class ShouldReekOf        # :nodoc:
      def initialize(klass, patterns)
        @klass = klass
        @patterns = patterns
      end

      def matches?(actual)
        @examiner = Examiner.new(actual)
        @all_smells = @examiner.smells
        @all_smells.any? { |warning| warning.matches?(@klass, @patterns) }
      end

      def failure_message
        "Expected #{@examiner.description} to reek of #{@klass}, but it didn't"
      end

      def failure_message_when_negated
        "Expected #{@examiner.description} not to reek of #{@klass}, but it did"
      end
    end

    #
    # Checks the target source code for instances of +smell_class+,
    # and returns +true+ only if one of them has a report string matching
    # all of the +patterns+.
    #
    def reek_of(smell_class, *patterns)
      ShouldReekOf.new(smell_class, patterns)
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
reek-1.5.1 lib/reek/spec/should_reek_of.rb
reek-1.5.0 lib/reek/spec/should_reek_of.rb
reek-1.4.0 lib/reek/spec/should_reek_of.rb