Sha256: 365853d8d14f0fa8479679ad212a5f89e7f6a5dd4f26920acd252017414bf891

Contents?: true

Size: 1.2 KB

Versions: 2

Compression:

Stored size: 1.2 KB

Contents

#          Copyright (c) 2009 Michael Fellinger m.fellinger@gmail.com
# All files in this distribution are subject to the terms of the MIT license.

require File.expand_path('../../../spec/helper', __FILE__)

Point = Ramaze::Struct.new(:x,:y)

describe "Ramaze::Struct" do
  describe '#values_at' do
    @point = Point.new(1,2)

    it "should access a single value" do
      @point.values_at(:x).should == [1]
    end

    it "should access multiple values" do
      @point.values_at(:x,:y).should == [1,2]
    end

    it "should access values regardless of order" do
      @point.values_at(:y,:x).should == [2,1]
    end

    it "should get same value twice" do
      @point.values_at(:x,:x).should == [1,1]
    end

    it "should raise on wrong value" do
      should.raise(NameError){
        @point.values_at(:k)
      }
    end

    it "should work with strings" do
      @point.values_at('x').should == [1]
    end

    it "should work with numbers (ruby compat)" do
      @point.values_at(0).should == [1]
    end

    should 'work with ranges' do
      @point.values_at(0..1).should == [1,2]
    end

    should 'work with multiple ranges' do
      @point.values_at(0..1, 0..1).should == [1,2,1,2]
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
ramaze-2012.04.14 spec/ramaze/struct.rb
ramaze-2012.03.07 spec/ramaze/struct.rb