Repository is archived
No commit activity in last 3 years
No release in over 3 years
Rack middleware for test client behavior. It can test client request to your rack applications.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.7
~> 10.0

Runtime

~> 1.4.3
~> 1.5
 Project Readme

Rack::ClientSpec

Rack::ClientSpec can test your client.

TODO

Current implementation is "it just works" for prototyping, not enough for release.

  • request flow
  • run multiple test methods
  • non-existence test
  • bug fix

Installation

Add this line to your application's Gemfile:

gem 'rack-client_spec'

And then execute:

$ bundle

Usage

Write your client spec like below (this code is included in lib/lobster_spec.rb):

require 'rack/client_spec'

class LobsterSpec < Rack::ClientSpec::TestCase # <-- test case
  def test_flip_referer # <-- test method
    get '/' do |req, res| # <-- expect request
      assert { res.status == 200 } # <-- assertion
    end

    get '/?flip=left' do |req, res| # <-- expect request
      assert { req['HTTP_REFERER'] == 'http://localhost:9292/' } # <-- assertion
    end

    get '/?flip=right' do |req, res| # <-- expect request
      assert { req['HTTP_REFERER'] == 'http://localhost:9292/?flip=left' }
    end
  end
end

Then, use ClientSpec in your config.ru:

require 'rack'
require 'rack/lobster'
require 'rack/client_spec'
require 'lobster_spec'

use Rack::ClientSpec, LobsterSpec
run Rack::Lobster.new

Finally, rackup your server, and you can test a client (eg. your favorite web browser).

Contributing

  1. Fork it.
  2. Create your feature branch (git checkout -b my-new-feature).
  3. Commit your changes (git commit -am 'Add some feature').
  4. Push to the branch (git push origin my-new-feature).
  5. Create a new Pull Request.