Module: Reek::Spec

Defined in:
lib/reek/spec.rb,
lib/reek/spec/should_reek.rb,
lib/reek/spec/should_reek_of.rb,
lib/reek/spec/should_reek_only_of.rb

Overview

Provides matchers for Rspec, making it easy to check code quality.

If you require this module somewhere within your spec (or in your spec_helper), Reek will arrange to update Spec::Runner's config so that it knows about the matchers defined here.

Examples

Here's a spec that ensures there are no active code smells in the current project:

describe 'source code quality' do
  Dir['lib/**/*.rb'].each do |path|
    it "reports no smells in #{path}" do
      File.new(path).should_not reek
    end
  end
end

And here's an even simpler way to do the same:

it 'has no code smells' do
  Dir['lib/**/*.rb'].should_not reek
end

Here's a simple check of a code fragment:

'def equals(other) other.thing == self.thing end'.should_not reek

To check for specific smells, use something like this:

ruby = 'def double_thing() @other.thing.foo + @other.thing.foo end'
ruby.should reek_of(:Duplication, /@other.thing[^\.]/)
ruby.should reek_of(:Duplication, /@other.thing.foo/)
ruby.should_not reek_of(:FeatureEnvy)

Defined Under Namespace

Classes: ShouldReek, ShouldReekOf, ShouldReekOnlyOf

Instance Method Summary collapse

Instance Method Details

#reekObject

Returns true if and only if the target source code contains smells.


30
31
32
# File 'lib/reek/spec/should_reek.rb', line 30

def reek
  ShouldReek.new
end

#reek_of(smell_category, *patterns) ⇒ Object

Checks the target source code for instances of smell_category, and returns true only if one of them has a report string matching all of the patterns.


35
36
37
# File 'lib/reek/spec/should_reek_of.rb', line 35

def reek_of(smell_category, *patterns)
  ShouldReekOf.new(smell_category, patterns)
end

#reek_only_of(smell_category, *patterns) ⇒ Object

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.


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

def reek_only_of(smell_category, *patterns)
  ShouldReekOnlyOf.new(smell_category, patterns)
end