Class: Reek::Spec::ShouldReekOf

Inherits:
Object
  • Object
show all
Defined in:
lib/reek/spec/should_reek_of.rb

Overview

An rspec matcher that matches when the actual has the specified code smell.

Direct Known Subclasses

ShouldReekOnlyOf

Instance Method Summary collapse

Constructor Details

#initialize(klass, patterns) ⇒ ShouldReekOf

:nodoc:


10
11
12
13
# File 'lib/reek/spec/should_reek_of.rb', line 10

def initialize(klass, patterns)
  @klass = klass
  @patterns = patterns
end

Instance Method Details

#failure_messageObject


21
22
23
# File 'lib/reek/spec/should_reek_of.rb', line 21

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

#failure_message_when_negatedObject


25
26
27
# File 'lib/reek/spec/should_reek_of.rb', line 25

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

#matches?(actual) ⇒ Boolean

Returns:

  • (Boolean)

15
16
17
18
19
# File 'lib/reek/spec/should_reek_of.rb', line 15

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