isolate 1.0.1 → 1.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,8 +1,17 @@
1
- === 1.0.0 / 2009-09-21
1
+ === 1.0.2 / 2009-09-21
2
2
 
3
- * Birthday!
3
+ * Fix some README typos.
4
+ * Add Entry#matches? to encapsulate activation and installation decisions.
5
+ * Remove block form of Isolate#enable, it's unused.
6
+ * Properly instance_eval Isolate#environment blocks.
7
+ * Reset stubs properly after tests (Random test order FTFW).
4
8
 
5
9
  === 1.0.1 / 2009-09-21
6
10
 
7
11
  * Doco updates. [Review by Evan]
8
12
  * Don't modify Entry#options on install. [Review by Evan]
13
+
14
+ === 1.0.0 / 2009-09-21
15
+
16
+ * Birthday!
17
+
@@ -30,7 +30,7 @@ YMMV, but I haven't tried Isolate with anything older than RubyGems
30
30
 
31
31
  === Defining Your Isolated Environment
32
32
 
33
- It'spretty easy: <tt>gem</tt> is similar to RubyGems' method of the
33
+ It's pretty easy: <tt>gem</tt> is similar to RubyGems' method of the
34
34
  same name. Version specifiers are optional, and any hash args tacked
35
35
  on to the end are passed through to Gem::DependencyInstaller as flags.
36
36
 
@@ -6,8 +6,15 @@ require "rubygems/requirement"
6
6
  # rationale, limitations, and examples.
7
7
 
8
8
  class Isolate
9
- Entry = Struct.new :name, :requirement, :environments, :options # :nodoc:
10
- VERSION = "1.0.1" # :nodoc:
9
+
10
+ # :nodoc:
11
+ class Entry < Struct.new(:name, :requirement, :environments, :options)
12
+ def matches? environment
13
+ environments.empty? || environments.include?(environment)
14
+ end
15
+ end
16
+
17
+ VERSION = "1.0.2" # :nodoc:
11
18
 
12
19
  attr_reader :entries # :nodoc:
13
20
 
@@ -70,9 +77,7 @@ class Isolate
70
77
  install environment if install?
71
78
 
72
79
  entries.each do |e|
73
- if e.environments.empty? || e.environments.include?(env)
74
- Gem.activate e.name, *e.requirement.as_list
75
- end
80
+ Gem.activate e.name, *e.requirement.as_list if e.matches? env
76
81
  end
77
82
 
78
83
  self
@@ -93,7 +98,7 @@ class Isolate
93
98
  self
94
99
  end
95
100
 
96
- def enable &block # :nodoc:
101
+ def enable # :nodoc:
97
102
  return self if enabled?
98
103
 
99
104
  @old_gem_path = ENV["GEM_PATH"]
@@ -113,7 +118,6 @@ class Isolate
113
118
  self.class.refresh
114
119
 
115
120
  @enabled = true
116
- begin; yield; ensure disable end if block_given?
117
121
  self
118
122
  end
119
123
 
@@ -128,7 +132,7 @@ class Isolate
128
132
  @environments.concat environments.map { |e| e.to_s }
129
133
 
130
134
  begin
131
- yield
135
+ instance_eval(&block)
132
136
  ensure
133
137
  @environments = old
134
138
  end
@@ -155,8 +159,7 @@ class Isolate
155
159
  env = environment.to_s if environment
156
160
 
157
161
  installable = entries.select do |e|
158
- !Gem.available?(e.name, *e.requirement.as_list) &&
159
- (env.nil? || e.environments.include?(env))
162
+ !Gem.available?(e.name, *e.requirement.as_list) && e.matches?(env)
160
163
  end
161
164
 
162
165
  installable.each_with_index do |e, i|
@@ -11,6 +11,7 @@ class TestIsolate < MiniTest::Unit::TestCase
11
11
  def teardown
12
12
  @isolate.disable
13
13
  Isolate.instance.disable if Isolate.instance
14
+ Gem::DependencyInstaller.reset_last_install
14
15
  FileUtils.rm_rf "tmp/gems"
15
16
  end
16
17
 
@@ -42,7 +43,7 @@ class TestIsolate < MiniTest::Unit::TestCase
42
43
  @isolate.gem "rubyforge"
43
44
 
44
45
  @isolate.environment "borg" do
45
- @isolate.gem "hoe"
46
+ gem "hoe"
46
47
  end
47
48
 
48
49
  @isolate.activate
@@ -56,7 +57,7 @@ class TestIsolate < MiniTest::Unit::TestCase
56
57
  @isolate.gem "rubyforge"
57
58
 
58
59
  @isolate.environment "borg" do
59
- @isolate.gem "hoe"
60
+ gem "hoe"
60
61
  end
61
62
 
62
63
  @isolate.activate "borg"
@@ -76,6 +77,14 @@ class TestIsolate < MiniTest::Unit::TestCase
76
77
  Gem::DependencyInstaller.last_install
77
78
  end
78
79
 
80
+ def test_activate_install_environment
81
+ @isolate = Isolate.new "tmp/gems", :install => true
82
+ @isolate.environment(:nope) { gem "foo" }
83
+
84
+ @isolate.activate
85
+ assert_nil Gem::DependencyInstaller.last_install
86
+ end
87
+
79
88
  def test_activate_ret
80
89
  assert_equal @isolate, @isolate.activate
81
90
  end
@@ -117,17 +126,6 @@ class TestIsolate < MiniTest::Unit::TestCase
117
126
  assert_equal [@isolate.path], Gem.path
118
127
  end
119
128
 
120
- def test_enable_block
121
- path = Gem.path.dup
122
- refute_equal [@isolate.path], Gem.path
123
-
124
- @isolate.enable do
125
- assert_equal [@isolate.path], Gem.path
126
- end
127
-
128
- assert_equal path, Gem.path
129
- end
130
-
131
129
  def test_enable_ret
132
130
  assert_equal @isolate, @isolate.enable
133
131
  end
@@ -136,10 +134,10 @@ class TestIsolate < MiniTest::Unit::TestCase
136
134
  @isolate.gem "none"
137
135
 
138
136
  @isolate.environment "test", "ci" do
139
- @isolate.gem "test-ci"
137
+ gem "test-ci"
140
138
 
141
- @isolate.environment "production" do
142
- @isolate.gem "test-ci-production"
139
+ environment "production" do
140
+ gem "test-ci-production"
143
141
  end
144
142
  end
145
143
 
@@ -188,6 +186,7 @@ end
188
186
  class Gem::DependencyInstaller
189
187
  @@last_install = nil
190
188
  def self.last_install; @@last_install end
189
+ def self.reset_last_install; @@last_install = nil end
191
190
 
192
191
  alias old_install install
193
192
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: isolate
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - John Barnette