@@ -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
@@ -103,8 +108,32 @@ def metadata(source)
103108 end
104109
105110 it 'withstands no arguments' do
106- expect ( metadata ( 'before { foo }' ) )
107- . to be_empty
111+ expect ( metadata ( 'before { foo }' ) ) . to be_empty
112+ end
113+
114+ it 'returns the symbol even when an invalid symbol scope is provided' do
115+ expect ( metadata ( 'before(:invalid) { foo }' ) )
116+ . to eq ( '{s(:sym, :invalid)=>true}' )
117+ end
118+
119+ it 'fails when a string argument is provided' do
120+ expect do
121+ metadata ( 'before("each") { foo } ' )
122+ end . to raise_error ( NoMethodError )
123+ end
124+
125+ context 'when multiple arguments are provided' do
126+ it 'returns a hash with all valid metadata' do
127+ expect ( metadata ( 'before(:each, :focus, metadata: true) { foo }' ) )
128+ . to include ( expected_symbol . sub ( 'symbol' , 'focus' ) )
129+ expect ( metadata ( 'before(:each, :focus, metadata: true) { foo }' ) )
130+ . to include ( 's(:sym, :metadata)=>true' )
131+ end
132+ end
133+
134+ it 'returns a hash with the metadata when only metadata is provided' do
135+ expect ( metadata ( 'before(focus: true) { foo }' ) )
136+ . to eq ( "{#{ expected_special . sub ( 'special' , 'focus' ) } }" )
108137 end
109138 end
110139end
0 commit comments