diff options
| author | Teddy Wing | 2017-06-08 18:13:12 +0200 |
|---|---|---|
| committer | Teddy Wing | 2017-06-08 18:13:12 +0200 |
| commit | 7319d9d1324db3da7da4ed441594aa5d05c1feec (patch) | |
| tree | aea309b319f8f4ca8092da323d50d6e2fc29f1b6 | |
| parent | 5d9ed9d90ada31f9ee895111613d970473981096 (diff) | |
| download | chouette-core-7319d9d1324db3da7da4ed441594aa5d05c1feec.tar.bz2 | |
TableBuilder spec: Beautify actual HTML result
In order to allow us to easily compare the HTML result with the expected
value, beautify the HTML that comes out of the helper call.
Otherwise, all the HTML is on a single line, and it can't be compared
with RSpec's diff output (even if RSpec outputted the entire contents of
the single line, we wouldn't really be able to compare it).
Thanks to this post for describing an easy way to get HTML
beautification:
https://stackoverflow.com/questions/5622269/how-to-beautify-xml-code-in-rails-application
We need to run the expected HTML string through the beautifier so we can
get the formatting right, but otherwise this gives us a better base for
test diffing.
Refs #3479
| -rw-r--r-- | spec/helpers/table_builder_helper_spec.rb | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/spec/helpers/table_builder_helper_spec.rb b/spec/helpers/table_builder_helper_spec.rb index b1c2b9a3f..5945b0f82 100644 --- a/spec/helpers/table_builder_helper_spec.rb +++ b/spec/helpers/table_builder_helper_spec.rb @@ -109,9 +109,7 @@ describe TableBuilderHelper, type: :helper do # </ul><span class="info-msg"><span>0</span> élément(s) sélectionné(s)</span> # </div> - minified_expected = expected.gsub(/^\s+/, '').gsub("\n", '') - - expect(helper.table_builder_2( + html_str = helper.table_builder_2( referentials, { :name => 'name', :status => Proc.new {|w| w.archived? ? ("<div class='td-block'><span class='fa fa-archive'></span><span>Conservé</span></div>").html_safe : ("<div class='td-block'><span class='sb sb-lg sb-preparing'></span><span>En préparation</span></div>").html_safe}, @@ -124,7 +122,11 @@ describe TableBuilderHelper, type: :helper do :published_at => ''}, links: [:show, :edit, :archive, :unarchive, :delete], cls: 'table has-filter has-search' - )).to eq(minified_expected) + ) + beautified_html = '' + REXML::Document.new(html_str).write(beautified_html, 4) + + expect(beautified_html).to eq(expected) end end end |
