Skip to content

Instantly share code, notes, and snippets.

@danhyun
Created July 27, 2015 23:02
Show Gist options
  • Save danhyun/398277d9ffdc83c4e093 to your computer and use it in GitHub Desktop.
Save danhyun/398277d9ffdc83c4e093 to your computer and use it in GitHub Desktop.
Registering Guice Modules via GroovyEmbeddedApp
package ratpack.groovy
import com.google.inject.AbstractModule
import ratpack.groovy.test.embed.GroovyEmbeddedApp
import ratpack.guice.Guice
import spock.lang.Specification
class EmbeddedSpec extends Specification {
def "GroovyEmbeddedApp with Guice Module"() {
given:
def app = GroovyEmbeddedApp.of {
registry(Guice.registry{ spec ->
spec.module new AbstractModule() {
@Override
protected void configure() {
bind(String).toInstance("World")
}
}
})
handlers {
all { String s ->
render("Hello, $s!" as String)
}
}
}
expect:
app.test { client ->
assert client.text == 'Hello, World!'
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment