Sha256: 5ed191622edb2a198578ca09960d10189e6c2f7863c0c3998e728bb6dad647f3

Contents?: true

Size: 956 Bytes

Versions: 22

Compression:

Stored size: 956 Bytes

Contents

RSpec::Matchers.define :contain_tag do |klass|
  match do |collection|
    if @num.blank?
      collection.any? {|tag| tag.is_a? klass}
    else
      (@count = collection.count {|tag| tag.is_a? klass}) == @num
    end
  end

  def count(num)
    @num = num
    self
  end

  description do
    "contain #{@num || 'any'} instance(s) of #{klass.name}"
  end
  failure_message_for_should do |collection|
    "expected #{@num || 'any'} instance(s) of #{klass.name} but was #{@count}"
  end
end

RSpec::Matchers.define :contain_tag_old do |count|
  match do |collection|
    (@count = collection.count {|tag| tag.is_a? @klass}) == count
  end

  def instance_of(klass)
    @klass = klass
    self
  end
  alias :instances_of :instance_of

  description do
    "contain #{count || 'any'} instance(s) of #{@klass.name}"
  end
  failure_message_for_should do |collection|
    "expected #{count || 'any'} instance(s) of #{@klass.name} but was #{@count}"
  end
end

Version data entries

22 entries across 22 versions & 1 rubygems

Version Path
kaminari-0.9.12 spec/support/matchers.rb
kaminari-0.9.10 spec/support/matchers.rb
kaminari-0.9.9 spec/support/matchers.rb
kaminari-0.9.8 spec/support/matchers.rb
kaminari-0.9.7 spec/support/matchers.rb
kaminari-0.9.6 spec/support/matchers.rb
kaminari-0.9.5 spec/support/matchers.rb
kaminari-0.9.4 spec/support/matchers.rb
kaminari-0.9.3 spec/support/matchers.rb
kaminari-0.9.2 spec/support/matchers.rb
kaminari-0.9.1 spec/support/matchers.rb
kaminari-0.9.0 spec/support/matchers.rb
kaminari-0.8.0 spec/support/matchers.rb
kaminari-0.7.0 spec/support/matchers.rb
kaminari-0.6.1 spec/support/matchers.rb
kaminari-0.6.0 spec/support/matchers.rb
kaminari-0.5.0 spec/support/matchers.rb
kaminari-0.4.0 spec/support/matchers.rb
kaminari-0.3.0 spec/support/matchers.rb
kaminari-0.2.1 spec/support/matchers.rb