Sha256: a60eb8ff4d36ec1171545cb9e5315f0f6762c100d5422518579cc1374832a3bf

Contents?: true

Size: 1.32 KB

Versions: 5

Compression:

Stored size: 1.32 KB

Contents

require File.expand_path(File.dirname(__FILE__) + '/spec_helper')

describe RipperPlus::ScopeStack do
  before do
    @stack = RipperPlus::ScopeStack.new
  end
  
  it 'can see variables added at top level' do
    @stack.should_not have_variable(:hello)
    @stack.add_variable :hello
    @stack.should have_variable(:hello)
  end
  
  it 'can not see variables added beyond a closed scope' do
    @stack.add_variable :hello
    @stack.with_closed_scope do
      @stack.should_not have_variable(:hello)
    end
    @stack.should have_variable(:hello)
  end
  
  it 'can see variables added beyond an open scope' do
    @stack.add_variable :hello
    @stack.with_open_scope do
      @stack.should have_variable(:hello)
    end
    @stack.should have_variable(:hello)
  end
  
  it 'tracks entry and exit of methods' do
    @stack.should_not be_in_method
    @stack.with_open_scope do
      @stack.should_not be_in_method
      @stack.with_closed_scope do
        @stack.should_not be_in_method
        @stack.with_closed_scope(true) do
          @stack.should be_in_method
          @stack.with_closed_scope do
            @stack.should be_in_method
          end
          @stack.should be_in_method
        end
        @stack.should_not be_in_method
      end
      @stack.should_not be_in_method
    end
    @stack.should_not be_in_method
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
ripper-plus-1.3.0 spec/scope_stack_spec.rb
ripper-plus-1.2.2 spec/scope_stack_spec.rb
ripper-plus-1.2.1 spec/scope_stack_spec.rb
ripper-plus-1.2.0 spec/scope_stack_spec.rb
ripper-plus-1.1.0.pre2 spec/scope_stack_spec.rb