[384] | 1 | require File.dirname(__FILE__) + '/../../../../../spec_helper'
|
---|
| 2 | include OpenEHR::AM::Archetype::Assertion
|
---|
| 3 |
|
---|
| 4 | describe Assertion do
|
---|
| 5 | before(:each) do
|
---|
| 6 | expression = stub(ExprItem, :type => 'Boolean')
|
---|
| 7 | $string_expression = "/[at0001]/speed[at0002]/kilometres/magnitude = " +
|
---|
| 8 | "/[at0003]/speed[at0004]/miles/magnitude * 1.6"
|
---|
| 9 | variables = stub(Array, :size => 2)
|
---|
[392] | 10 | @assertion = OpenEHR::AM::Archetype::Assertion::Assertion.new(:tag => 'validity',
|
---|
[384] | 11 | :expression => expression,
|
---|
| 12 | :string_expression => $string_expression,
|
---|
| 13 | :variables => variables)
|
---|
| 14 | end
|
---|
| 15 |
|
---|
| 16 | it 'should be an instance of Assertion' do
|
---|
[392] | 17 | @assertion.should be_an_instance_of OpenEHR::AM::Archetype::Assertion::Assertion
|
---|
[384] | 18 | end
|
---|
| 19 |
|
---|
| 20 | it 'expression should be assigned properly' do
|
---|
| 21 | @assertion.expression.type.should == 'Boolean'
|
---|
| 22 | end
|
---|
| 23 |
|
---|
| 24 | it 'should raise ArgumentError when expression is nil' do
|
---|
| 25 | lambda {
|
---|
| 26 | @assertion.expression = nil
|
---|
| 27 | }.should raise_error ArgumentError
|
---|
| 28 | end
|
---|
| 29 |
|
---|
| 30 | it 'should raise ArgumentError when expression type is not Boolean' do
|
---|
| 31 | invalid_expression = stub(ExprItem, :type => 'Real')
|
---|
| 32 | lambda {
|
---|
| 33 | @assertion.expression = invalid_expression
|
---|
| 34 | }.should raise_error ArgumentError
|
---|
| 35 | end
|
---|
| 36 |
|
---|
| 37 | it 'tag should be assigned properly' do
|
---|
| 38 | @assertion.tag.should == 'validity'
|
---|
| 39 | end
|
---|
| 40 |
|
---|
| 41 | it 'tag should not be empty' do
|
---|
| 42 | lambda {
|
---|
| 43 | @assertion.tag = ''
|
---|
| 44 | }.should raise_error ArgumentError
|
---|
| 45 | end
|
---|
| 46 |
|
---|
| 47 | it 'should not raise ArgumentError when tag = nil' do
|
---|
| 48 | lambda {
|
---|
| 49 | @assertion.tag = nil
|
---|
| 50 | }.should_not raise_error ArgumentError
|
---|
| 51 | end
|
---|
| 52 |
|
---|
| 53 | it 'string_expression should be assigned properly' do
|
---|
| 54 | @assertion.string_expression.should == $string_expression
|
---|
| 55 | end
|
---|
| 56 |
|
---|
| 57 | it 'variables should be assigned properly' do
|
---|
| 58 | @assertion.variables.size.should be_equal 2
|
---|
| 59 | end
|
---|
| 60 | end
|
---|