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.
- checksums.yaml +7 -0
- data/.gitignore +22 -0
- data/.ruby-gemset +1 -0
- data/.ruby-version +1 -0
- data/.travis.yml +6 -0
- data/Gemfile +2 -0
- data/Gemfile.lock +193 -0
- data/README.md +112 -0
- data/Rakefile +20 -0
- data/config/haml-lint.yml +74 -0
- data/config/rubocop.yml +35 -0
- data/config/yardopts +7 -0
- data/lib/polishgeeks-dev-tools.rb +43 -0
- data/lib/polishgeeks/dev-tools/command/allowed_extensions.rb +62 -0
- data/lib/polishgeeks/dev-tools/command/base.rb +73 -0
- data/lib/polishgeeks/dev-tools/command/brakeman.rb +46 -0
- data/lib/polishgeeks/dev-tools/command/coverage.rb +43 -0
- data/lib/polishgeeks/dev-tools/command/examples_comparator.rb +75 -0
- data/lib/polishgeeks/dev-tools/command/expires_in.rb +74 -0
- data/lib/polishgeeks/dev-tools/command/haml_lint.rb +28 -0
- data/lib/polishgeeks/dev-tools/command/readme.rb +32 -0
- data/lib/polishgeeks/dev-tools/command/rspec.rb +38 -0
- data/lib/polishgeeks/dev-tools/command/rspec_files_names.rb +58 -0
- data/lib/polishgeeks/dev-tools/command/rspec_files_structure.rb +134 -0
- data/lib/polishgeeks/dev-tools/command/rubocop.rb +50 -0
- data/lib/polishgeeks/dev-tools/command/rubycritic.rb +17 -0
- data/lib/polishgeeks/dev-tools/command/simplecov.rb +32 -0
- data/lib/polishgeeks/dev-tools/command/tasks_files_names.rb +76 -0
- data/lib/polishgeeks/dev-tools/command/yard.rb +35 -0
- data/lib/polishgeeks/dev-tools/command/yml_parser.rb +85 -0
- data/lib/polishgeeks/dev-tools/config.rb +91 -0
- data/lib/polishgeeks/dev-tools/hash.rb +24 -0
- data/lib/polishgeeks/dev-tools/logger.rb +63 -0
- data/lib/polishgeeks/dev-tools/output_storer.rb +17 -0
- data/lib/polishgeeks/dev-tools/runner.rb +27 -0
- data/lib/polishgeeks/dev-tools/shell.rb +16 -0
- data/lib/polishgeeks/dev-tools/tasks/dev-tools.rake +15 -0
- data/lib/polishgeeks/dev-tools/version.rb +8 -0
- data/polishgeeks_dev_tools.gemspec +36 -0
- data/spec/lib/polishgeeks-dev-tools_spec.rb +35 -0
- data/spec/lib/polishgeeks/dev-tools/command/allowed_extensions_spec.rb +66 -0
- data/spec/lib/polishgeeks/dev-tools/command/base_spec.rb +127 -0
- data/spec/lib/polishgeeks/dev-tools/command/brakeman_spec.rb +95 -0
- data/spec/lib/polishgeeks/dev-tools/command/coverage_spec.rb +121 -0
- data/spec/lib/polishgeeks/dev-tools/command/examples_comparator_spec.rb +171 -0
- data/spec/lib/polishgeeks/dev-tools/command/expires_in_spec.rb +69 -0
- data/spec/lib/polishgeeks/dev-tools/command/haml_lint_spec.rb +79 -0
- data/spec/lib/polishgeeks/dev-tools/command/readme_spec.rb +38 -0
- data/spec/lib/polishgeeks/dev-tools/command/rspec_files_names_spec.rb +91 -0
- data/spec/lib/polishgeeks/dev-tools/command/rspec_files_structure_spec.rb +262 -0
- data/spec/lib/polishgeeks/dev-tools/command/rspec_spec.rb +63 -0
- data/spec/lib/polishgeeks/dev-tools/command/rubocop_spec.rb +127 -0
- data/spec/lib/polishgeeks/dev-tools/command/rubycritic_spec.rb +27 -0
- data/spec/lib/polishgeeks/dev-tools/command/simplecov_spec.rb +53 -0
- data/spec/lib/polishgeeks/dev-tools/command/tasks_files_names_spec.rb +108 -0
- data/spec/lib/polishgeeks/dev-tools/command/yard_spec.rb +86 -0
- data/spec/lib/polishgeeks/dev-tools/command/yml_parser_spec.rb +104 -0
- data/spec/lib/polishgeeks/dev-tools/config_spec.rb +78 -0
- data/spec/lib/polishgeeks/dev-tools/hash_spec.rb +37 -0
- data/spec/lib/polishgeeks/dev-tools/logger_spec.rb +162 -0
- data/spec/lib/polishgeeks/dev-tools/output_storer_spec.rb +20 -0
- data/spec/lib/polishgeeks/dev-tools/runner_spec.rb +57 -0
- data/spec/lib/polishgeeks/dev-tools/shell_spec.rb +13 -0
- data/spec/lib/polishgeeks/dev-tools/version_spec.rb +7 -0
- data/spec/spec_helper.rb +28 -0
- metadata +330 -0
@@ -0,0 +1,66 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
RSpec.describe PolishGeeks::DevTools::Command::AllowedExtensions do
|
4
|
+
subject { described_class.new }
|
5
|
+
|
6
|
+
describe '#execute' do
|
7
|
+
let(:file_name) { 'file.rb' }
|
8
|
+
let(:files) { [PolishGeeks::DevTools.app_root + '/config/' + file_name] }
|
9
|
+
before do
|
10
|
+
expect(Dir)
|
11
|
+
.to receive(:[])
|
12
|
+
.and_return(files)
|
13
|
+
expect(described_class::ALLOWED_EXTENSIONS)
|
14
|
+
.to receive(:any?)
|
15
|
+
.and_return(allow_extension)
|
16
|
+
|
17
|
+
subject.execute
|
18
|
+
end
|
19
|
+
|
20
|
+
context 'when we dont have invalid files' do
|
21
|
+
let(:allow_extension) { true }
|
22
|
+
it { expect(subject.output).to eq [] }
|
23
|
+
end
|
24
|
+
|
25
|
+
context 'when we have invalid files' do
|
26
|
+
let(:allow_extension) { false }
|
27
|
+
it { expect(subject.output).to eq [file_name] }
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
describe '#label' do
|
32
|
+
let(:expected) { 'Allowed Extensions' }
|
33
|
+
|
34
|
+
it { expect(subject.label).to eq expected }
|
35
|
+
end
|
36
|
+
|
37
|
+
describe '#error_message' do
|
38
|
+
let(:output) { [rand.to_s, rand.to_s] }
|
39
|
+
let(:expected) do
|
40
|
+
'Following files are not allowed in config directory:'\
|
41
|
+
"\n\n#{output.join("\n")}\n"
|
42
|
+
end
|
43
|
+
|
44
|
+
before do
|
45
|
+
subject.instance_variable_set('@output', output)
|
46
|
+
end
|
47
|
+
|
48
|
+
it { expect(subject.error_message).to eq expected }
|
49
|
+
end
|
50
|
+
|
51
|
+
describe do
|
52
|
+
before do
|
53
|
+
subject.instance_variable_set('@output', output)
|
54
|
+
end
|
55
|
+
|
56
|
+
context 'when output is empty' do
|
57
|
+
let(:output) { '' }
|
58
|
+
it { expect(subject.valid?).to eq true }
|
59
|
+
end
|
60
|
+
|
61
|
+
context 'when output is empty' do
|
62
|
+
let(:output) { rand.to_s }
|
63
|
+
it { expect(subject.valid?).to eq false }
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
@@ -0,0 +1,127 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
RSpec.describe PolishGeeks::DevTools::Command::Base do
|
4
|
+
subject { described_class.new }
|
5
|
+
|
6
|
+
describe '#execute' do
|
7
|
+
it { expect { subject.execute }. to raise_error(NotImplementedError) }
|
8
|
+
end
|
9
|
+
|
10
|
+
describe '#valid?' do
|
11
|
+
it { expect { subject.valid? }. to raise_error(NotImplementedError) }
|
12
|
+
end
|
13
|
+
|
14
|
+
describe '#error_message' do
|
15
|
+
let(:output) { rand.to_s }
|
16
|
+
|
17
|
+
before do
|
18
|
+
subject.instance_variable_set('@output', output)
|
19
|
+
end
|
20
|
+
|
21
|
+
it 'by default should equal raw output' do
|
22
|
+
expect(subject.error_message).to eq output
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
describe '#new' do
|
27
|
+
it 'should execute ensure_framework_if_required' do
|
28
|
+
expect_any_instance_of(described_class)
|
29
|
+
.to receive(:ensure_framework_if_required)
|
30
|
+
.once
|
31
|
+
|
32
|
+
described_class.new
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
describe '#ensure_framework_if_required' do
|
37
|
+
context 'when there is no framework required' do
|
38
|
+
before { described_class.framework = nil }
|
39
|
+
|
40
|
+
it { expect { subject.send(:ensure_framework_if_required) }.to_not raise_error }
|
41
|
+
end
|
42
|
+
|
43
|
+
context 'when there rails is required' do
|
44
|
+
before { described_class.framework = :rails }
|
45
|
+
|
46
|
+
context 'and it is included' do
|
47
|
+
before do
|
48
|
+
expect(PolishGeeks::DevTools)
|
49
|
+
.to receive(:config)
|
50
|
+
.and_return(double(rails?: true))
|
51
|
+
.exactly(2).times
|
52
|
+
end
|
53
|
+
|
54
|
+
it { expect { subject.send(:ensure_framework_if_required) }.to_not raise_error }
|
55
|
+
end
|
56
|
+
|
57
|
+
context 'and it is not included' do
|
58
|
+
before do
|
59
|
+
expect(PolishGeeks::DevTools)
|
60
|
+
.to receive(:config)
|
61
|
+
.and_return(double(rails?: false))
|
62
|
+
end
|
63
|
+
|
64
|
+
it 'should raise exception' do
|
65
|
+
error = described_class::MissingFramework
|
66
|
+
expect { subject.send(:ensure_framework_if_required) }.to raise_error(error, 'rails')
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
context 'when there sinatra is required' do
|
72
|
+
before { described_class.framework = :sinatra }
|
73
|
+
|
74
|
+
context 'and it is included' do
|
75
|
+
before do
|
76
|
+
expect(PolishGeeks::DevTools)
|
77
|
+
.to receive(:config)
|
78
|
+
.and_return(double(sinatra?: true))
|
79
|
+
.exactly(2).times
|
80
|
+
end
|
81
|
+
|
82
|
+
it { expect { subject.send(:ensure_framework_if_required) }.to_not raise_error }
|
83
|
+
end
|
84
|
+
|
85
|
+
context 'and it is not included' do
|
86
|
+
before do
|
87
|
+
expect(PolishGeeks::DevTools)
|
88
|
+
.to receive(:config)
|
89
|
+
.and_return(double(sinatra?: false))
|
90
|
+
end
|
91
|
+
|
92
|
+
it 'should raise exception' do
|
93
|
+
error = described_class::MissingFramework
|
94
|
+
expect { subject.send(:ensure_framework_if_required) }.to raise_error(error, 'sinatra')
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
describe 'class type definer' do
|
101
|
+
subject { described_class.dup }
|
102
|
+
|
103
|
+
context 'when it is generator' do
|
104
|
+
before { subject.type = :generator }
|
105
|
+
|
106
|
+
describe '.generator?' do
|
107
|
+
it { expect(subject.generator?).to eq true }
|
108
|
+
end
|
109
|
+
|
110
|
+
describe '.validator?' do
|
111
|
+
it { expect(subject.validator?).to eq false }
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
context 'when it is validator' do
|
116
|
+
before { subject.type = :validator }
|
117
|
+
|
118
|
+
describe '.generator?' do
|
119
|
+
it { expect(subject.generator?).to eq false }
|
120
|
+
end
|
121
|
+
|
122
|
+
describe '.validator?' do
|
123
|
+
it { expect(subject.validator?).to eq true }
|
124
|
+
end
|
125
|
+
end
|
126
|
+
end
|
127
|
+
end
|
@@ -0,0 +1,95 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
RSpec.describe PolishGeeks::DevTools::Command::Brakeman do
|
4
|
+
subject { described_class.new }
|
5
|
+
let(:config) { double(rails?: true) }
|
6
|
+
|
7
|
+
before do
|
8
|
+
expect(PolishGeeks::DevTools)
|
9
|
+
.to receive(:config)
|
10
|
+
.and_return(config)
|
11
|
+
|
12
|
+
subject
|
13
|
+
end
|
14
|
+
|
15
|
+
describe '#execute' do
|
16
|
+
context 'when we run brakeman' do
|
17
|
+
before do
|
18
|
+
expect_any_instance_of(PolishGeeks::DevTools::Shell)
|
19
|
+
.to receive(:execute)
|
20
|
+
.with('bundle exec brakeman -q')
|
21
|
+
end
|
22
|
+
|
23
|
+
it 'should execute the command' do
|
24
|
+
subject.execute
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
describe '#valid?' do
|
30
|
+
context 'when warnings are equal 0' do
|
31
|
+
before do
|
32
|
+
expect(subject)
|
33
|
+
.to receive(:warnings)
|
34
|
+
.and_return(0)
|
35
|
+
end
|
36
|
+
|
37
|
+
context 'and errors are equal 0' do
|
38
|
+
before do
|
39
|
+
expect(subject)
|
40
|
+
.to receive(:errors)
|
41
|
+
.and_return(0)
|
42
|
+
end
|
43
|
+
|
44
|
+
it 'should return true' do
|
45
|
+
expect(subject.valid?).to eq true
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
context 'and errors are not equal 0' do
|
50
|
+
before do
|
51
|
+
expect(subject)
|
52
|
+
.to receive(:errors)
|
53
|
+
.and_return(1)
|
54
|
+
end
|
55
|
+
|
56
|
+
it 'should return true' do
|
57
|
+
expect(subject.valid?).to eq false
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
describe 'label' do
|
64
|
+
let(:models) { rand(1000) }
|
65
|
+
let(:controllers) { rand(1000) }
|
66
|
+
let(:templates) { rand(1000) }
|
67
|
+
|
68
|
+
before do
|
69
|
+
expect(subject).to receive(:models).and_return(models)
|
70
|
+
expect(subject).to receive(:controllers).and_return(controllers)
|
71
|
+
expect(subject).to receive(:templates).and_return(templates)
|
72
|
+
end
|
73
|
+
|
74
|
+
it 'should use details' do
|
75
|
+
label = "Brakeman (#{controllers} con, #{models} mod, #{templates} temp)"
|
76
|
+
expect(subject.label).to eq label
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
describe 'counter' do
|
81
|
+
described_class::REGEXPS.each do |name, _regexp|
|
82
|
+
describe "##{name}" do
|
83
|
+
let(:amount) { rand(1000) }
|
84
|
+
|
85
|
+
before do
|
86
|
+
subject.instance_variable_set(:@output, "#{name.to_s.capitalize} #{amount}")
|
87
|
+
end
|
88
|
+
|
89
|
+
it 'should return a proper value' do
|
90
|
+
expect(subject.send(name)).to eq amount
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
@@ -0,0 +1,121 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
RSpec.describe PolishGeeks::DevTools::Command::Coverage do
|
4
|
+
subject { described_class.new }
|
5
|
+
|
6
|
+
let(:label) { '(95.00%) covered' }
|
7
|
+
let(:config) { double }
|
8
|
+
|
9
|
+
describe '#to_f' do
|
10
|
+
context 'when we run simplecov' do
|
11
|
+
before do
|
12
|
+
subject.instance_variable_set(:@output, label)
|
13
|
+
end
|
14
|
+
|
15
|
+
it 'should return number of coverage as a float value' do
|
16
|
+
expect(subject.to_f).to eq 95.00
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
describe '#execute' do
|
22
|
+
context 'when we run simplecov' do
|
23
|
+
let(:output) { OpenStruct.new(rspec: label) }
|
24
|
+
|
25
|
+
before do
|
26
|
+
subject.instance_variable_set(:@stored_output, output)
|
27
|
+
end
|
28
|
+
|
29
|
+
it 'should execute the command' do
|
30
|
+
expect(subject.execute).to eq label
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
describe '#valid?' do
|
36
|
+
context 'when cc level is greater or equal than expected' do
|
37
|
+
before do
|
38
|
+
expect(subject)
|
39
|
+
.to receive(:to_f)
|
40
|
+
.and_return(95.0)
|
41
|
+
expect(PolishGeeks::DevTools::Config)
|
42
|
+
.to receive(:config)
|
43
|
+
.and_return(config)
|
44
|
+
expect(config)
|
45
|
+
.to receive(:simplecov_threshold)
|
46
|
+
.and_return(65.0)
|
47
|
+
end
|
48
|
+
|
49
|
+
it 'should return true' do
|
50
|
+
expect(subject.valid?).to eq true
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
context 'when cc level is less than expected' do
|
55
|
+
before do
|
56
|
+
expect(subject)
|
57
|
+
.to receive(:to_f)
|
58
|
+
.and_return(65.0)
|
59
|
+
expect(PolishGeeks::DevTools::Config)
|
60
|
+
.to receive(:config)
|
61
|
+
.and_return(config)
|
62
|
+
expect(config)
|
63
|
+
.to receive(:simplecov_threshold)
|
64
|
+
.and_return(95.0)
|
65
|
+
end
|
66
|
+
|
67
|
+
it 'should return false' do
|
68
|
+
expect(subject.valid?).to eq false
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
describe '#label' do
|
74
|
+
context 'when we run simplecov and cc is greater or equal than expected' do
|
75
|
+
before do
|
76
|
+
expect(subject)
|
77
|
+
.to receive(:to_f)
|
78
|
+
.and_return(95.0)
|
79
|
+
expect(PolishGeeks::DevTools::Config)
|
80
|
+
.to receive(:config)
|
81
|
+
.and_return(config)
|
82
|
+
expect(config)
|
83
|
+
.to receive(:simplecov_threshold)
|
84
|
+
.and_return(65.0)
|
85
|
+
end
|
86
|
+
|
87
|
+
it 'should return the label' do
|
88
|
+
expect(subject.label).to eq 'Coverage 95.0% covered - 65.0% required'
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
describe '#error_message' do
|
94
|
+
context 'when we run simplecov and cc is less than expected' do
|
95
|
+
before do
|
96
|
+
expect(subject)
|
97
|
+
.to receive(:to_f)
|
98
|
+
.and_return(65.0)
|
99
|
+
expect(PolishGeeks::DevTools::Config)
|
100
|
+
.to receive(:config)
|
101
|
+
.and_return(config)
|
102
|
+
expect(config)
|
103
|
+
.to receive(:simplecov_threshold)
|
104
|
+
.and_return(95.0)
|
105
|
+
end
|
106
|
+
|
107
|
+
it 'should return the error message' do
|
108
|
+
expect(subject.error_message)
|
109
|
+
.to eq 'Coverage level should more or equal to 95.0%. was: 65.0'
|
110
|
+
end
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
describe '.generator?' do
|
115
|
+
it { expect(described_class.generator?).to eq false }
|
116
|
+
end
|
117
|
+
|
118
|
+
describe '.validator?' do
|
119
|
+
it { expect(described_class.validator?).to eq true }
|
120
|
+
end
|
121
|
+
end
|
@@ -0,0 +1,171 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
RSpec.describe PolishGeeks::DevTools::Command::ExamplesComparator do
|
4
|
+
subject { described_class.new }
|
5
|
+
|
6
|
+
let(:example_file) { rand.to_s }
|
7
|
+
let(:dedicated_file) { rand.to_s }
|
8
|
+
|
9
|
+
describe '#execute' do
|
10
|
+
let(:config_path) { rand.to_s }
|
11
|
+
|
12
|
+
before do
|
13
|
+
expect(subject)
|
14
|
+
.to receive(:config_path)
|
15
|
+
.and_return(config_path)
|
16
|
+
|
17
|
+
expect(subject)
|
18
|
+
.to receive(:same_key_structure?)
|
19
|
+
.and_return(compare_result)
|
20
|
+
|
21
|
+
expect(Dir)
|
22
|
+
.to receive(:[])
|
23
|
+
.with(config_path)
|
24
|
+
.and_return([example_file])
|
25
|
+
end
|
26
|
+
|
27
|
+
context 'when compared files structure is the same' do
|
28
|
+
let(:compare_result) { true }
|
29
|
+
|
30
|
+
it 'should put a successful message into output' do
|
31
|
+
subject.execute
|
32
|
+
|
33
|
+
expect(subject.output).to include 'success'
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
context 'when compared files structure is not the same' do
|
38
|
+
let(:compare_result) { false }
|
39
|
+
|
40
|
+
it 'should put a failed message into output' do
|
41
|
+
subject.execute
|
42
|
+
expect(subject.output).to include 'failed'
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
describe '#config_path' do
|
48
|
+
let(:expected) do
|
49
|
+
"#{File.expand_path(PolishGeeks::DevTools.app_root + '/config')}/**/*.yml.example"
|
50
|
+
end
|
51
|
+
|
52
|
+
it 'should be equal to expected message' do
|
53
|
+
expect(subject.send(:config_path)).to eq expected
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
describe '#successful_compare' do
|
58
|
+
let(:compare_header) { rand.to_s }
|
59
|
+
let(:expected) { "\e[32m success\e[0m - #{compare_header}\n" }
|
60
|
+
|
61
|
+
it 'should be equal to expected message' do
|
62
|
+
expect(subject.send(:successful_compare, compare_header)).to eq expected
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
describe '#failed_compare' do
|
67
|
+
let(:compare_header) { rand.to_s }
|
68
|
+
let(:expected) { "\e[31m failed\e[0m - #{compare_header} - structure not equal\n" }
|
69
|
+
|
70
|
+
it 'should be equal to expected message' do
|
71
|
+
expect(subject.send(:failed_compare, compare_header)).to eq expected
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
describe '#compare_header' do
|
76
|
+
let(:expected) { "#{File.basename(example_file)} and #{File.basename(dedicated_file)}" }
|
77
|
+
|
78
|
+
it 'should be equal to expected message' do
|
79
|
+
expect(subject.send(:compare_header, example_file, dedicated_file)).to eq expected
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
describe '#same_key_structure?' do
|
84
|
+
let(:structure1) { double }
|
85
|
+
let(:structure2) { double }
|
86
|
+
let(:hash) { double }
|
87
|
+
|
88
|
+
before do
|
89
|
+
expect(PolishGeeks::DevTools::Hash)
|
90
|
+
.to receive(:new)
|
91
|
+
.and_return(hash)
|
92
|
+
.exactly(2).times
|
93
|
+
|
94
|
+
expect(YAML)
|
95
|
+
.to receive(:load_file)
|
96
|
+
.with(example_file)
|
97
|
+
.and_return(structure1)
|
98
|
+
|
99
|
+
expect(YAML)
|
100
|
+
.to receive(:load_file)
|
101
|
+
.with(dedicated_file)
|
102
|
+
.and_return(structure2)
|
103
|
+
|
104
|
+
expect(hash)
|
105
|
+
.to receive(:merge!)
|
106
|
+
.exactly(2).times
|
107
|
+
|
108
|
+
expect(hash)
|
109
|
+
.to receive(:same_key_structure?)
|
110
|
+
.and_return(result)
|
111
|
+
end
|
112
|
+
|
113
|
+
context 'when structure is the same' do
|
114
|
+
let(:result) { true }
|
115
|
+
|
116
|
+
it '' do
|
117
|
+
executed = subject.send(
|
118
|
+
:same_key_structure?,
|
119
|
+
example_file,
|
120
|
+
dedicated_file
|
121
|
+
)
|
122
|
+
|
123
|
+
expect(executed).to eq result
|
124
|
+
end
|
125
|
+
end
|
126
|
+
|
127
|
+
context 'when structure is not the same' do
|
128
|
+
let(:result) { false }
|
129
|
+
|
130
|
+
it '' do
|
131
|
+
executed = subject.send(
|
132
|
+
:same_key_structure?,
|
133
|
+
example_file,
|
134
|
+
dedicated_file
|
135
|
+
)
|
136
|
+
|
137
|
+
expect(executed).to eq result
|
138
|
+
end
|
139
|
+
end
|
140
|
+
end
|
141
|
+
|
142
|
+
describe '#valid?' do
|
143
|
+
context 'when example files have the same structure' do
|
144
|
+
before do
|
145
|
+
subject.instance_variable_set(:@output, 'OK')
|
146
|
+
end
|
147
|
+
|
148
|
+
it 'should return true' do
|
149
|
+
expect(subject.valid?).to eq true
|
150
|
+
end
|
151
|
+
end
|
152
|
+
|
153
|
+
context 'when example files do not have the same structure' do
|
154
|
+
before do
|
155
|
+
subject.instance_variable_set(:@output, 'failed')
|
156
|
+
end
|
157
|
+
|
158
|
+
it 'should return false' do
|
159
|
+
expect(subject.valid?).to eq false
|
160
|
+
end
|
161
|
+
end
|
162
|
+
end
|
163
|
+
|
164
|
+
describe '.generator?' do
|
165
|
+
it { expect(described_class.generator?).to eq false }
|
166
|
+
end
|
167
|
+
|
168
|
+
describe '.validator?' do
|
169
|
+
it { expect(described_class.validator?).to eq true }
|
170
|
+
end
|
171
|
+
end
|