Skip to content

Commit

Permalink
Flesh out Kernel#remove_instance_variable spec
Browse files Browse the repository at this point in the history
  • Loading branch information
Evan Phoenix committed May 7, 2010
1 parent e6bb6eb commit 5761bb0
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
6 changes: 6 additions & 0 deletions spec/ruby/core/kernel/fixtures/classes.rb
Expand Up @@ -295,6 +295,12 @@ def method_missing(method, *args)
"Done #{method}(#{args})"
end
end

class Ivar
def initialize
@greeting = "hello"
end
end
end

class EvalSpecs
Expand Down
30 changes: 30 additions & 0 deletions spec/ruby/core/kernel/remove_instance_variable_spec.rb
Expand Up @@ -5,4 +5,34 @@
it "is a private method" do
Kernel.should have_private_instance_method(:remove_instance_variable)
end

it "removes an ivar of a given name and return it's value" do
val = KernelSpecs::Ivar.new.send :remove_instance_variable, :@greeting
val.should == "hello"
end

it "supports the name being a string" do
val = KernelSpecs::Ivar.new.send :remove_instance_variable, "@greeting"
val.should == "hello"
end

it "tries to call #to_str if it's not a String or Symbol" do
s = mock("str")
s.should_receive(:to_str).and_return("@greeting")

val = KernelSpecs::Ivar.new.send :remove_instance_variable, s
val.should == "hello"
end

it "raises NameError if the ivar isn't defined" do
lambda {
KernelSpecs::Ivar.new.send :remove_instance_variable, :@unknown
}.should raise_error(NameError)
end

it "rejects unknown argument types" do
lambda {
KernelSpecs::Ivar.new.send :remove_instance_variable, Object
}.should raise_error(TypeError)
end
end

0 comments on commit 5761bb0

Please sign in to comment.