Skip to content

Instantly share code, notes, and snippets.

View bethesque's full-sized avatar
💭
Intermittently coding

Beth Skurrie bethesque

💭
Intermittently coding
View GitHub Profile
@bethesque
bethesque / task.rb
Created April 21, 2015 23:21
Ordered provider verification
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 August 29, 2015 14:17
Using Github oauth with the pact broker
# 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 August 29, 2015 14:16
An appropach to writing tests

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 / idea.md
Created February 13, 2015 00:51
Using mocked interactions from pact unit tests for stubbing in integration tests

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 August 29, 2015 14:10
I don't know what the name of this pattern is but I've been using it a lot recently and I like it
class Action
def self.call parameter
new(parameter).call
end
def initialize parameter
@parameter = parameter
end
@bethesque
bethesque / reform.rb
Last active August 29, 2015 14:10
Reform writeable:false behaviour not the same as virtual: true
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 November 27, 2014 21:19
Modifying headers before replaying request using Pact
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 November 26, 2014 21:06
Using Representable to convert one hash to another hash without having to create intermediate classes
require 'representable'
require 'representable/json'
require 'ostruct'
require 'json'
require 'hashie'
json = {
person: {
name: 'Beth',
surname: 'Someone'
@bethesque
bethesque / echoHttpRequest.js
Last active August 29, 2015 14:10 — forked from Marak/echoHttpRequest.js
Echo HTTP requests
module['exports'] = function echoHttp (hook) {
hook.debug("Debug messages are sent to the debug console");
hook.debug(hook.params);
hook.debug(hook.req.path);
hook.debug(hook.req.method);
@bethesque
bethesque / document.rb
Last active August 29, 2015 14:09
Pact Broker document
PactBroker::Client::PacticipantDocumentationTask.new do | pacticipant |
pacticipant.repository git: 'git@github.com/bethesque/some-consumer'
pacticipant.doc 'http://github.com/bethesque/some-consumer'
end