Class: Reek::Spec::ShouldReek

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

Overview

An rspec matcher that matches when the actual has code smells.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(configuration: Configuration::AppConfiguration.default) ⇒ ShouldReek

Returns a new instance of ShouldReek.



12
13
14
# File 'lib/reek/spec/should_reek.rb', line 12

def initialize(configuration: Configuration::AppConfiguration.default)
  @configuration = configuration
end

Instance Attribute Details

#configurationObject (readonly, private)

Returns the value of attribute configuration.



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

def configuration
  @configuration
end

#examinerObject (private)

Returns the value of attribute examiner.



33
34
35
# File 'lib/reek/spec/should_reek.rb', line 33

def examiner
  @examiner
end

Instance Method Details

#failure_messageObject



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

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

#failure_message_when_negatedObject



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

def failure_message_when_negated
  rpt = Report::SimpleWarningFormatter.new.format_list(examiner.smells)
  "Expected no smells, but got:\n#{rpt}"
end

#matches?(source) ⇒ Boolean

Returns:

  • (Boolean)


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

def matches?(source)
  self.examiner = Examiner.new(source, configuration: configuration)
  examiner.smelly?
end