Class: Reek::Spec::ShouldReekOnlyOf

Inherits:
ShouldReekOf show all
Defined in:
lib/reek/spec/should_reek_only_of.rb

Overview

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

Instance Attribute Summary collapse

Attributes inherited from ShouldReekOf

#configuration, #examiner, #smell_details, #smell_type

Instance Method Summary collapse

Methods inherited from ShouldReekOf

#all_relevant_smell_details_formatted, #initialize, #matching_smell_details?, #matching_smell_types, #matching_smell_types?, #origin, #set_failure_messages, #set_failure_messages_for_smell_details, #set_failure_messages_for_smell_type, #with_config

Constructor Details

This class inherits a constructor from Reek::Spec::ShouldReekOf

Instance Attribute Details

#warningsObject (private)

Returns the value of attribute warnings.



38
39
40
# File 'lib/reek/spec/should_reek_only_of.rb', line 38

def warnings
  @warnings
end

Instance Method Details

#failure_messageObject



27
28
29
30
# File 'lib/reek/spec/should_reek_only_of.rb', line 27

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

#failure_message_when_negatedObject



32
33
34
# File 'lib/reek/spec/should_reek_only_of.rb', line 32

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

#matches?(source) ⇒ Boolean

Returns:

  • (Boolean)


15
16
17
# File 'lib/reek/spec/should_reek_only_of.rb', line 15

def matches?(source)
  matches_examiner?(Examiner.new(source, configuration: configuration))
end

#matches_examiner?(examiner) ⇒ Boolean

Returns:

  • (Boolean)


19
20
21
22
23
24
25
# File 'lib/reek/spec/should_reek_only_of.rb', line 19

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