fake_gem 0.1.5 → 0.1.6
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +5 -5
- data/lib/fake_gem.rb +41 -15
- data/readme.md +1 -1
- data/spec/fake_gem_spec/{project_a → common/project_a}/fake_gem +0 -0
- data/spec/fake_gem_spec/{project_a → common/project_a}/lib/project_a_file.rb +0 -0
- data/spec/fake_gem_spec/{project_b → common/project_b}/lib/project_b_file.rb +0 -0
- data/spec/fake_gem_spec/twice/kit/fake_gem +1 -0
- data/spec/fake_gem_spec/twice/kit/lib/the_kit.rb +1 -0
- data/spec/fake_gem_spec/twice/kit/spec/spec_helper.rb +1 -0
- data/spec/fake_gem_spec/twice/saas/fake_gem +1 -0
- data/spec/fake_gem_spec/twice/saas/lib/the_saas.rb +4 -0
- data/spec/fake_gem_spec.rb +28 -22
- metadata +27 -42
data/Rakefile
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
require 'rake_ext'
|
2
2
|
|
3
3
|
project(
|
4
|
-
:
|
5
|
-
:
|
6
|
-
:
|
4
|
+
name: "fake_gem",
|
5
|
+
gem: true,
|
6
|
+
summary: "Makes any directory looks like Ruby Gem",
|
7
7
|
|
8
|
-
:
|
9
|
-
:
|
8
|
+
author: "Alexey Petrushin",
|
9
|
+
homepage: "http://github.com/alexeypetrushin/fake_gem"
|
10
10
|
)
|
data/lib/fake_gem.rb
CHANGED
@@ -1,18 +1,45 @@
|
|
1
1
|
# If you inject this module wia RUBYOPTS it may be already be processed,
|
2
2
|
# and include('fake_gem') will executes it one more time, so we check it manually.
|
3
3
|
unless defined?(FakeGem) or defined?(JRuby)
|
4
|
-
|
5
|
-
|
6
|
-
require_without_fgem path
|
7
|
-
rescue LoadError => e
|
8
|
-
FakeGem.activate(path + '.rb') ? retry : raise(e)
|
4
|
+
class LoadError
|
5
|
+
attr_accessor :raised_in_fake_gem
|
9
6
|
end
|
7
|
+
|
8
|
+
$indent = -1
|
9
|
+
Kernel.class_eval do
|
10
|
+
alias :require_without_fgem :require
|
11
|
+
def require path
|
12
|
+
require_without_fgem path
|
13
|
+
rescue LoadError => e
|
14
|
+
|
15
|
+
# need this check to prevent very tricky bug caused by recursive retry and resulting in
|
16
|
+
# files will be required multiple times and strange error messages will be produced
|
17
|
+
raise e if e.raised_in_fake_gem
|
18
|
+
|
19
|
+
if FakeGem.activate(path + '.rb')
|
20
|
+
retry
|
21
|
+
else
|
22
|
+
e.raised_in_fake_gem = true
|
23
|
+
raise e
|
24
|
+
end
|
25
|
+
end
|
10
26
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
27
|
+
alias :load_without_fgem :load
|
28
|
+
def load path, wrap = false
|
29
|
+
load_without_fgem path, wrap
|
30
|
+
rescue LoadError => e
|
31
|
+
|
32
|
+
# need this check to prevent very tricky bug caused by recursive retry and resulting in
|
33
|
+
# files will be required multiple times and strange error messages will be produced
|
34
|
+
raise e if e.raised_in_fake_gem
|
35
|
+
|
36
|
+
if FakeGem.activate(path)
|
37
|
+
retry
|
38
|
+
else
|
39
|
+
e.raised_in_fake_gem = true
|
40
|
+
raise e
|
41
|
+
end
|
42
|
+
end
|
16
43
|
end
|
17
44
|
|
18
45
|
module FakeGem
|
@@ -32,7 +59,7 @@ unless defined?(FakeGem) or defined?(JRuby)
|
|
32
59
|
args = args.collect do |d|
|
33
60
|
d = d.to_s
|
34
61
|
d = (d =~ /^\//) ? d : "#{dir}/#{d}"
|
35
|
-
should_exist d
|
62
|
+
should_exist d, "file '%{file}' not exist (folder '#{dir}' is false_gem but the folder declared as :lib not exist)!"
|
36
63
|
d
|
37
64
|
end
|
38
65
|
@libs.push(*args)
|
@@ -48,8 +75,8 @@ unless defined?(FakeGem) or defined?(JRuby)
|
|
48
75
|
|
49
76
|
|
50
77
|
protected
|
51
|
-
def should_exist file
|
52
|
-
raise
|
78
|
+
def should_exist file, msg = "file '%{file}' not exist!"
|
79
|
+
raise msg.sub('%{file}', file) unless File.exist? file
|
53
80
|
file
|
54
81
|
end
|
55
82
|
end
|
@@ -60,7 +87,7 @@ unless defined?(FakeGem) or defined?(JRuby)
|
|
60
87
|
paths = paths.first if paths.first.is_a? Array
|
61
88
|
if paths.empty?
|
62
89
|
unless @paths
|
63
|
-
if env_paths = ENV['
|
90
|
+
if env_paths = ENV['FAKE_GEM_PATH']
|
64
91
|
self.paths = env_paths.split(':')
|
65
92
|
else
|
66
93
|
self.paths = []
|
@@ -122,5 +149,4 @@ unless defined?(FakeGem) or defined?(JRuby)
|
|
122
149
|
|
123
150
|
end
|
124
151
|
end
|
125
|
-
|
126
152
|
end
|
data/readme.md
CHANGED
@@ -51,7 +51,7 @@ FakeGem ignores and don't mess with your other projects don't marked with the 'f
|
|
51
51
|
|
52
52
|
**Note**: there's a better way, without affecting the 'app.rb' file. Add following lines to your ~/.profile
|
53
53
|
|
54
|
-
export
|
54
|
+
export FAKE_GEM_PATH="~/projects"
|
55
55
|
export RUBYOPT="-rrubygems -r<your path to the 'fake_gem' gem dir>/lib/fake_gem.rb"
|
56
56
|
|
57
57
|
now you don't need the step 2 (don't forget to reload your .profile changes by executing $source ~/.profile).
|
File without changes
|
File without changes
|
File without changes
|
@@ -0,0 +1 @@
|
|
1
|
+
libs :lib
|
@@ -0,0 +1 @@
|
|
1
|
+
require 'the_saas'
|
@@ -0,0 +1 @@
|
|
1
|
+
require 'the_kit'
|
@@ -0,0 +1 @@
|
|
1
|
+
libs :lib
|
data/spec/fake_gem_spec.rb
CHANGED
@@ -1,29 +1,25 @@
|
|
1
1
|
require 'rspec_ext'
|
2
|
-
|
3
|
-
lib_dir = "#{__FILE__.parent_dirname}/lib"
|
4
|
-
$LOAD_PATH << lib_dir unless $LOAD_PATH.include? lib_dir
|
5
|
-
|
6
2
|
require "fake_gem"
|
7
3
|
|
8
4
|
describe FakeGem do
|
9
|
-
|
10
|
-
|
11
|
-
ENV['
|
12
|
-
FakeGem.clear
|
5
|
+
old_environment = nil
|
6
|
+
before do
|
7
|
+
old_environment = [$LOAD_PATH.clone, ENV['FAKE_GEM_PATH']]
|
13
8
|
|
14
|
-
|
9
|
+
ENV['FAKE_GEM_PATH'] = nil
|
10
|
+
FakeGem.clear
|
15
11
|
end
|
16
12
|
|
17
|
-
after
|
18
|
-
|
19
|
-
|
13
|
+
after do
|
14
|
+
$LOAD_PATH.replace old_environment.first
|
15
|
+
ENV['FAKE_GEM_PATH'] = old_environment.last
|
20
16
|
end
|
21
17
|
|
22
|
-
it "should use
|
18
|
+
it "should use FAKE_GEM_PATH environment variable or paths assigned to FakeGem::paths attribute" do
|
23
19
|
FakeGem.paths.should == []
|
24
20
|
|
25
21
|
FakeGem.clear
|
26
|
-
ENV['
|
22
|
+
ENV['FAKE_GEM_PATH'] = "/first_path:/second_path"
|
27
23
|
FakeGem.paths.should == %w(/first_path /second_path)
|
28
24
|
|
29
25
|
FakeGem.paths '.'
|
@@ -35,24 +31,34 @@ describe FakeGem do
|
|
35
31
|
end
|
36
32
|
|
37
33
|
it "should require directories with fake_gem as gems" do
|
38
|
-
FakeGem.paths
|
34
|
+
FakeGem.paths "#{spec_dir}/common"
|
39
35
|
FakeGem.gems.size.should == 1
|
40
36
|
|
41
37
|
require 'project_a_file'
|
42
|
-
|
38
|
+
-> {require 'project_b_file'}.should raise_error(/no such file to load/)
|
43
39
|
|
44
|
-
$LOAD_PATH.should include("#{
|
45
|
-
$LOAD_PATH.should_not include("#{
|
40
|
+
$LOAD_PATH.should include("#{spec_dir}/common/project_a/lib")
|
41
|
+
$LOAD_PATH.should_not include("#{spec_dir}/common/project_b/lib")
|
46
42
|
end
|
47
43
|
|
48
44
|
it "should load directories with fake_gem as gems" do
|
49
|
-
FakeGem.paths
|
45
|
+
FakeGem.paths "#{spec_dir}/common"
|
50
46
|
FakeGem.gems.size.should == 1
|
51
47
|
|
52
48
|
load 'project_a_file.rb'
|
53
|
-
|
49
|
+
-> {load 'project_b_file.rb'}.should raise_error(/no such file to load/)
|
50
|
+
|
51
|
+
$LOAD_PATH.should include("#{spec_dir}/common/project_a/lib")
|
52
|
+
$LOAD_PATH.should_not include("#{spec_dir}/common/project_b/lib")
|
53
|
+
end
|
54
|
+
|
55
|
+
it "should not require twice" do
|
56
|
+
FakeGem.paths "#{spec_dir}/twice"
|
57
|
+
|
58
|
+
# rspec usually adds this dirs, and its mandatory for our spec to add thouse dirs to $LOAD_PATH
|
59
|
+
$LOAD_PATH << "#{spec_dir}/twice/kit/lib"
|
60
|
+
$LOAD_PATH << "#{spec_dir}/twice/kit/spec"
|
54
61
|
|
55
|
-
|
56
|
-
$LOAD_PATH.should_not include("#{@data_dir}/project_b/lib")
|
62
|
+
-> {require 'spec_helper'}.should raise_error(LoadError, /non_existing_file/)
|
57
63
|
end
|
58
64
|
end
|
metadata
CHANGED
@@ -1,73 +1,58 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: fake_gem
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
prerelease:
|
6
|
-
segments:
|
7
|
-
- 0
|
8
|
-
- 1
|
9
|
-
- 5
|
10
|
-
version: 0.1.5
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.6
|
5
|
+
prerelease:
|
11
6
|
platform: ruby
|
12
|
-
authors:
|
7
|
+
authors:
|
13
8
|
- Alexey Petrushin
|
14
9
|
autorequire:
|
15
10
|
bindir: bin
|
16
11
|
cert_chain: []
|
17
|
-
|
18
|
-
date: 2010-10-15 00:00:00 +04:00
|
12
|
+
date: 2011-07-04 00:00:00.000000000 +04:00
|
19
13
|
default_executable:
|
20
14
|
dependencies: []
|
21
|
-
|
22
15
|
description:
|
23
16
|
email:
|
24
17
|
executables: []
|
25
|
-
|
26
18
|
extensions: []
|
27
|
-
|
28
19
|
extra_rdoc_files: []
|
29
|
-
|
30
|
-
files:
|
20
|
+
files:
|
31
21
|
- Rakefile
|
32
22
|
- readme.md
|
33
23
|
- lib/fake_gem.rb
|
34
|
-
- spec/fake_gem_spec/project_a/fake_gem
|
35
|
-
- spec/fake_gem_spec/project_a/lib/project_a_file.rb
|
36
|
-
- spec/fake_gem_spec/project_b/lib/project_b_file.rb
|
24
|
+
- spec/fake_gem_spec/common/project_a/fake_gem
|
25
|
+
- spec/fake_gem_spec/common/project_a/lib/project_a_file.rb
|
26
|
+
- spec/fake_gem_spec/common/project_b/lib/project_b_file.rb
|
27
|
+
- spec/fake_gem_spec/twice/kit/fake_gem
|
28
|
+
- spec/fake_gem_spec/twice/kit/lib/the_kit.rb
|
29
|
+
- spec/fake_gem_spec/twice/kit/spec/spec_helper.rb
|
30
|
+
- spec/fake_gem_spec/twice/saas/fake_gem
|
31
|
+
- spec/fake_gem_spec/twice/saas/lib/the_saas.rb
|
37
32
|
- spec/fake_gem_spec.rb
|
38
33
|
has_rdoc: true
|
39
34
|
homepage: http://github.com/alexeypetrushin/fake_gem
|
40
35
|
licenses: []
|
41
|
-
|
42
36
|
post_install_message:
|
43
37
|
rdoc_options: []
|
44
|
-
|
45
|
-
require_paths:
|
38
|
+
require_paths:
|
46
39
|
- lib
|
47
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
40
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
48
41
|
none: false
|
49
|
-
requirements:
|
50
|
-
- -
|
51
|
-
- !ruby/object:Gem::Version
|
52
|
-
|
53
|
-
|
54
|
-
- 0
|
55
|
-
version: "0"
|
56
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
57
47
|
none: false
|
58
|
-
requirements:
|
59
|
-
- -
|
60
|
-
- !ruby/object:Gem::Version
|
61
|
-
|
62
|
-
segments:
|
63
|
-
- 0
|
64
|
-
version: "0"
|
48
|
+
requirements:
|
49
|
+
- - ! '>='
|
50
|
+
- !ruby/object:Gem::Version
|
51
|
+
version: '0'
|
65
52
|
requirements: []
|
66
|
-
|
67
53
|
rubyforge_project:
|
68
|
-
rubygems_version: 1.
|
54
|
+
rubygems_version: 1.5.1
|
69
55
|
signing_key:
|
70
56
|
specification_version: 3
|
71
57
|
summary: Makes any directory looks like Ruby Gem
|
72
58
|
test_files: []
|
73
|
-
|