public
Rubygem
Description: Merb Core: All you need. None you don't.
Homepage: http://www.merbivore.com
Clone URL: git://github.com/wycats/merb-core.git
merb-core / spec / private / config / config_spec.rb
100644 168 lines (135 sloc) 5.142 kb
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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
require File.dirname(__FILE__) + '/spec_helper'
 
describe Merb::Config do
  before do
    Merb::Config.setup
  end
 
  it "should be able to yield the configuration via #use" do
    res = nil
    Merb::Config.use {|c| res = c}
    res.should == Merb::Config.defaults
  end
 
  it "should be able to get a configuration key" do
    Merb::Config[:host].should == "0.0.0.0"
  end
 
  it "should be able to set a configuration key" do
    Merb::Config[:bar] = "Hello"
    Merb::Config[:bar].should == "Hello"
  end
 
  it "should be able to #delete a configuration key" do
    Merb::Config[:bar] = "Hello"
    Merb::Config[:bar].should == "Hello"
    Merb::Config.delete(:bar)
    Merb::Config[:bar].should == nil
  end
 
  it "should be able to #fetch a key that does exist" do
    Merb::Config.fetch(:host, "192.168.2.1").should == "0.0.0.0"
  end
 
  it "should be able to #fetch a key that does exist" do
    Merb::Config.fetch(:bar, "heylo").should == "heylo"
  end
 
  it "should be able to dump to YAML" do
    Merb::Config.to_yaml.should == Merb::Config.instance_variable_get("@configuration").to_yaml
  end
 
  it "should support -u to set the user to run Merb as" do
    Merb::Config.parse_args(["-u", "tester"])
    Merb::Config[:user].should == "tester"
  end
 
  it "should support -G to set the group to run Merb as" do
    Merb::Config.parse_args(["-G", "tester"])
    Merb::Config[:group].should == "tester"
  end
 
  it "should support -f to set the filename to run Merb as" do
    Merb::Config.parse_args(["-d"])
    Merb::Config[:daemonize].should == true
  end
 
  it "should support -c to set the number of cluster nodes" do
    Merb::Config.parse_args(["-c", "4"])
    Merb::Config[:cluster].should == "4"
  end
 
  it "should support -p to set the port number" do
    Merb::Config.parse_args(["-p", "6000"])
    Merb::Config[:port].should == "6000"
  end
 
  it "should support -P to set the PIDfile" do
    Merb::Config.parse_args(["-P", "pidfile"])
    Merb::Config[:pid_file].should == "pidfile"
  end
 
  it "should have server return PIDfile setting as is with no cluster nodes" do
    Merb::Config.parse_args(["-P", "pidfile", "-p", "6000"])
    Merb::Server.pid_file(6000).should == "pidfile"
    Merb::Server.pid_files.should == ["pidfile"]
  end
 
  it "should support setting of PIDfile with cluster nodes" do
    Merb::Config.parse_args(["-P", "/tmp/merb.pidfile", "-c", "2", "-p", "6000"])
    Merb::Server.pid_file(6000).should == "/tmp/merb.6000.pidfile"
    Merb::Server.pid_file(6001).should == "/tmp/merb.6001.pidfile"
    
    Dir.should_receive(:[]).with("/tmp/merb.*.pidfile")
    Merb::Server.pid_files
  end
 
  it "should support default PIDfile setting" do
    Merb::Config.parse_args(["-p", "6000"])
    Merb::Server.pid_file(6000).should == Merb.log_path / "merb.6000.pid"
    
    Dir.should_receive(:[]).with(Merb.log_path / "merb.*.pid")
    Merb::Server.pid_files
  end
 
  it "should support -h to set the hostname" do
    Merb::Config.parse_args(["-h", "hostname"])
    Merb::Config[:host].should == "hostname"
  end
 
  it "should support -i to specify loading IRB" do
    Merb::Config.parse_args(["-i"])
    Merb::Config[:adapter].should == "irb"
  end
 
  it "should support -l to specify the log level" do
    Merb::Config.parse_args(["-l", "debug"])
    Merb::Config[:log_level].should == :debug
  end
 
  it "should support -L to specify the location of the log file" do
    Merb::Config.parse_args(["-L", "log_file"])
    Merb::Config[:log_file].should == "log_file"
  end
 
  it "should support -r to specify a runner" do
    Merb::Config.parse_args(["-r", "foo_runner"])
    Merb::Config[:runner_code].should == "foo_runner"
    Merb::Config[:adapter].should == "runner"
  end
 
  it "should support -R to specify a rackup file" do
    Merb::Config.parse_args(["-R", "config.ru"])
    Merb::Config[:rackup].should == "config.ru"
  end
 
  it "should support -K for a graceful kill" do
    Merb::Server.should_receive(:kill).with("all", 1)
    Merb.start(["-K", "all"])
  end
 
  it "should support -k for a hard kill" do
    Merb::Server.should_receive(:kill).with("all", 9)
    Merb.start(["-k", "all"])
  end
 
  it "should support -X off to turn off the mutex" do
    Merb::Config.parse_args(["-X", "off"])
    Merb::Config[:use_mutex].should == false
  end
 
  it "should support -X on to turn off the mutex" do
    Merb::Config.parse_args(["-X", "on"])
    Merb::Config[:use_mutex].should == true
  end
 
  it "should take Merb.disable into account" do
    Merb::Config[:disabled_components].should == []
    Merb::Config[:disabled_components] << :foo
    Merb.disable(:bar)
    Merb.disable(:buz, :fux)
    Merb::Config[:disabled_components].should == [:foo, :bar, :buz, :fux]
    Merb.disabled?(:foo).should == true
    Merb.disabled?(:foo, :buz).should == true
  end
 
  it "should take Merb.testing? into account" do
    $TESTING.should == true
    Merb::Config[:testing].should be_nil
    Merb.should be_testing
    $TESTING = false
    Merb.should_not be_testing
    Merb::Config[:testing] = true
    Merb.should be_testing
    $TESTING = true; Merb::Config[:testing] = false # reset
  end
 
end