Sha256: 5e160f01d9bed435bf235eec9640fbd99795efeaac7e20ece5701a8bd4381404

Contents?: true

Size: 1.81 KB

Versions: 3

Compression:

Stored size: 1.81 KB

Contents

RSpec::Matchers.define :generate do |html|
  match do |helper, options = nil|
    if helper.is_a?(Hash)
      helper, options = helper.keys.first, helper.values.first
    end

    if helper == :link_to && options == :nil_name
      @inline = bh.send helper, nil, '/'
      @block = @inline
    elsif helper == :link_to && options == :xss_script
      @inline = bh.send helper, '<script>alert("xss")</script>', '/'
      @block = bh.send(helper, '/') { '<script>alert("xss")</script>' }
    elsif helper == :link_to && options == :safe_html
      @inline = bh.send helper, bh.tag(:hr), '/'
      @block = bh.send(helper, '/') { bh.tag(:hr) }
    elsif helper == :link_to || helper == :button_to
      @inline = bh.send helper, *['content', '/', options].compact
      if bh.test_button_to_with_block
        @block = bh.send(helper, *['/', options].compact) { 'content' }
      else
        @block = @inline
      end
    elsif helper == :dropdown
      @block = bh.send(helper, *['caption', options].compact) { 'content' }
      @inline = @block
    elsif helper == :glyphicon || helper == :icon
      @inline = bh.send helper, *['zoom-in', options].compact
      @block = bh.send helper, *[:zoom_in, options].compact
    elsif helper == :progress_bar
      @inline = bh.send helper, *Array.wrap(options)
      @block = @inline
    elsif helper == :navbar || helper == :nav || helper == :panel_row
      @block = bh.send(helper, *[options].compact) { 'content' }
      @inline = @block
    else
      @inline = bh.send helper, *['content', options].compact
      @block = bh.send(helper, *[options].compact) { 'content' }
    end

    case html
      when Regexp then @inline.match(html) && @block.match(html)
      else @inline.eql?(html) && @block.eql?(html)
    end
  end

  failure_message{|actual| "expected #{html}, got #{@inline} and #{@block}"}
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
bh-1.3.6 spec/support/matchers.rb
bh-1.3.5 spec/support/matchers.rb
bh-1.3.4 spec/support/matchers.rb