forked from zipmark/rspec_api_documentation
/
configuration_spec.rb
122 lines (101 loc) · 3.54 KB
/
configuration_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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
require 'spec_helper'
describe RspecApiDocumentation::Configuration do
let(:parent) { nil }
let(:configuration) { RspecApiDocumentation::Configuration.new(parent) }
subject { configuration }
its(:parent) { should equal(parent) }
its(:settings) { should == {} }
its(:groups) { should == [] }
describe ".add_setting" do
it 'should allow creating a new setting' do
RspecApiDocumentation::Configuration.add_setting :new_setting
configuration.should respond_to(:new_setting)
configuration.should respond_to(:new_setting=)
end
it 'should allow setting a default' do
RspecApiDocumentation::Configuration.add_setting :new_setting, :default => "default"
configuration.new_setting.should == "default"
end
it "should allow the default setting to be a lambda" do
RspecApiDocumentation::Configuration.add_setting :another_setting, :default => lambda { |config| config.new_setting }
configuration.another_setting.should == "default"
end
end
describe "default settings" do
let(:default_template_path) { File.expand_path("../../templates", __FILE__) }
context "when Rails is defined" do
let(:rails_root) { Pathname.new("tmp") }
let(:rails_app) { stub }
before { Rails = stub(:application => rails_app, :root => rails_root) }
after { Object.send(:remove_const, :Rails) }
its(:docs_dir) { should == rails_root.join("docs") }
its(:app) { should == rails_app }
end
its(:docs_dir) { should == Pathname.new("docs") }
its(:format) { should == :html }
its(:template_path) { should == default_template_path }
its(:filter) { should == :all }
its(:exclusion_filter) { should be_nil }
its(:app) { should be_nil }
its(:curl_host) { should be_nil }
its(:url_prefix) { should be_blank }
its(:keep_source_order) { should be_false }
its(:api_name) { should == "API Documentation" }
end
describe "#define_groups" do
it "should take a block" do
called = false
subject.define_group(:foo) { called = true }
called.should eq(true)
end
it "should yield a sub-configuration" do
subject.define_group(:foo) do |config|
config.should be_a(described_class)
config.parent.should equal(subject)
end
end
it "should set the sub-configuration filter" do
subject.define_group(:foo) do |config|
config.filter.should eq(:foo)
end
end
it "should inherit its parents configurations" do
subject.format = :json
subject.define_group(:sub) do |config|
config.format.should == :json
end
end
it "should scope the documentation directory" do
subject.define_group(:sub) do |config|
config.docs_dir.should == subject.docs_dir.join('sub')
end
end
it "should scope the url_prefix directory" do
subject.url_prefix = "/docs"
subject.define_group(:sub) do |config|
config.url_prefix.should == "/docs/sub"
end
end
end
it { should be_a(Enumerable) }
it "should enumerate through recursively and include self" do
configs = [subject]
subject.define_group(:sub1) do |config|
configs << config
config.define_group(:sub2) do |config|
configs << config
config.define_group(:sub3) do |config|
configs << config
end
end
end
subject.to_a.should eq(configs)
end
describe "#groups" do
it "should list all of the defined groups" do
subject.define_group(:sub) do |config|
end
subject.groups.should have(1).group
end
end
end