Skip to content

Instantly share code, notes, and snippets.

💭
Currently in the garden. Will be back in (Australian) Winter.

Beth Skurrie bethesque

💭
Currently in the garden. Will be back in (Australian) Winter.
Block or report user

Report or block bethesque

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@bethesque
bethesque / Gemfile
Last active Aug 29, 2015
Write a pact without a consumer
View Gemfile
source 'https://rubygems.org'
gem 'pact', '~>1.7.0'
@bethesque
bethesque / task.rb
Created Apr 21, 2015
Ordered provider verification
View task.rb
require 'pact/provider/proxy/tasks'
Pact::ProxyVerificationTask.new :userapi_service do | task |
task.pact_url './spec/pacts/userapi_service_consumer-userapi_service_provider.json'
task.provider_base_url 'https://userapi.com/'
end
Pact::ProxyVerificationTask.new :otherapi_service do | task |
task.pact_url './spec/pacts/otherapi_service_consumer-otherapi_service_provider.json'
task.provider_base_url 'https://otherapi.com'
@bethesque
bethesque / config.ru
Last active Aug 29, 2015
Using Github oauth with the pact broker
View config.ru
# gem "omniauth-github"
# gem "rack-rewrite"
require 'fileutils'
require 'logger'
require 'sequel'
require 'pact_broker'
require 'omniauth/strategies/github'
require 'rack/rewrite'
@bethesque
bethesque / testing.md
Last active Aug 29, 2015
An appropach to writing tests
View testing.md

Our tests should:

  1. Assure us that the code is behaving correctly.
  2. Allow us to refactor with confidence.
  3. Help us write more maintainable code.

A process to help you write tests that achieve these goals

  1. Choose the part of the code you want to test (a class, a group of classes, the full end to end stack). For functional tests, try and pick a group that is at the same "level", or that achieve an isolated unit of work that makes sense as a standalone function.
  2. Draw a mental box around the classes that will be in the test. Everything inside that box should be able to be completely refactored (methods renamed, classes renamed, code moved around) without breaking this test. Only mock or stub or test calls to things at the edges of the box.
@bethesque
bethesque / hipster-batch-in-ruby.md
Last active May 2, 2016
A way to write a hipster batch microservice in Ruby
View hipster-batch-in-ruby.md
  1. Identify the steps in the high level process

    eg.

    • Step 1: Download CSV files from box
    • Step 2: Convert CSV to JSON
    • Step 3: Upload JSON and CSV files to S3
  2. Create modules for each of those steps. In our use case, the top level process matches a pattern called "ETL" or "Extract, Transform, Load", so we used those names.

@bethesque
bethesque / idea.md
Created Feb 13, 2015
Using mocked interactions from pact unit tests for stubbing in integration tests
View idea.md

An idea: Set up an interaction for a unit test (using strict, exact matching), but specify that it can be used for stubbing in a later test, and specify the route that it should be matched against (with optional tags?). The Mock Server would write these interactions to a separate file, or add metadata to them in the normal pact file. Then, during an integration test, interactions can be loaded and will act as stubs using "type based" matching (something_like).

This means that our stubs will be verified as well as our mocks.

@bethesque
bethesque / example.rb
Last active Aug 29, 2015
I don't know what the name of this pattern is but I've been using it a lot recently and I like it
View example.rb
class Action
def self.call parameter
new(parameter).call
end
def initialize parameter
@parameter = parameter
end
@bethesque
bethesque / reform.rb
Last active Aug 29, 2015
Reform writeable:false behaviour not the same as virtual: true
View reform.rb
require 'minitest/autorun'
require 'date'
require 'reform' # 1.2.2
Person = Struct.new(:date_of_birth)
class DateForm < Reform::Form
property :day
property :month
property :year
@bethesque
bethesque / spike.rb
Created Nov 27, 2014
Modifying headers before replaying request using Pact
View spike.rb
class ProxyApp
def initialize real_app
@real_app = real_app
end
def call env
@real_app.call(env.merge('HTTP_AUTHORIZATION' => '12345'))
end
end
@bethesque
bethesque / example.rb
Created Nov 26, 2014
Using Representable to convert one hash to another hash without having to create intermediate classes
View example.rb
require 'representable'
require 'representable/json'
require 'ostruct'
require 'json'
require 'hashie'
json = {
person: {
name: 'Beth',
surname: 'Someone'
You can’t perform that action at this time.