@@ -45,6 +45,11 @@ def hook(source)
4545 . to be ( :each )
4646 end
4747
48+ it 'ignores invalid hooks' do
49+ expect ( hook ( 'before(:invalid) { example_setup }' ) . scope )
50+ . to be_nil
51+ end
52+
4853 it 'classifies :each as an example hook' do
4954 expect ( hook ( 'before(:each) { }' ) . example? ) . to be ( true )
5055 end
@@ -75,9 +80,13 @@ def metadata(source)
7580 end
7681
7782 if RUBY_VERSION >= '3.4'
83+ let ( :expected_focus ) { 's(:sym, :focus) => true' }
84+ let ( :expected_invalid ) { '{s(:sym, :invalid) => true}' }
7885 let ( :expected_special ) { 's(:sym, :special) => true' }
7986 let ( :expected_symbol ) { 's(:sym, :symbol) => true' }
8087 else
88+ let ( :expected_focus ) { 's(:sym, :focus)=>true' }
89+ let ( :expected_invalid ) { '{s(:sym, :invalid)=>true}' }
8190 let ( :expected_special ) { 's(:sym, :special)=>true' }
8291 let ( :expected_symbol ) { 's(:sym, :symbol)=>true' }
8392 end
@@ -103,8 +112,29 @@ def metadata(source)
103112 end
104113
105114 it 'withstands no arguments' do
106- expect ( metadata ( 'before { foo }' ) )
107- . to be_empty
115+ expect ( metadata ( 'before { foo }' ) ) . to be_empty
116+ end
117+
118+ it 'returns the symbol even when an invalid symbol scope is provided' do
119+ expect ( metadata ( 'before(:invalid) { foo }' ) ) . to eq ( expected_invalid )
120+ end
121+
122+ it 'extracts multiple symbol metadata' do
123+ expect ( metadata ( 'before(:example, :special, :focus) { foo }' ) )
124+ . to eq ( "{#{ expected_special } , #{ expected_focus } }" )
125+ end
126+
127+ it 'extracts multiple hash metadata' do
128+ expect ( metadata ( 'before(:example, special: true, focus: true) { foo }' ) )
129+ . to eq ( "{#{ expected_special } , #{ expected_focus } }" )
130+ end
131+
132+ it 'combines multiple symbol and hash metadata' do
133+ expect (
134+ metadata (
135+ 'before(:example, :symbol, special: true, focus: true) { foo }'
136+ )
137+ ) . to eq ( "{#{ expected_symbol } , #{ expected_special } , #{ expected_focus } }" )
108138 end
109139 end
110140end
0 commit comments