Skip to content


Subversion checkout URL

You can clone with
Download ZIP
Fetching contributors…
Cannot retrieve contributors at this time
134 lines (88 sloc) 4.17 KB
# Testing and Logging, and Debugging
## Testing
### Adding Unit Tests
When you [generate a model](generator#add-new-model), you will now get an _spec.rb file generated along with your controller.
Generating with model generator:
[ADDED] app/Person/person_spec.rb
This file contains tests for your controller and is in the mspec format: [](
describe "Person" do
#this test always fails, you really should have tests!
it "should have tests" do
true.should == false
We use this test format internally as well. You can see our specs for the core framework [here]( which use many functions of mspec.
To run these tests however, you need the testing framework to be included in your app. To add this, you would run the rhogen task in your application folder:
$ rhogen spec
You will then see the mspec framework added to your application:
Generating with spec generator:
[ADDED] app/SpecRunner
[ADDED] app/spec
[ADDED] app/mspec.rb
[ADDED] app/spec_runner.rb
Finally, add the fileutils and mspec extensions to your build.yml:
extensions: ["fileutils", "mspec"]
You are now ready to run the tests. Simply add a link to the SpecRunner controller, and you will get a summary of number of passing/failing tests
In your index.erb:
<li><a href="SpecRunner">Run tests</a></li>
A summary of the results will be displayed on the screen.
Detailed results will be displayed in your rholog.txt:
I 01/15/2010 16:36:33 b0185000 APP| FAIL: Product - Expected true
to equal false
apps/app/mspec/expectations/expectations.rb:15:in `fail_with'
apps/app/mspec/matchers/base.rb:8:in `=='
apps/app/Product/product_spec.rb:5:in `block (2 levels) in <main>'
And finally, a summary will be printed in rholog.txt as well:
I 01/15/2010 16:36:33 b0185000 APP| ***Total: 3
I 01/15/2010 16:36:33 b0185000 APP| ***Passed: 1
I 01/15/2010 16:36:33 b0185000 APP| ***Failed: 2
### Disabling tests
When you are ready to do a production build of your application, change build.yml's build property to 'release' and the specs will not be included in the binary:
vendor: Acme, Inc.
build: release
## Logging
There are two methods to log messages.
From any controller you can log using the methods app_info and app_error. These methods take a string and will write that to rholog.txt with the category of your controllers name. See platform specific [build topic](build) to see notes on how to get rholog.txt.
Call app_info and app_error from a method in your controller:
def index
app_info "My info message"
app_error "My error message"
There also is a logging Ruby class called RhoLog. This class has methods info and error which take 2 strings. The first string is the category, the second string is the message.
Call the RhoLog error or info methods from a method in your Rhodes app:
def index
RhoLog.error("Some Category", "Some message")
In rholog.txt the lines appear as follows:
<Timestamp> <category> | <message>
To enable remote logging just add the line to `rhoconfig.txt`:
rhologurl = 'http://<host>:<port>[/path]'
Then all log messages will be sent to the specified URL via POST HTTP-requests.
### RhoError class
You may find access to the error class useful in logging and reporting:
This class contains error codes and the method message() to translate error code to a text message.
All callbacks return an error code from this class. The status text in the callback contains some internal error message, so in most cases it should not be exposed to user.
Currently RhoError contains the following error codes:
### Sample
See [Login/Logout Manager]() as an example.
## Debugging
You can use the [RhoStudio debugger](rhostudio.tutorial#using-the-debugger) to debug your Rhodes app.
Jump to Line
Something went wrong with that request. Please try again.