Sha256: 45156e8decde5895cfbb35a672b07432e9ff3c7e7c150d232437998f5181e6f2

Contents?: true

Size: 933 Bytes

Versions: 6

Compression:

Stored size: 933 Bytes

Contents

RSpec::Matchers.define(:find_with) do |find_options|
  extend RSpec::Mocks::ExampleMethods
  
  match do |klass|
    selector, options = MongoModel::MongoOptions.new(klass, find_options).to_a
    
    result = double('find result', :to_a => (@result || []).map { |d| d.to_mongo })
    klass.collection.should_receive(:find).once.with(selector, options).and_return(result)
    
    true
  end
  
  def and_return(result)
    @result = result
    self
  end
end

RSpec::Matchers.define(:count_with) do |find_options|
  extend RSpec::Mocks::ExampleMethods
  
  match do |klass|
    selector, options = MongoModel::MongoOptions.new(klass, find_options).to_a
    result = double('find result')
    
    klass.collection.should_receive(:find).once.with(selector, options).and_return(result)
    result.should_receive(:count).once.and_return(@count || 5)
    
    true
  end
  
  def and_return(count)
    @count = count
    self
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
mongomodel-0.5.5 spec/support/matchers/find_with.rb
mongomodel-0.5.4 spec/support/matchers/find_with.rb
mongomodel-0.5.3 spec/support/matchers/find_with.rb
mongomodel-0.5.2 spec/support/matchers/find_with.rb
mongomodel-0.5.1 spec/support/matchers/find_with.rb
mongomodel-0.5.0 spec/support/matchers/find_with.rb