Skip to content
View writing-great-tests-consistently.md

Title

How to Start Writing Great Tests—Consistently!

Abstract

Your app is a unique snowflake. Your tests are too… but they shouldn't be!

Years helping teams write better tests has taught me one thing: consistency is crucial. Inconsistent tests slow teams down, wasting time to understand how each test works. Deciding on conventions—even arbitrary ones—can prevent tremendous pain later.

This talk will introduce a ready-to-fork Test Style Guide of carefully-considered rules and templates for Rubyists. You can customize it to fit your preferred tools, too. Soon, you'll be on your way to having more consistent tests that are much more fun to maintain!

View gist:65352c95199e5b51c94f
common:
phoenix_mode: true #default to false
environments:
dev:
phoenix_mode: false # turn off for dev env for faster deployment
strategy: inplace-update # default strategy: blue-green
option_settings:
- namespace: aws:elb:loadbalancer
option_name: SSLCertificateId
View gist:a930b41e5058b9076837
components:
- name: bg
strategy: inplace-update
option_settings:
- namespace: aws:autoscaling:asg
option_name: MinSize
value: "1"
- namespace: aws:autoscaling:asg
option_name: MaxSize
value: "1"
View s3-multipart-upload-example-step2.yaml
resources:
template: config/aws_resources.json
capabilities:
- CAPABILITY_IAM
inputs:
DBPassword: <%= ENV.fetch('AWSRESOURCES_DBPassword') %>
outputs:
S3UploadAccessKeyId:
namespace: aws:elasticbeanstalk:application:environment
option_name: S3_MULTIPART_UPLOAD_ACCESS_KEY_ID
View s3-multipart-upload-example-step1.json
"S3UploadUser" : {
"Type" : "AWS::IAM::User",
"Properties" : {
"Path" : "/",
"Policies" : [ {
"PolicyName" : "S3MultipartUpload",
"PolicyDocument" : {
"Version": "2012-10-17",
"Statement" : [ {
"Effect" : "Allow",
View s3-multipart-upload-example-step5.rb
# in a Rails controller action
string_to_sign = params["to_sign"]
encoded = Base64.encode64(
OpenSSL::HMAC.digest(
OpenSSL::Digest::Digest.new("sha1"),
ENV["S3_MULTIPART_UPLOAD_SECRET_ACCESS_KEY"],
string_to_sign)).gsub("\n","")
render :text => encoded, :status => 200
View s3-multipart-upload-example-step4.js
// need jQuery and EvaporateJS
var config = $("[data-signer-url]");
var _e_ = new Evaporate({
signerUrl: config.data("signer-url"),
bucket: config.data("bucket"),
aws_key: config.data("aws-id")
});
var configuration = {
name: config.data("key"),
// see EvaporateJS document for other configurations need setup here
View s3-multipart-upload-example-step3.rb
bucket = <s3 bucket name>
s3key = <s3 file key> # use a random uniq key
{
"data-aws-id" => ENV["S3_MULTIPART_UPLOAD_ACCESS_KEY_ID"],
"data-bucket" => bucket,
"data-key" => s3key,
"data-signer-url" => <your-data-signer-url>
}
View s3 multipart upload temp credentials.rb
# aws-ruby-sdk v1 API
def s3_multipart_upload_credentials(bucket, key, role_arn)
sts = AWS::STS.new
policy = AWS::STS::Policy.new
policy.allow(:actions => ["s3:PutObject",
"s3:GetObject",
"s3:AbortMultipartUpload",
"s3:ListMultipartUploadParts",
"s3:ListBucketMultipartUploads"],
:resources => "arn:aws:s3:::#{[bucket,key].join('/')}")
View gist:dc9b857be8814d598669
export PATH=$PATH:~/Downloads/IAMCli-1.5.0/bin
export AWS_IAM_HOME=~/Downloads/IAMCli-1.5.0
iam-servercertupload --aws-credential-file <credential.csv> -s <sname> -b <ssl.crt.txt> -k <ssl.key.txt> -c intermediate.crt.txt -p /cloudfront/<sname>/
Something went wrong with that request. Please try again.