public
Rubygem
Description: Take FogBugz offline with you
Clone URL: git://github.com/francois/fogbugz_offline.git
Search Repo:
FogbugzOffline::GlobalConfig specifications.
francois (author)
Thu May 15 13:15:01 -0700 2008
commit  3f9b7fa5aa364b0b9233b3219b8555a68fa0f45f
tree    4a55d2ed1a813d4626c450cc81c0d3bfb8e0826f
parent  5dff84aafc55995fdb520cfe78595b33ed73cdfa
...
 
 
1
2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3
4
...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
0
@@ -1,5 +1,25 @@
0
+require "yaml"
0
+
0
 module FogbugzOffline
0
   class GlobalConfig
0
+ attr_reader :path, :config
0
+
0
+ def initialize(path)
0
+ @path = path
0
+
0
+ begin
0
+ @config = YAML.load_file(@path)
0
+ rescue SystemCallError
0
+ @config = Hash.new
0
+ end
0
+ end
0
+
0
+ def write
0
+ @path.dirname.mkdir unless @path.dirname.directory?
0
+ File.open(@path, "wb") do |io|
0
+ YAML.dump(@config, io)
0
+ end
0
+ end
0
   end
0
 end
...
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
...
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
0
@@ -1 +1,56 @@
0
+require File.dirname(__FILE__) + "/spec_helper"
0
+require "yaml"
0
+
0
+describe FogbugzOffline::GlobalConfig, "#initialize" do
0
+ before do
0
+ YAML.stub!(:load_file).and_return(@config = {"http://my.project.com/" => []})
0
+ end
0
+
0
+ it "should read the config file as YAML" do
0
+ YAML.should_receive(:load_file).with(path = mock("config file path")).and_return({})
0
+ FogbugzOffline::GlobalConfig.new(path)
0
+ end
0
+
0
+ it "should rescue Errno::ENOENT and not raise any exception" do
0
+ YAML.stub!(:load_file).and_raise(Errno::ENOENT)
0
+ lambda { FogbugzOffline::GlobalConfig.new(mock("config file path")) }.should_not raise_error
0
+ end
0
+
0
+ it "should make the config available in #config" do
0
+ global = FogbugzOffline::GlobalConfig.new(mock("config file path"))
0
+ global.config.should == @config
0
+ end
0
+
0
+ it "should remember the original path in #path" do
0
+ global = FogbugzOffline::GlobalConfig.new(path = mock("config file path"))
0
+ global.path.should == path
0
+ end
0
+end
0
+
0
+describe FogbugzOffline::GlobalConfig, "#write" do
0
+ before do
0
+ YAML.stub!(:load_file).and_return(@config = {"config" => "value"})
0
+ @global = FogbugzOffline::GlobalConfig.new(@path = Pathname.new("config file path"))
0
+ @path.stub!(:dirname).and_return(@dir = mock("config file dir"))
0
+ @dir.stub!(:directory?).and_return(true)
0
+ File.stub!(:open).and_yield(@io = mock("io"))
0
+ YAML.stub!(:dump)
0
+ end
0
+
0
+ it "should open a File for writing on the original path" do
0
+ File.should_receive(:open).with(@path, "wb")
0
+ @global.write
0
+ end
0
+
0
+ it "should call YAML#dump with @config and @io" do
0
+ YAML.should_receive(:dump).with(@config, @io)
0
+ @global.write
0
+ end
0
+
0
+ it "should create missing directories in the path" do
0
+ @dir.stub!(:directory?).and_return(false)
0
+ @dir.should_receive(:mkdir)
0
+ @global.write
0
+ end
0
+end

Comments

    No one has commented yet.