|
10 | 10 | @formatting_line_count = 12 # number of lines the formatting.docx file has |
11 | 11 | end |
12 | 12 |
|
13 | | - shared_examples_for 'reading' do |
14 | | - it 'should read the document' do |
15 | | - expect(@doc.paragraphs.size).to eq(2) |
16 | | - expect(@doc.paragraphs.first.text).to eq('hello') |
17 | | - expect(@doc.paragraphs.last.text).to eq('world') |
18 | | - expect(@doc.text).to eq("hello\nworld") |
19 | | - end |
20 | | - |
21 | | - it 'should read bookmarks' do |
22 | | - expect(@doc.bookmarks.size).to eq(1) |
23 | | - expect(@doc.bookmarks['test_bookmark']).to_not eq(nil) |
24 | | - end |
25 | | - |
26 | | - it 'should have paragraphs' do |
27 | | - @doc.each_paragraph do |p| |
28 | | - expect(p).to be_an_instance_of(Docx::Elements::Containers::Paragraph) |
29 | | - end |
30 | | - end |
31 | | - |
32 | | - it 'should have properly formatted text runs' do |
33 | | - @doc.each_paragraph do |p| |
34 | | - p.each_text_run do |tr| |
35 | | - expect(tr).to be_an_instance_of(Docx::Elements::Containers::TextRun) |
36 | | - expect(tr.formatting).to eq(Docx::Elements::Containers::TextRun::DEFAULT_FORMATTING) |
37 | | - end |
38 | | - end |
39 | | - end |
40 | | - |
41 | | - describe '#font_size' do |
42 | | - context 'When a docx files has no styles.xml' do |
43 | | - before do |
44 | | - @doc = Docx::Document.new(@fixtures_path + '/no_styles.docx') |
45 | | - end |
46 | | - |
47 | | - it 'should raise an error' do |
48 | | - expect(@doc.font_size).to be_nil |
49 | | - end |
50 | | - end |
51 | | - end |
52 | | - end |
53 | | - |
54 | | - shared_examples_for 'saving to file' do |
55 | | - it 'should save to a normal file path' do |
56 | | - @new_doc_path = @fixtures_path + '/new_save.docx' |
57 | | - @doc.save(@new_doc_path) |
58 | | - @new_doc = Docx::Document.open(@new_doc_path) |
59 | | - expect(@new_doc.paragraphs.size).to eq(@doc.paragraphs.size) |
60 | | - end |
61 | | - |
62 | | - it 'should save to a tempfile' do |
63 | | - temp_file = Tempfile.new(['docx_gem', '.docx']) |
64 | | - @new_doc_path = temp_file.path |
65 | | - @doc.save(@new_doc_path) |
66 | | - @new_doc = Docx::Document.open(@new_doc_path) |
67 | | - expect(@new_doc.paragraphs.size).to eq(@doc.paragraphs.size) |
68 | | - |
69 | | - temp_file.close |
70 | | - temp_file.unlink |
71 | | - # ensure temp file has been removed |
72 | | - expect(File.exist?(@new_doc_path)).to eq(false) |
73 | | - end |
74 | | - |
75 | | - after do |
76 | | - File.delete(@new_doc_path) if File.exist?(@new_doc_path) |
77 | | - end |
78 | | - end |
79 | | - |
80 | 13 | describe '#open' do |
81 | 14 | context 'When reading a file made by Office365' do |
82 | 15 | it 'supports it' do |
|
0 commit comments