Skip to content

Instantly share code, notes, and snippets.

@bobthemighty
Last active August 29, 2015 14:14
Show Gist options
  • Save bobthemighty/921a89da42e12b09d965 to your computer and use it in GitHub Desktop.
Save bobthemighty/921a89da42e12b09d965 to your computer and use it in GitHub Desktop.
will_respond_with(
{
status: 200,
headers: {
'Content-Type': 'application/atom+xml'
},
schema: {
# this is the document we expect the mock server to return.
example: '<atom:entry>
<atom:title>Atom-Powered Robots Run Amok</atom:title>
<atom:link rel="self" href="http://example.org/2003/12/13/atom03"/>
<atom:id>urn:uuid:1225c695-cfb8-4ebb-aaaa-80da344efa6a</atom:id>
</atom:entry>',
# this is an optional mapping from schema-prefixes to namespace URIs
nsmap: {'atom':'http://www.w3.org/2005/Atom'},
# patterns is a list of named 'test-suites' to run on a document
# each pattern has a context, which is the node we execute xpath on
# plus a set of assertions, each of which is an xpath expression, with a message in case of failure
patterns: [
'<pattern name="Link tests">
<rule context="atom:entry">
<assert test="link[@rel=\'self\'">An entry must have a self link</assert>
</rule>
</pattern>'
]
}
})
will_respond_with(
{
status: 200,
headers: {
'Content-Type': 'application/atom+xml'
},
schema: {
example: '<atom:entry>
<atom:title>Atom-Powered Robots Run Amok</atom:title>
<atom:link rel="self" href="http://example.org/2003/12/13/atom03"/>
<atom:id>urn:uuid:1225c695-cfb8-4ebb-aaaa-80da344efa6a</atom:id>
<atom:category term="Robot" />
<atom:content>AAAAARGH!</atom:content>
</atom:entry>',
nsmap: {'atom':'http://www.w3.org/2005/Atom'},
patterns: [
{
name: 'Link Tests',
rules: [
{ context: 'atom:entry',
assert: [{test: 'link[@rel="self"]', msg: 'entry must have a self link'}]
}]
},
{
name: 'Content Tests',
rules: [
{
content: 'atom:entry',
assert: [
{ test: 'content', msg: 'entries must contain a content element'},
{ test: 'normalize-space(content)', msg: 'content must not be empty'}
]
}
]
}
]
}
})
will_respond_with(
{
status: 200,
headers: {
'Content-Type': 'application/atom+xml'
},
schema: {
example: '<entry>
<title>% title %</title>
<link rel="self" href="%self_href%" />
<category term="Robot" />
<content>%content%</content>
</entry>',
match: {
title: { pattern : '.+' },
self_href: { type: 'anyURI' },
content: { eg: "Here come the robots" }
}
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment