Permalink
Browse files

Tighten up with_constant

  • Loading branch information...
Nikolai Weibull
Nikolai Weibull committed Jul 31, 2012
1 parent c5600ab commit a020793a8a650afe36ac58232034b75378b1d9eb
Showing with 14 additions and 1 deletion.
  1. +2 −1 lib/lookout/expect/object/context.rb
  2. +12 −0 test/unit/lookout/expect/object/context.rb
@@ -81,7 +81,8 @@ def with_verbose(verbose = true)
# @return [::Object] The result of the block
def with_constant(name, value)
missing = nil
- parts = name.split('::')
+ parts = name.split('::', -1)
+ parts.shift if parts.first.empty?
begin
parent = parts[0..-2].reduce(Object){ |o, e|
begin
@@ -63,6 +63,18 @@
end
end
+ expect 'hello' do
+ with_constant '::Inventory::Rake::Tasks', 'hello' do
+ ::Inventory::Rake::Tasks
+ end
+ end
+
+ expect NameError do
+ with_constant '::Inventory::Rake::Tasks::', 'hello' do
+ ::Inventory::Rake::Tasks
+ end
+ end
+
expect '123' do
with_environment 'LINE' => '123' do
ENV['LINE']

0 comments on commit a020793

Please sign in to comment.