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 / 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
@bethesque
bethesque / example.rb
Created October 9, 2014 23:45
How to do a multipart updatable date with Reform
require 'date'
class Applicant
attr_accessor :date
end
applicant = Applicant.new
applicant.date = Date.new(2014, 10, 13)
require 'reform'
@bethesque
bethesque / documentation.md
Last active August 29, 2015 14:06
A quick start guide to Webmachine

GET

  • Override resource_exists?, content_types_provided, allowed_methods, and implement the method to render the resource.
class OrderResource < Webmachine::Resource
  def allowed_methods
    ["GET"]
  end
  
 def content_types_provided