spec/support/crud.rb in mongo-2.9.2 vs spec/support/crud.rb in mongo-2.10.0.rc0

- old
+ new

@@ -13,17 +13,21 @@ # limitations under the License. require 'support/gridfs' require 'support/crud/requirement' require 'support/crud/spec' +require 'support/crud/test_base' require 'support/crud/test' require 'support/crud/outcome' +require 'support/crud/context' require 'support/crud/operation' -require 'support/crud/read' -require 'support/crud/write' require 'support/crud/verifier' +def collection_data(collection) + collection.find.to_a +end + def crud_execute_operations(spec, test, num_ops, event_subscriber, expect_error, client ) cache_key = "#{test.object_id}:#{num_ops}" $crud_result_cache ||= {} @@ -40,25 +44,25 @@ event_subscriber.clear_events! result = if expect_error.nil? res = nil begin - res = test.run(spec, client, num_ops) + res = test.run(client, num_ops) rescue => e res = e end res elsif expect_error error = nil begin - test.run(spec, client, num_ops) + test.run(client, num_ops) rescue => e error = e end error else - test.run(spec, client, num_ops) + test.run(client, num_ops) end $crud_event_cache ||= {} # It only makes sense to assert on events if all operations succeeded, # but populate our cache in any event for simplicity @@ -66,11 +70,11 @@ last_op = test.operations[num_ops-1] if last_op.outcome && last_op.outcome.collection_data? verify_collection = client[last_op.verify_collection_name] $crud_collection_data_cache ||= {} - $crud_collection_data_cache[cache_key] = verify_collection.find.to_a + $crud_collection_data_cache[cache_key] = collection_data(verify_collection) end result ensure test.clear_fail_point(client) @@ -134,11 +138,11 @@ tested = true it 'has the correct data in the collection' do result verifier.verify_collection_data( operation.outcome.collection_data, - verify_collection.find.to_a) + collection_data(verify_collection)) end end unless tested it 'succeeds' do @@ -171,10 +175,24 @@ verifier.verify_command_started_event( test.expectations, actual_events, i) end end end + + if test.outcome && test.outcome.collection_data? + let(:result) do + crud_execute_operations(spec, test, test.operations.length, + event_subscriber, nil, client) + end + + it 'has the correct data in the collection' do + result + verifier.verify_collection_data( + test.outcome.collection_data, + collection_data(client[test.outcome.collection_name || spec.collection_name])) + end + end end end end def define_spec_tests_with_requirements(spec, &block) @@ -201,20 +219,17 @@ else yield end end -def define_crud_spec_tests(description, test_paths, &block) - describe(description) do +def define_crud_spec_tests(test_paths, spec_cls = Mongo::CRUD::Spec, &block) + test_paths.each do |path| - test_paths.each do |path| + spec = spec_cls.new(path) - spec = Mongo::CRUD::Spec.new(path) - - context(spec.description) do - define_spec_tests_with_requirements(spec) do |req| - define_crud_spec_test_examples(spec, req, &block) - end + context(spec.description) do + define_spec_tests_with_requirements(spec) do |req| + define_crud_spec_test_examples(spec, req, &block) end end end end