@@ -11,43 +11,86 @@ def hook(source)
11
11
expect ( hook ( 'around(:each) { }' ) . name ) . to be ( :around )
12
12
end
13
13
14
- it 'does not break if a hook is not given a symbol literal' do
15
- expect ( hook ( 'before(scope) { example_setup }' ) . knowable_scope? ) . to be ( false )
16
- end
14
+ describe '#knowable_scope?' do
15
+ it 'does not break if a hook is not given a symbol literal' do
16
+ expect ( hook ( 'before(scope) { example_setup }' ) . knowable_scope? )
17
+ . to be ( false )
18
+ end
17
19
18
- it 'knows the scope of a hook with a symbol literal' do
19
- expect ( hook ( 'before { example_setup }' ) . knowable_scope? ) . to be ( true )
20
- end
20
+ it 'knows the scope of a hook with a symbol literal' do
21
+ expect ( hook ( 'before(:example) { example_setup }' ) . knowable_scope? )
22
+ . to be ( true )
23
+ end
21
24
22
- it 'ignores other arguments to hooks ' do
23
- expect ( hook ( 'before(:each, :metadata) { example_setup }' ) . scope )
24
- . to be ( :each )
25
- end
25
+ it 'knows the scope of a hook with no argument ' do
26
+ expect ( hook ( 'before { example_setup }' ) . knowable_scope? )
27
+ . to be ( true )
28
+ end
26
29
27
- it 'classifies nonstandard hook arguments as invalid' do
28
- expect ( hook ( 'before(:nothing) { example_setup }' ) . valid_scope? ) . to be ( false )
30
+ it 'knows the scope of a hook with hash metadata' do
31
+ expect ( hook ( 'before(special: true) { example_setup }' ) . knowable_scope? )
32
+ . to be ( true )
33
+ end
29
34
end
30
35
31
- it 'classifies :each as a valid hook argument' do
32
- expect ( hook ( 'before(:each) { example_setup }' ) . valid_scope? ) . to be ( true )
33
- end
36
+ describe '#scope' do
37
+ it 'ignores other arguments to hooks' do
38
+ expect ( hook ( 'before(:each, :metadata) { example_setup }' ) . scope )
39
+ . to be ( :each )
40
+ end
34
41
35
- it 'classifies :each as an example hook' do
36
- expect ( hook ( 'before(:each) { }' ) . example? ) . to be ( true )
37
- end
42
+ it 'classifies :each as an example hook' do
43
+ expect ( hook ( 'before(:each) { }' ) . example? ) . to be ( true )
44
+ end
45
+
46
+ it 'defaults to example hook with hash metadata' do
47
+ expect ( hook ( 'before(special: true) { }' ) . example? ) . to be ( true )
48
+ end
38
49
39
- shared_examples 'standardizes scope' do |source , scope |
40
- it "interprets #{ source } as having scope #{ scope } " do
41
- expect ( hook ( source ) . scope ) . to equal ( scope )
50
+ shared_examples 'standardizes scope' do |source , scope |
51
+ it "interprets #{ source } as having scope #{ scope } " do
52
+ expect ( hook ( source ) . scope ) . to equal ( scope )
53
+ end
42
54
end
55
+
56
+ include_examples 'standardizes scope' , 'before(:each) { }' , :each
57
+ include_examples 'standardizes scope' , 'around(:example) { }' , :each
58
+ include_examples 'standardizes scope' , 'after { }' , :each
59
+
60
+ include_examples 'standardizes scope' , 'before(:all) { }' , :context
61
+ include_examples 'standardizes scope' , 'around(:context) { }' , :context
62
+
63
+ include_examples 'standardizes scope' , 'after(:suite) { }' , :suite
43
64
end
44
65
45
- include_examples 'standardizes scope' , 'before(:each) { }' , :each
46
- include_examples 'standardizes scope' , 'around(:example) { }' , :each
47
- include_examples 'standardizes scope' , 'after { }' , :each
66
+ describe '#metadata' do
67
+ def metadata ( source )
68
+ hook ( source ) . metadata . to_s
69
+ end
48
70
49
- include_examples 'standardizes scope' , 'before(:all) { }' , :context
50
- include_examples 'standardizes scope' , 'around(:context) { }' , :context
71
+ it 'extracts symbol metadata' do
72
+ expect ( metadata ( 'before(:example, :special) { foo }' ) )
73
+ . to eq ( '{s(:sym, :special)=>true}' )
74
+ end
75
+
76
+ it 'extracts hash metadata' do
77
+ expect ( metadata ( 'before(:example, special: true) { foo }' ) )
78
+ . to eq ( '{s(:sym, :special)=>true}' )
79
+ end
51
80
52
- include_examples 'standardizes scope' , 'after(:suite) { }' , :suite
81
+ it 'combines symbol and hash metadata' do
82
+ expect ( metadata ( 'before(:example, :symbol, special: true) { foo }' ) )
83
+ . to eq ( '{s(:sym, :symbol)=>true, s(:sym, :special)=>true}' )
84
+ end
85
+
86
+ it 'extracts hash metadata with no scope given' do
87
+ expect ( metadata ( 'before(special: true) { foo }' ) )
88
+ . to eq ( '{s(:sym, :special)=>true}' )
89
+ end
90
+
91
+ it 'withstands no arguments' do
92
+ expect ( metadata ( 'before { foo }' ) )
93
+ . to be_empty
94
+ end
95
+ end
53
96
end
0 commit comments