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,104 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe PolishGeeks::DevTools::Command::YmlParser do
4
+ subject { described_class.new }
5
+
6
+ let(:config) { double }
7
+ let(:file) { rand.to_s }
8
+ let(:line) { rand.to_s }
9
+ let(:row) { { file: file, lines: [line] } }
10
+
11
+ describe '#execute' do
12
+ let(:results) { [file] }
13
+ let(:json) { { key: 'test', value: 'test' } }
14
+ before do
15
+ expect(Dir)
16
+ .to receive(:[])
17
+ .and_return(results)
18
+ expect(subject)
19
+ .to receive(:parse_yaml)
20
+ .with(file)
21
+ .and_return(json)
22
+ expect(subject)
23
+ .to receive(:check_params)
24
+ .and_return(json)
25
+ end
26
+
27
+ it 'should execute the command' do
28
+ subject.execute
29
+ end
30
+ end
31
+
32
+ describe '#label' do
33
+ it { expect(subject.label).to eq 'Yaml parser' }
34
+ end
35
+
36
+ describe '#error_message' do
37
+ let(:output) { [file: file, lines: [line]] }
38
+ let(:expected) { "Following yml files have nil as a value:\n#{file}:\n - Key '#{line}'\n" }
39
+ before do
40
+ subject.instance_variable_set('@output', output)
41
+ end
42
+
43
+ it 'should return lines with nil value' do
44
+ expect(subject.error_message).to eq expected
45
+ end
46
+ end
47
+
48
+ describe '#valid?' do
49
+ before do
50
+ subject.instance_variable_set('@output', '')
51
+ end
52
+
53
+ it { expect(subject.valid?).to eq true }
54
+ end
55
+
56
+ describe '#file_error' do
57
+ let(:expected) { "\n#{file}:\n - Key '#{line}'" }
58
+
59
+ it { expect(subject.send(:file_error, row)).to eq expected }
60
+ end
61
+
62
+ describe '#config_path' do
63
+ let(:expected) { '/**/*.yml.example' }
64
+ before do
65
+ expect(File)
66
+ .to receive(:expand_path)
67
+ .and_return('')
68
+ end
69
+ it { expect(subject.send(:config_path)).to eq expected }
70
+ end
71
+
72
+ describe '#sanitize' do
73
+ let(:file_path) { PolishGeeks::DevTools.app_root + '/config/' + file }
74
+
75
+ it { expect(subject.send(:sanitize, file_path)).to eq file }
76
+ end
77
+
78
+ describe '#parse_yaml' do
79
+ before do
80
+ expect(File)
81
+ .to receive(:open)
82
+ .with(file)
83
+ .and_return(file)
84
+ expect(YAML)
85
+ .to receive(:load)
86
+ .and_return(file)
87
+ end
88
+ it { expect(subject.send(:parse_yaml, file)).to eq file }
89
+ end
90
+
91
+ describe '#check_params' do
92
+ context 'when file have nil value' do
93
+ let(:hash) { { key: 'my_key', val: { user: 'test', pass: nil } } }
94
+
95
+ it { expect(subject.send(:check_params, hash)).to eq [:pass] }
96
+ end
97
+
98
+ context 'when file have not nil value' do
99
+ let(:hash) { { key: 'key', val: 'val' } }
100
+
101
+ it { expect(subject.send(:check_params, hash)).to be_empty }
102
+ end
103
+ end
104
+ end
@@ -0,0 +1,78 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe PolishGeeks::DevTools::Config do
4
+ subject { described_class.new }
5
+
6
+ described_class::COMMANDS.each do |attribute|
7
+ describe "#{attribute}=" do
8
+ let(:value) { rand }
9
+ before { subject.public_send(:"#{attribute}=", value) }
10
+
11
+ it 'should assign a given value' do
12
+ expect(subject.public_send(attribute)).to eq value
13
+ end
14
+ end
15
+
16
+ describe "#{attribute}?" do
17
+ let(:value) { rand(2) == 0 }
18
+ before { subject.public_send(:"#{attribute}=", value) }
19
+
20
+ it 'should assign a given value' do
21
+ expect(subject.public_send(:"#{attribute}?")).to eq value
22
+ end
23
+ end
24
+ end
25
+
26
+ describe '.setup' do
27
+ subject { described_class }
28
+ let(:instance) { described_class.new }
29
+ let(:block) { -> {} }
30
+
31
+ before do
32
+ instance
33
+
34
+ expect(subject)
35
+ .to receive(:new)
36
+ .and_return(instance)
37
+
38
+ expect(block)
39
+ .to receive(:call)
40
+ .with(instance)
41
+
42
+ expect(instance)
43
+ .to receive(:freeze)
44
+ end
45
+
46
+ it { subject.setup(&block) }
47
+ end
48
+
49
+ describe '#detect_framework' do
50
+ before do
51
+ subject. detect_framework
52
+ end
53
+
54
+ describe '#rails?' do
55
+ context 'when Rails is not defined' do
56
+ it { expect(subject.rails?).to eq false }
57
+ end
58
+ end
59
+
60
+ describe '#sinatra?' do
61
+ context 'when Sinatra is not defined' do
62
+ it { expect(subject.sinatra?).to eq false }
63
+ end
64
+ end
65
+ end
66
+
67
+ describe '#initialize' do
68
+ described_class::COMMANDS.each do |attribute|
69
+ it "should have #{attribute} command turned on by default" do
70
+ expect(subject.public_send(attribute)).to eq true
71
+ end
72
+ end
73
+
74
+ it 'should have simplecov_threshold set to 100 by default' do
75
+ expect(subject.simplecov_threshold).to eq 100
76
+ end
77
+ end
78
+ end
@@ -0,0 +1,37 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe PolishGeeks::DevTools::Hash do
4
+ describe 'same_key_structure?' do
5
+ subject { h1.same_key_structure?(h2) }
6
+
7
+ context 'when both are empty' do
8
+ let(:h1) { PolishGeeks::DevTools::Hash.new }
9
+ let(:h2) { PolishGeeks::DevTools::Hash.new }
10
+
11
+ it { expect(subject).to be true }
12
+ end
13
+
14
+ context 'when first hash is not equal to second' do
15
+ context 'on the first level' do
16
+ let(:h1) { PolishGeeks::DevTools::Hash.new.merge(a: 1) }
17
+ let(:h2) { PolishGeeks::DevTools::Hash.new.merge(b: 1) }
18
+
19
+ it { expect(subject).to be false }
20
+ end
21
+
22
+ context 'on the second level' do
23
+ let(:h1) { PolishGeeks::DevTools::Hash.new.merge(a: { b: 2 }) }
24
+ let(:h2) { PolishGeeks::DevTools::Hash.new.merge(a: { c: 3 }) }
25
+
26
+ it { expect(subject).to be false }
27
+ end
28
+ end
29
+
30
+ context 'when they have same structure but different data' do
31
+ let(:h1) { PolishGeeks::DevTools::Hash.new.merge(a: { b: rand }) }
32
+ let(:h2) { PolishGeeks::DevTools::Hash.new.merge(a: { b: rand }) }
33
+
34
+ it { expect(subject).to be true }
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,162 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe PolishGeeks::DevTools::Logger do
4
+ subject { described_class.new }
5
+
6
+ let(:task) { PolishGeeks::DevTools::Command::Rubocop.new }
7
+ let(:tmp) { double }
8
+
9
+ describe '#log' do
10
+ context 'when we print an output' do
11
+ before do
12
+ expect(task)
13
+ .to receive(:class)
14
+ .and_return(tmp)
15
+ expect(tmp)
16
+ .to receive(:generator?)
17
+ .and_return(true)
18
+ expect(subject)
19
+ .to receive(:info)
20
+ .with(task)
21
+ end
22
+
23
+ it 'should return some information' do
24
+ subject.log(task)
25
+ end
26
+ end
27
+
28
+ context 'when we print an output with an error' do
29
+ before do
30
+ expect(tmp)
31
+ .to receive(:class)
32
+ .and_return(tmp)
33
+ expect(tmp)
34
+ .to receive(:generator?)
35
+ .and_return(false)
36
+ expect(tmp)
37
+ .to receive(:valid?)
38
+ .and_return(false)
39
+ expect(subject)
40
+ .to receive(:fatal)
41
+ .with(tmp)
42
+ end
43
+
44
+ it 'should raise RequirementsError' do
45
+ expect { subject.log(tmp) }
46
+ .to raise_error PolishGeeks::DevTools::Logger::RequirementsError
47
+ end
48
+ end
49
+ end
50
+
51
+ describe '#info' do
52
+ context 'when we print a final message for a validator' do
53
+ before do
54
+ expect(task)
55
+ .to receive(:label)
56
+ .and_return('Rubocop')
57
+ expect(task)
58
+ .to receive(:class)
59
+ .and_return(tmp)
60
+ expect(tmp)
61
+ .to receive(:generator?)
62
+ .and_return(false)
63
+ expect(task)
64
+ .to receive(:class)
65
+ .and_return(tmp)
66
+ expect(tmp)
67
+ .to receive(:validator?)
68
+ .and_return(true)
69
+ end
70
+
71
+ it 'should display "OK" text' do
72
+ expect(subject)
73
+ .to receive(:printf)
74
+ .with('%-40s %2s', 'Rubocop ', "\e[32mOK\e[0m\n")
75
+ subject.send(:info, task)
76
+ end
77
+ end
78
+
79
+ context 'when we print a final message for a generator' do
80
+ before do
81
+ expect(task)
82
+ .to receive(:label)
83
+ .and_return('Rubocop')
84
+ expect(task)
85
+ .to receive(:class)
86
+ .and_return(tmp)
87
+ expect(tmp)
88
+ .to receive(:generator?)
89
+ .and_return(true)
90
+ expect(task)
91
+ .to receive(:class)
92
+ .and_return(tmp)
93
+ expect(tmp)
94
+ .to receive(:validator?)
95
+ .and_return(false)
96
+ end
97
+
98
+ it 'should display "OK" text' do
99
+ expect(subject)
100
+ .to receive(:printf)
101
+ .with('%-40s %2s', 'Rubocop ', "\e[32mGENERATED\e[0m\n")
102
+ subject.send(:info, task)
103
+ end
104
+ end
105
+
106
+ context 'when a task fails' do
107
+ before do
108
+ expect(tmp)
109
+ .to receive(:class)
110
+ .and_return(tmp)
111
+ expect(tmp)
112
+ .to receive(:generator?)
113
+ .and_return(false)
114
+ expect(tmp)
115
+ .to receive(:class)
116
+ .and_return(tmp)
117
+ expect(tmp)
118
+ .to receive(:validator?)
119
+ .and_return(false)
120
+ end
121
+
122
+ it 'should raise UnknownTaskType' do
123
+ expect { subject.send(:info, tmp) }
124
+ .to raise_error PolishGeeks::DevTools::Logger::UnknownTaskType
125
+ end
126
+ end
127
+ end
128
+
129
+ describe '#fatal' do
130
+ context 'when a task failed' do
131
+ before do
132
+ expect(task)
133
+ .to receive(:label)
134
+ .and_return('Rubocop')
135
+ expect(task)
136
+ .to receive(:error_message)
137
+ .and_return('')
138
+ end
139
+
140
+ it 'should return a message' do
141
+ expect(subject)
142
+ .to receive(:printf)
143
+ .with('%-30s %20s', 'Rubocop ', "\e[31mFAILURE\e[0m\n\n")
144
+ subject.send(:fatal, task)
145
+ end
146
+ end
147
+ end
148
+
149
+ describe '#label' do
150
+ context 'when we get a label for task' do
151
+ before do
152
+ expect(task)
153
+ .to receive(:label)
154
+ .and_return('Rubocop')
155
+ end
156
+
157
+ it 'should return the label' do
158
+ expect(subject.send(:label, task)).to eq 'Rubocop'
159
+ end
160
+ end
161
+ end
162
+ end
@@ -0,0 +1,20 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe PolishGeeks::DevTools::OutputStorer do
4
+ subject { described_class.new }
5
+
6
+ describe '#initialize' do
7
+ context 'when we execute the command' do
8
+ let(:commands) { %i(rubocop yard) }
9
+ let(:result) { { rubocop: '', yard: '' } }
10
+
11
+ before do
12
+ stub_const('PolishGeeks::DevTools::Config::COMMANDS', commands)
13
+ end
14
+
15
+ it 'should store an output' do
16
+ expect(subject.send(:initialize)).to eq result
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,57 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe PolishGeeks::DevTools::Runner do
4
+ subject { described_class.new }
5
+
6
+ describe '#execute' do
7
+ let(:logger) { double }
8
+ let(:output_storer) { double }
9
+ let(:config) { PolishGeeks::DevTools::Config.new }
10
+
11
+ before do
12
+ expect(::PolishGeeks::DevTools::OutputStorer)
13
+ .to receive(:new)
14
+ .and_return(output_storer)
15
+
16
+ expect(::PolishGeeks::DevTools)
17
+ .to receive(:config)
18
+ .and_return(config)
19
+ .at_least(:once)
20
+
21
+ PolishGeeks::DevTools::Config::COMMANDS.each do |command|
22
+ config.public_send(:"#{command}=", true)
23
+
24
+ klass_name = command.to_s.gsub(/(?<=_|^)(\w)/) { |el| el.upcase }.gsub(/(?:_)(\w)/, '\1')
25
+ klass = Object.const_get("PolishGeeks::DevTools::Command::#{klass_name}")
26
+
27
+ instance = double
28
+ output = double
29
+
30
+ expect(klass)
31
+ .to receive(:new)
32
+ .and_return(instance)
33
+
34
+ expect(instance)
35
+ .to receive(:stored_output=)
36
+ .with(output_storer)
37
+
38
+ expect(instance)
39
+ .to receive(:execute)
40
+
41
+ expect(instance)
42
+ .to receive(:output)
43
+ .and_return(output)
44
+
45
+ expect(output_storer)
46
+ .to receive(:"#{command}=")
47
+ .with(output)
48
+
49
+ expect(logger)
50
+ .to receive(:log)
51
+ .with(instance)
52
+ end
53
+ end
54
+
55
+ it { subject.execute(logger) }
56
+ end
57
+ end