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 / flexible-matching.rb
Last active Jan 1, 2016
An idea of what a flexible matching fluent API might look like, and how it could be serialised.
View flexible-matching.rb
# Notes:
# Headers and status would still be value based matching
# Default to type based matching???
# like(xxx) means xxx and all children would be matched using type based matching
# literal(xxx) means xxx and all children would be matched using exact value matching
# eg(generate, matcher) would be a regular expression match
# each_like([]) would indicate the each element in the array should be like the example given
# A like() could be nested inside a literal() which could be nested inside a like() - at each stage,
# it changes the matching type for all children until it gets switched back.
bethesque /
Last active Jan 1, 2016
Thoughts on flexible matching for Pact

Assumptions based on experience with pacts so for:

  • The most common type of matching that is useful is asserting that:
    • The expected keys are present
    • The values at the actual keys are of the same class (string/number/nil) as the expected values
    • Occasionally we'll want a literal match
    • Occasionally we'll want a regular expresssion
    • Extra keys in a hash are OK for responses but not for requests (following the "be strict with what you send out, be lax with what you accept" principle)
    • Extra items in an array are debatable (extra keys in a hash are generally ignored, however, all items in an array are generally processed, so allowing "unverified" extras to sneak in could be a bad thing. Working out what to do with "extras" is not immediately obvious to me however.)
bethesque / gist:9385794
Created Mar 6, 2014
Naming conventions in Ruby
View gist:9385794
def method_names_are_like_this
module Things
class UserThing
bethesque / gist:69ae590e8312523e5337
Last active Aug 29, 2015
Thoughts on verifying that mocked models are actually valid
View gist:69ae590e8312523e5337

It's about ensuring the model used to stub client responses can actually be produced by the response you expect. Imagine your client returns a model like so:

class MyModel
   attr_reader :timestamp
   def initialize attrs
      @timestamp = attr[:timestamp]
bethesque / preload-interactions.rb
Last active Aug 29, 2015
Server with preloaded interactions
View preload-interactions.rb
# $ pact service -p 8080
# (new window)
# $ ruby preload-interactions.rb
# $ curl localhost:8080/path_one #Yay all good!
# $ curl localhost:8080/path_two #Boo... which response do we want???
require 'json'
require 'net/http'
require 'pact/consumer/consumer_contract_builder'
require 'pact/consumer_contract'
bethesque / idea.rb
Last active Aug 29, 2015
Using pact for Capybara tests and unit tests
View idea.rb
class InternalProviderClient
def thing
#get a thing from the internal provider
# pact_helper
Pact.configure do | config |
config.pactfile_write_mode = :update
bethesque /
Last active Jul 10, 2018
HTTP requests to ruby mock server
You will need ruby or the standalone mock service to run these examples.
$ gem install pact-mock_service
bethesque /
Last active Aug 29, 2015
Idea for FixturePact

Pact is great for HTTP microservices that communicate directly with each other, but many services use an intermediate system that acts as a pipe (eg. a queue, S3 bucket). The agreement about the format of the message is really between the two ends of the chain, not between the links immediatly adjacent.

The pact concept should be able to be applied to non-http services. The code below is an attempt to come up with a DSL for a new pact library that uses the same pact matching concepts, but does not constrain the communication protocol.

Thoughts/improvements appreciated, but remember Gists do not send notifications when you post a comment :|

bethesque /
Last active Aug 29, 2015
A quick start guide to Webmachine


  • Override resource_exists?, content_types_provided, allowed_methods, and implement the method to render the resource.
class OrderResource < Webmachine::Resource
  def allowed_methods
  def content_types_provided
You can’t perform that action at this time.