Sha256: c29a88240b951af5c15418df053e180bf57b86131a0961ade45e1f4b23a8558d

Contents?: true

Size: 1.96 KB

Versions: 1

Compression:

Stored size: 1.96 KB

Contents

require File.dirname(File.dirname(__FILE__)) + '/spec_helper.rb'
describe Drill do

  it 'knows its options when it is the first choice' do
    AMEEMocker.new(self,:path=>'transport/car/generic',
      :selections=>[],
      :choices=>['diesel','petrol']).drill
    Transport.begin_calculation[:fuel].send(:choices).should eql ['diesel','petrol']
  end

  it 'knows its options when it is a later choice' do
    AMEEMocker.new(self,:path=>'transport/car/generic',
      :selections=>[['fuel','diesel']],
      :choices=>['large','small']).drill
    t=Transport.begin_calculation
    t[:fuel].value 'diesel'
    t[:size].send(:choices).should eql ['large','small']
  end
  
  it 'is enabled iff it is the next choice or has been chosen' do
    t=Transport.begin_calculation
    t[:fuel].enabled?.should be_true
    t[:size].enabled?.should be_false
    t[:fuel].value 'diesel'
    t[:fuel].enabled?.should be_true
    t[:size].enabled?.should be_true
    t[:size].value 'large'
    t[:fuel].enabled?.should be_true
    t[:size].enabled?.should be_true
  end

  it 'is valid iff assigned a choice in the choices' do
    AMEEMocker.new(self,:path=>'transport/car/generic',
      :selections=>[],
      :choices=>['diesel','petrol']).drill
    t=Transport.begin_calculation
    t[:fuel].value 'diesel'
    t[:fuel].send(:valid?).should be_true
    t[:fuel].value 'banana'
    t[:fuel].send(:valid?).should be_false
  end

  it "should set and get custom choices" do
    t=Transport.begin_calculation
    t[:fuel].choices 'anthracite', 'lignite'
    t[:fuel].choices.should eql ['anthracite', 'lignite']
  end

  it 'is sets correct single choice if AMEE skips during drill' do
    mocker = AMEEMocker.new(self,:path=>'transport/car/generic',
      :selections=>[['fuel','diesel']])
    mocker.drill_with_skip('size'=>'small')
    t=Transport.begin_calculation
    t[:fuel].value 'diesel'
    t[:fuel].should_not be_disabled
    t[:size].choices.should eql ['small']
    t[:size].should be_disabled
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
amee-data-abstraction-2.1.1 spec/amee-data-abstraction/drill_spec.rb