forked from sandrods/odf-report
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfields_spec.rb
77 lines (46 loc) · 1.66 KB
/
fields_spec.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
RSpec.describe "Fields" do
before(:context) do
@field_01 = Faker::Company.name
@field_02 = Faker::Name.name
@itens_01 = Item.get_list(3)
report = ODFReport::Report.new("spec/templates/specs.odt") do |r|
r.add_field(:field_01, @field_01)
r.add_field(:field_02, @field_02)
r.add_table('TABLE_01', @itens_01) do |t|
t.add_column(:column_01, :id)
t.add_column(:column_02, :name)
end
r.add_section('SECTION_01', @itens_01) do |t|
t.add_field(:s01_field_01, :id)
t.add_field(:s01_field_02, :name)
end
end
report.generate("spec/result/specs.odt")
@data = Inspector.new("spec/result/specs.odt")
end
it "simple fields replacement" do
expect(@data.text).not_to match(/\[FIELD_01\]/)
expect(@data.text).not_to match(/\[FIELD_02\]/)
expect(@data.text).to match @field_01
expect(@data.text).to match @field_02
end
it "table columns replacement" do
table = @data.xml.xpath(".//table:table[@table:name='TABLE_01']").to_s
@itens_01.each do |item|
expect(table).not_to match(/\[COLUMN_01\]/)
expect(table).not_to match(/\[COLUMN_02\]/)
expect(table).to match(/\[COLUMN_03\]/)
expect(table).to match(item.id.to_s)
expect(table).to match(item.name)
end
end
it "section fields replacement" do
expect(@data.text).not_to match(/\[S01_FIELD_01\]/)
expect(@data.text).not_to match(/\[S01_FIELD_02\]/)
@itens_01.each_with_index do |item, idx|
section = @data.xml.at_xpath(".//text:section[#{idx+1}]").to_s
expect(section).to match(item.id.to_s)
expect(section).to match(item.name)
end
end
end