Sha256: 4d71ed5293e8c650291bae3b939ef25d093bfb8e14bd6540559714fcd8d10ae4

Contents?: true

Size: 1.47 KB

Versions: 11

Compression:

Stored size: 1.47 KB

Contents

# Reek Driven Development

## rake

One way to drive quality into your code from the very beginning of a project is to run Reek as a part of your testing process. For example, you could do that by adding a [Rake Task](Rake-Task.md) to your rakefile, which will make it easy to run Reek on all your source files whenever you need to.

```Ruby
require 'reek/rake/task'

Reek::Rake::Task.new do |t|
  t.fail_on_error = true
  t.verbose = false
  t.source_files = 'lib/**/*.rb'
end
```

Now the command `reek` will run Reek on your source code (and in this case, it fails if it finds any smells). For more detailed information about Reek's integration with Rake, see [Rake Task](Rake-Task.md).

## reek/spec

But there's another way; a much more effective "Reek-driven" approach: add Reek expectations directly into your Rspec specs. Here's an example taken directly from Reek's own source code:

```Ruby
it 'contains no code smells' do
  Pathname.glob('lib/**/*.rb').each do |file|
    expect(file).not_to reek
  end
end
```

By requiring "reek/spec":http://reek.rubyforge.org/rdoc/classes/Reek/Spec.html you gain access to the `reek` matcher, which returns true if and only if Reek finds smells in your code. And if the test fails, the matcher produces an error message that includes details of all the smells it found.

## assert

If you're not yet into BDD with Rspec, you can still gain the benefits of Reek-driven development using assertions:

```Ruby
assert !Dir['lib/**/*.rb'].to_source.smelly?
```

Version data entries

11 entries across 9 versions & 2 rubygems

Version Path
reek-5.3.1 docs/Reek-Driven-Development.md
reek-5.3.0 docs/Reek-Driven-Development.md
config_gems_initialization_aim-0.1.4 vendor/bundle/ruby/2.5.0/gems/reek-5.2.0/docs/Reek-Driven-Development.md
config_gems_initialization_aim-0.1.4 vendor/bundle/ruby/2.5.0/gems/config_gems_initialization_aim-0.1.1/vendor/bundle/ruby/2.5.0/gems/reek-5.2.0/docs/Reek-Driven-Development.md
config_gems_initialization_aim-0.1.3 vendor/bundle/ruby/2.5.0/gems/config_gems_initialization_aim-0.1.1/vendor/bundle/ruby/2.5.0/gems/reek-5.2.0/docs/Reek-Driven-Development.md
config_gems_initialization_aim-0.1.3 vendor/bundle/ruby/2.5.0/gems/reek-5.2.0/docs/Reek-Driven-Development.md
reek-5.2.0 docs/Reek-Driven-Development.md
reek-5.1.0 docs/Reek-Driven-Development.md
reek-5.0.2 docs/Reek-Driven-Development.md
reek-5.0.1 docs/Reek-Driven-Development.md
reek-5.0.0 docs/Reek-Driven-Development.md