Skip to content

Commit 38126c0

Browse files
committed
Add rest of position flags to Parser
1 parent 88b3158 commit 38126c0

File tree

2 files changed

+136
-3
lines changed

2 files changed

+136
-3
lines changed

lib/parser.rb

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,42 @@ def parser(options)
4444
ENV[key] = p unless has_set_position[key]
4545
end
4646
end
47+
48+
opts.on('--pc', '--position-in-class [before|top|after|bottom]', positions,
49+
'Place the annotations at the top (before) or the bottom (after) of the model file') do |p|
50+
ENV['position_in_class'] = p
51+
has_set_position['position_in_class'] = true
52+
end
53+
54+
opts.on('--pf', '--position-in-factory [before|top|after|bottom]', positions,
55+
'Place the annotations at the top (before) or the bottom (after) of any factory files') do |p|
56+
ENV['position_in_factory'] = p
57+
has_set_position['position_in_factory'] = true
58+
end
59+
60+
opts.on('--px', '--position-in-fixture [before|top|after|bottom]', positions,
61+
'Place the annotations at the top (before) or the bottom (after) of any fixture files') do |p|
62+
ENV['position_in_fixture'] = p
63+
has_set_position['position_in_fixture'] = true
64+
end
65+
66+
opts.on('--pt', '--position-in-test [before|top|after|bottom]', positions,
67+
'Place the annotations at the top (before) or the bottom (after) of any test files') do |p|
68+
ENV['position_in_test'] = p
69+
has_set_position['position_in_test'] = true
70+
end
71+
72+
opts.on('--pr', '--position-in-routes [before|top|after|bottom]', positions,
73+
'Place the annotations at the top (before) or the bottom (after) of the routes.rb file') do |p|
74+
ENV['position_in_routes'] = p
75+
has_set_position['position_in_routes'] = true
76+
end
77+
78+
opts.on('--ps', '--position-in-serializer [before|top|after|bottom]', positions,
79+
'Place the annotations at the top (before) or the bottom (after) of the serializer files') do |p|
80+
ENV['position_in_serializer'] = p
81+
has_set_position['position_in_serializer'] = true
82+
end
4783
end
4884
end
4985

spec/parser_spec.rb

Lines changed: 100 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
end
2121
end
2222

23-
['-p', '--position'].each do |option|
23+
%w[-p --position].each do |option|
2424
describe option do
2525
Parser::ANNOTATION_POSITIONS.each do |position|
2626
context "when specifying #{position}" do
@@ -30,16 +30,113 @@
3030
end
3131

3232
it "sets ENV['position'] to be position" do
33+
allow(ENV).to receive(:[]=)
3334
Parser.parse([option, position])
34-
expect(ENV['position']).to eq(position)
35+
36+
expect(ENV).to have_received(:[]=).with('position', position)
3537
end
3638

3739
it 'sets the value in ENV for the different file types' do
40+
allow(ENV).to receive(:[]=)
3841
Parser.parse([option, position])
42+
3943
Parser::FILE_TYPE_POSITIONS.each do |file_type|
40-
expect(ENV[file_type]).to eq(position)
44+
expect(ENV).to have_received(:[]=).with(file_type, position)
4145
end
4246
end
47+
48+
context 'the ENV value for different file type has already been set' do
49+
end
50+
end
51+
end
52+
end
53+
end
54+
55+
%w[--pc --position-in-class].each do |option|
56+
describe option do
57+
let(:env_key) { 'position_in_class' }
58+
59+
Parser::ANNOTATION_POSITIONS.each do |position|
60+
context "when specifying '#{position}'" do
61+
it "sets the ENV variable to '#{position}'" do
62+
expect(ENV).to receive(:[]=).with(env_key, position)
63+
Parser.parse([option, position])
64+
end
65+
end
66+
end
67+
end
68+
end
69+
70+
%w[--pf --position-in-factory].each do |option|
71+
describe option do
72+
let(:env_key) { 'position_in_factory' }
73+
74+
Parser::ANNOTATION_POSITIONS.each do |position|
75+
context "when specifying #{position}" do
76+
it "sets the ENV variable to #{position}" do
77+
expect(ENV).to receive(:[]=).with(env_key, position)
78+
Parser.parse([option, position])
79+
end
80+
end
81+
end
82+
end
83+
end
84+
85+
%w[--px --position-in-fixture].each do |option|
86+
describe option do
87+
let(:env_key) { 'position_in_fixture' }
88+
89+
Parser::ANNOTATION_POSITIONS.each do |position|
90+
context "when specifying #{position}" do
91+
it "sets the ENV variable to #{position}" do
92+
expect(ENV).to receive(:[]=).with(env_key, position)
93+
Parser.parse([option, position])
94+
end
95+
end
96+
end
97+
end
98+
end
99+
100+
%w[--pt --position-in-test].each do |option|
101+
describe option do
102+
let(:env_key) { 'position_in_test' }
103+
104+
Parser::ANNOTATION_POSITIONS.each do |position|
105+
context "when specifying #{position}" do
106+
it "sets the ENV variable to #{position}" do
107+
expect(ENV).to receive(:[]=).with(env_key, position)
108+
Parser.parse([option, position])
109+
end
110+
end
111+
end
112+
end
113+
end
114+
115+
%w[--pr --position-in-routes].each do |option|
116+
describe option do
117+
let(:env_key) { 'position_in_routes' }
118+
119+
Parser::ANNOTATION_POSITIONS.each do |position|
120+
context "when specifying #{position}" do
121+
it "sets the ENV variable to #{position}" do
122+
expect(ENV).to receive(:[]=).with(env_key, position)
123+
Parser.parse([option, position])
124+
end
125+
end
126+
end
127+
end
128+
end
129+
130+
%w[--ps --position-in-serializer].each do |option|
131+
describe option do
132+
let(:env_key) { 'position_in_serializer' }
133+
134+
Parser::ANNOTATION_POSITIONS.each do |position|
135+
context "when specifying #{position}" do
136+
it "sets the ENV variable to #{position}" do
137+
expect(ENV).to receive(:[]=).with(env_key, position)
138+
Parser.parse([option, position])
139+
end
43140
end
44141
end
45142
end

0 commit comments

Comments
 (0)