Skip to content

Commit

Permalink
Merge pull request #7 from spk/tests
Browse files Browse the repository at this point in the history
Add test
  • Loading branch information
m4i committed Jan 26, 2016
2 parents 15fcc08 + 083f842 commit b19ade1
Show file tree
Hide file tree
Showing 8 changed files with 67 additions and 2 deletions.
8 changes: 8 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1 +1,9 @@
require 'bundler/gem_tasks'
require 'rake/testtask'

task default: [:test]

Rake::TestTask.new do |t|
t.pattern = 'test/**/*_test.rb'
end
task spec: :test
3 changes: 2 additions & 1 deletion lib/rubocop/git/options.rb
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@ def commit_last
def from_hash(hash_options)
hash_options = hash_options.dup
%w(config cached hound rubocop commits).each do |key|
public_send("#{key}=", hash_options.delete(key))
value = hash_options.delete(key) || hash_options.delete(key.to_sym)
public_send("#{key}=", value)
end
unless hash_options.empty?
fail Invalid, "invalid keys: #{hash_options.keys.join(' ')}"
Expand Down
2 changes: 1 addition & 1 deletion lib/rubocop/git/runner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def run(options)
@files = DiffParser.parse(git_diff(options))

display_violations($stdout)

exit(1) if violations.any?
end

Expand Down
1 change: 1 addition & 0 deletions rubocop-git.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ Gem::Specification.new do |spec|

spec.add_development_dependency 'bundler', '~> 1.6'
spec.add_development_dependency 'rake'
spec.add_development_dependency 'minitest'

spec.add_dependency 'rubocop', '>= 0.24.1'
end
12 changes: 12 additions & 0 deletions test/rubocop/git/cli_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
require_relative '../../test_helper'
require 'rubocop/git/cli'

describe RuboCop::Git::CLI do
it 'fail with invalid options' do
proc do
_out, _err = capture_io do
RuboCop::Git::CLI.new.run(['--gruß'])
end
end.must_raise(SystemExit)
end
end
18 changes: 18 additions & 0 deletions test/rubocop/git/options_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
require_relative '../../test_helper'
require 'rubocop/git/options'

describe RuboCop::Git::Options do
it 'fail with no options' do
proc do
RuboCop::Git::Options.new({})
end.must_raise(RuboCop::Git::Options::Invalid)
end

it 'can pass string hash options' do
RuboCop::Git::Options.new('rubocop' => {}, 'commits' => [])
end

it 'can pass symbol hash options' do
RuboCop::Git::Options.new(rubocop: {}, commits: [])
end
end
23 changes: 23 additions & 0 deletions test/rubocop/git/runner_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
require_relative '../../test_helper'
require 'rubocop/git/runner'

describe RuboCop::Git::Runner do
it 'exit with violations' do
options = RuboCop::Git::Options.new
# lib/rubocop/git/runner.rb:14:1: C: Trailing whitespace detected.
options.commits = ["v0.0.4", "v0.0.5"]
proc do
_out, _err = capture_io do
RuboCop::Git::Runner.new.run(options)
end
end.must_raise(SystemExit)
end

it 'fail with no options' do
proc do
_out, _err = capture_io do
RuboCop::Git::Runner.new.run({})
end
end.must_raise(RuboCop::Git::Options::Invalid)
end
end
2 changes: 2 additions & 0 deletions test/test_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
require 'minitest/autorun'
require 'rubocop/git'

0 comments on commit b19ade1

Please sign in to comment.