File: scope_spec.rb

package info (click to toggle)
ruby-parslet 2.0.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,260 kB
  • sloc: ruby: 6,157; sh: 8; javascript: 3; makefile: 3
file content (45 lines) | stat: -rw-r--r-- 1,009 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
require 'spec_helper'

describe Parslet::Scope do
  let(:scope) { described_class.new }
  
  describe 'simple store/retrieve' do
    before(:each) { scope[:foo] = :bar }
    it "allows storing objects" do
      scope[:obj] = 42
    end 
    it "raises on access of empty slots" do
      expect {
        scope[:empty]
      }.to raise_error(Parslet::Scope::NotFound)
    end 
    it "allows retrieval of stored values" do
      scope[:foo].should == :bar
    end 
  end
  
  describe 'scoping' do
    before(:each) { scope[:depth] = 1 }
    before(:each) { scope.push }
    
    let(:depth) { scope[:depth] }
    subject { depth }
    
    it { should == 1 }
    describe 'after a push' do
      before(:each) { scope.push }
      it { should == 1 }
      
      describe 'and reassign' do
        before(:each) { scope[:depth] = 2 }
        
        it { should == 2 }

        describe 'and a pop' do
          before(:each) { scope.pop }
          it { should == 1 }
        end
      end
    end
  end
end