require File.expand_path('../../../spec_helper', __FILE__) require 'nokogiri' module NcsNavigator::Mdes describe TransmissionTable do describe '.from_element' do let(:element) { Nokogiri::XML(<<-XSD).root.xpath('//xs:element[@name="study_center"]').first XSD } subject { TransmissionTable.from_element(element) } it 'has the right name' do subject.name.should == 'study_center' end it 'has the right variables' do subject.variables.collect(&:name). should == %w(sc_id sc_name comments transaction_type) end end describe '#initialize' do it 'accepts a name' do TransmissionTable.new('study_center').name.should == 'study_center' end end describe '#[]' do subject { TransmissionTable.new('example').tap do |t| t.variables = %w(foo bar baz).collect do |n| Variable.new(n) end end } it 'gets a variable' do subject['bar'].should be_a(Variable) end it 'gets a variable by name' do subject['baz'].name.should == 'baz' end it 'is nil for an unknown variable' do subject['quux'].should be_nil end end end end