1313 end
1414
1515 it 'should read the document' do
16- @doc . paragraphs . size . should eq 2
17- @doc . paragraphs . first . text . should eq 'hello'
18- @doc . paragraphs . last . text . should eq 'world'
19- @doc . text . should eq "hello\n world"
16+ expect ( @doc . paragraphs . size ) . to eq ( 2 )
17+ expect ( @doc . paragraphs . first . text ) . to eq ( 'hello' )
18+ expect ( @doc . paragraphs . last . text ) . to eq ( 'world' )
19+ expect ( @doc . text ) . to eq ( "hello\n world" )
2020 end
2121
2222 it 'should read bookmarks' do
23- @doc . bookmarks . size . should eq 1
24- @doc . bookmarks [ 'test_bookmark' ] . should_not be_nil
23+ expect ( @doc . bookmarks . size ) . to eq ( 1 )
24+ expect ( @doc . bookmarks [ 'test_bookmark' ] ) . to_not eq ( nil )
2525 end
2626
2727 it 'should have paragraphs' do
3434 @doc . each_paragraph do |p |
3535 p . each_text_run do |tr |
3636 expect ( tr ) . to be_an_instance_of ( Docx ::Elements ::Containers ::TextRun )
37- tr . formatting . should eq Docx ::Elements ::Containers ::TextRun ::DEFAULT_FORMATTING
37+ expect ( tr . formatting ) . to eq ( Docx ::Elements ::Containers ::TextRun ::DEFAULT_FORMATTING )
3838 end
3939 end
4040 end
7777 end
7878
7979 it "should have tables with proper text" do
80- @doc . tables [ 0 ] . rows [ 0 ] . cells [ 0 ] . text . should eq "ENGLISH"
81- @doc . tables [ 0 ] . rows [ 0 ] . cells [ 1 ] . text . should eq "FRANÇAIS"
82- @doc . tables [ 1 ] . rows [ 0 ] . cells [ 0 ] . text . should eq "Second table"
83- @doc . tables [ 1 ] . rows [ 0 ] . cells [ 1 ] . text . should eq "Second tableau"
84- @doc . tables [ 0 ] . columns [ 0 ] . cells [ 5 ] . text . should eq "aphids"
85- @doc . tables [ 0 ] . columns [ 1 ] . cells [ 5 ] . text . should eq "puceron"
80+ expect ( @doc . tables [ 0 ] . rows [ 0 ] . cells [ 0 ] . text ) . to eq "ENGLISH"
81+ expect ( @doc . tables [ 0 ] . rows [ 0 ] . cells [ 1 ] . text ) . to eq "FRANÇAIS"
82+ expect ( @doc . tables [ 1 ] . rows [ 0 ] . cells [ 0 ] . text ) . to eq "Second table"
83+ expect ( @doc . tables [ 1 ] . rows [ 0 ] . cells [ 1 ] . text ) . to eq "Second tableau"
84+ expect ( @doc . tables [ 0 ] . columns [ 0 ] . cells [ 5 ] . text ) . to eq "aphids"
85+ expect ( @doc . tables [ 0 ] . columns [ 1 ] . cells [ 5 ] . text ) . to eq "puceron"
8686 end
8787
8888 it "should read embedded links" do
89- @doc . tables [ 0 ] . columns [ 1 ] . cells [ 1 ] . text . should =~ /^Directive/
89+ expect ( @doc . tables [ 0 ] . columns [ 1 ] . cells [ 1 ] . text ) . to match ( /^Directive/ )
9090 end
9191 end
9292
9999 old_p = @doc . paragraphs . first
100100 new_p = old_p . copy
101101 expect ( new_p ) . to be_an_instance_of ( Docx ::Elements ::Containers ::Paragraph )
102- new_p . should_not be_nil
103- new_p . should_not eq ( old_p )
102+ expect ( new_p ) . not_to eq ( nil )
103+ expect ( new_p ) . not_to eq ( old_p )
104104 end
105105
106106 it 'allows insertion of text' do
107- @doc . paragraphs . size . should eq 3
107+ expect ( @doc . paragraphs . size ) . to eq ( 3 )
108108 first_p = @doc . paragraphs . first
109109 new_p = first_p . copy
110110 new_p . insert_after first_p
111- @doc . paragraphs . size . should eq 4
111+ expect ( @doc . paragraphs . size ) . to eq ( 4 )
112112 end
113113
114114 it 'should change text' do
115- @doc . paragraphs . first . text . should eq 'test text'
115+ expect ( @doc . paragraphs . first . text ) . to eq ( 'test text' )
116116 @doc . paragraphs . first . text = 'the real test'
117- @doc . paragraphs . first . text . should eq 'the real test'
117+ expect ( @doc . paragraphs . first . text ) . to eq ( 'the real test' )
118118 end
119119
120120 it 'should allow insertion of text before a bookmark' do
121- @doc . paragraphs . first . text . should eq 'test text'
121+ expect ( @doc . paragraphs . first . text ) . to eq ( 'test text' )
122122 @doc . bookmarks [ 'beginning_bookmark' ] . insert_text_before ( 'foo' )
123- @doc . paragraphs . first . text . should eq 'footest text'
123+ expect ( @doc . paragraphs . first . text ) . to eq ( 'footest text' )
124124 end
125125
126126 it 'should allow insertion of text after a bookmark' do
127- @doc . paragraphs . first . text . should eq 'test text'
127+ expect ( @doc . paragraphs . first . text ) . to eq ( 'test text' )
128128 @doc . bookmarks [ 'end_bookmark' ] . insert_text_after ( 'bar' )
129- @doc . paragraphs . first . text . should eq 'test textbar'
129+ expect ( @doc . paragraphs . first . text ) . to eq ( 'test textbar' )
130130 end
131131
132132 it 'should allow multiple lines of text to be inserted at a bookmark' do
133- @doc . paragraphs . last . text . should eq ''
133+ expect ( @doc . paragraphs . last . text ) . to eq ( '' )
134134 new_lines = [ 'replacement test' , 'second paragraph test' , 'and a third paragraph test' ]
135135 @doc . bookmarks [ 'isolated_bookmark' ] . insert_multiple_lines ( new_lines )
136136 new_lines . each_index do |line |
137- @doc . paragraphs [ line + 2 ] . text . should eq new_lines [ line ]
137+ expect ( @doc . paragraphs [ line + 2 ] . text ) . to eq ( new_lines [ line ] )
138138 end
139139 end
140140
141141 it 'should allow multi-line insertion with replacement' do
142- @doc . paragraphs [ 1 ] . text . should eq 'placeholder text'
142+ expect ( @doc . paragraphs [ 1 ] . text ) . to eq ( 'placeholder text' )
143143 new_lines = [ 'replacement test' , 'second paragraph test' , 'and a third paragraph test' ]
144144 @doc . bookmarks [ 'word_splitting_bookmark' ] . insert_multiple_lines ( new_lines )
145145 new_lines . each_index do |line |
146- @doc . paragraphs [ line + 1 ] . text . should eq new_lines [ line ]
146+ expect ( @doc . paragraphs [ line + 1 ] . text ) . to eq ( new_lines [ line ] )
147147 end
148148 end
149149
150150 it 'should allow content deletion' do
151- @doc . paragraphs . first . text . should eq 'test text'
151+ expect ( @doc . paragraphs . first . text ) . to eq ( 'test text' )
152152 @doc . paragraphs . first . blank!
153- @doc . paragraphs . first . text . should eq ''
153+ expect ( @doc . paragraphs . first . text ) . to eq ( '' )
154154 end
155155 end
156156
166166 end
167167
168168 it 'should have the correct text' do
169- @doc . paragraphs . size . should eq 6
170- @doc . paragraphs [ 0 ] . text . should eq 'Normal'
171- @doc . paragraphs [ 1 ] . text . should eq 'Italic'
172- @doc . paragraphs [ 2 ] . text . should eq 'Bold'
173- @doc . paragraphs [ 3 ] . text . should eq 'Underline'
174- @doc . paragraphs [ 4 ] . text . should eq 'Normal'
175- @doc . paragraphs [ 5 ] . text . should eq 'This is a sentence with all formatting options in the middle of the sentence.'
169+ expect ( @doc . paragraphs . size ) . to eq ( 6 )
170+ expect ( @doc . paragraphs [ 0 ] . text ) . to eq ( 'Normal' )
171+ expect ( @doc . paragraphs [ 1 ] . text ) . to eq ( 'Italic' )
172+ expect ( @doc . paragraphs [ 2 ] . text ) . to eq ( 'Bold' )
173+ expect ( @doc . paragraphs [ 3 ] . text ) . to eq ( 'Underline' )
174+ expect ( @doc . paragraphs [ 4 ] . text ) . to eq ( 'Normal' )
175+ expect ( @doc . paragraphs [ 5 ] . text ) . to eq ( 'This is a sentence with all formatting options in the middle of the sentence.' )
176176 end
177177
178178 it 'should contain a paragraph with multiple text runs' do
181181
182182 it 'should detect normal formatting' do
183183 [ 0 , 4 ] . each do |i |
184- @formatting [ i ] [ 0 ] . should eq @default_formatting
185- @doc . paragraphs [ i ] . text_runs [ 0 ] . italicized? . should be_false
186- @doc . paragraphs [ i ] . text_runs [ 0 ] . bolded? . should be_false
187- @doc . paragraphs [ i ] . text_runs [ 0 ] . underlined? . should be_false
184+ expect ( @formatting [ i ] [ 0 ] ) . to eq ( @default_formatting )
185+ expect ( @doc . paragraphs [ i ] . text_runs [ 0 ] . italicized? ) . to eq ( false )
186+ expect ( @doc . paragraphs [ i ] . text_runs [ 0 ] . bolded? ) . to eq ( false )
187+ expect ( @doc . paragraphs [ i ] . text_runs [ 0 ] . underlined? ) . to eq ( false )
188188 end
189189 end
190190
191191 it 'should detect italic formatting' do
192- @formatting [ 1 ] [ 0 ] . should eq @only_italic
193- @doc . paragraphs [ 1 ] . text_runs [ 0 ] . italicized? . should be_true
194- @doc . paragraphs [ 1 ] . text_runs [ 0 ] . bolded? . should be_false
195- @doc . paragraphs [ 1 ] . text_runs [ 0 ] . underlined? . should be_false
192+ expect ( @formatting [ 1 ] [ 0 ] ) . to eq ( @only_italic )
193+ expect ( @doc . paragraphs [ 1 ] . text_runs [ 0 ] . italicized? ) . to eq ( true )
194+ expect ( @doc . paragraphs [ 1 ] . text_runs [ 0 ] . bolded? ) . to eq ( false )
195+ expect ( @doc . paragraphs [ 1 ] . text_runs [ 0 ] . underlined? ) . to eq ( false )
196196 end
197197
198198 it 'should detect bold formatting' do
199- @formatting [ 2 ] [ 0 ] . should eq @only_bold
200- @doc . paragraphs [ 2 ] . text_runs [ 0 ] . italicized? . should be_false
201- @doc . paragraphs [ 2 ] . text_runs [ 0 ] . bolded? . should be_true
202- @doc . paragraphs [ 2 ] . text_runs [ 0 ] . underlined? . should be_false
199+ expect ( @formatting [ 2 ] [ 0 ] ) . to eq ( @only_bold )
200+ expect ( @doc . paragraphs [ 2 ] . text_runs [ 0 ] . italicized? ) . to eq ( false )
201+ expect ( @doc . paragraphs [ 2 ] . text_runs [ 0 ] . bolded? ) . to eq ( true )
202+ expect ( @doc . paragraphs [ 2 ] . text_runs [ 0 ] . underlined? ) . to eq ( false )
203203 end
204204
205205 it 'should detect underline formatting' do
206- @formatting [ 3 ] [ 0 ] . should eq @only_underline
207- @doc . paragraphs [ 3 ] . text_runs [ 0 ] . italicized? . should be_false
208- @doc . paragraphs [ 3 ] . text_runs [ 0 ] . bolded? . should be_false
209- @doc . paragraphs [ 3 ] . text_runs [ 0 ] . underlined? . should be_true
206+ expect ( @formatting [ 3 ] [ 0 ] ) . to eq ( @only_underline )
207+ expect ( @doc . paragraphs [ 3 ] . text_runs [ 0 ] . italicized? ) . to eq ( false )
208+ expect ( @doc . paragraphs [ 3 ] . text_runs [ 0 ] . bolded? ) . to eq ( false )
209+ expect ( @doc . paragraphs [ 3 ] . text_runs [ 0 ] . underlined? ) . to eq ( true )
210210 end
211211
212212 it 'should detect mixed formatting' do
213- @formatting [ 5 ] [ 0 ] . should eq @default_formatting
214- @doc . paragraphs [ 5 ] . text_runs [ 0 ] . italicized? . should be_false
215- @doc . paragraphs [ 5 ] . text_runs [ 0 ] . bolded? . should be_false
216- @doc . paragraphs [ 5 ] . text_runs [ 0 ] . underlined? . should be_false
213+ expect ( @formatting [ 5 ] [ 0 ] ) . to eq ( @default_formatting )
214+ expect ( @doc . paragraphs [ 5 ] . text_runs [ 0 ] . italicized? ) . to eq ( false )
215+ expect ( @doc . paragraphs [ 5 ] . text_runs [ 0 ] . bolded? ) . to eq ( false )
216+ expect ( @doc . paragraphs [ 5 ] . text_runs [ 0 ] . underlined? ) . to eq ( false )
217217
218- @formatting [ 5 ] [ 1 ] . should eq @all_formatted
219- @doc . paragraphs [ 5 ] . text_runs [ 1 ] . italicized? . should be_true
220- @doc . paragraphs [ 5 ] . text_runs [ 1 ] . bolded? . should be_true
221- @doc . paragraphs [ 5 ] . text_runs [ 1 ] . underlined? . should be_true
218+ expect ( @formatting [ 5 ] [ 1 ] ) . to eq ( @all_formatted )
219+ expect ( @doc . paragraphs [ 5 ] . text_runs [ 1 ] . italicized? ) . to eq ( true )
220+ expect ( @doc . paragraphs [ 5 ] . text_runs [ 1 ] . bolded? ) . to eq ( true )
221+ expect ( @doc . paragraphs [ 5 ] . text_runs [ 1 ] . underlined? ) . to eq ( true )
222222
223- @formatting [ 5 ] [ 2 ] . should eq @default_formatting
224- @doc . paragraphs [ 5 ] . text_runs [ 2 ] . italicized? . should be_false
225- @doc . paragraphs [ 5 ] . text_runs [ 2 ] . bolded? . should be_false
226- @doc . paragraphs [ 5 ] . text_runs [ 2 ] . underlined? . should be_false
223+ expect ( @formatting [ 5 ] [ 2 ] ) . to eq ( @default_formatting )
224+ expect ( @doc . paragraphs [ 5 ] . text_runs [ 2 ] . italicized? ) . to eq ( false )
225+ expect ( @doc . paragraphs [ 5 ] . text_runs [ 2 ] . bolded? ) . to eq ( false )
226+ expect ( @doc . paragraphs [ 5 ] . text_runs [ 2 ] . underlined? ) . to eq ( false )
227227 end
228228 end
229229
236236 @new_doc_path = @fixtures_path + '/new_save.docx'
237237 @doc . save ( @new_doc_path )
238238 @new_doc = Docx ::Document . open ( @new_doc_path )
239- @new_doc . paragraphs . size . should eq @doc . paragraphs . size
239+ expect ( @new_doc . paragraphs . size ) . to eq ( @doc . paragraphs . size )
240240 end
241241
242242 it 'should save to a tempfile' do
243243 temp_file = Tempfile . new ( [ 'docx_gem' , '.docx' ] )
244244 @new_doc_path = temp_file . path
245245 @doc . save ( @new_doc_path )
246246 @new_doc = Docx ::Document . open ( @new_doc_path )
247- @new_doc . paragraphs . size . should eq @doc . paragraphs . size
247+ expect ( @new_doc . paragraphs . size ) . to eq ( @doc . paragraphs . size )
248248
249249 temp_file . close
250250 temp_file . unlink
251251 # ensure temp file has been removed
252- File . exists? ( @new_doc_path ) . should be_false
252+ expect ( File . exists? ( @new_doc_path ) ) . to eq ( false )
253253 end
254254
255255 after do
258258 end
259259 end
260260 end
261- end
261+ end
0 commit comments