Skip to content

Commit 19888c4

Browse files
committed
Simplify type matcher tests with shared examples
1 parent 07212bd commit 19888c4

File tree

1 file changed

+12
-22
lines changed

1 file changed

+12
-22
lines changed

spec/unit/puppet-lint/lexer_spec.rb

Lines changed: 12 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1359,6 +1359,14 @@
13591359
end
13601360

13611361
context ':TYPE' do
1362+
shared_examples 'a type matcher' do |type|
1363+
it "matches #{type}" do
1364+
token = lexer.tokenise(type).first
1365+
expect(token.type).to eq(:TYPE)
1366+
expect(token.value).to eq(type)
1367+
end
1368+
end
1369+
13621370
it 'matches Data Types' do
13631371
token = lexer.tokenise('Integer').first
13641372
expect(token.type).to eq(:TYPE)
@@ -1378,30 +1386,12 @@
13781386
end
13791387

13801388
describe 'Platform Types' do
1381-
it 'matches Callable' do
1382-
token = lexer.tokenise('Callable').first
1383-
expect(token.type).to eq(:TYPE)
1384-
expect(token.value).to eq('Callable')
1385-
end
1386-
1387-
it 'matches Sensitive' do
1388-
token = lexer.tokenise('Sensitive').first
1389-
expect(token.type).to eq(:TYPE)
1390-
expect(token.value).to eq('Sensitive')
1391-
end
1389+
it_behaves_like 'a type matcher', 'Callable'
1390+
it_behaves_like 'a type matcher', 'Sensitive'
13921391
end
13931392

1394-
it 'matches Error type' do
1395-
token = lexer.tokenise('Error').first
1396-
expect(token.type).to eq(:TYPE)
1397-
expect(token.value).to eq('Error')
1398-
end
1399-
1400-
it 'matches Binary type' do
1401-
token = lexer.tokenise('Binary').first
1402-
expect(token.type).to eq(:TYPE)
1403-
expect(token.value).to eq('Binary')
1404-
end
1393+
it_behaves_like 'a type matcher', 'Error'
1394+
it_behaves_like 'a type matcher', 'Binary'
14051395
end
14061396

14071397
context ':HEREDOC without interpolation' do

0 commit comments

Comments
 (0)