Sha256: 9ad83420a39bf301b37198c549359b51aedc3ddfc236170d569df3da3097d29e

Contents?: true

Size: 1.33 KB

Versions: 68

Compression:

Stored size: 1.33 KB

Contents

RSpec::Matchers.define :match_url do |url|
  match do |given|
    given_path, given_query_string = given.split('?')
    path, query_string = url.split('?')

    path == given_path && given_query_string.split('&').sort == query_string.split('&').sort
  end
end

RSpec::Matchers.define :be_an_empty_directory do
  match do |given|
    Dir.entries(given) == ['.','..']
  end
end

RSpec::Matchers.define :include_hash do |hash|
  match do |given|
    given.merge(hash) == given
  end
end

def memory_usage
  GC.start # Garbage collect
  `ps -o rss= -p #{$$}`.strip.to_i
end

RSpec::Matchers.define :leak_memory do
  match do |given|
    memory_before = memory_usage
    given.call
    memory_after = memory_usage
    result = memory_after > memory_before
    puts "#{memory_after} > #{memory_before}" if result
    result
  end
end

RSpec::Matchers.define :match_attachment_classes do |classes|
  match do |given_classes|
    given_classes.length == classes.length &&
      classes.zip(given_classes).all? do |(klass, given)|
        given.model_class == klass[0] && given.attribute == klass[1] && given.app == klass[2]
      end
  end
end

RSpec::Matchers.define :be_a_text_response do
  match do |given_response|
    given_response.status.should == 200
    given_response.body.length.should > 0
    given_response.content_type.should == 'text/plain'
  end
end

Version data entries

68 entries across 68 versions & 4 rubygems

Version Path
classiccms-0.7.5 vendor/bundle/gems/dragonfly-0.9.12/spec/support/simple_matchers.rb
classiccms-0.7.4 vendor/bundle/gems/dragonfly-0.9.12/spec/support/simple_matchers.rb
classiccms-0.7.3 vendor/bundle/gems/dragonfly-0.9.12/spec/support/simple_matchers.rb
image_resizer-0.5.1 spec/support/simple_matchers.rb
classiccms-0.7.2 vendor/bundle/gems/dragonfly-0.9.12/spec/support/simple_matchers.rb
classiccms-0.7.1 vendor/bundle/gems/dragonfly-0.9.12/spec/support/simple_matchers.rb
classiccms-0.7.0 vendor/bundle/gems/dragonfly-0.9.12/spec/support/simple_matchers.rb
dragonfly-0.9.15 spec/support/simple_matchers.rb
image_resizer-0.5.0 spec/support/simple_matchers.rb
image_resizer-0.4.0 spec/support/simple_matchers.rb
dragonfly-0.9.14 spec/support/simple_matchers.rb
dragonfly-0.9.13 spec/support/simple_matchers.rb
classiccms-0.6.9 vendor/bundle/gems/dragonfly-0.9.12/spec/support/simple_matchers.rb
classiccms-0.6.8 vendor/bundle/gems/dragonfly-0.9.12/spec/support/simple_matchers.rb
classiccms-0.6.7 vendor/bundle/gems/dragonfly-0.9.12/spec/support/simple_matchers.rb
classiccms-0.6.6 vendor/bundle/gems/dragonfly-0.9.12/spec/support/simple_matchers.rb
classiccms-0.6.5 vendor/bundle/gems/dragonfly-0.9.12/spec/support/simple_matchers.rb
classiccms-0.6.4 vendor/bundle/gems/dragonfly-0.9.12/spec/support/simple_matchers.rb
classiccms-0.6.3 vendor/bundle/gems/dragonfly-0.9.12/spec/support/simple_matchers.rb
classiccms-0.6.2 vendor/bundle/gems/dragonfly-0.9.12/spec/support/simple_matchers.rb