|
15 | 15 | } |
16 | 16 |
|
17 | 17 | it 'has single <p:description> tag which contains description' do |
18 | | - print(xml) |
19 | 18 | descriptions = xml.xpath('p:task/p:description/text()') |
20 | 19 | expect(descriptions.size()).to be 1 |
21 | 20 | expect(descriptions[0].content).to eq 'Very descriptive' |
|
44 | 43 |
|
45 | 44 | end |
46 | 45 |
|
| 46 | + describe 'files' do |
| 47 | + let(:xml) { |
| 48 | + ::Nokogiri::XML( |
| 49 | + FactoryGirl.create(:only_meta_data).to_proforma_xml |
| 50 | + ).xpath('/root')[0] |
| 51 | + } |
| 52 | + |
| 53 | + context 'no files' do |
| 54 | + |
| 55 | + it 'contains a single empty <p:files>-tag' do |
| 56 | + filesContainer = xml.xpath('p:task/p:files') |
| 57 | + expect(filesContainer.size()).to be 1 |
| 58 | + allFiles = xml.xpath('p:task/*/p:file') |
| 59 | + expect(allFiles.size).to be 0 |
| 60 | + end |
| 61 | + |
| 62 | + end |
| 63 | + |
| 64 | + context 'one Java main file' do |
| 65 | + let(:xml) { |
| 66 | + ::Nokogiri::XML( |
| 67 | + FactoryGirl.create(:exercise_with_single_java_main_file).to_proforma_xml |
| 68 | + ).xpath('/root')[0] |
| 69 | + } |
| 70 | + |
| 71 | + it 'has single /p:files/p:file tag' do |
| 72 | + files = xml.xpath('p:task/p:files/p:file') |
| 73 | + expect(files.size()).to be 1 |
| 74 | + end |
| 75 | + |
| 76 | + it 'p:file tag has class="template"' do |
| 77 | + filesClass = xml.xpath('p:task/p:files/p:file/@class').first |
| 78 | + expect(filesClass.value).to eq 'template' |
| 79 | + end |
| 80 | + |
| 81 | + it 'has attribute id on <p:file>-tag' do |
| 82 | + ids = xml.xpath('p:task/p:files/p:file/@id') |
| 83 | + expect(ids.size).to be 1 |
| 84 | + expect(ids.first.value.size).to be > 0 |
| 85 | + end |
| 86 | + |
| 87 | + it 'has attribute filename on <p:file>-tag with name and extension' do |
| 88 | + file_names = xml.xpath('p:task/p:files/p:file/@filename') |
| 89 | + expect(file_names.size).to be 1 |
| 90 | + expect(file_names.first.value).to eq 'Main.java' |
| 91 | + end |
| 92 | + |
| 93 | + it 'has attribute class="template" on <p:file>-tag because it is the main file' do |
| 94 | + file_names = xml.xpath('p:task/p:files/p:file/@class') |
| 95 | + expect(file_names.size).to be 1 |
| 96 | + expect(file_names.first.value).to eq 'template' |
| 97 | + end |
| 98 | + |
| 99 | + it '<p:file> contains file contents as plain text ' do |
| 100 | + file_contents = xml.xpath('p:task/p:files/p:file/text()') |
| 101 | + expect(file_contents.size).to be 1 |
| 102 | + expect(file_contents.first.content).to eq 'public class AsteriksPattern{ public static void main String[] args) { } }' |
| 103 | + end |
| 104 | + |
| 105 | + end |
| 106 | + |
| 107 | + end |
| 108 | + |
47 | 109 | end |
0 commit comments