0.01
No commit activity in last 3 years
No release in over 3 years
Webmachine::Test provides a testing API for webmachine-ruby inspired by rack-test.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

Runtime

 Project Readme

Webmachine::Test

travis

WARNING

This library is still under development and incomplete!

It will be merged into webmachine-ruby when it's ready.

Description

Webmachine::Test provides a testing API for webmachine-ruby inspired by rack-test.

Example Usage

Application

    require 'webmachine'

    class MyResource < Webmachine::Resource
      def content_types_provided
        [['text/plain', :to_text]]
      end

      def to_text
        'OK'
      end
    end

    MyApp = Webmachine::Application.new do |app|
      app.add_route(['*'], MyResource)
    end

    # decouple runner from application so that adapter
    # does not start and block test thread
    #
    # MyApp.run

Test with Test::Unit

    class MyAppTest < Test::Unit::TestCase
      include Webmachine::Test

      def test_get_root_succeeds
        get '/'
        assert_equal 200, response.code
      end

      def test_get_root_replies_with_string_ok
        get '/'
        assert_equal 'OK', response.body
      end

      def test_get_root_replies_with_content_type_of_text_plain
        get '/'
        assert_equal 'text/plain', response.headers['Content-Type']
      end

      def app
        MyApp
      end
    end

Test with RSpec

    require 'webmachine/test'
    require 'myapp'

    describe MyApp do
      include Webmachine::Test

      let(:app) { MyApp }

      describe 'GET /' do
        it 'succeeds' do
          get '/'
          response.code.should == 200
        end

        it 'replies with the string OK' do
          get '/'
          response.body.should == 'OK'
        end

        it 'replies with a content type of text/plain' do
          get '/'
          response.headers['Content-Type'].should == 'text/plain'
        end
      end
    end