/
verifier_spec.rb
106 lines (91 loc) · 3.06 KB
/
verifier_spec.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
require File.dirname(__FILE__) + '/spec_helper'
describe YARD::Verifier do
describe '#parse_expressions' do
it "should create #__execute method" do
v = Verifier.new("expr1")
v.should respond_to(:__execute)
end
it "should parse @tagname into tag('tagname')" do
obj = mock(:object)
obj.should_receive(:tag).with('return')
Verifier.new('@return').call(obj)
end
it "should parse @@tagname into object.tags('tagname')" do
obj = mock(:object)
obj.should_receive(:tags).with('return')
Verifier.new('@@return').call(obj)
end
it "should allow namespaced tag using @{} syntax" do
obj = mock(:object)
obj.should_receive(:tag).with('yard.return')
Verifier.new('@{yard.return}').call(obj)
end
it "should allow namespaced tags using @{} syntax" do
obj = mock(:object)
obj.should_receive(:tags).with('yard.return')
Verifier.new('@@{yard.return}').call(obj)
end
it "should call methods on tag object" do
obj = mock(:object)
obj2 = mock(:tag)
obj.should_receive(:tag).with('return').and_return obj2
obj2.should_receive(:foo)
Verifier.new('@return.foo').call(obj)
end
it "should send any missing methods to object" do
obj = mock(:object)
obj.should_receive(:has_tag?).with('return')
Verifier.new('has_tag?("return")').call(obj)
end
it "should allow multiple expressions" do
obj = mock(:object)
obj.should_receive(:tag).with('return').and_return(true)
obj.should_receive(:tag).with('param').and_return(false)
Verifier.new('@return', '@param').call(obj).should == false
end
end
describe '#o' do
it "should alias object to o" do
obj = mock(:object)
obj.should_receive(:a).ordered
Verifier.new('o.a').call(obj)
end
end
describe '#call' do
it "should mock a nonexistent tag so that exceptions are not raised" do
obj = mock(:object)
obj.should_receive(:tag).and_return(nil)
Verifier.new('@return.text').call(obj).should == false
end
it "should not fail if no expressions were added" do
lambda { Verifier.new.call(nil) }.should_not raise_error
end
it "should always ignore proxy objects and return true" do
v = Verifier.new('tag(:x)')
lambda { v.call(P('foo')).should == true }.should_not raise_error
end
end
describe '#expressions' do
it "should maintain a list of all unparsed expressions" do
Verifier.new('@return.text', '@private').expressions.should == ['@return.text', '@private']
end
end
describe '#expressions=' do
it "should recompile expressions when attribute is modified" do
obj = mock(:object)
obj.should_receive(:tag).with('return')
v = Verifier.new
v.expressions = ['@return']
v.call(obj)
end
end
describe '#add_expressions' do
it "should add new expressions and recompile" do
obj = mock(:object)
obj.should_receive(:tag).with('return')
v = Verifier.new
v.add_expressions '@return'
v.call(obj)
end
end
end