falkorlib 0.1.0 → 0.2.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile.lock +56 -4
- data/README.md +147 -34
- data/Rakefile +42 -23
- data/falkorlib.gemspec +11 -7
- data/lib/falkorlib.rb +31 -2
- data/lib/falkorlib/common.rb +93 -41
- data/lib/falkorlib/config.rb +91 -0
- data/lib/falkorlib/git.rb +15 -0
- data/lib/falkorlib/git/base.rb +405 -0
- data/lib/falkorlib/git/flow.rb +120 -0
- data/lib/falkorlib/git_tasks.rb +56 -0
- data/lib/falkorlib/loader.rb +9 -1
- data/lib/falkorlib/tasks.rb +30 -0
- data/lib/falkorlib/tasks/git.rake +121 -0
- data/lib/falkorlib/tasks/git.rb +56 -0
- data/lib/falkorlib/tasks/gitflow.rake +139 -0
- data/{tasks/spec_test.rake → lib/falkorlib/tasks/rspec.rake} +4 -3
- data/lib/falkorlib/tasks/yard.rake +78 -0
- data/lib/falkorlib/version.rb +62 -54
- data/lib/falkorlib/versioning.rb +162 -0
- data/spec/falkorlib/common_spec.rb +12 -12
- data/spec/falkorlib/git_spec.rb +191 -0
- data/spec/falkorlib/gitflow_spec.rb +47 -45
- data/spec/falkorlib/versioning_spec.rb +108 -0
- data/spec/spec_helper.rb +58 -9
- metadata +80 -24
- data/lib/falkorlib/gitflow.rb +0 -71
- data/tasks/debug_mail.rake +0 -75
- data/tasks/debug_mail.txt +0 -13
- data/tasks/gem.rake +0 -73
- data/tasks/unit_test.rake +0 -77
- data/tasks/yard.rake +0 -51
- data/test/test_gitflow.rb +0 -16
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
#!/usr/bin/ruby
|
|
2
|
+
#########################################
|
|
3
|
+
# git_spec.rb
|
|
4
|
+
# @author Sebastien Varrette <Sebastien.Varrette@uni.lu>
|
|
5
|
+
# Time-stamp: <Mer 2014-06-18 21:46 svarrette>
|
|
6
|
+
#
|
|
7
|
+
# @description Check the Git operations
|
|
8
|
+
#
|
|
9
|
+
# Copyright (c) 2013 Sebastien Varrette <Sebastien.Varrette@uni.lu>
|
|
10
|
+
# . http://varrette.gforge.uni.lu
|
|
11
|
+
##############################################################################
|
|
12
|
+
|
|
13
|
+
require 'spec_helper'
|
|
14
|
+
require 'tmpdir'
|
|
15
|
+
|
|
16
|
+
describe FalkorLib::Git do
|
|
17
|
+
|
|
18
|
+
include FalkorLib::Common
|
|
19
|
+
default_branches = [ 'devel', 'production' ]
|
|
20
|
+
|
|
21
|
+
dir = Dir.mktmpdir
|
|
22
|
+
afile = File.join(dir, 'a_file')
|
|
23
|
+
|
|
24
|
+
before :all do
|
|
25
|
+
$stdout.sync = true
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
after :all do
|
|
29
|
+
FileUtils.remove_entry_secure dir
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
#############################################################
|
|
33
|
+
context "Test git operations within temporary directory " do
|
|
34
|
+
|
|
35
|
+
it "#init? - fails on non-git directory" do
|
|
36
|
+
t = FalkorLib::Git.init?(dir)
|
|
37
|
+
t.should be_false
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
it "#init - initialize a git repository" do
|
|
41
|
+
FalkorLib::Git.init(dir)
|
|
42
|
+
t = FalkorLib::Git.init?(dir)
|
|
43
|
+
t.should be_true
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
it "#rootdir #gitdir - checks git dir and working tree" do
|
|
47
|
+
subdir = File.join(dir, 'some_dir')
|
|
48
|
+
Dir.mkdir( subdir )
|
|
49
|
+
Dir.chdir( subdir ) do
|
|
50
|
+
r = File.realpath( FalkorLib::Git.rootdir )
|
|
51
|
+
g = FalkorLib::Git.gitdir
|
|
52
|
+
r.should == File.realpath(dir)
|
|
53
|
+
g.should == File.realpath( File.join(dir, '.git') )
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
it "#has_commits? - not yet any commits" do
|
|
58
|
+
b = FalkorLib::Git.has_commits?( dir )
|
|
59
|
+
b.should be_false
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
it "#branch? - check non-existing branch" do
|
|
63
|
+
br = FalkorLib::Git.branch?( dir )
|
|
64
|
+
br.should be_nil
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
it "#list_files -- should not list any files" do
|
|
68
|
+
l = FalkorLib::Git.list_files( dir )
|
|
69
|
+
l.should be_empty
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
it "#add - makes a first commit" do
|
|
73
|
+
FileUtils.touch( afile )
|
|
74
|
+
t = FalkorLib::Git.add(afile)
|
|
75
|
+
t.should == 0
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
it "#list_files -- should list a single files" do
|
|
79
|
+
l = FalkorLib::Git.list_files( dir )
|
|
80
|
+
l.should include 'a_file'
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
it "#has_commits? - no some commits have been done" do
|
|
85
|
+
b = FalkorLib::Git.has_commits?( dir )
|
|
86
|
+
b.should be_true
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
it "#branch? - check existing branch" do
|
|
91
|
+
br = FalkorLib::Git.branch?( dir )
|
|
92
|
+
br.should == 'master'
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
it "#dirty? - check non-dirty git directory" do
|
|
96
|
+
b = FalkorLib::Git.dirty?( dir )
|
|
97
|
+
b.should be_false
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
default_branches.each do |br|
|
|
101
|
+
it "#create_branch #list_branch - creates branch #{br}" do
|
|
102
|
+
FalkorLib::Git.create_branch( br, dir )
|
|
103
|
+
l = FalkorLib::Git.list_branch( dir )
|
|
104
|
+
l.should include "#{br}"
|
|
105
|
+
end
|
|
106
|
+
end
|
|
107
|
+
|
|
108
|
+
default_branches.each do |br|
|
|
109
|
+
it "#delete_branch #list_branch - deletes branch #{br}" do
|
|
110
|
+
FalkorLib::Git.delete_branch( br, dir) #, :force => true )
|
|
111
|
+
l = FalkorLib::Git.list_branch( dir )
|
|
112
|
+
l.should_not include "#{br}"
|
|
113
|
+
end
|
|
114
|
+
end
|
|
115
|
+
|
|
116
|
+
it "#command? - check non-availability of git command 'toto'" do
|
|
117
|
+
c = FalkorLib::Git.command?('toto')
|
|
118
|
+
c.should be_false
|
|
119
|
+
end
|
|
120
|
+
|
|
121
|
+
it "#command? - check availability of git command 'init'" do
|
|
122
|
+
c = FalkorLib::Git.command?('init')
|
|
123
|
+
c.should be_true
|
|
124
|
+
end
|
|
125
|
+
|
|
126
|
+
# ---------- Submodules ---------------
|
|
127
|
+
it "#submodules_init" do
|
|
128
|
+
FalkorLib.config.git do |c|
|
|
129
|
+
c[:submodules] = {
|
|
130
|
+
'falkorgit' => {
|
|
131
|
+
:url => 'https://github.com/Falkor/falkorlib.git',
|
|
132
|
+
:branch => 'devel'
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
end
|
|
136
|
+
b = FalkorLib::Git.submodule_init( dir )
|
|
137
|
+
b.should == 0
|
|
138
|
+
end
|
|
139
|
+
|
|
140
|
+
it "#submodules_update" do
|
|
141
|
+
b = FalkorLib::Git.submodule_update( dir )
|
|
142
|
+
b.should == 0
|
|
143
|
+
end
|
|
144
|
+
|
|
145
|
+
it "#submodules_upgrade" do
|
|
146
|
+
b = FalkorLib::Git.submodule_upgrade( dir )
|
|
147
|
+
b.should == 0
|
|
148
|
+
end
|
|
149
|
+
|
|
150
|
+
# ---------- Subtrees ---------------
|
|
151
|
+
if FalkorLib::Git.command? 'subtree'
|
|
152
|
+
it "#subtree_init - initialize some Git Subtrees" do
|
|
153
|
+
FalkorLib.config.git do |c|
|
|
154
|
+
c[:subtrees] = {
|
|
155
|
+
'falkor/lib' => {
|
|
156
|
+
:url => 'https://github.com/Falkor/falkorlib.git',
|
|
157
|
+
:branch => 'devel'
|
|
158
|
+
},
|
|
159
|
+
}
|
|
160
|
+
end
|
|
161
|
+
b = FalkorLib::Git.subtree_init( dir )
|
|
162
|
+
b.should == 0
|
|
163
|
+
end
|
|
164
|
+
|
|
165
|
+
it "#subtree_up" do
|
|
166
|
+
b = FalkorLib::Git.subtree_up( dir )
|
|
167
|
+
b.should == 0
|
|
168
|
+
end
|
|
169
|
+
|
|
170
|
+
it "#subtree_diff" do
|
|
171
|
+
b = FalkorLib::Git.subtree_diff( dir )
|
|
172
|
+
b.should == 0
|
|
173
|
+
puts FalkorLib::Git.dirty?( dir )
|
|
174
|
+
end
|
|
175
|
+
end
|
|
176
|
+
|
|
177
|
+
|
|
178
|
+
|
|
179
|
+
|
|
180
|
+
# shall be the last check
|
|
181
|
+
it "#dirty? - check dirty git directory" do
|
|
182
|
+
execute "echo 'toto' > #{afile}"
|
|
183
|
+
b = FalkorLib::Git.dirty?( dir )
|
|
184
|
+
b.should be_true
|
|
185
|
+
end
|
|
186
|
+
|
|
187
|
+
end
|
|
188
|
+
|
|
189
|
+
|
|
190
|
+
|
|
191
|
+
end
|
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
#########################################
|
|
3
3
|
# gitflow_spec.rb
|
|
4
4
|
# @author Sebastien Varrette <Sebastien.Varrette@uni.lu>
|
|
5
|
-
# Time-stamp: <
|
|
5
|
+
# Time-stamp: <Mer 2014-06-18 20:42 svarrette>
|
|
6
6
|
#
|
|
7
|
-
# @description Check the
|
|
7
|
+
# @description Check the Git Flow operations -- see https://github.com/nvie/gitflow
|
|
8
8
|
#
|
|
9
9
|
# Copyright (c) 2013 Sebastien Varrette <Sebastien.Varrette@uni.lu>
|
|
10
10
|
# . http://varrette.gforge.uni.lu
|
|
@@ -13,52 +13,54 @@
|
|
|
13
13
|
require 'spec_helper'
|
|
14
14
|
require 'tmpdir'
|
|
15
15
|
|
|
16
|
-
describe FalkorLib do
|
|
16
|
+
describe FalkorLib::GitFlow do
|
|
17
17
|
|
|
18
18
|
include FalkorLib::Common
|
|
19
|
+
|
|
20
|
+
dir = Dir.mktmpdir
|
|
21
|
+
afile = File.join(dir, 'a_file')
|
|
22
|
+
|
|
23
|
+
after :all do
|
|
24
|
+
FileUtils.remove_entry_secure dir
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
#############################################################
|
|
28
|
+
context "Test git-flow operations within temporary directory " do
|
|
29
|
+
|
|
30
|
+
it "#init? - fails on non-git directory" do
|
|
31
|
+
t = FalkorLib::Git.init?(dir)
|
|
32
|
+
t.should be_false
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
it "#init - initialize a git-flow repository" do
|
|
36
|
+
STDIN.should_receive(:gets).and_return('Yes')
|
|
37
|
+
i = FalkorLib::GitFlow.init(dir)
|
|
38
|
+
i.should == 0
|
|
39
|
+
t = FalkorLib::Git.init?(dir)
|
|
40
|
+
t.should be_true
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
#['feature', 'hotfix', 'support'].each do |op|
|
|
44
|
+
['feature'].each do |op|
|
|
45
|
+
name = 'toto'
|
|
46
|
+
it "#start -- should start a '#{op}' GitFlow operation" do
|
|
47
|
+
a = FalkorLib::GitFlow.start(op, name, dir)
|
|
48
|
+
a.should == 0
|
|
49
|
+
br = FalkorLib::Git.branch?( dir )
|
|
50
|
+
br.should == "#{op}/#{name}"
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
it "#finish -- should finish a '#{op}' GitFlow operation" do
|
|
54
|
+
STDIN.should_receive(:gets).and_return("Test #{op} operation") if [ 'hotfix', 'support' ].include?(op)
|
|
55
|
+
a = FalkorLib::GitFlow.finish(op, name, dir)
|
|
56
|
+
a.should == 0
|
|
57
|
+
br = FalkorLib::Git.branch?( dir )
|
|
58
|
+
br.should == FalkorLib.config[:gitflow][:branches][:develop]
|
|
59
|
+
end
|
|
60
|
+
end
|
|
61
|
+
end
|
|
19
62
|
|
|
20
|
-
|
|
21
|
-
# tempdir = Dir.tmpdir
|
|
22
|
-
# #puts "tempdir = #{tempdir}"
|
|
23
|
-
|
|
24
|
-
# FalkorLib::GitFlow::init(tempdir)
|
|
25
|
-
|
|
26
|
-
# File.directory?(File.join(tempdir, '.git')).should be_true
|
|
27
|
-
|
|
28
|
-
# g = Git.open(tempdir)
|
|
29
|
-
# g.config['gitflow.branch.master'].should == FalkorLib::GitFlow::global_config(:master)
|
|
30
|
-
# g.config['gitflow.branch.develop'].should == FalkorLib::GitFlow::global_config(:develop)
|
|
31
|
-
# [ :feature, :release, :hotfix, :support, :versiontag ].each do |e|
|
|
32
|
-
# g.config["gitflow.prefix.#{e}"].should == FalkorLib::GitFlow::global_config(e.to_sym)
|
|
33
|
-
# end
|
|
34
|
-
# FileUtils.rm_rf(tempdir)
|
|
35
|
-
# end
|
|
36
|
-
|
|
37
|
-
# [ :master, :develop, :feature, :release, :hotfix, :support, :versiontag ].each do |elem|
|
|
38
|
-
# specialvalue = 'uncommonvalue'
|
|
39
|
-
|
|
40
|
-
# it "test specialized initialization of a git-flow dir (alter '#{elem}' option with special value #{specialvalue})" do
|
|
41
|
-
# tempdir = Dir.tmpdir
|
|
42
|
-
# #puts "tempdir = #{tempdir}"
|
|
43
|
-
|
|
44
|
-
# FalkorLib::GitFlow::init(tempdir, { elem.to_sym => "#{specialvalue}"})
|
|
45
|
-
|
|
46
|
-
# File.directory?(File.join(tempdir, '.git')).should be_true
|
|
47
|
-
|
|
48
|
-
# g = Git.open(tempdir)
|
|
49
|
-
# [ :master, :develop].each do |e|
|
|
50
|
-
# #puts "elem = #{elem}, e = #{e}, ", g.config["gitflow.branch.#{e}"]
|
|
51
|
-
# g.config["gitflow.branch.#{e}"].should == ((elem == e) ? specialvalue : FalkorLib::GitFlow::global_config(e.to_sym))
|
|
52
|
-
# end
|
|
53
|
-
# [ :feature, :release, :hotfix, :support, :versiontag ].each do |e|
|
|
54
|
-
# g.config["gitflow.prefix.#{e}"].should == ((elem == e) ? specialvalue : FalkorLib::GitFlow::global_config(e.to_sym))
|
|
55
|
-
# end
|
|
56
|
-
# FileUtils.rm_rf(tempdir)
|
|
57
|
-
# end
|
|
58
|
-
# end
|
|
59
|
-
|
|
60
|
-
|
|
63
|
+
end
|
|
61
64
|
|
|
62
65
|
|
|
63
66
|
|
|
64
|
-
end
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
#!/usr/bin/ruby
|
|
2
|
+
#########################################
|
|
3
|
+
# gitflow_spec.rb
|
|
4
|
+
# @author Sebastien Varrette <Sebastien.Varrette@uni.lu>
|
|
5
|
+
# Time-stamp: <Jeu 2014-06-19 00:54 svarrette>
|
|
6
|
+
#
|
|
7
|
+
# @description Check the Git Flow operations -- see https://github.com/nvie/gitflow
|
|
8
|
+
#
|
|
9
|
+
# Copyright (c) 2013 Sebastien Varrette <Sebastien.Varrette@uni.lu>
|
|
10
|
+
# . http://varrette.gforge.uni.lu
|
|
11
|
+
##############################################################################
|
|
12
|
+
|
|
13
|
+
require 'spec_helper'
|
|
14
|
+
require 'tmpdir'
|
|
15
|
+
|
|
16
|
+
describe FalkorLib::Versioning do
|
|
17
|
+
|
|
18
|
+
include FalkorLib::Common
|
|
19
|
+
|
|
20
|
+
dir = Dir.mktmpdir
|
|
21
|
+
afile = File.join(dir, 'a_file')
|
|
22
|
+
versionfile = FalkorLib.config[:versioning][:source]['file'][:filename]
|
|
23
|
+
default_version = FalkorLib.config[:versioning][:default]
|
|
24
|
+
workingversion = {
|
|
25
|
+
:default => '1.2.3',
|
|
26
|
+
:patch => '1.2.4',
|
|
27
|
+
:minor => '1.3.0',
|
|
28
|
+
:major => '2.0.0'
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
after :all do
|
|
32
|
+
FileUtils.remove_entry_secure dir
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
###################################################################
|
|
37
|
+
context 'Test versioning operations within temporary directory' do
|
|
38
|
+
|
|
39
|
+
it "#get_version -- get default version #{default_version}" do
|
|
40
|
+
STDIN.should_receive(:gets).and_return('Yes')
|
|
41
|
+
i = FalkorLib::GitFlow.init(dir)
|
|
42
|
+
i.should == 0
|
|
43
|
+
v = FalkorLib::Versioning.get_version(dir)
|
|
44
|
+
v.should == default_version
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
it "#get_version -- should get the '#{workingversion[:default]}' version set in the file #{versionfile}" do
|
|
48
|
+
execute "echo #{workingversion[:default]} > #{dir}/#{versionfile}"
|
|
49
|
+
v = FalkorLib::Versioning.get_version(dir)
|
|
50
|
+
v.should == workingversion[:default]
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
it "#set_version -- set version #{default_version} in version file #{versionfile}" do
|
|
54
|
+
STDIN.should_receive(:gets).and_return('no')
|
|
55
|
+
v = FalkorLib::Versioning.set_version(default_version, dir)
|
|
56
|
+
v.should == 0
|
|
57
|
+
v = FalkorLib::Versioning.get_version(dir)
|
|
58
|
+
v.should == default_version
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
FalkorLib.config[:versioning][:levels].reverse.each do |level|
|
|
62
|
+
it "#set_version #bump -- #{level} bump version number from #{workingversion[:default]} to #{workingversion[level.to_sym]}" do
|
|
63
|
+
# restore version file
|
|
64
|
+
execute "echo #{workingversion[:default]} > #{dir}/#{versionfile}"
|
|
65
|
+
v = FalkorLib::Versioning.get_version(dir)
|
|
66
|
+
v.should == workingversion[:default]
|
|
67
|
+
v2 = FalkorLib::Versioning.bump(v, level.to_sym)
|
|
68
|
+
v2.should == workingversion[level.to_sym]
|
|
69
|
+
STDIN.should_receive(:gets).and_return('no')
|
|
70
|
+
d = FalkorLib::Versioning.set_version(v2, dir)
|
|
71
|
+
d.should == 0
|
|
72
|
+
v3 = FalkorLib::Versioning.get_version(dir)
|
|
73
|
+
v3.should == v2
|
|
74
|
+
end
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
it "should do something" do
|
|
78
|
+
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
it "#set_version -- restore versionfile and add it to git" do
|
|
83
|
+
STDIN.should_receive(:gets).and_return('Yes')
|
|
84
|
+
t = FalkorLib::Versioning.set_version(workingversion[:default], dir)
|
|
85
|
+
t.should == 0
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
FalkorLib.config[:versioning][:levels].reverse.each do |level|
|
|
89
|
+
it "#set_version #bump -- #{level} bump version number from #{workingversion[:default]} to #{workingversion[level.to_sym]} with git commit" do
|
|
90
|
+
if FalkorLib::Versioning.get_version(dir) != workingversion[:default]
|
|
91
|
+
STDIN.should_receive(:gets).and_return('Yes')
|
|
92
|
+
t = FalkorLib::Versioning.set_version(workingversion[:default], dir)
|
|
93
|
+
t.should == 0
|
|
94
|
+
end
|
|
95
|
+
v = FalkorLib::Versioning.get_version(dir)
|
|
96
|
+
v.should == workingversion[:default]
|
|
97
|
+
v2 = FalkorLib::Versioning.bump(v, level.to_sym)
|
|
98
|
+
v2.should == workingversion[level.to_sym]
|
|
99
|
+
STDIN.should_receive(:gets).and_return('Yes')
|
|
100
|
+
d = FalkorLib::Versioning.set_version(v2, dir)
|
|
101
|
+
d.should == 0
|
|
102
|
+
v3 = FalkorLib::Versioning.get_version(dir)
|
|
103
|
+
v3.should == v2
|
|
104
|
+
end
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
end
|
|
108
|
+
end
|
data/spec/spec_helper.rb
CHANGED
|
@@ -1,16 +1,65 @@
|
|
|
1
|
+
require 'rubygems'
|
|
2
|
+
require 'bundler/setup'
|
|
3
|
+
Bundler.setup
|
|
4
|
+
|
|
5
|
+
require 'fileutils'
|
|
6
|
+
require 'pathname'
|
|
7
|
+
|
|
8
|
+
|
|
1
9
|
$LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
|
|
2
10
|
require 'falkorlib'
|
|
3
11
|
require 'falkorlib/common'
|
|
4
|
-
require 'falkorlib/
|
|
12
|
+
require 'falkorlib/git'
|
|
5
13
|
|
|
6
14
|
def capture(stream)
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
15
|
+
begin
|
|
16
|
+
stream = stream.to_s
|
|
17
|
+
eval "$#{stream} = StringIO.new"
|
|
18
|
+
yield
|
|
19
|
+
result = eval("$#{stream}").string
|
|
20
|
+
ensure
|
|
21
|
+
eval("$#{stream} = #{stream.upcase}")
|
|
22
|
+
end
|
|
23
|
+
result
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
# require 'minitest/autorun'
|
|
27
|
+
# require 'minitest/spec'
|
|
28
|
+
|
|
29
|
+
# class MiniTest::Spec
|
|
30
|
+
# attr_reader :tmp_path
|
|
31
|
+
# before do
|
|
32
|
+
# @tmp_path = Pathname.new(__FILE__).dirname.dirname.join('tmp').expand_path
|
|
33
|
+
# end
|
|
34
|
+
# end
|
|
35
|
+
|
|
36
|
+
# credits to [gabebw](http://gabebw.wordpress.com/2011/03/21/temp-files-in-rspec/)
|
|
37
|
+
module UsesTempFiles
|
|
38
|
+
def self.included(example_group)
|
|
39
|
+
example_group.extend(self)
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def in_directory_with_file(file)
|
|
43
|
+
before do
|
|
44
|
+
@pwd = Dir.pwd
|
|
45
|
+
@tmp_dir = File.join(File.dirname(__FILE__), 'tmp')
|
|
46
|
+
FileUtils.mkdir_p(@tmp_dir)
|
|
47
|
+
Dir.chdir(@tmp_dir)
|
|
48
|
+
|
|
49
|
+
FileUtils.mkdir_p(File.dirname(file))
|
|
50
|
+
FileUtils.touch(file)
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
define_method(:content_for_file) do |content|
|
|
54
|
+
f = File.new(File.join(@tmp_dir, file), 'a+')
|
|
55
|
+
f.write(content)
|
|
56
|
+
f.flush # VERY IMPORTANT
|
|
57
|
+
f.close
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
after do
|
|
61
|
+
Dir.chdir(@pwd)
|
|
62
|
+
FileUtils.rm_rf(@tmp_dir)
|
|
63
|
+
end
|
|
14
64
|
end
|
|
15
|
-
result
|
|
16
65
|
end
|