Sha256: 4cf357b7465683aa724cf39f9bf1c2e7f6a582574384d3f76ba08d18080402f5

Contents?: true

Size: 1.22 KB

Versions: 3

Compression:

Stored size: 1.22 KB

Contents

require 'spec_helper'

describe Polly::Calculation do

  let(:calc_class) { Polly::Calculation }

  before :each do
    @calc = calc_class.new do
      var :a, 1
      var :b, 2
      var :c, 3
      var :d, a + b + c
    end
  end

  it 'should be able to toggle calculation options' do
    @calc.verbose_toggle
    calc_class.verbose.should be_true
    @calc.verbose_toggle
    calc_class.verbose.should be_false
  end

  it 'should eval the initialization block inside the context' do
    @calc.context.should_not respond_to(:e, :f, :g)
    @calc.context.should respond_to(:a, :b, :c, :d)
  end

  it 'should get and set variables in the context' do
    @calc.a.should == 1
    @calc.a = 2
    @calc.a.should == 2
  end

  it 'should respond to delegated methods' do
    @calc.should respond_to(:atomic_variables)
    @calc.should respond_to(:defined_variables)
    @calc.should respond_to(:undefined_variables)
    @calc.should respond_to(:evaluate)
    @calc.should respond_to(:to_yaml)
  end

  it 'should initialize from a yaml dump' do
    dump = calc_class.dump(@calc)
    c = calc_class.load(dump)
    c.context.should respond_to(:a, :b, :c, :d)
    c.a.should == 1
    c.b.should == 2
    c.c.should == 3
    c.d.should == 6
  end

end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
polly-0.0.6 spec/calculation.rb
polly-0.0.5 spec/calculation.rb
polly-0.0.4 spec/calculation.rb