contrast / exceptional

This URL has Read+Write access

exceptional / spec / config_spec.rb
100644 110 lines (81 sloc) 3.178 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
require File.dirname(__FILE__) + '/spec_helper'
 
 
describe Exceptional::Config do
  
  before(:all) do
 
    def Exceptional.reset_state
      @api_key = nil
      @ssl_enabled = nil
      @log_level = nil
      @enabled = nil
      @remote_port = nil
      @remote_host = nil
      @applicaton_root = nil
    end
    
  end
 
  after(:each) do
    Exceptional.reset_state
  end
  
  before(:each) do
    Exceptional.stub!(:log!) # Don't even attempt to log
    Exceptional.stub!(:to_log)
  end
  
  describe "default configuration" do
    
    it "should use port 80 by default if ssl not enabled" do
      Exceptional.ssl_enabled?.should be_false
      Exceptional.remote_port.should == 80
    end
 
    it "should use port 443 if ssl enabled" do
      Exceptional.ssl_enabled= true
      Exceptional.remote_port.should == 443
      Exceptional.ssl_enabled= false
    end
 
    it "should use log level of info by default" do
      Exceptional.log_level.should == "info"
    end
 
    it "should not be enabled by default" do
      Exceptional.enabled?.should be_false
    end
 
    it "should overwrite default host" do
      Exceptional.remote_host.should == "getexceptional.com"
      Exceptional.remote_host = "localhost"
      Exceptional.remote_host.should == "localhost"
    end
 
    it "should overwrite default port" do
      Exceptional.remote_port.should == 80
 
      Exceptional.remote_port = 3000
      Exceptional.remote_port.should == 3000
      Exceptional.remote_port = nil
    end
    
    it "api_key should by default be in-valid" do
      Exceptional.valid_api_key?.should be_false
    end
  end
 
  describe "load config" do
 
    it "error during config file loading raises configuration exception" do
      File.should_receive(:open).once.and_raise(IOError)
      
      lambda{Exceptional.setup_config("development", File.dirname(__FILE__))}.should raise_error(Exceptional::Config::ConfigurationException)
    end
 
    it "is enabled for production environment" do
      Exceptional.enabled?.should be_false
 
      Exceptional.setup_config "production", File.join(File.dirname(__FILE__), "/../exceptional.yml")
      Exceptional.enabled?.should be_true
    end
 
    it "is enabled by default for production and staging environments" do
      Exceptional.enabled?.should be_false
 
      Exceptional.setup_config "production", File.join(File.dirname(__FILE__), "/../exceptional.yml")
      Exceptional.enabled?.should be_true
 
      Exceptional.reset_state
      Exceptional.enabled?.should be_false
 
      Exceptional.setup_config "staging", File.join(File.dirname(__FILE__), "/../exceptional.yml")
      Exceptional.enabled?.should be_true
    end
 
    it "is disabled by default for development & test environments" do
      Exceptional.enabled?.should be_false
 
      Exceptional.setup_config "development", File.join(File.dirname(__FILE__), "/../exceptional.yml")
      Exceptional.enabled?.should be_false
 
      Exceptional.reset_state
      Exceptional.enabled?.should be_false
 
      Exceptional.setup_config "test", File.join(File.dirname(__FILE__), "/../exceptional.yml")
      Exceptional.enabled?.should be_false
    end
  end
end