README.md in bbq-0.0.4 vs README.md in bbq-0.1.0
- old
+ new
@@ -1,11 +1,11 @@
Warning & disclaimer
====================
This gem is currently under development. We're targeting most popular use cases - Rails & Rack applications (ex. Sinatra). However the philosophy behind it is not limited to Rails nor web applications in general. There is even example usage with EventMachine. Feel free to modify it for your own needs.
-[![Build Status](https://secure.travis-ci.org/drugpl/bbq.png)](http://travis-ci.org/drugpl/bbq)
+[![Build Status](https://secure.travis-ci.org/drugpl/bbq.png)](http://travis-ci.org/drugpl/bbq) [![Dependency Status](https://gemnasium.com/drugpl/bbq.png)](https://gemnasium.com/drugpl/bbq)
BBQ
===
Object oriented acceptance testing using personas.
@@ -40,11 +40,11 @@
First, add BBQ to your apps Gemfile:
```ruby
# Gemfile
-gem "bbq", "~> 0.0.2"
+gem "bbq", :git => "git://github.com/drugpl/bbq"
```
Run install generator:
```
@@ -52,11 +52,11 @@
```
Require BBQ in test/test_helper.rb (in case of Test::Unit):
```ruby
-require "bbq/test"
+require "bbq/test_unit"
```
Require BBQ in spec/spec_helper.rb (in case of RSpec):
```ruby
@@ -97,13 +97,18 @@
show_ticket(summary)
fill_in "Comment", :with => comment
click_on "Add update"
end
+ def open_application
+ visit '/'
+ end
+
module TicketReporter
def open_tickets_listing
- visit tickets_path
+ open_application
+ click_link 'Tickets'
end
def open_ticket(summary, description)
open_tickets_listing
click_on "Open a new ticket"
@@ -117,12 +122,17 @@
click_on summary
end
end
module TicketManager
+ def open_administration
+ visit '/admin'
+ end
+
def open_tickets_listing
- visit admin_tickets_path
+ open_administration
+ click_link 'Tickets'
end
def close_ticket(summary, comment = nil)
open_tickets_listing
click_on summary
@@ -172,10 +182,71 @@
charlie.not_see!(summaries.first, descriptions.first)
end
end
```
+Testing REST APIs
+================
+
+Bbq provides `Bbq::TestClient`, similar to `Bbq::TestUser`, but intended for testing APIs.
+It's a thin wrapper around `Rack::Test` which allows you to send requests and run assertions
+against responses.
+
+```ruby
+class ApiTest < Bbq::TestCase
+ background do
+ headers = {'HTTP_ACCEPT' => 'application/json'}
+ @client = TestClient.new(:headers => headers)
+ end
+
+ scenario "admin can browse all user tickets" do
+ @client.get "/unicorn" do |response|
+ assert_equal 200, response.status
+ assert_equal "pink", response.body["unicorn"]["color"]
+ end
+ @client.post "/ponies", { :name => "Miracle" } do |response|
+ assert_equal 200, response.status
+ end
+ end
+end
+```
+
+Rails' URL Helpers
+================
+
+Using url helpers from Rails in integration tests is not recommended.
+Testing routes is part of integration test, so you should actually use only
+
+```ruby
+ visit '/'
+```
+
+in your integration test. Use links and buttons in order to get to other pages in your app.
+
+If you really need url helpers in your test user, just include them in your TestUser class:
+
+```ruby
+require 'bbq/rails/routes'
+
+module Roundtrip
+ class TestUser < Bbq::TestUser
+ include Bbq::Rails::Routes
+ end
+end
+```
+or just
+
+```ruby
+module Roundtrip
+ class TestUser < Bbq::TestUser
+ include ::ActionDispatch::Routing::UrlFor
+ include ::Rails.application.routes.url_helpers
+ include ::ActionDispatch::Routing::RouteSet::MountedHelpers unless ::Rails.version < "3.1"
+ end
+end
+```
+
Deal with Devise
================
```ruby
require "bbq/test_user"
@@ -200,31 +271,21 @@
=======
<h2>Timeout::Error</h2>
If you simulate multiple users in your tests and spawn multiple browsers with selenium it might
-be a good idea to use `Mongrel` instead of `Webrick` to create application server.
-We have experienced some problems with `Webrick` that lead to `Timeout::Error` exception
+be a good idea to use Thin instead of Webrick to create application server.
+We have experienced some problems with Webrick that lead to `Timeout::Error` exception
when user/browser that was inactive for some time (due to other users/browsers
activities) was requested to execute an action.
-Put this code into a file loaded before running any acceptance scenario like:
-`test/test_helper.rb` or `spec/spec_helper.rb`:
+Capybara will use Thin instead of Webrick when it's available, so you only need to add Thin to you Gemfile:
```ruby
-Capybara.server do |app, port|
- require 'rack/handler/mongrel'
- Rack::Handler::Mongrel.run(app, :Port => port)
-end
-```
-
-Add `mongrel` to your `Gemfile`:
-
-```ruby
# In test group if you want it to
# be used only in tests and not in your development mode
# ex. when running 'rails s'
-gem 'mongrel', "1.2.0.pre2", :require => false
+gem 'thin', :require => false
```
Development environment
=======================