Sha256: 5887c61d0c2fb3fda36cf97c827c326a2ec7b665aa8997dabbecc5e43a05b5d6

Contents?: true

Size: 925 Bytes

Versions: 25

Compression:

Stored size: 925 Bytes

Contents

Spec::Matchers.define(:find_with) do |find_options|
  extend Spec::Mocks::ExampleMethods
  
  match do |klass|
    selector, options = MongoModel::MongoOptions.new(klass, find_options).to_a
    
    result = mock('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

Spec::Matchers.define(:count_with) do |find_options|
  extend Spec::Mocks::ExampleMethods
  
  match do |klass|
    selector, options = MongoModel::MongoOptions.new(klass, find_options).to_a
    result = mock('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

25 entries across 25 versions & 1 rubygems

Version Path
mongomodel-0.3.3 spec/support/matchers/find_with.rb
mongomodel-0.3.2 spec/support/matchers/find_with.rb
mongomodel-0.3.1 spec/support/matchers/find_with.rb
mongomodel-0.3.0 spec/support/matchers/find_with.rb
mongomodel-0.2.20 spec/support/matchers/find_with.rb
mongomodel-0.2.19 spec/support/matchers/find_with.rb
mongomodel-0.2.18 spec/support/matchers/find_with.rb
mongomodel-0.2.17 spec/support/matchers/find_with.rb
mongomodel-0.2.16 spec/support/matchers/find_with.rb
mongomodel-0.2.15 spec/support/matchers/find_with.rb
mongomodel-0.2.14 spec/support/matchers/find_with.rb
mongomodel-0.2.13 spec/support/matchers/find_with.rb
mongomodel-0.2.12 spec/support/matchers/find_with.rb
mongomodel-0.2.11 spec/support/matchers/find_with.rb
mongomodel-0.2.10 spec/support/matchers/find_with.rb
mongomodel-0.2.9 spec/support/matchers/find_with.rb
mongomodel-0.2.8 spec/support/matchers/find_with.rb
mongomodel-0.2.7 spec/support/matchers/find_with.rb
mongomodel-0.2.6 spec/support/matchers/find_with.rb
mongomodel-0.2.5 spec/support/matchers/find_with.rb