Move helper methods away from tests setup to avoid redefinition on each test run
This commit is contained in:
parent
e5ef555f9f
commit
c6491461bc
@ -1,6 +1,22 @@
|
|||||||
require './test/test_helper'
|
require './test/test_helper'
|
||||||
include Mongo
|
include Mongo
|
||||||
|
|
||||||
|
def read_and_write_stream(filename, read_length, opts={})
|
||||||
|
io = File.open(File.join(File.dirname(__FILE__), 'data', filename), 'r')
|
||||||
|
id = @grid.put(io, opts.merge!(:filename => filename + read_length.to_s))
|
||||||
|
file = @grid.get(id)
|
||||||
|
io.rewind
|
||||||
|
data = io.read
|
||||||
|
if data.respond_to?(:force_encoding)
|
||||||
|
data.force_encoding("binary")
|
||||||
|
end
|
||||||
|
read_data = ""
|
||||||
|
while(chunk = file.read(read_length))
|
||||||
|
read_data << chunk
|
||||||
|
end
|
||||||
|
assert_equal data.length, read_data.length
|
||||||
|
end
|
||||||
|
|
||||||
class GridTest < Test::Unit::TestCase
|
class GridTest < Test::Unit::TestCase
|
||||||
context "Tests:" do
|
context "Tests:" do
|
||||||
setup do
|
setup do
|
||||||
@ -161,22 +177,6 @@ class GridTest < Test::Unit::TestCase
|
|||||||
|
|
||||||
context "Streaming: " do || {}
|
context "Streaming: " do || {}
|
||||||
setup do
|
setup do
|
||||||
def read_and_write_stream(filename, read_length, opts={})
|
|
||||||
io = File.open(File.join(File.dirname(__FILE__), 'data', filename), 'r')
|
|
||||||
id = @grid.put(io, opts.merge!(:filename => filename + read_length.to_s))
|
|
||||||
file = @grid.get(id)
|
|
||||||
io.rewind
|
|
||||||
data = io.read
|
|
||||||
if data.respond_to?(:force_encoding)
|
|
||||||
data.force_encoding("binary")
|
|
||||||
end
|
|
||||||
read_data = ""
|
|
||||||
while(chunk = file.read(read_length))
|
|
||||||
read_data << chunk
|
|
||||||
end
|
|
||||||
assert_equal data.length, read_data.length
|
|
||||||
end
|
|
||||||
|
|
||||||
@grid = Grid.new(@db, 'test-fs')
|
@grid = Grid.new(@db, 'test-fs')
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user