diff options
| author | Dan Allen <dan.j.allen@gmail.com> | 2017-07-01 16:21:04 -0600 |
|---|---|---|
| committer | Dan Allen <dan.j.allen@gmail.com> | 2017-07-01 16:21:04 -0600 |
| commit | 161a5fe068152b8fdb99caa98824c56a0051b73e (patch) | |
| tree | bd8e32d4d7b6248aa18f8efa70b20e738c24fe7b | |
| parent | 8827261a8b2c0ca5afe24691a2c8c64186d92a2f (diff) | |
rework cucumber step definitions
- add support for contains matcher
- consolidate code
- use expect instead of should
- add space before end of short XML tag
| -rw-r--r-- | features/step_definitions.rb | 28 |
1 files changed, 12 insertions, 16 deletions
diff --git a/features/step_definitions.rb b/features/step_definitions.rb index 6b977115..a843aae1 100644 --- a/features/step_definitions.rb +++ b/features/step_definitions.rb @@ -29,25 +29,21 @@ When /it is converted to docbook/ do @output = Asciidoctor.convert @source, :backend => :docbook end -Then /the result should match the (HTML|XML) source/ do |format, expect| - @output.should == expect +Then /the result should (match|contain) the (HTML|XML) source/ do |matcher, format, expected| + match_expectation = matcher == 'match' ? (eq expected) : (include expected) + (expect @output).to match_expectation end -Then /the result should match the (HTML|XML) structure/ do |format, expect| - case format - when 'HTML' +Then /the result should (match|contain) the (HTML|XML) structure/ do |matcher, format, expected| + result = @output + if format == 'HTML' options = { :format => :html, :disable_escape => true, :sort_attrs => false } - when 'XML' + else # format == 'XML' options = { :format => :xhtml, :disable_escape => true, :sort_attrs => false } - else - options = {} + result = result.gsub '"/>', '" />' if result.include? '"/>' end - slim_friendly_output = @output.each_line.map {|line| - if line.start_with? '<' - line - else - %(|#{line}) - end - }.join - Slim::Template.new(options) { slim_friendly_output }.render.should == Slim::Template.new(options) { expect }.render + result = Slim::Template.new(options) { result.each_line.map {|l| (l.start_with? '<') ? l : %(|#{l}) }.join }.render + expected = Slim::Template.new(options) { expected }.render + match_expectation = matcher == 'match' ? (eq expected) : (include expected) + (expect result).to match_expectation end |
