Although the Bounce API is fairly limited at the moment, I thought it would be interesting to share as an example of Sizzle and Butter usage.
Quick Start
1). Create a text file called Example.fan:
using afBounce
using afBedSheet::Text
using afBedSheet::Route
using afBedSheet::Routes
using afIoc
class Example : Test {
Void testBedApp() {
// given
server := BedServer(Type.find("Example_0::AppModule")).startup
client := server.makeClient
// when
client.get(`/index`)
// then
title := client.selectCss("#title").first
verifyEq(title.text.writeToStr, "Sizzle Kicks Ass!")
}
}
** A Really Simple Bed App!!!
class AppModule {
@Contribute { serviceType=Routes# }
static Void contributeRoutes(OrderedConfig config) {
config.add(Route(`/index`, Text.fromHtml("""<html><p id="title">Sizzle Kicks Ass!</p></html>""")))
}
}
2). Run Example.fan as a Fantom test script ( fant ) from the command line:
C:\> fant Example.fan
-- Run: Example_0::Example.testBedApp...
[info] [afIoc] Adding modules from dependencies of 'afBedSheet'
[info] [afIoc] Adding module definition for afBedSheet::BedSheetModule
[info] [afIoc] Adding module definition for afIocConfig::IocConfigModule
[info] [afIoc] Adding module definition for afIocEnv::IocEnvModule
[info] [afIoc] Adding module definition for Example_0::AppModule
[info] [afIoc]
___ __ _____ _
/ _ | / / _____ _____ / ___/__ ___/ /_________ __ __
/ _ | / /_ / / -_|/ _ / / __// _ \/ _/ __/ _ / __|/ // /
/_/ |_|/___//_/\__|/_//_/ /_/ \_,_/__/\__/____/_/ \_, /
Alien-Factory BedServer v0.0.2, IoC v1.5.0 /___/
BedServer started up in 597ms
Pass: Example_0::Example.testBedApp [1]
Time: 2052ms
***
*** All tests passed! [1 tests, 1 methods, 1 verifies]
***
Usage
The Quick Start example pretty much sums up Bounce usage.
BedClient is just a ButterDish that wraps a Butter instance - all the functionality is provided by Butter middleware. BedTerminator is the terminator of the stack, which sends requests to the BedServer, which holds the instance of your Bed App.
By creating BedClient with a Butter stack that ends with a real HTTP terminator, Bounce can also be used to test web applications in any environment. Example:
Void testFantomFactory() {
client := BedClient(Butter.churnOut)
// make real calls out to the web / your integration environment
client.get(`http://www.fantomfactory.org/`)
elems := client.selectCss("h1 small")
echo(elems.first.toStr) // --> Where Pods Are Made
}
Have fun!
:)
LightDyeThu 6 Mar 2014
For people using the example above, compilation fails on this line
Yeah, it changed to client.selectCss() in v0.0.4. Thanks LightDye for pointing that out, I've edited the above example.
To make life easier, Bounce now has HTML Elements that contain lots of useful verify() methods:
title := Element("#title")
title.verifyTextEq("Sizzle Kicks Ass!")
So Example.fan now becomes:
using afBounce
using afBedSheet
using afIoc
class Example : Test {
Void testBedApp() {
// given
server := BedServer(Type.find("Example_0::AppModule")).startup
client := server.makeClient
// when
client.get(`/index`)
// then
title := Element("#title")
title.verifyTextEq("Sizzle Kicks Ass!")
// clean up
server.shutdown
}
}
** A Really Simple Bed App!!!
class AppModule {
@Contribute { serviceType=Routes# }
static Void contributeRoutes(OrderedConfig config) {
config.add(Route(`/index`, Text.fromHtml("""<html><p id="title">Sizzle Kicks Ass!</p></html>""")))
}
}
SlimerDude Fri 17 Jan 2014
Bounce v0.0.2 Released!
Bounce
- use it to test your Bed Apps!Bounce
is a testing framework that makes requests to a Bed App without the overhead of starting up a web server and making expensive network requests.fanr install -r http://eggbox.fantomfactory.org/fanr/ afBounce
Although the Bounce API is fairly limited at the moment, I thought it would be interesting to share as an example of Sizzle and Butter usage.
Quick Start
1). Create a text file called
Example.fan
:2). Run
Example.fan
as a Fantom test script ( fant ) from the command line:Usage
The
Quick Start
example pretty much sums upBounce
usage.BedClient
is just aButterDish
that wraps aButter
instance - all the functionality is provided by Butter middleware.BedTerminator
is the terminator of the stack, which sends requests to theBedServer
, which holds the instance of your Bed App.By creating
BedClient
with aButter
stack that ends with a real HTTP terminator,Bounce
can also be used to test web applications in any environment. Example:Have fun!
:)
LightDye Thu 6 Mar 2014
For people using the example above, compilation fails on this line
due to
I believe it has changed to client.selectCss instead.
SlimerDude Thu 6 Mar 2014
Yeah, it changed to
client.selectCss()
in v0.0.4. ThanksLightDye
for pointing that out, I've edited the above example.To make life easier,
Bounce
now has HTML Elements that contain lots of usefulverify()
methods:So
Example.fan
now becomes: