-
Notifications
You must be signed in to change notification settings - Fork 14
TestComponents
This section covers the specifics of setting up an application using the sinatra_more generators and each test component.
In order to use bacon, you must install the associated gem:
$ sudo gem install bacon --source http://gemcutter.orgTo generate an application using the bacon testing framework, simply invoke:
sinatra_gen demo_app . -t baconThis will setup the test/test_config.rb file to use bacon and include the necessary modules to make testing easy. In order to add tests, simply create a test file within test/models or test/routes in order to get started testing a piece of the application.
# test/routes/app_test.rb
require File.dirname(__FILE__) + '/../test_config.rb'
describe "Basic Application" do
it 'returns hello world at root' do
get '/'
last_response.body.should == "Hello World"
end
end
This does a basic test of the routes by requesting the root url and then ensuring that the response body matches the expected content.
You can execute the test file by invoking:
$ bacon test/routes/app_test.rbFor more information on using bacon, check out the Bacon README
In order to use shoulda, you must install the associated gem:
$ sudo gem install shoulda --source http://gemcutter.orgTo generate an application using the shoulda testing framework, simply invoke:
sinatra_gen demo_app . -t shouldaThis will setup the test/test_config.rb file to use shoulda and include the necessary modules to make testing easy. In order to add tests, simply create a test file within test/models or test/routes in order to get started testing a piece of the application.
# test/routes/app_test.rb
require File.dirname(__FILE__) + '/../test_config.rb'
class PostsControllerTest < Test::Unit::TestCase
context "on GET to root" do
setup do
get '/'
end
should "return hello world text" do
assert_equal "Hello World", last_response.body
end
end
end
This does a basic test of the routes by requesting the root url and then ensuring that the response body matches the expected content.
You can execute the test file by invoking:
$ ruby test/routes/app_test.rbFor more information on using shoulda, check out the Shoulda README
In order to use riot, you must install the associated gem:
$ sudo gem install riot --source http://gemcutter.orgTo generate an application using the riot testing framework, simply invoke:
sinatra_gen demo_app . -t riotThis will setup the test/test_config.rb file to use riot and include the necessary modules to make testing easy. In order to add tests, simply create a test file within test/models or test/routes in order to get started testing a piece of the application.
# test/routes/app_test.rb
require File.dirname(__FILE__) + '/../test_config.rb'
context 'Basic Application' do
context "/index" do
setup { get '/' }
asserts("the response body") { last_response.body }.equals "Hello World"
end
end
This does a basic test of the routes by requesting the root url and then ensuring that the response body matches the expected content.
You can execute the test file by invoking:
$ ruby test/routes/app_test.rbFor more information on using riot, check out the Riot README
In order to use testspec, you must install the associated gem:
$ sudo gem install test-spec --source http://gemcutter.orgTo generate an application using the test/spec testing framework, simply invoke:
sinatra_gen demo_app . -t testspecThis will setup the test/test_config.rb file to use testspec and include the necessary modules to make testing easy. In order to add tests, simply create a test file within test/models or test/routes in order to get started testing a piece of the application.
# test/routes/app_test.rb
require File.dirname(__FILE__) + '/../test_config.rb'
context "for root url" do
setup { get('/') }
specify "returns hello world" do
last_response.body.should.equal "Hello World"
end
end
This does a basic test of the routes by requesting the root url and then ensuring that the response body matches the expected content.
You can execute the test file by invoking:
$ ruby test/routes/app_test.rbFor more information on using shoulda, check out the TestSpec README
In order to use rspec, you must install the associated gem:
$ sudo gem install rspec --source http://gemcutter.orgTo generate an application using the rspec testing framework, simply invoke:
sinatra_gen demo_app . -t rspecThis will setup the test/test_config.rb file to use rspec and include the necessary modules to make testing easy. In order to add tests, simply create a test file within test/models or test/routes in order to get started testing a piece of the application.
# test/routes/app_test.rb
require File.dirname(__FILE__) + '/../test_config.rb'
describe "for root url" do
setup { get('/') }
it "returns hello world" do
last_response.body.should == "Hello World"
end
end
This does a basic test of the routes by requesting the root url and then ensuring that the response body matches the expected content.
You can execute the test file by invoking:
$ spec test/routes/app_test.rbFor more information on using rspec, check out the Rspec README