hound-tools 0.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (40) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +14 -0
  3. data/.hound.yml +6 -0
  4. data/.hound/defaults.yml +265 -0
  5. data/.hound/overrides.yml +19 -0
  6. data/.rspec +3 -0
  7. data/.rubocop.yml +8 -0
  8. data/.rubocop_merged_for_hound.yml +41 -0
  9. data/.rubocop_todo.yml +11 -0
  10. data/.travis.yml +12 -0
  11. data/Gemfile +12 -0
  12. data/Guardfile +40 -0
  13. data/LICENSE.txt +22 -0
  14. data/README.md +98 -0
  15. data/Rakefile +22 -0
  16. data/bin/hound-tools +5 -0
  17. data/hound-tools.gemspec +26 -0
  18. data/lib/hound/tools.rb +7 -0
  19. data/lib/hound/tools/cli.rb +74 -0
  20. data/lib/hound/tools/hound_defaults.rb +30 -0
  21. data/lib/hound/tools/hound_overrides.rb +26 -0
  22. data/lib/hound/tools/hound_yml.rb +31 -0
  23. data/lib/hound/tools/merged_yml.rb +40 -0
  24. data/lib/hound/tools/rubocop_yml.rb +24 -0
  25. data/lib/hound/tools/runner.rb +71 -0
  26. data/lib/hound/tools/template.rb +38 -0
  27. data/lib/hound/tools/templates/_.hound.yml +6 -0
  28. data/lib/hound/tools/templates/_.hound/defaults.yml +265 -0
  29. data/lib/hound/tools/templates/_.hound/overrides.yml +19 -0
  30. data/lib/hound/tools/templates/_.rubocop.yml +8 -0
  31. data/lib/hound/tools/version.rb +5 -0
  32. data/spec/lib/hound/tools/cli_spec.rb +90 -0
  33. data/spec/lib/hound/tools/hound_defaults_spec.rb +52 -0
  34. data/spec/lib/hound/tools/hound_overrides_spec.rb +52 -0
  35. data/spec/lib/hound/tools/hound_yml_spec.rb +77 -0
  36. data/spec/lib/hound/tools/merged_yml_spec.rb +53 -0
  37. data/spec/lib/hound/tools/rubocop_yml_spec.rb +68 -0
  38. data/spec/lib/hound/tools/template_spec.rb +43 -0
  39. data/spec/spec_helper.rb +47 -0
  40. metadata +147 -0
@@ -0,0 +1,52 @@
1
+ require 'hound/tools/hound_overrides'
2
+
3
+ require_relative 'template_spec'
4
+
5
+ RSpec.describe Hound::Tools::HoundOverrides do
6
+ filename = '.hound/overrides.yml'
7
+
8
+ it_behaves_like 'a template', filename
9
+
10
+ describe '#generate' do
11
+ before do
12
+ allow(IO).to receive(:read).
13
+ with(/lib\/hound\/tools\/templates\/_#{filename}$/).and_call_original
14
+ allow($stderr).to receive(:puts)
15
+ allow($stdout).to receive(:puts)
16
+ allow(FileUtils).to receive(:mkpath).with('.hound')
17
+ end
18
+
19
+ context "with no #{filename}" do
20
+ before do
21
+ allow(IO).to receive(:read).with(filename).and_raise(Errno::ENOENT)
22
+ allow(IO).to receive(:write).with(filename, anything)
23
+ end
24
+
25
+ it "creates a valid #{filename} file" do
26
+ expect(IO).to receive(:write).with(filename, anything) do |_file, data|
27
+ expect(data).to be
28
+ config = YAML::load(data)
29
+ expect(config).to be
30
+ expect(config['AllCops']).to include('Exclude' => %w(db/schema.rb Gemfile Rakefile))
31
+ end
32
+
33
+ subject.generate
34
+ end
35
+ end
36
+
37
+ context "with existing invalid #{filename}" do
38
+ let(:contents) { 'foo: :bar' }
39
+ before { allow(IO).to receive(:read).with(filename).and_return(contents) }
40
+
41
+ it 'returns false' do
42
+ expect(subject.generate).to be_falsey
43
+ end
44
+
45
+ it 'displays the file already exists' do
46
+ msg = "Error: #{filename} is invalid! (No AllCops section)"
47
+ expect($stderr).to receive(:puts).with(msg)
48
+ subject.generate
49
+ end
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,77 @@
1
+ require 'hound/tools/hound_yml'
2
+
3
+ require_relative 'template_spec'
4
+
5
+ RSpec.describe Hound::Tools::HoundYml do
6
+ filename = '.hound.yml'
7
+
8
+ it_behaves_like 'a template', filename
9
+
10
+ describe '#rubocop_filename' do
11
+ before do
12
+ allow(IO).to receive(:read).with(filename).and_return("ruby:\n config_file: foo.yml")
13
+ end
14
+
15
+ it 'reads the name from the YAML' do
16
+ expect(subject.rubocop_filename).to eq('foo.yml')
17
+ end
18
+ end
19
+
20
+ describe '#generate' do
21
+ before do
22
+ allow(IO).to receive(:read).
23
+ with(/lib\/hound\/tools\/templates\/_#{filename}$/).and_call_original
24
+ allow($stderr).to receive(:puts)
25
+ allow($stdout).to receive(:puts)
26
+ end
27
+
28
+ context "with no #{filename}" do
29
+ before do
30
+ allow(IO).to receive(:read).with(filename).and_raise(Errno::ENOENT)
31
+ allow(IO).to receive(:write).with(filename, anything)
32
+ allow(FileUtils).to receive(:mkpath).with('.')
33
+ end
34
+
35
+ it "creates a valid #{filename} file" do
36
+ expect(IO).to receive(:write).with(filename, anything) do |_file, data|
37
+ expect(data).to be
38
+ config = YAML::load(data)['ruby']
39
+ expect(config).to include('enabled' => true)
40
+ expect(config).to include('config_file' => '.rubocop_merged_for_hound.yml')
41
+ end
42
+
43
+ subject.generate
44
+ end
45
+ end
46
+
47
+ context "with existing invalid #{filename}" do
48
+ before do
49
+ allow(IO).to receive(:read).with(filename).and_return(data)
50
+ end
51
+
52
+ context "with no 'ruby' section" do
53
+ let(:data) { 'foo: :bar' }
54
+
55
+ it 'says the file is invalid' do
56
+ msg = "Error: #{filename} is invalid! (No 'ruby' section)"
57
+ expect($stderr).to receive(:puts).with(msg)
58
+ subject.generate
59
+ end
60
+
61
+ it 'returns false' do
62
+ expect(subject.generate).to be_falsey
63
+ end
64
+ end
65
+
66
+ context "with no 'config_file' section" do
67
+ let(:data) { "ruby:\n\ bar: baz" }
68
+
69
+ it 'says the file is invalid' do
70
+ msg = "Error: #{filename} is invalid! (No 'config_file' section)"
71
+ expect($stderr).to receive(:puts).with(msg)
72
+ subject.generate
73
+ end
74
+ end
75
+ end
76
+ end
77
+ end
@@ -0,0 +1,53 @@
1
+ require 'hound/tools/merged_yml'
2
+
3
+ require_relative 'template_spec'
4
+
5
+ RSpec.describe Hound::Tools::MergedYml do
6
+ filename = '.rubocop_merged_for_hound.yml'
7
+
8
+ # it_behaves_like "a template", filename
9
+ specify { expect(subject.filename).to eq(filename) }
10
+
11
+ describe '#generate' do
12
+ let(:hound_yml) { instance_double(Hound::Tools::HoundYml) }
13
+
14
+ before do
15
+ allow(Hound::Tools::HoundYml).to receive(:new).and_return(hound_yml)
16
+ allow(hound_yml).to receive(:rubocop_filename).and_return(filename)
17
+
18
+ allow(IO).to receive(:read).with('.hound/overrides.yml').and_return('foo')
19
+ allow(IO).to receive(:read).with('.rubocop_todo.yml').and_return('bar')
20
+ allow(FileUtils).to receive(:mkpath).with('.')
21
+
22
+ allow(IO).to receive(:write).with(filename, anything)
23
+ end
24
+
25
+ it 'regenerates the file' do
26
+ expected = <<-EOS.gsub(/^\s+/, '')
27
+ # This is a file generated by `hound-tools`
28
+ #
29
+ # We don't include .hound/defaults.yml, because Hound has internally
30
+ # loaded them at this point
31
+ #
32
+ # ---------------------------------
33
+ # .hound/overrides.yml
34
+ # ---------------------------------
35
+ foo
36
+ # ---------------------------------
37
+ # .rubocop_todo.yml
38
+ # ---------------------------------
39
+ bar
40
+ EOS
41
+ expect(IO).to receive(:write).with(filename, anything) do |_, data|
42
+ expect(data).to eq(expected)
43
+ end
44
+
45
+ subject.generate
46
+ end
47
+
48
+ it 'prints info about merging' do
49
+ expect($stdout).to receive(:puts).with(/\.rubocop_merged_for_hound\.yml \(regenerated\)/)
50
+ subject.generate
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,68 @@
1
+ require 'hound/tools/rubocop_yml'
2
+
3
+ require_relative 'template_spec'
4
+
5
+ RSpec.describe Hound::Tools::RubocopYml do
6
+ filename = '.rubocop.yml'
7
+ it_behaves_like 'a template', filename
8
+
9
+ describe '#generate' do
10
+ before do
11
+ allow(IO).to receive(:read).
12
+ with(/lib\/hound\/tools\/templates\/_#{filename}$/).and_call_original
13
+ allow($stderr).to receive(:puts)
14
+ allow($stdout).to receive(:puts)
15
+ end
16
+
17
+ context "with no #{filename}" do
18
+ before do
19
+ allow(IO).to receive(:read).with("#{filename}").and_raise(Errno::ENOENT)
20
+ allow(IO).to receive(:write).with("#{filename}", anything)
21
+ allow(FileUtils).to receive(:mkpath).with(File.dirname('.'))
22
+ end
23
+
24
+ it "creates a valid #{filename} file" do
25
+ expect(IO).to receive(:write).with("#{filename}", anything) do |_file, data|
26
+ expect(data).to be
27
+ config = YAML::load(data)
28
+
29
+ expected = %w(.hound/defaults.yml .hound/overrides.yml .rubocop_todo.yml)
30
+ expect(config['inherit_from']).to match_array(expected)
31
+ expect(config['AllCops']).to include('RunRailsCops' => true)
32
+ end
33
+
34
+ subject.generate
35
+ end
36
+ end
37
+
38
+ context "with existing invalid #{filename}" do
39
+ before do
40
+ allow(IO).to receive(:read).with("#{filename}").and_return(data)
41
+ end
42
+
43
+ context "with no 'inherit_from' section" do
44
+ let(:data) { 'foo: :bar' }
45
+
46
+ it 'says the file is invalid' do
47
+ msg = "Error: #{filename} is invalid! (No 'inherit_from' section)"
48
+ expect($stderr).to receive(:puts).with(msg)
49
+ subject.generate
50
+ end
51
+
52
+ it 'returns false' do
53
+ expect(subject.generate).to be_falsey
54
+ end
55
+ end
56
+
57
+ context "when inherit_from lacks '.hound/defaults.yml'" do
58
+ let(:data) { "inherit_from:\n\ bar: baz" }
59
+
60
+ it 'says the file is invalid' do
61
+ msg = "Error: #{filename} is invalid! ('.hound/defaults.yml' not inherited)"
62
+ expect($stderr).to receive(:puts).with(msg)
63
+ subject.generate
64
+ end
65
+ end
66
+ end
67
+ end
68
+ end
@@ -0,0 +1,43 @@
1
+ RSpec.shared_examples 'a template' do |filename|
2
+
3
+ specify { expect(subject.filename).to eq(filename) }
4
+
5
+ describe '#generate' do
6
+ before do
7
+ allow(IO).to receive(:read).
8
+ with(/lib\/hound\/tools\/templates\/_#{filename}$/).and_call_original
9
+ allow($stderr).to receive(:puts)
10
+ allow($stdout).to receive(:puts)
11
+ end
12
+
13
+ context "with no #{filename}" do
14
+ before do
15
+ allow(IO).to receive(:read).with(filename).and_raise(Errno::ENOENT)
16
+ allow(IO).to receive(:write).with(filename, anything)
17
+ allow(FileUtils).to receive(:mkpath).with(File.dirname(filename))
18
+ end
19
+
20
+ it 'displays the file was created' do
21
+ expect($stdout).to receive(:puts).with("#{filename} created")
22
+ subject.generate
23
+ end
24
+
25
+ context "with existing valid #{filename}" do
26
+ let(:contents) { IO.read("lib/hound/tools/templates/_#{filename}") }
27
+
28
+ before do
29
+ allow(IO).to receive(:read).with(filename).and_return(contents)
30
+ end
31
+
32
+ it 'displays the files was skipped' do
33
+ expect($stdout).to receive(:puts).with("#{filename} (seems ok - skipped)")
34
+ subject.generate
35
+ end
36
+
37
+ it 'returns true' do
38
+ expect(subject.generate).to be_truthy
39
+ end
40
+ end
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,47 @@
1
+ RSpec.configure do |config|
2
+ config.expect_with :rspec do |expectations|
3
+ expectations.include_chain_clauses_in_custom_matcher_descriptions = true
4
+ end
5
+
6
+ config.mock_with :rspec do |mocks|
7
+ mocks.verify_partial_doubles = true
8
+ end
9
+
10
+ config.filter_run :focus
11
+ config.run_all_when_everything_filtered = true
12
+
13
+ config.disable_monkey_patching!
14
+
15
+ # config.warnings = true
16
+
17
+ if config.files_to_run.one?
18
+ config.default_formatter = 'doc'
19
+ end
20
+
21
+ # config.profile_examples = 10
22
+
23
+ config.order = :random
24
+
25
+ Kernel.srand config.seed
26
+
27
+ config.before do
28
+ %w(write read).each do |meth|
29
+ allow(IO).to receive(meth) do |*args|
30
+ fail "stub me: IO.#{meth}(#{args.map(&:inspect) * ', '})"
31
+ end
32
+ end
33
+
34
+ %w(mkdir mkpath).each do |meth|
35
+ allow(FileUtils).to receive(meth) do |*args|
36
+ fail "stub me: FileUtils.#{meth}(#{args.map(&:inspect) * ', '})"
37
+ end
38
+ end
39
+
40
+ %w(` system).each do |meth|
41
+ allow(Kernel).to receive(meth) do |*args|
42
+ fail "stub me: Kernel.#{meth}(#{args.map(&:inspect) * ', '})"
43
+ end
44
+ end
45
+
46
+ end
47
+ end
metadata ADDED
@@ -0,0 +1,147 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: hound-tools
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.4
5
+ platform: ruby
6
+ authors:
7
+ - Cezary Baginski
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-12-09 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rubocop
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '='
18
+ - !ruby/object:Gem::Version
19
+ version: 0.25.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '='
25
+ - !ruby/object:Gem::Version
26
+ version: 0.25.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: thor
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.7'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.7'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '10.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '10.0'
69
+ description: Matches your project config to give the same errors as HoundCi
70
+ email:
71
+ - cezary@chronomantic.net
72
+ executables:
73
+ - hound-tools
74
+ extensions: []
75
+ extra_rdoc_files: []
76
+ files:
77
+ - ".gitignore"
78
+ - ".hound.yml"
79
+ - ".hound/defaults.yml"
80
+ - ".hound/overrides.yml"
81
+ - ".rspec"
82
+ - ".rubocop.yml"
83
+ - ".rubocop_merged_for_hound.yml"
84
+ - ".rubocop_todo.yml"
85
+ - ".travis.yml"
86
+ - Gemfile
87
+ - Guardfile
88
+ - LICENSE.txt
89
+ - README.md
90
+ - Rakefile
91
+ - bin/hound-tools
92
+ - hound-tools.gemspec
93
+ - lib/hound/tools.rb
94
+ - lib/hound/tools/cli.rb
95
+ - lib/hound/tools/hound_defaults.rb
96
+ - lib/hound/tools/hound_overrides.rb
97
+ - lib/hound/tools/hound_yml.rb
98
+ - lib/hound/tools/merged_yml.rb
99
+ - lib/hound/tools/rubocop_yml.rb
100
+ - lib/hound/tools/runner.rb
101
+ - lib/hound/tools/template.rb
102
+ - lib/hound/tools/templates/_.hound.yml
103
+ - lib/hound/tools/templates/_.hound/defaults.yml
104
+ - lib/hound/tools/templates/_.hound/overrides.yml
105
+ - lib/hound/tools/templates/_.rubocop.yml
106
+ - lib/hound/tools/version.rb
107
+ - spec/lib/hound/tools/cli_spec.rb
108
+ - spec/lib/hound/tools/hound_defaults_spec.rb
109
+ - spec/lib/hound/tools/hound_overrides_spec.rb
110
+ - spec/lib/hound/tools/hound_yml_spec.rb
111
+ - spec/lib/hound/tools/merged_yml_spec.rb
112
+ - spec/lib/hound/tools/rubocop_yml_spec.rb
113
+ - spec/lib/hound/tools/template_spec.rb
114
+ - spec/spec_helper.rb
115
+ homepage: ''
116
+ licenses:
117
+ - MIT
118
+ metadata: {}
119
+ post_install_message:
120
+ rdoc_options: []
121
+ require_paths:
122
+ - lib
123
+ required_ruby_version: !ruby/object:Gem::Requirement
124
+ requirements:
125
+ - - ">="
126
+ - !ruby/object:Gem::Version
127
+ version: '0'
128
+ required_rubygems_version: !ruby/object:Gem::Requirement
129
+ requirements:
130
+ - - ">="
131
+ - !ruby/object:Gem::Version
132
+ version: '0'
133
+ requirements: []
134
+ rubyforge_project:
135
+ rubygems_version: 2.2.2
136
+ signing_key:
137
+ specification_version: 4
138
+ summary: Tools for configuring and using HoundCI
139
+ test_files:
140
+ - spec/lib/hound/tools/cli_spec.rb
141
+ - spec/lib/hound/tools/hound_defaults_spec.rb
142
+ - spec/lib/hound/tools/hound_overrides_spec.rb
143
+ - spec/lib/hound/tools/hound_yml_spec.rb
144
+ - spec/lib/hound/tools/merged_yml_spec.rb
145
+ - spec/lib/hound/tools/rubocop_yml_spec.rb
146
+ - spec/lib/hound/tools/template_spec.rb
147
+ - spec/spec_helper.rb