Adding all tracks, I guess
This commit is contained in:
13
cfml/hello-world/HelloWorld.cfc
Normal file
13
cfml/hello-world/HelloWorld.cfc
Normal file
@@ -0,0 +1,13 @@
|
||||
/**
|
||||
* Your implmentation of the Hello World exercise
|
||||
*/
|
||||
component {
|
||||
|
||||
/**
|
||||
* @returns A string greeting the world
|
||||
*/
|
||||
function hello() {
|
||||
return '';
|
||||
}
|
||||
|
||||
}
|
19
cfml/hello-world/HelloWorldTest.cfc
Normal file
19
cfml/hello-world/HelloWorldTest.cfc
Normal file
@@ -0,0 +1,19 @@
|
||||
component extends="testbox.system.BaseSpec" {
|
||||
|
||||
function beforeAll(){
|
||||
SUT = createObject( 'HelloWorld' );
|
||||
}
|
||||
|
||||
function run(){
|
||||
|
||||
describe( "My HelloWorld class", function(){
|
||||
|
||||
it( 'Say Hi!', function(){
|
||||
expect( SUT.hello() ).toBe( 'Hello, World!' );
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
}
|
37
cfml/hello-world/README.md
Normal file
37
cfml/hello-world/README.md
Normal file
@@ -0,0 +1,37 @@
|
||||
# Hello World
|
||||
|
||||
The classical introductory exercise. Just say "Hello, World!".
|
||||
|
||||
["Hello, World!"](http://en.wikipedia.org/wiki/%22Hello,_world!%22_program) is
|
||||
the traditional first program for beginning programming in a new language
|
||||
or environment.
|
||||
|
||||
The objectives are simple:
|
||||
|
||||
- Write a function that returns the string "Hello, World!".
|
||||
- Run the test suite and make sure that it succeeds.
|
||||
- Submit your solution and check it at the website.
|
||||
|
||||
If everything goes well, you will be ready to fetch your first real exercise.
|
||||
|
||||
* * * *
|
||||
|
||||
To run the code in this exercise, you will only need to have [CommandBox CLI installed](https://ortus.gitbooks.io/commandbox-documentation/content/setup/installation.html). This binary runs CFML code from the command line.
|
||||
|
||||
To run the tests, `cd` into the exercise folder and run the following:
|
||||
|
||||
```bash
|
||||
box task run TestRunner
|
||||
# Or start up a test watcher that will rerun when files change
|
||||
box task run TestRunner --:watcher
|
||||
```
|
||||
|
||||
The tests leverage a library called TestBox which supports xUnit and BDD style of testing. All test suites will be written in the [BDD style](https://testbox.ortusbooks.com/content/primers/bdd/specs.html) which uses closures to define test specs. You won't need to worry about installing TestBox. The CLI test runner will take care of that for you. You just need to be connected to the internet the first time you run it. You can read more about it here:
|
||||
|
||||
[https://testbox.ortusbooks.com/content/](https://testbox.ortusbooks.com/content/)
|
||||
## Source
|
||||
|
||||
This is an exercise to introduce users to using Exercism [http://en.wikipedia.org/wiki/%22Hello,_world!%22_program](http://en.wikipedia.org/wiki/%22Hello,_world!%22_program)
|
||||
|
||||
## Submitting Incomplete Solutions
|
||||
It's possible to submit an incomplete solution so you can see how others have completed the exercise.
|
103
cfml/hello-world/TestRunner.cfc
Normal file
103
cfml/hello-world/TestRunner.cfc
Normal file
@@ -0,0 +1,103 @@
|
||||
/**
|
||||
* I am a CommandBox task runner which you can use to test your implementation of this exercise against the
|
||||
* provided test suite. To use me, open the CommandBox CLI and run this:
|
||||
*
|
||||
* CommandBox> task run TestRunner
|
||||
*
|
||||
* To start up a test watcher that will automatically rerun the test suite every time you save a file change, run this:
|
||||
*
|
||||
* CommandBox> task run TestRunner --watcher
|
||||
*
|
||||
*/
|
||||
component {
|
||||
|
||||
/**
|
||||
* @solution Runs the tests against the solution
|
||||
* @watcher Start up a file watch that re-runs the tests on file changes. Use Ctrl-C to stop
|
||||
*/
|
||||
function run( boolean solution=false, boolean watcher=false ) {
|
||||
|
||||
ensureTestBox();
|
||||
|
||||
if( watcher ) {
|
||||
|
||||
// Tabula rasa
|
||||
command( 'cls' ).run();
|
||||
|
||||
// Start watcher
|
||||
watch()
|
||||
.paths( '*.cfc' )
|
||||
.inDirectory( getCWD() )
|
||||
.withDelay( 500 )
|
||||
.onChange( function() {
|
||||
|
||||
// Clear the screen
|
||||
command( 'cls' )
|
||||
.run();
|
||||
|
||||
// This is neccessary so changes to tests get picked up right away.
|
||||
pagePoolClear();
|
||||
|
||||
runTests( solution );
|
||||
|
||||
} )
|
||||
.start();
|
||||
|
||||
} else {
|
||||
runTests( solution );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Make sure the TestBox framework is installed
|
||||
*/
|
||||
private function ensureTestBox() {
|
||||
var excerciseRoot = getCWD();
|
||||
var testBoxRoot = excerciseRoot & '/testbox';
|
||||
|
||||
if( !directoryExists( testBoxRoot ) ) {
|
||||
|
||||
print.boldYellowLine( 'Installing some missing dependencies for you!' ).toConsole();
|
||||
command( 'install' )
|
||||
.inWorkingDirectory( excerciseRoot )
|
||||
.run();
|
||||
}
|
||||
|
||||
// Bootstrap TestBox framework
|
||||
filesystemUtil.createMapping( '/testbox', testBoxRoot );
|
||||
}
|
||||
|
||||
/**
|
||||
* Invoke TestBox to run the test suite
|
||||
*/
|
||||
private function runTests( boolean solution=false ) {
|
||||
|
||||
// Create TestBox and run the tests
|
||||
testData = new testbox.system.TestBox()
|
||||
.runRaw( directory = {
|
||||
// Find all CFCs...
|
||||
mapping = filesystemUtil.makePathRelative( getCWD() ),
|
||||
// ... in this directory ...
|
||||
recurse = false,
|
||||
// ... whose name ends in "test"
|
||||
filter = function( path ) {
|
||||
return path.reFind( ( solution ? 'Solution' : '' ) & 'Test.cfc$' );
|
||||
}
|
||||
} )
|
||||
.getMemento();
|
||||
|
||||
// Print out the results with ANSI formatting for the CLI
|
||||
getInstance( 'CLIRenderer@testbox-commands' )
|
||||
.render( print, testData, true );
|
||||
|
||||
print.toConsole();
|
||||
|
||||
// Set proper exit code
|
||||
if( testData.totalFail || testData.totalError ) {
|
||||
setExitCode( 1 );
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
8
cfml/hello-world/box.json
Normal file
8
cfml/hello-world/box.json
Normal file
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"dependencies":{
|
||||
"testbox":"^2.5.0+107"
|
||||
},
|
||||
"installPaths":{
|
||||
"testbox":"testbox"
|
||||
}
|
||||
}
|
37
cfml/hello-world/index.cfm
Normal file
37
cfml/hello-world/index.cfm
Normal file
@@ -0,0 +1,37 @@
|
||||
<!---
|
||||
|
||||
This file will only be used if you want to start up a web server in this directory. You can do so by running:
|
||||
|
||||
$> box
|
||||
CommandBox> install
|
||||
CommandBox> server start
|
||||
|
||||
However, this is not necessary unless you really just want to use the HTML reporters on TestBox.
|
||||
Ideally, you'll skip the need for this file entirely and just run the tests directly frm the CLI like this:
|
||||
|
||||
CommandBox> task run TestRunner
|
||||
|
||||
--->
|
||||
<cfsetting showDebugOutput="false">
|
||||
<cfparam name="url.reporter" default="simple">
|
||||
<cfscript>
|
||||
// get a list of all CFCs in this folder whose name looks like "XXXTest.cfc"
|
||||
// And turn it into compnent path relative to the web root
|
||||
url.bundles = directoryList(
|
||||
path=expandPath( '/' ),
|
||||
filter='*Test.cfc' )
|
||||
.map( function( path ) {
|
||||
return path
|
||||
.replaceNoCase( expandPath( '/' ), '' )
|
||||
.left( -4 )
|
||||
} )
|
||||
.toList();
|
||||
</cfscript>
|
||||
|
||||
<!--- Ensure TestBox --->
|
||||
<cfif fileExists( "/testbox/system/runners/HTMLRunner.cfm" )>
|
||||
<!--- Include the TestBox HTML Runner --->
|
||||
<cfinclude template="/testbox/system/runners/HTMLRunner.cfm">
|
||||
<cfelse>
|
||||
Oops, you don't have TestBox installed yet! Please run <b>box install</b> from the root of your excercise folder and refresh this page.
|
||||
</cfif>
|
Reference in New Issue
Block a user