polishgeeks-dev-tools 1.0.0

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 (66) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +22 -0
  3. data/.ruby-gemset +1 -0
  4. data/.ruby-version +1 -0
  5. data/.travis.yml +6 -0
  6. data/Gemfile +2 -0
  7. data/Gemfile.lock +193 -0
  8. data/README.md +112 -0
  9. data/Rakefile +20 -0
  10. data/config/haml-lint.yml +74 -0
  11. data/config/rubocop.yml +35 -0
  12. data/config/yardopts +7 -0
  13. data/lib/polishgeeks-dev-tools.rb +43 -0
  14. data/lib/polishgeeks/dev-tools/command/allowed_extensions.rb +62 -0
  15. data/lib/polishgeeks/dev-tools/command/base.rb +73 -0
  16. data/lib/polishgeeks/dev-tools/command/brakeman.rb +46 -0
  17. data/lib/polishgeeks/dev-tools/command/coverage.rb +43 -0
  18. data/lib/polishgeeks/dev-tools/command/examples_comparator.rb +75 -0
  19. data/lib/polishgeeks/dev-tools/command/expires_in.rb +74 -0
  20. data/lib/polishgeeks/dev-tools/command/haml_lint.rb +28 -0
  21. data/lib/polishgeeks/dev-tools/command/readme.rb +32 -0
  22. data/lib/polishgeeks/dev-tools/command/rspec.rb +38 -0
  23. data/lib/polishgeeks/dev-tools/command/rspec_files_names.rb +58 -0
  24. data/lib/polishgeeks/dev-tools/command/rspec_files_structure.rb +134 -0
  25. data/lib/polishgeeks/dev-tools/command/rubocop.rb +50 -0
  26. data/lib/polishgeeks/dev-tools/command/rubycritic.rb +17 -0
  27. data/lib/polishgeeks/dev-tools/command/simplecov.rb +32 -0
  28. data/lib/polishgeeks/dev-tools/command/tasks_files_names.rb +76 -0
  29. data/lib/polishgeeks/dev-tools/command/yard.rb +35 -0
  30. data/lib/polishgeeks/dev-tools/command/yml_parser.rb +85 -0
  31. data/lib/polishgeeks/dev-tools/config.rb +91 -0
  32. data/lib/polishgeeks/dev-tools/hash.rb +24 -0
  33. data/lib/polishgeeks/dev-tools/logger.rb +63 -0
  34. data/lib/polishgeeks/dev-tools/output_storer.rb +17 -0
  35. data/lib/polishgeeks/dev-tools/runner.rb +27 -0
  36. data/lib/polishgeeks/dev-tools/shell.rb +16 -0
  37. data/lib/polishgeeks/dev-tools/tasks/dev-tools.rake +15 -0
  38. data/lib/polishgeeks/dev-tools/version.rb +8 -0
  39. data/polishgeeks_dev_tools.gemspec +36 -0
  40. data/spec/lib/polishgeeks-dev-tools_spec.rb +35 -0
  41. data/spec/lib/polishgeeks/dev-tools/command/allowed_extensions_spec.rb +66 -0
  42. data/spec/lib/polishgeeks/dev-tools/command/base_spec.rb +127 -0
  43. data/spec/lib/polishgeeks/dev-tools/command/brakeman_spec.rb +95 -0
  44. data/spec/lib/polishgeeks/dev-tools/command/coverage_spec.rb +121 -0
  45. data/spec/lib/polishgeeks/dev-tools/command/examples_comparator_spec.rb +171 -0
  46. data/spec/lib/polishgeeks/dev-tools/command/expires_in_spec.rb +69 -0
  47. data/spec/lib/polishgeeks/dev-tools/command/haml_lint_spec.rb +79 -0
  48. data/spec/lib/polishgeeks/dev-tools/command/readme_spec.rb +38 -0
  49. data/spec/lib/polishgeeks/dev-tools/command/rspec_files_names_spec.rb +91 -0
  50. data/spec/lib/polishgeeks/dev-tools/command/rspec_files_structure_spec.rb +262 -0
  51. data/spec/lib/polishgeeks/dev-tools/command/rspec_spec.rb +63 -0
  52. data/spec/lib/polishgeeks/dev-tools/command/rubocop_spec.rb +127 -0
  53. data/spec/lib/polishgeeks/dev-tools/command/rubycritic_spec.rb +27 -0
  54. data/spec/lib/polishgeeks/dev-tools/command/simplecov_spec.rb +53 -0
  55. data/spec/lib/polishgeeks/dev-tools/command/tasks_files_names_spec.rb +108 -0
  56. data/spec/lib/polishgeeks/dev-tools/command/yard_spec.rb +86 -0
  57. data/spec/lib/polishgeeks/dev-tools/command/yml_parser_spec.rb +104 -0
  58. data/spec/lib/polishgeeks/dev-tools/config_spec.rb +78 -0
  59. data/spec/lib/polishgeeks/dev-tools/hash_spec.rb +37 -0
  60. data/spec/lib/polishgeeks/dev-tools/logger_spec.rb +162 -0
  61. data/spec/lib/polishgeeks/dev-tools/output_storer_spec.rb +20 -0
  62. data/spec/lib/polishgeeks/dev-tools/runner_spec.rb +57 -0
  63. data/spec/lib/polishgeeks/dev-tools/shell_spec.rb +13 -0
  64. data/spec/lib/polishgeeks/dev-tools/version_spec.rb +7 -0
  65. data/spec/spec_helper.rb +28 -0
  66. metadata +330 -0
@@ -0,0 +1,69 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe PolishGeeks::DevTools::Command::ExpiresIn do
4
+ subject { described_class.new }
5
+
6
+ let(:config) { double }
7
+
8
+ describe '#execute' do
9
+ it 'should execute the command' do
10
+ subject.execute
11
+ end
12
+ end
13
+
14
+ describe '#label' do
15
+ it { expect(subject.label).to eq 'Expires in' }
16
+ end
17
+
18
+ describe '#error_message' do
19
+ context 'when output is not empty' do
20
+ let(:file_name) { rand.to_s }
21
+ let(:output) { [file_name] }
22
+ let(:expected) { "Following files use expire_in instead of expires_in:\n\n#{file_name}\n" }
23
+ before do
24
+ subject.instance_variable_set('@output', output)
25
+ end
26
+ it { expect(subject.error_message).to eq expected }
27
+ end
28
+ end
29
+
30
+ describe '#valid?' do
31
+ context 'when output is empty' do
32
+ before do
33
+ subject.instance_variable_set('@output', '')
34
+ end
35
+ it { expect(subject.valid?).to eq true }
36
+ end
37
+ end
38
+
39
+ describe '#excludes' do
40
+ context 'when expire_files_ignored is not set' do
41
+ let(:config) { double(expires_in_files_ignored: nil) }
42
+
43
+ before do
44
+ expect(PolishGeeks::DevTools)
45
+ .to receive(:config)
46
+ .and_return(config)
47
+ end
48
+
49
+ it { expect(subject.send(:excludes)).to eq [] }
50
+ end
51
+
52
+ context 'when expire_files_ignored is set' do
53
+ let(:expires_in_files_ignored) { rand }
54
+ let(:config) do
55
+ double(
56
+ expires_in_files_ignored: expires_in_files_ignored
57
+ )
58
+ end
59
+
60
+ before do
61
+ expect(PolishGeeks::DevTools)
62
+ .to receive(:config)
63
+ .and_return(config)
64
+ end
65
+
66
+ it { expect(subject.send(:excludes)).to eq expires_in_files_ignored }
67
+ end
68
+ end
69
+ end
@@ -0,0 +1,79 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe PolishGeeks::DevTools::Command::HamlLint do
4
+ subject { described_class.new }
5
+
6
+ describe '#execute' do
7
+ let(:path) { '/' }
8
+ before do
9
+ expect(ENV)
10
+ .to receive(:[])
11
+ .with('BUNDLE_GEMFILE')
12
+ .and_return(path)
13
+ end
14
+
15
+ context 'when app config exists' do
16
+ before do
17
+ expect(File)
18
+ .to receive(:exist?)
19
+ .and_return(true)
20
+ expect_any_instance_of(PolishGeeks::DevTools::Shell)
21
+ .to receive(:execute)
22
+ .with("bundle exec haml-lint -c #{path}.haml-lint.yml app/views")
23
+ end
24
+
25
+ it 'should execute the command' do
26
+ subject.execute
27
+ end
28
+ end
29
+
30
+ context 'when app config does not exist' do
31
+ let(:path) { Dir.pwd }
32
+ before do
33
+ expect(PolishGeeks::DevTools)
34
+ .to receive(:gem_root)
35
+ .and_return(path)
36
+ expect(File)
37
+ .to receive(:exist?)
38
+ .and_return(false)
39
+ expect_any_instance_of(PolishGeeks::DevTools::Shell)
40
+ .to receive(:execute)
41
+ .with("bundle exec haml-lint -c #{path}/config/haml-lint.yml app/views")
42
+ end
43
+
44
+ it 'should execute the command' do
45
+ subject.execute
46
+ end
47
+ end
48
+ end
49
+
50
+ describe '#valid?' do
51
+ context 'when there are some issues' do
52
+ before do
53
+ subject.instance_variable_set('@output', '[W] SpaceInsideHashAttributes')
54
+ end
55
+
56
+ it 'should be false' do
57
+ expect(subject.valid?).to eq false
58
+ end
59
+ end
60
+
61
+ context 'when there are no issues' do
62
+ before do
63
+ subject.instance_variable_set('@output', '')
64
+ end
65
+
66
+ it 'should be true' do
67
+ expect(subject.valid?).to eq true
68
+ end
69
+ end
70
+ end
71
+
72
+ describe '.generator?' do
73
+ it { expect(described_class.generator?).to eq false }
74
+ end
75
+
76
+ describe '.validator?' do
77
+ it { expect(described_class.validator?).to eq true }
78
+ end
79
+ end
@@ -0,0 +1,38 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe PolishGeeks::DevTools::Command::Readme do
4
+ subject { described_class.new }
5
+
6
+ let(:config) { double }
7
+
8
+ describe '#execute' do
9
+ it 'should execute the command' do
10
+ subject.execute
11
+ end
12
+ end
13
+
14
+ describe '#label' do
15
+ let(:expected) { 'README.rb required' }
16
+
17
+ it { expect(subject.label).to eq expected }
18
+ end
19
+
20
+ describe '#error_message' do
21
+ let(:expected) { "README.rb doesn't exist!" }
22
+ let(:output) { false }
23
+
24
+ it { expect(subject.error_message).to eq expected }
25
+ end
26
+
27
+ describe '#valid?' do
28
+ context 'when README.md exist' do
29
+ before do
30
+ subject.instance_variable_set('@output', true)
31
+ end
32
+
33
+ it 'should return true' do
34
+ expect(subject.valid?).to be true
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,91 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe PolishGeeks::DevTools::Command::RspecFilesNames do
4
+ subject { described_class.new }
5
+
6
+ let(:config) { double }
7
+
8
+ describe '#execute' do
9
+ let(:path) { rand.to_s }
10
+
11
+ before do
12
+ described_class::CHECKED_DIRS.each do |name|
13
+ expect(File)
14
+ .to receive(:join)
15
+ .with(::PolishGeeks::DevTools.app_root, 'spec', name)
16
+ .and_return(path)
17
+ end
18
+
19
+ expect(Dir)
20
+ .to receive(:glob)
21
+ .with("#{path}/**/*")
22
+ .exactly(described_class::CHECKED_DIRS.count).times
23
+ .and_return(files)
24
+
25
+ expect(File)
26
+ .to receive(:file?)
27
+ .and_return(true)
28
+ .exactly(described_class::CHECKED_DIRS.count).times
29
+
30
+ subject.execute
31
+ end
32
+
33
+ context 'when we dont have invalid files' do
34
+ let(:files) { ['test_spec.rb'] }
35
+
36
+ it 'should set appropriate variables' do
37
+ expect(subject.output).to eq []
38
+ expect(subject.counter).to eq(described_class::CHECKED_DIRS.count * files.count)
39
+ end
40
+ end
41
+
42
+ context 'when we have invalid files' do
43
+ let(:files) { ['test_spe.rb'] }
44
+
45
+ it 'should set appropriate variables' do
46
+ expect(subject.output).to eq(files * described_class::CHECKED_DIRS.count)
47
+ expect(subject.counter).to eq(described_class::CHECKED_DIRS.count * files.count)
48
+ end
49
+ end
50
+ end
51
+
52
+ describe '#valid?' do
53
+ before do
54
+ subject.instance_variable_set('@output', output)
55
+ end
56
+
57
+ context 'when output is empty' do
58
+ let(:output) { [] }
59
+
60
+ it { expect(subject.valid?).to eq true }
61
+ end
62
+
63
+ context 'when output is not empty' do
64
+ let(:output) { ['file_name'] }
65
+
66
+ it { expect(subject.valid?).to eq false }
67
+ end
68
+ end
69
+
70
+ describe '#label' do
71
+ let(:counter) { rand(1000) }
72
+ let(:expected) { "Rspec files names: #{counter} files checked" }
73
+
74
+ before do
75
+ subject.instance_variable_set('@counter', counter)
76
+ end
77
+
78
+ it { expect(subject.label).to eq expected }
79
+ end
80
+
81
+ describe '#error_message' do
82
+ let(:output) { [rand.to_s, rand.to_s] }
83
+ let(:expected) { "Following files have invalid name: \n #{output.join("\n")}\n" }
84
+
85
+ before do
86
+ subject.instance_variable_set('@output', output)
87
+ end
88
+
89
+ it { expect(subject.error_message).to eq expected }
90
+ end
91
+ end
@@ -0,0 +1,262 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe PolishGeeks::DevTools::Command::RspecFilesStructure do
4
+ subject { described_class.new }
5
+
6
+ describe '#execute' do
7
+ let(:analyzed_files_result) { double }
8
+ let(:rspec_files_result) { double }
9
+ let(:substract_result) { double }
10
+ let(:substract_rspec_result) { double }
11
+ let(:expected) { Hash(app: substract_result, rspec: substract_rspec_result) }
12
+
13
+ before do
14
+ expect(subject)
15
+ .to receive(:analyzed_files)
16
+ .twice
17
+ .and_return(analyzed_files_result)
18
+
19
+ expect(subject)
20
+ .to receive(:rspec_files)
21
+ .exactly(2).times
22
+ .and_return(rspec_files_result)
23
+
24
+ expect(analyzed_files_result)
25
+ .to receive(:-)
26
+ .and_return(substract_result)
27
+
28
+ expect(rspec_files_result)
29
+ .to receive(:-)
30
+ .and_return(substract_rspec_result)
31
+ end
32
+
33
+ it 'should be subtraction' do
34
+ subject.execute
35
+
36
+ expect(subject.instance_variable_get(:@output)).to eq expected
37
+ end
38
+ end
39
+
40
+ describe '#analyzed_files' do
41
+ let(:config) { double(rspec_files_structure_ignored: nil) }
42
+
43
+ before do
44
+ expect(PolishGeeks::DevTools)
45
+ .to receive(:config)
46
+ .and_return(config)
47
+ .at_least(:once)
48
+ end
49
+
50
+ it { expect(subject.send(:analyzed_files)).to_not be_empty }
51
+
52
+ context 'when we gather files for analyze' do
53
+ let(:file) { double }
54
+ let(:files_collection) { [file] }
55
+
56
+ before do
57
+ expect(described_class::FILES_CHECKED)
58
+ .to receive(:map)
59
+ .and_return(files_collection)
60
+ end
61
+
62
+ it 'should flatten, uniq and sanitize' do
63
+ expect(files_collection)
64
+ .to receive(:flatten!)
65
+
66
+ expect(files_collection)
67
+ .to receive(:uniq!)
68
+
69
+ expect(subject)
70
+ .to receive(:sanitize)
71
+ .with(file)
72
+
73
+ subject.send(:analyzed_files)
74
+ end
75
+ end
76
+ end
77
+
78
+ describe '#rspec_files' do
79
+ let(:config) { double(rspec_files_structure_ignored: nil) }
80
+
81
+ before do
82
+ expect(PolishGeeks::DevTools)
83
+ .to receive(:config)
84
+ .and_return(config)
85
+ .at_least(:once)
86
+ end
87
+
88
+ it { expect(subject.send(:rspec_files)).to_not be_empty }
89
+
90
+ context 'when we gather rspec files' do
91
+ let(:file) { double }
92
+ let(:files_collection) { [file] }
93
+
94
+ before do
95
+ expect(described_class::RSPEC_FILES)
96
+ .to receive(:map)
97
+ .and_return(files_collection)
98
+ end
99
+
100
+ it 'should flatten, uniq and sanitize' do
101
+ expect(files_collection)
102
+ .to receive(:flatten!)
103
+
104
+ expect(files_collection)
105
+ .to receive(:uniq!)
106
+
107
+ expect(subject)
108
+ .to receive(:sanitize)
109
+ .with(file)
110
+
111
+ subject.send(:rspec_files)
112
+ end
113
+ end
114
+ end
115
+
116
+ describe '#valid?' do
117
+ before do
118
+ subject.instance_variable_set('@output', output)
119
+ end
120
+
121
+ context 'when output is empty' do
122
+ let(:output) { Hash(app: [], rspec: []) }
123
+
124
+ it { expect(subject.valid?).to eq true }
125
+ end
126
+
127
+ context 'when output is not empty' do
128
+ let(:output) { Hash(app: [double], rspec: [double]) }
129
+
130
+ it { expect(subject.valid?).to eq false }
131
+ end
132
+ end
133
+
134
+ describe '#label' do
135
+ context 'when we run rspec_files_structure' do
136
+ let(:analyzed_files_result) { double(count: rand(1000)) }
137
+
138
+ before do
139
+ expect(subject)
140
+ .to receive(:analyzed_files)
141
+ .and_return(analyzed_files_result)
142
+ end
143
+
144
+ it 'should return the label' do
145
+ expected = "Rspec files structure (#{analyzed_files_result.count} checked)"
146
+ expect(subject.label).to eq expected
147
+ end
148
+ end
149
+ end
150
+
151
+ describe '#error_message' do
152
+ context 'when files don\'t have corresponding Rspec files' do
153
+ let(:message) { rand.to_s }
154
+ let(:expected) { message + message }
155
+ before do
156
+ expect(subject)
157
+ .to receive(:files_error_message)
158
+ .and_return(message)
159
+ expect(subject)
160
+ .to receive(:rspec_error_message)
161
+ .and_return(message)
162
+ end
163
+
164
+ it 'should return the error message' do
165
+ expect(subject.error_message).to eq expected
166
+ end
167
+ end
168
+ end
169
+
170
+ describe '#excludes' do
171
+ context 'when rspec_files_structure_ignored is not set' do
172
+ let(:config) { double(rspec_files_structure_ignored: nil) }
173
+
174
+ before do
175
+ expect(PolishGeeks::DevTools)
176
+ .to receive(:config)
177
+ .and_return(config)
178
+ end
179
+
180
+ it { expect(subject.send(:excludes)).to eq [] }
181
+ end
182
+
183
+ context 'when rspec_files_structure_ignored is set' do
184
+ let(:rspec_files_structure_ignored) { rand }
185
+ let(:config) do
186
+ double(
187
+ rspec_files_structure_ignored: rspec_files_structure_ignored
188
+ )
189
+ end
190
+
191
+ before do
192
+ expect(PolishGeeks::DevTools)
193
+ .to receive(:config)
194
+ .and_return(config)
195
+ end
196
+
197
+ it { expect(subject.send(:excludes)).to eq rspec_files_structure_ignored }
198
+ end
199
+ end
200
+
201
+ describe '#sanitize' do
202
+ let(:base) { rand.to_s }
203
+
204
+ context 'app root' do
205
+ let(:string) { "#{PolishGeeks::DevTools.app_root}/#{base}" }
206
+
207
+ it ' should be removed' do
208
+ expect(subject.send(:sanitize, string)).to eq base
209
+ end
210
+ end
211
+
212
+ context '_spec' do
213
+ let(:string) { "#{base}_spec.rb" }
214
+
215
+ it ' should be removed' do
216
+ expect(subject.send(:sanitize, string)).to eq "#{base}.rb"
217
+ end
218
+ end
219
+
220
+ context 'spec/' do
221
+ let(:string) { "spec/#{base}" }
222
+
223
+ it ' should be removed' do
224
+ expect(subject.send(:sanitize, string)).to eq base
225
+ end
226
+ end
227
+
228
+ context 'app/' do
229
+ let(:string) { "app/#{base}" }
230
+
231
+ it ' should be removed' do
232
+ expect(subject.send(:sanitize, string)).to eq base
233
+ end
234
+ end
235
+ end
236
+
237
+ describe '#files_error_message' do
238
+ let(:output) { Hash(app: ['test.rb'], rspec: ['test_rspec.rb']) }
239
+
240
+ before do
241
+ subject.instance_variable_set(:@output, output)
242
+ end
243
+
244
+ it 'should return the error message' do
245
+ expect(subject.send(:files_error_message))
246
+ .to eq "Following files don't have corresponding Rspec files:\n\ntest.rb\n"
247
+ end
248
+ end
249
+
250
+ describe '#rspec_error_message' do
251
+ let(:output) { Hash(app: ['test.rb'], rspec: ['test_rspec.rb']) }
252
+
253
+ before do
254
+ subject.instance_variable_set(:@output, output)
255
+ end
256
+
257
+ it 'should return the error message' do
258
+ expect(subject.send(:rspec_error_message))
259
+ .to eq "\n\nFollowing Rspec don't have corresponding files:\n\ntest_rspec_spec.rb\n"
260
+ end
261
+ end
262
+ end