Skip to content

Instantly share code, notes, and snippets.

View robfletcher's full-sized avatar

Rob Fletcher robfletcher

View GitHub Profile
@robfletcher
robfletcher / TumblrToMiddleman.groovy
Last active November 5, 2019 14:15
Scrape markdown posts from a Tumblr blog and export for Middleman
/*
* This script will scrape text posts from a Tumblr blog and export them as `.md`
* files with YAML frontmatter ready to be used in a Middleman blog.
*
* Aliases are added for the _middleman-alias_ gem so Tumblr style URLs like
* `/post/{id}/{slug}` will redirect to the Middleman-style URL.
*
* Although I built this for migrating to Middleman it should be pretty easy to
* adapt this for any similar static site generator.
*/
import io.mockk.Called
import io.mockk.every
import io.mockk.mockk
import io.mockk.verify
import org.junit.jupiter.api.Test
import java.util.function.Consumer
import java.util.function.Supplier
class NullOrUnitWasNotCalled {
@Test
@robfletcher
robfletcher / MockkUnitLambdaTest.kt
Created March 16, 2019 16:44
Demonstration of error verifying calls to a lambda that returns `Unit`
import io.mockk.mockk
import io.mockk.verify
import org.junit.jupiter.api.Test
class MockkUnitLambdaTest {
@Test
fun mockUnitLambda() {
val fn: (String) -> Unit = mockk(relaxUnitFun = true)
@robfletcher
robfletcher / SetPropertySpec.groovy
Last active February 25, 2019 21:46
Demonstrates issue with comparing objects with set properties whose elements are > 1 level deep value objects
import groovy.transform.TupleConstructor
import org.javers.core.JaversBuilder
import org.javers.core.diff.changetype.container.SetChange
import org.javers.core.diff.changetype.container.ValueAdded
import org.javers.core.metamodel.annotation.Id
import spock.lang.Specification
import static java.util.UUID.randomUUID
class SetPropertySpec extends Specification {
@robfletcher
robfletcher / VertxHandler.groovy
Created May 10, 2012 00:16
A Spock extension for automatically registering and unregistering handlers on the Vert.x event bus
package co.freeside.spock.vertx
import org.spockframework.runtime.extension.ExtensionAnnotation
import java.lang.annotation.*
/**
* Add this annotation to any specification fields that should be registered as Vert.x event bus handlers during test
* execution. The field will be registered on the event bus before each feature method and unregistered afterwards. If
* the field is `@Shared` it will be registered and unregistered at the start and end of the spec.
*
@robfletcher
robfletcher / gist:1486156
Created December 16, 2011 14:06
Geb module methods demonstrating how to wait for jQuery animation to complete
void next() {
nextButton.click()
waitForAnimationComplete()
}
private void waitForAnimationComplete() {
waitFor {
js.exec(this.firstElement(), "return \$(arguments[0]).find(':animated').length == 0")
}
}
@robfletcher
robfletcher / ThinkSpec.kt
Created June 7, 2017 13:11
Example of trying to use `SubjectSpek` and `itBehavesLike` if the subject requires a collaborator
import org.jetbrains.spek.api.dsl.describe
import org.jetbrains.spek.api.dsl.given
import org.jetbrains.spek.api.dsl.it
import org.jetbrains.spek.api.dsl.on
import org.jetbrains.spek.subject.SubjectSpek
import org.jetbrains.spek.subject.itBehavesLike
import org.junit.Assert.assertFalse
import org.junit.Assert.assertTrue
open class Thing(protected val fn: () -> Unit) {
import org.jetbrains.spek.api.Spek
class TableSpec : Spek({
describe("using a table") {
table { a: String, b: Int ->
describe("$a and $b are parameters") {
it("should work") {
assert(a is String)
assert(b is Int)
}
@robfletcher
robfletcher / DatabaseSchemaSpec.groovy
Created August 18, 2011 16:27
Example of data-driving a Spock specification using database metadata
import grails.plugin.spock.IntegrationSpec
import java.sql.Connection
import javax.sql.DataSource
import spock.lang.*
class DatabaseSchemaSpec extends IntegrationSpec {
@Shared def dataSource
@Shared List<String> tableNames
import groovy.transform.*
@CompileStatic
Map<String, ?> makeMap() {
def map = [string: "string"]
map.number = 1
return map
}
def map = makeMap()