Sha256: 38de3df39a2a216e28f7015ae8c556878e8656df2c71d969010e3315d00e0261

Contents?: true

Size: 1.12 KB

Versions: 8

Compression:

Stored size: 1.12 KB

Contents

module TestingHelpers
  def add_stubs(target, atts = {})
    target = create(target.to_sym) if target.is_a? Symbol

    target.tap do |it|
      klass = [Class, Module].include?(target.class) ? target : target.class
      atts.each do |(attr, v)|
        allow_any_instance_of(klass).to receive(attr.to_sym) { v }
      end
    end
  end

  def current_order_stubs(order)
    allow_any_instance_of(Spree::CheckoutController).to receive_messages(current_order: order)
    allow_any_instance_of(Spree::OrdersController).to receive_messages(current_order: order)
  end

  # Builds a regex matcher for script tag contents
  # @param tag_name [String] Value of script's data-tag attribute
  # @param matches [Array] Keywords that must appear in script contents (order matters!)
  # @return [Object] Returns a capybara matcher for a script tag with specific attributes and contents
  def track_analytics_event(tag_name, event_name, matches)
    matches = matches.flatten.map {|v| Regexp.escape(v.to_s) }.join('.+')
    have_selector :css, "script[data-tag=#{tag_name}][data-fired-events=#{event_name}]", visible: false, text: /#{matches}/i
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
solidus_seo-1.1.2 spec/support/testing_helpers.rb
solidus_seo-1.1.1 spec/support/testing_helpers.rb
solidus_seo-1.1.0 spec/support/testing_helpers.rb
solidus_seo-1.0.13 spec/support/testing_helpers.rb
solidus_seo-1.0.12 spec/support/testing_helpers.rb
solidus_seo-1.0.11 spec/support/testing_helpers.rb
solidus_seo-1.0.10 spec/support/testing_helpers.rb
solidus_seo-1.0.8 spec/support/testing_helpers.rb