Skip to content

Commit

Permalink
Revert "refactor rubocop rspec"
Browse files Browse the repository at this point in the history
This reverts commit 175c0c0.
  • Loading branch information
nijikon committed Dec 1, 2015
1 parent 8a5060b commit f736f5d
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 3 deletions.
28 changes: 25 additions & 3 deletions lib/polish_geeks/dev_tools/commands/rubocop_rspec.rb
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
module PolishGeeks
module DevTools
module Commands
# Command wrapper for Rubocop Rspec validation
# It informs us if rspec specs are formatted in a proper way
class RubocopRspec < Rubocop
# Command wrapper for Rubocop validation
# It informs us if code is formatted in a proper way
class RubocopRspec < Base
self.config_name = '.rubocop.yml'
self.type = :validator
self.validators = [
Validators::Rubocop
]

# Regexp used to get number of inspected files
FILES_REGEXP = /(\d+) files inspected/
# Regexp used to get number of offenses detected
OFFENSES_REGEXP = /(\d+) offense.* detected/

# Executes this command
# @return [String] command output
def execute
Expand All @@ -19,10 +24,27 @@ def execute
@output = Shell.new.execute(cmd.join(' '))
end

# @return [Boolean] true if there were no Rubocop offenses detected
def valid?
offenses_count == 0
end

# @return [String] default label for this command
def label
"RubocopRspec (#{files_count} files, #{offenses_count} offenses)"
end

private

# @return [Integer] number of files inspected
def files_count
output.scan(FILES_REGEXP).flatten.first.to_i
end

# @return [Integer] number of offences found
def offenses_count
output.scan(OFFENSES_REGEXP).flatten.first.to_i
end
end
end
end
Expand Down
50 changes: 50 additions & 0 deletions spec/lib/polish_geeks/dev_tools/commands/rubocop_rspec_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,32 @@
end
end

describe '#valid?' do
context 'when offenses count is equal 0' do
before do
expect(subject)
.to receive(:offenses_count)
.and_return(0)
end

it 'returns true' do
expect(subject.valid?).to eq true
end
end

context 'when offenses count is different from 0' do
before do
expect(subject)
.to receive(:offenses_count)
.and_return(100)
end

it 'returns false' do
expect(subject.valid?).to eq false
end
end
end

describe '#label' do
context 'when we run rubocop' do
before do
Expand All @@ -65,6 +91,30 @@
end
end

describe '#files_count' do
context 'when we count files' do
before do
subject.instance_variable_set(:@output, '10 files inspected')
end

it 'returns a proper value' do
expect(subject.send(:files_count)).to eq 10
end
end
end

describe '#offenses_count' do
context 'when we count offenses' do
before do
subject.instance_variable_set(:@output, '5 offenses detected')
end

it 'returns a proper value' do
expect(subject.send(:offenses_count)).to eq 5
end
end
end

describe '.generator?' do
it { expect(described_class.generator?).to eq false }
end
Expand Down

0 comments on commit f736f5d

Please sign in to comment.