forked from troessner/reek
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Replaced code_checks by the new rspec matcher
- Loading branch information
1 parent
082e553
commit 7b0c5c1
Showing
20 changed files
with
379 additions
and
263 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,3 +8,6 @@ LargeClass: | |
LongMethod: | ||
exclude: | ||
- Reek::SexpFormatter#self.format | ||
UtilityFunction: | ||
exclude: | ||
- Reek::Spec |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
module Reek | ||
module Spec | ||
class ShouldReek | ||
def matches?(actual) | ||
@source = actual.to_source | ||
@source.smelly? | ||
end | ||
def failure_message_for_should | ||
"Expected source to reek, but it didn't" | ||
end | ||
def failure_message_for_should_not | ||
"Expected no smells, but got the following:\n#{@source.report}" | ||
end | ||
end | ||
|
||
def reek | ||
ShouldReek.new | ||
end | ||
|
||
class ShouldReekOf | ||
def initialize(klass, patterns) | ||
@klass = klass | ||
@patterns = patterns | ||
end | ||
def matches?(actual) | ||
@source = actual.to_source | ||
@source.has_smell?(@klass, @patterns) | ||
end | ||
def failure_message_for_should | ||
"Expected source to reek of #{@klass}, but it didn't" | ||
end | ||
def failure_message_for_should_not | ||
"Expected source not to reek of #{@klass}, but got:\n#{@source.report}" | ||
end | ||
end | ||
|
||
def reek_of(klass, *patterns) | ||
ShouldReekOf.new(klass, patterns) | ||
end | ||
|
||
class ShouldReekOnlyOf | ||
def initialize(klass, patterns) | ||
@klass = klass | ||
@patterns = patterns | ||
end | ||
def matches?(actual) | ||
@source = actual.to_source | ||
@source.report.length == 1 and @source.has_smell?(@klass, @patterns) | ||
end | ||
def failure_message_for_should | ||
"Expected source to reek only of #{@klass}, but got:\n#{@source.report}" | ||
end | ||
def failure_message_for_should_not | ||
"Expected source not to reek only of #{@klass}, but it did" | ||
end | ||
end | ||
|
||
def reek_only_of(klass, *patterns) | ||
ShouldReekOnlyOf.new(klass, patterns) | ||
end | ||
end | ||
end | ||
|
||
class String | ||
def to_source | ||
Source.from_s(self) | ||
end | ||
end | ||
|
||
module Reek | ||
class Source | ||
def to_source | ||
self | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,23 @@ | ||
require File.dirname(__FILE__) + '/../../spec_helper.rb' | ||
|
||
require 'spec/reek/code_checks' | ||
require 'reek/smells/control_couple' | ||
|
||
include CodeChecks | ||
include Reek::Smells | ||
|
||
describe ControlCouple do | ||
check 'should report a ternary check on a parameter', | ||
'def simple(arga) arga ? @ivar : 3 end', [[/arga/]] | ||
check 'should not report a ternary check on an ivar', | ||
'def simple(arga) @ivar ? arga : 3 end', [] | ||
check 'should not report a ternary check on a lvar', | ||
'def simple(arga) lvar = 27; lvar ? arga : @ivar end', [] | ||
check 'should spot a couple inside a block', | ||
'def blocks(arg) @text.map { |blk| arg ? blk : "#{blk}" } end', [[/arg/]] | ||
it 'should report a ternary check on a parameter' do | ||
'def simple(arga) arga ? @ivar : 3 end'.should reek_of(:ControlCouple, /arga/) | ||
end | ||
|
||
it 'should not report a ternary check on an ivar' do | ||
'def simple(arga) @ivar ? arga : 3 end'.should_not reek | ||
end | ||
|
||
it 'should not report a ternary check on a lvar' do | ||
'def simple(arga) lvar = 27; lvar ? arga : @ivar end'.should_not reek | ||
end | ||
|
||
it 'should spot a couple inside a block' do | ||
'def blocks(arg) @text.map { |blk| arg ? blk : "#{blk}" } end'.should reek_of(:ControlCouple, /arg/) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.