Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

cleanup

  • Loading branch information...
commit 4b1e270e81e33bbea8c75e72ce7915945654afd4 1 parent eb32996
@rkh authored
View
27 LICENSE
@@ -1,27 +0,0 @@
-copyright (c) 2010 Konstantin Haase. All rights reserved.
-
-Developed by: Konstantin Haase
- http://github.com/rkh/big_band
-
-Permission is hereby granted, free of charge, to any person obtaining a copy
-of this software and associated documentation files (the "Software"), to
-deal with the Software without restriction, including without limitation the
-rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
-sell copies of the Software, and to permit persons to whom the Software is
-furnished to do so, subject to the following conditions:
- 1. Redistributions of source code must retain the above copyright notice,
- this list of conditions and the following disclaimers.
- 2. Redistributions in binary form must reproduce the above copyright
- notice, this list of conditions and the following disclaimers in the
- documentation and/or other materials provided with the distribution.
- 3. Neither the name of Konstantin Haase, nor the names of other contributors
- may be used to endorse or promote products derived from this Software without
- specific prior written permission.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
-FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
-WITH THE SOFTWARE.
View
53 README.md
@@ -1,52 +1 @@
-Sinatra::TestHelper
-===================
-
-Adds helper methods and better integration for various testing frameworks to
-[Sinatra](http://sinatrarb.com).
-
-
-Installation
-------------
-
- gem install sinatra-test-helper
-
-Frameworks
-----------
-
-Currently Sinatra::TestHelper ships with support for:
-
-* Bacon
-* Contest
-* Minitest
-* MSpec
-* Protest
-* RSpec
-* Test::Spec
-* Test::Unit
-
-Usage
------
-
-In you test\_helper.rb or spec\_helper.rb (or your test), place this line:
-
- require "sinatra/YOUR_FRAMEWORK"
-
-Example:
-
- require "sinatra/rspec"
- require "sinatra/funky_extension"
-
- describe Sinatra::FunkyExtension do
- # Let's always start with an empty app, using Sinatra::FunkyExtension
- before { app :FunkyExtension }
- it "should do funky thinks" do
- define_route(:get, '/funky') { "funky" }
- browse_route(:get, '/funky').body.should == "funky"
- end
- end
-
-BigBand
--------
-
-Sinatra::TestHelper is part of the [BigBand](http://github.com/rkh/big_band)
-stack. Check it out if you are looking for other fancy Sinatra extensions.
+This project is now part of [sinatra-contrib](https://github.com/sinatra/sinatra-contrib/).
View
9 lib/sinatra/bacon.rb
@@ -1,9 +0,0 @@
-require "sinatra/test_helper"
-require "bacon"
-
-module Sinatra
- module Bacon
- ::Bacon::Context.send :include, self
- include Sinatra::TestHelper
- end
-end
View
2  lib/sinatra/contest.rb
@@ -1,2 +0,0 @@
-require "contest"
-require "sinatra/test_unit"
View
9 lib/sinatra/minitest.rb
@@ -1,9 +0,0 @@
-require "sinatra/test_helper"
-require "minitest/unit"
-
-module Sinatra
- module Minitest
- ::Minitest::Unit.send :include, self
- include Sinatra::TestHelper
- end
-end
View
10 lib/sinatra/mspec.rb
@@ -1,10 +0,0 @@
-require "sinatra/test_helper"
-require "mspec"
-
-module Sinatra
- # Some Bacon example and description goes here.
- module MSpec
- ::Object.send :include, self
- include Sinatra::TestHelper
- end
-end
View
9 lib/sinatra/protest.rb
@@ -1,9 +0,0 @@
-require "sinatra/test_helper"
-require "protest"
-
-module Sinatra
- module Protest
- ::Protest::TestCase.send :include, self
- include Sinatra::TestHelper
- end
-end
View
10 lib/sinatra/rspec.rb
@@ -1,10 +0,0 @@
-require "sinatra/test_helper"
-require "spec"
-
-module Sinatra
- module RSpec
- include Sinatra::TestHelper
- ::Spec::Runner.configure { |c| c.include self }
- end
- Rspec = RSpec
-end
View
6 lib/sinatra/rspec/shared.rb
@@ -1,6 +0,0 @@
-require 'sinatra/rspec'
-require 'sinatra/rspec/shared/routing'
-
-shared_examples_for 'sinatra' do
- it_should_behave_like 'sinatra routing'
-end
View
61 lib/sinatra/rspec/shared/routing.rb
@@ -1,61 +0,0 @@
-require 'sinatra/rspec/shared'
-
-shared_examples_for 'sinatra routing' do
- %w[get head post put delete].each do |verb|
- describe verb.upcase do
- it "should route matching patterns" do
- app.routes.clear
- define_route(verb, '/foo') { 'bar' }
- result = browse_route(verb, '/foo')
- result.should be_ok
- result.body.should == 'bar' unless verb == 'head'
- end
-
- it "404s when no route satisfies the request" do
- app.routes.clear
- define_route(verb, '/foo') { }
- browse_route(verb, '/bar').status.should == 404
- end
-
- it "404s and sets X-Cascade header when no route satisfies the request" do
- app.routes.clear
- define_route(verb, '/foo') { }
- result = browse_route(verb, '/bar')
- result.status.should == 404
- result.headers['X-Cascade'].should == 'pass'
- end
-
- it "overrides the content-type in error handlers" do
- app.routes.clear
- app.before { content_type 'text/plain' }
- app.error Sinatra::NotFound do
- content_type "text/html"
- "<h1>Not Found</h1>"
- end
- result = browse_route(verb, '/bar')
- result.status.should == 404
- result["Content-Type"].should include('text/html')
- result.body.should == "<h1>Not Found</h1>" unless verb == 'head'
- end
-
- it 'takes multiple definitions of a route' do
- app.routes.clear
- app.send(:user_agent, /Foo/)
- define_route(verb, '/foo') { 'foo' }
- define_route(verb, '/foo') { 'not foo' }
- browse_route verb, '/foo', {}, 'HTTP_USER_AGENT' => 'Foo'
- last_response.should be_ok
- last_response.body.should == 'foo' unless verb == 'head'
- last_response.should be_ok
- browse_route verb, '/foo'
- last_response.body.should == 'not foo' unless verb == 'head'
- end
- end
- end
-
- it "defines HEAD request handlers with HEAD" do
- app.routes.clear
- define_route(:head, '/hello') { response['X-Hello'] = 'World!' }
- head('/hello')['X-Hello'].should == 'World!'
- end
-end
View
1  lib/sinatra/test/spec.rb
@@ -1 +0,0 @@
-require "sinatra/test_spec"
View
1  lib/sinatra/test/unit.rb
@@ -1 +0,0 @@
-require "sinatra/test_unit"
View
97 lib/sinatra/test_helper.rb
@@ -1,97 +0,0 @@
-require "sinatra/base"
-require "rack/test"
-require "forwardable"
-
-Sinatra::Base.set :environment, :test
-
-module Sinatra
- # This encapsulates general test helpers. See Bacon, RSpec, Test::Spec and Test::Unit for examples.
- module TestHelper
- module AppMixin
- def call!(env)
- env['sinatra.test_helper'].last_sinatra_instance = self if env['sinatra.test_helper']
- super
- end
- end
-
- class Session < Rack::Test::Session
- def global_env
- @global_env ||= {}
- end
- private
- def default_env
- super.merge global_env
- end
- end
-
- include ::Rack::Test::Methods
- extend Forwardable
-
- def build_rack_test_session(name) # :nodoc:
- Session.new(rack_mock_session(name)).tap do |s|
- s.global_env['sinatra.test_helper'] = self
- end
- end
-
- def_delegators :app, :configure, :set, :enable, :disable, :use, :helpers, :register
- attr_writer :last_sinatra_instance
-
- attr_writer :app
- def app(*options, &block)
- unless block.nil? and options.empty?
- options.map! do |option|
- case option
- when String, Symbol then Sinatra.const_get option
- when Module, Hash then option
- else raise ArgumentError, "cannot handle #{option.inspect}"
- end
- end
- inspection = "app"
- inspection << "(" << options.map { |o| o.inspect }.join(", ") << ")" unless options.empty?
- inspection << " { ... }" if block
- if options.first.is_a? Class
- @app = options.shift
- @app.class_eval(&block) if block
- else
- @app = Class.new(Sinatra::Base, &block)
- end
- options.each do |option|
- if option.is_a? Hash then @app.set option
- else @app.register option
- end
- @app.class_eval "def self.inspect; #{inspection.inspect}; end"
- end
- end
- @app ||= Sinatra::Application
- @app.extend AppMixin unless @app.is_a? AppMixin
- @app
- end
-
- def last_request?
- last_request
- true
- rescue Rack::Test::Error
- false
- end
-
- def session
- return {} unless last_request?
- raise Rack::Test:Error, "session not enabled for app" unless last_env["rack.session"] or app.session?
- last_request.session
- end
-
- def last_env
- last_request.env
- end
-
- def define_route(verb, *args, &block)
- app.send(verb, *args, &block)
- end
-
- def browse_route(verb, *args, &block)
- send(verb, *args, &block)
- last_response
- end
-
- end
-end
View
2  lib/sinatra/test_spec.rb
@@ -1,2 +0,0 @@
-require "test/spec"
-require "sinatra/test_unit"
View
9 lib/sinatra/test_unit.rb
@@ -1,9 +0,0 @@
-require "sinatra/test_helper"
-require "test/unit"
-
-module Sinatra
- module TestUnit
- ::Test::Unit::TestCase.send :include, self
- include Sinatra::TestHelper
- end
-end
View
18 sinatra-test-helper.gemspec
@@ -1,18 +0,0 @@
-SPEC = Gem::Specification.new do |s|
- # Get the facts.
- s.name = "sinatra-test-helper"
- s.version = "0.6.0"
- s.description = "Test helper and framework integration for Sinatra."
-
- # External dependencies
- s.add_dependency "sinatra", "~> 1.0"
-
- # Those should be about the same in any BigBand extension.
- s.authors = ["Konstantin Haase"]
- s.email = "konstantin.mailinglists@googlemail.com"
- s.files = Dir["**/*.{rb,md}"]<< "LICENSE"
- s.has_rdoc = 'yard'
- s.homepage = "http://github.com/rkh/#{s.name}"
- s.require_paths = ["lib"]
- s.summary = s.description
-end
View
76 spec/sinatra/test_helper_spec.rb
@@ -1,76 +0,0 @@
-require File.expand_path("../../spec_helper", __FILE__)
-
-describe Sinatra::TestHelper do
- it_should_behave_like 'sinatra'
-
- describe :app do
- before { @app = nil }
-
- it "should use Sinatra::Application if app is not set" do
- app.should == Sinatra::Application
- end
-
- it "should use another app if passed directly" do
- some_app = Class.new Sinatra::Base
- app(some_app).should == some_app
- end
-
- it "should register a mixin that is passed in" do
- mod = Module.new
- app(mod).should be_a(mod)
- end
-
- it "takes an option hash" do
- app(:foo => 42).foo.should == 42
- end
-
- it "does no modify Sinatra::Application" do
- app { set :foo, 42 }
- app.should_not == Sinatra::Application
- end
-
- it "does no modify Sinatra::Base" do
- app :foo => 42
- app.should_not == Sinatra::Base
- end
-
- it "should register a mixin from the Sinatra module if a symbol is given" do
- module ::Sinatra::Foo; end
- app(:Foo).should be_a(::Sinatra::Foo)
- end
-
- it "should take both a class an mixins" do
- some_app, mod = Class.new(Sinatra::Base), Module.new
- module ::Sinatra::Foo; end
- app(some_app, mod, :Foo)
- app.should == some_app
- app.should be_a(mod)
- app.should be_a(::Sinatra::Foo)
- end
-
- it "should use the given block for setting up app" do
- app { set :foo, 42 }.foo.should == 42
- end
- end
-
- describe :define_route do
- before { app {} }
- %w[get head post put delete].each do |verb|
- it "defines #{verb} routes" do
- define_route(verb, %r{^/foo$}) { "bar" }
- app.routes[verb.upcase].last.first.should == %r{^/foo$}
- end
- end
- end
-
- describe :browse_route do
- before { app {} }
- %w[get head post put delete].each do |verb|
- it "able to browse #{verb} routes" do
- define_route(verb, "/foo") { "bar" }
- browse_route(verb, "/foo").should be_ok
- browse_route(verb, "/foo").body.should == "bar" unless verb == "head"
- end
- end
- end
-end
View
1  spec/spec_helper.rb
@@ -1 +0,0 @@
-require "sinatra/rspec/shared"
Please sign in to comment.
Something went wrong with that request. Please try again.