module Reek::Spec

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 RSpec::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
  Pathname.glob('lib/**/*.rb').each do |path|
    it "reports no smells in #{path}" do
      expect(path).not_to reek
    end
  end
end

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

it 'has no code smells' do
  Pathname.glob('lib/**/*.rb').each do |path|
    expect(path).not_to reek
  end
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(:DuplicateMethodCall, name: '@other.thing')
ruby.should reek_of(:DuplicateMethodCall, name: '@other.thing.foo', count: 2)
ruby.should_not reek_of(:FeatureEnvy)

@public