diff options
Diffstat (limited to 'spec/rubyspec/core/binding')
| -rw-r--r-- | spec/rubyspec/core/binding/clone_spec.rb | 7 | ||||
| -rw-r--r-- | spec/rubyspec/core/binding/dup_spec.rb | 7 | ||||
| -rw-r--r-- | spec/rubyspec/core/binding/eval_spec.rb | 37 | ||||
| -rw-r--r-- | spec/rubyspec/core/binding/fixtures/classes.rb | 40 | ||||
| -rw-r--r-- | spec/rubyspec/core/binding/local_variable_defined_spec.rb | 46 | ||||
| -rw-r--r-- | spec/rubyspec/core/binding/local_variable_get_spec.rb | 56 | ||||
| -rw-r--r-- | spec/rubyspec/core/binding/local_variable_set_spec.rb | 71 | ||||
| -rw-r--r-- | spec/rubyspec/core/binding/local_variables_spec.rb | 35 | ||||
| -rw-r--r-- | spec/rubyspec/core/binding/location_spec.rb | 46 | ||||
| -rw-r--r-- | spec/rubyspec/core/binding/receiver_spec.rb | 11 | ||||
| -rw-r--r-- | spec/rubyspec/core/binding/shared/clone.rb | 34 |
11 files changed, 0 insertions, 390 deletions
diff --git a/spec/rubyspec/core/binding/clone_spec.rb b/spec/rubyspec/core/binding/clone_spec.rb deleted file mode 100644 index d607ae2a9e..0000000000 --- a/spec/rubyspec/core/binding/clone_spec.rb +++ /dev/null @@ -1,7 +0,0 @@ -require File.expand_path('../../../spec_helper', __FILE__) -require File.expand_path('../fixtures/classes', __FILE__) -require File.expand_path('../shared/clone', __FILE__) - -describe "Binding#clone" do - it_behaves_like(:binding_clone, :clone) -end diff --git a/spec/rubyspec/core/binding/dup_spec.rb b/spec/rubyspec/core/binding/dup_spec.rb deleted file mode 100644 index 7f242626d7..0000000000 --- a/spec/rubyspec/core/binding/dup_spec.rb +++ /dev/null @@ -1,7 +0,0 @@ -require File.expand_path('../../../spec_helper', __FILE__) -require File.expand_path('../fixtures/classes', __FILE__) -require File.expand_path('../shared/clone', __FILE__) - -describe "Binding#dup" do - it_behaves_like(:binding_clone, :dup) -end diff --git a/spec/rubyspec/core/binding/eval_spec.rb b/spec/rubyspec/core/binding/eval_spec.rb deleted file mode 100644 index 4864b9f61f..0000000000 --- a/spec/rubyspec/core/binding/eval_spec.rb +++ /dev/null @@ -1,37 +0,0 @@ -require File.expand_path('../../../spec_helper', __FILE__) -require File.expand_path('../fixtures/classes', __FILE__) - -describe "Binding#eval" do - it "behaves like Kernel.eval(..., self)" do - obj = BindingSpecs::Demo.new(1) - bind = obj.get_binding - - bind.eval("@secret += square(3)").should == 10 - bind.eval("a").should be_true - - bind.eval("class Inside; end") - bind.eval("Inside.name").should == "BindingSpecs::Demo::Inside" - end - - it "does not leak variables to cloned bindings" do - obj = BindingSpecs::Demo.new(1) - bind = obj.get_empty_binding - bind2 = bind.dup - - bind.eval("x = 72") - bind.local_variables.should == [:x] - bind2.local_variables.should == [] - end - - describe "with a file given" do - it "does not store the filename permanently" do - obj = BindingSpecs::Demo.new(1) - bind = obj.get_binding - - bind.eval("__FILE__", "test.rb").should == "test.rb" - bind.eval("__FILE__").should_not == "test.rb" - end - end - - it "needs to be reviewed for spec completeness" -end diff --git a/spec/rubyspec/core/binding/fixtures/classes.rb b/spec/rubyspec/core/binding/fixtures/classes.rb deleted file mode 100644 index 05ca2479ba..0000000000 --- a/spec/rubyspec/core/binding/fixtures/classes.rb +++ /dev/null @@ -1,40 +0,0 @@ -module BindingSpecs - class Demo - def initialize(n) - @secret = n - end - - def square(n) - n * n - end - - def get_binding_and_line - a = true - [binding, __LINE__] - end - - def get_binding - get_binding_and_line[0] - end - - def get_line_of_binding - get_binding_and_line[1] - end - - def get_file_of_binding - __FILE__ - end - - def get_empty_binding - binding - end - - def get_binding_in_block - a = true - 1.times do - b = false - return binding - end - end - end -end diff --git a/spec/rubyspec/core/binding/local_variable_defined_spec.rb b/spec/rubyspec/core/binding/local_variable_defined_spec.rb deleted file mode 100644 index 5fa79b19e2..0000000000 --- a/spec/rubyspec/core/binding/local_variable_defined_spec.rb +++ /dev/null @@ -1,46 +0,0 @@ -require File.expand_path('../../../spec_helper', __FILE__) - -describe 'Binding#local_variable_defined?' do - it 'returns false when a variable is not defined' do - binding.local_variable_defined?(:foo).should == false - end - - it 'returns true when a regular local variable is defined' do - foo = 10 - binding.local_variable_defined?(:foo).should == true - end - - it 'returns true when a local variable is defined using eval()' do - bind = binding - bind.eval('foo = 10') - - bind.local_variable_defined?(:foo).should == true - end - - it 'returns true when a local variable is defined using Binding#local_variable_set' do - bind = binding - bind.local_variable_set(:foo, 10) - - bind.local_variable_defined?(:foo).should == true - end - - it 'returns true when a local variable is defined in a parent scope' do - foo = 10 - lambda { - binding.local_variable_defined?(:foo) - }.call.should == true - end - - it 'allows usage of a String as the variable name' do - foo = 10 - binding.local_variable_defined?('foo').should == true - end - - it 'allows usage of an object responding to #to_str as the variable name' do - foo = 10 - name = mock(:obj) - name.stub!(:to_str).and_return('foo') - - binding.local_variable_defined?(name).should == true - end -end diff --git a/spec/rubyspec/core/binding/local_variable_get_spec.rb b/spec/rubyspec/core/binding/local_variable_get_spec.rb deleted file mode 100644 index e65d08130e..0000000000 --- a/spec/rubyspec/core/binding/local_variable_get_spec.rb +++ /dev/null @@ -1,56 +0,0 @@ -require File.expand_path('../../../spec_helper', __FILE__) -require File.expand_path('../fixtures/classes', __FILE__) - -describe "Binding#local_variable_get" do - it "reads local variables captured in the binding" do - a = 42 - bind = binding - bind.local_variable_get(:a).should == 42 - end - - it "raises a NameError for missing variables" do - bind = BindingSpecs::Demo.new(1).get_empty_binding - - lambda { - bind.local_variable_get(:no_such_variable) - }.should raise_error(NameError) - end - - it "reads variables added later to the binding" do - bind = BindingSpecs::Demo.new(1).get_empty_binding - - lambda { - bind.local_variable_get(:a) - }.should raise_error(NameError) - - bind.local_variable_set(:a, 42) - - bind.local_variable_get(:a).should == 42 - end - - it 'gets a local variable defined in a parent scope' do - number = 10 - - lambda { - binding.local_variable_get(:number) - }.call.should == 10 - end - - it 'gets a local variable defined using eval()' do - bind = binding - bind.eval('number = 10') - - bind.local_variable_get(:number).should == 10 - end - - it "raises a NameError on global access" do - bind = binding - lambda { bind.local_variable_get(:$0) }.should raise_error(NameError) - end - - it "raises a NameError on special variable access" do - bind = binding - lambda { bind.local_variable_get(:$~) }.should raise_error(NameError) - lambda { bind.local_variable_get(:$_) }.should raise_error(NameError) - end -end diff --git a/spec/rubyspec/core/binding/local_variable_set_spec.rb b/spec/rubyspec/core/binding/local_variable_set_spec.rb deleted file mode 100644 index 067dcbd03e..0000000000 --- a/spec/rubyspec/core/binding/local_variable_set_spec.rb +++ /dev/null @@ -1,71 +0,0 @@ -require File.expand_path('../../../spec_helper', __FILE__) -require File.expand_path('../fixtures/classes', __FILE__) - -describe "Binding#local_variable_set" do - it "adds nonexistent variables to the binding's eval scope" do - obj = BindingSpecs::Demo.new(1) - bind = obj.get_empty_binding - bind.eval('local_variables').should == [] - bind.local_variable_set :foo, 1 - bind.eval('local_variables').should == [:foo] - bind.eval('foo').should == 1 - end - - it 'sets a new local variable' do - bind = binding - - bind.local_variable_set(:number, 10) - bind.local_variable_get(:number).should == 10 - end - - it 'sets a local variable using a String as the variable name' do - bind = binding - - bind.local_variable_set('number', 10) - bind.local_variable_get('number').should == 10 - end - - it 'sets a local variable using an object responding to #to_str as the variable name' do - bind = binding - name = mock(:obj) - name.stub!(:to_str).and_return('number') - - bind.local_variable_set(name, 10) - bind.local_variable_get(name).should == 10 - end - - it 'scopes new local variables to the receiving Binding' do - bind = binding - bind.local_variable_set(:number, 10) - - lambda { number }.should raise_error(NameError) - end - - it 'overwrites an existing local variable defined before a Binding' do - number = 10 - bind = binding - - bind.local_variable_set(:number, 20) - number.should == 20 - end - - it 'overwrites a local variable defined using eval()' do - bind = binding - bind.eval('number = 10') - - bind.local_variable_set(:number, 20) - bind.local_variable_get(:number).should == 20 - end - - it "raises a NameError on global access" do - bind = binding - lambda { bind.local_variable_set(:$0, "") }.should raise_error(NameError) - end - - it "raises a NameError on special variable access" do - bind = binding - lambda { bind.local_variable_set(:$~, "") }.should raise_error(NameError) - lambda { bind.local_variable_set(:$_, "") }.should raise_error(NameError) - end - -end diff --git a/spec/rubyspec/core/binding/local_variables_spec.rb b/spec/rubyspec/core/binding/local_variables_spec.rb deleted file mode 100644 index bc6ea71f10..0000000000 --- a/spec/rubyspec/core/binding/local_variables_spec.rb +++ /dev/null @@ -1,35 +0,0 @@ -require File.expand_path('../../../spec_helper', __FILE__) - -describe "Binding#local_variables" do - it "returns an Array" do - binding.local_variables.should be_kind_of(Array) - end - - it "includes local variables in the current scope" do - a = 1 - b = nil - binding.local_variables.should == [:a, :b] - end - - it "includes local variables defined after calling binding.local_variables" do - binding.local_variables.should == [:a, :b] - a = 1 - b = 2 - end - - it "includes local variables of inherited scopes and eval'ed context" do - p = proc { |a| b = 1; eval("c = 2; binding.local_variables") } - p.call.should == [:c, :a, :b, :p] - end - - it "includes shadowed local variables only once" do - a = 1 - proc { |a| binding.local_variables }.call(2).should == [:a] - end - - it "includes new variables defined in the binding" do - b = binding - b.local_variable_set :a, 42 - b.local_variables.should == [:a, :b] - end -end diff --git a/spec/rubyspec/core/binding/location_spec.rb b/spec/rubyspec/core/binding/location_spec.rb deleted file mode 100644 index b4a066038d..0000000000 --- a/spec/rubyspec/core/binding/location_spec.rb +++ /dev/null @@ -1,46 +0,0 @@ -require File.expand_path('../../../spec_helper', __FILE__) -require File.expand_path('../fixtures/classes', __FILE__) - -describe "Binding#eval" do - it "inherits __LINE__ from the enclosing scope" do - obj = BindingSpecs::Demo.new(1) - bind = obj.get_binding - bind.eval("__LINE__").should == obj.get_line_of_binding - end - - it "preserves __LINE__ across multiple calls to eval" do - obj = BindingSpecs::Demo.new(1) - bind = obj.get_binding - bind.eval("__LINE__").should == obj.get_line_of_binding - bind.eval("__LINE__").should == obj.get_line_of_binding - end - - it "increments __LINE__ on each line of a multiline eval" do - obj = BindingSpecs::Demo.new(1) - bind = obj.get_binding - bind.eval("#foo\n__LINE__").should == obj.get_line_of_binding + 1 - end - - it "starts with a __LINE__ of 1 if a filename is passed" do - bind = BindingSpecs::Demo.new(1).get_binding - bind.eval("__LINE__", "(test)").should == 1 - bind.eval("#foo\n__LINE__", "(test)").should == 2 - end - - it "starts with a __LINE__ from the third argument if passed" do - bind = BindingSpecs::Demo.new(1).get_binding - bind.eval("__LINE__", "(test)", 88).should == 88 - bind.eval("#foo\n__LINE__", "(test)", 88).should == 89 - end - - it "inherits __FILE__ from the enclosing scope" do - obj = BindingSpecs::Demo.new(1) - bind = obj.get_binding - bind.eval("__FILE__").should == obj.get_file_of_binding - end - - it "uses the __FILE__ that is passed in" do - bind = BindingSpecs::Demo.new(1).get_binding - bind.eval("__FILE__", "(test)").should == "(test)" - end -end diff --git a/spec/rubyspec/core/binding/receiver_spec.rb b/spec/rubyspec/core/binding/receiver_spec.rb deleted file mode 100644 index 8784ab0e38..0000000000 --- a/spec/rubyspec/core/binding/receiver_spec.rb +++ /dev/null @@ -1,11 +0,0 @@ -require File.expand_path('../../../spec_helper', __FILE__) -require File.expand_path('../fixtures/classes', __FILE__) - -describe "Binding#receiver" do - it "returns the object to which binding is bound" do - obj = BindingSpecs::Demo.new(1) - obj.get_binding.receiver.should == obj - - binding.receiver.should == self - end -end diff --git a/spec/rubyspec/core/binding/shared/clone.rb b/spec/rubyspec/core/binding/shared/clone.rb deleted file mode 100644 index 0e934ac1b5..0000000000 --- a/spec/rubyspec/core/binding/shared/clone.rb +++ /dev/null @@ -1,34 +0,0 @@ -describe :binding_clone, shared: true do - before :each do - @b1 = BindingSpecs::Demo.new(99).get_binding - @b2 = @b1.send(@method) - @b3 = BindingSpecs::Demo.new(99).get_binding_in_block - @b4 = @b3.send(@method) - end - - it "returns a copy of the Binding object" do - [[@b1, @b2, "a"], - [@b3, @b4, "a", "b"]].each do |b1, b2, *vars| - b1.should_not == b2 - - eval("@secret", b1).should == eval("@secret", b2) - eval("square(2)", b1).should == eval("square(2)", b2) - eval("self.square(2)", b1).should == eval("self.square(2)", b2) - vars.each do |v| - eval("#{v}", b1).should == eval("#{v}", b2) - end - end - end - - it "is a shallow copy of the Binding object" do - [[@b1, @b2, "a"], - [@b3, @b4, "a", "b"]].each do |b1, b2, *vars| - vars.each do |v| - eval("#{v} = false", b1) - eval("#{v}", b2).should == false - end - b1.local_variable_set(:x, 37) - b2.local_variable_defined?(:x).should == false - end - end -end |
