Created by Ted Winslow / Github: deltreey
Automated Software Testing
Run all the code
Run from the tested code all the way down the stack
and segments of code in the middle of the stack
Run only the code under test (one method or function)
There need to be a bunch of these.
You build them when stuff doesn't work.
should('Write files to S3 when the user clicks save') do
# Given: the user has some files to save
file_path = 'test'
user_files = [{
name: file_path,
data: 'data'
}]
visit 'pages/s3'
page.files = user_files
# When: the user clicks save and we check S3
page.button({ id: 'save' }).click
s3 = S3.new
result = s3.read(file_path)
# Then: we should see the files are on S3
assert_false(result == nil)
end
should('result in the S3 bucket files being read in chunks based ' +
'on the selected chunk size, ignoring empty files') do
# Given: a file on S3 with more than 5 bytes of data
# and less than 10 bytes, a file on S3 with no data,
# and an S3Implementation object with the chunk size set to 5 bytes
s3 = S3.new
file_path = 'test'
s3.write(file_path + "/data", 'some data')
s3.write(file_path + "/nodata", '')
s3_implementation = S3Implementation.new(file_path)
s3_implementation.chunk_size = 5
# When: we iterate over the data with the s3_implementation object
count = 0
s3_implementation.each do |chunk|
count += 1
end
# Then: we should see 2 chunks: 2 for the file with more than 5 bytes,
# and none for the empty file
assert_equal(2, count)
end
should('set s3 chunk_size property') do
# Given: a value to set the chunk_size to and an S3Implementation
chunk_size = 9000
s3_implementation = S3Implementation.new('test')
# When: we set the chunk size to the new value
s3_implementation.chunk_size = chunk_size
# We should see that the S3 base object has the new chunk size
assert_equal chunk_size, s3_implementation.send(:s3).chunk_size
end
[1] http://eedevsln.com/test-goodbadugly/index.html