Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Port test suite to nanotest

jeremymcanally-matchy doesn't seem to be supported anymore.
  • Loading branch information...
commit dc7dddc9cabb942ed8bb9fec5fc7e6e9b6c8bd2e 1 parent fc736ee
@mynyml authored
View
1  simple_router.gemspec
@@ -13,5 +13,6 @@ Gem::Specification.new do |s|
s.add_development_dependency 'rack'
s.add_development_dependency 'nanotest'
+ s.add_development_dependency 'nanotest_extensions'
end
View
113 test/engines/test_simple_engine.rb
@@ -1,126 +1,145 @@
require 'test/test_helper'
-class SimpleEngineTest < Test::Unit::TestCase
+## SimpleEngine
+context do
include SimpleRouter::Engines::SimpleEngine
- test "matches static paths" do
- Base.match('/', ['/', '/foo']).first.should be('/')
- Base.match('/foo', ['/', '/foo']).first.should be('/foo')
- Base.match('/bar', ['/', '/foo']).first.should be(nil)
+ # matches static paths
+ test do
+ Base.match('/', ['/', '/foo']).first.must == '/'
+ Base.match('/foo', ['/', '/foo']).first.must == '/foo'
+ Base.match('/bar', ['/', '/foo']).first.must == nil
end
- test "matches variable paths" do
+ # matches variable paths
+ test do
path, vars = Base.match('/80/07', ['/foo', '/:year/:month'])
- path.should be('/:year/:month')
- vars.should be(['80','07'])
+ path.must == '/:year/:month'
+ vars.must == ['80','07']
end
- test "matches hybrid paths" do
+ # matches hybrid paths
+ test do
path, vars = Base.match('/archives/80/07', ['/foo', '/archives/:year/:month'])
- path.should be('/archives/:year/:month')
- vars.should be(['80','07'])
+ path.must == '/archives/:year/:month'
+ vars.must == ['80','07']
end
- test "ignores leading slash in path" do
+ # ignores leading slash in path
+ test do
path, vars = Base.match('archives/80/07', ['/foo', '/archives/:year/:month'])
- path.should be('/archives/:year/:month')
- vars.should be(['80','07'])
+ path.must == '/archives/:year/:month'
+ vars.must == ['80','07']
end
- test "no matches" do
+ # no matches
+ test do
path, vars = Base.match('/80/07/01', ['/foo', '/:year/:month'])
- path.should be(nil)
- vars.should be([])
+ path.must == nil
+ vars.must == []
end
- test "treats extension as pattern part" do
+ # treats extension as pattern part
+ test do
path, vars = Base.match('/a/b.xml', ['/:foo/:bar', '/:foo/:bar.:type'])
- path.should be('/:foo/:bar.:type')
- vars.should be(['a','b','xml'])
+ path.must == '/:foo/:bar.:type'
+ vars.must == ['a','b','xml']
end
end
-class PatternTest < Test::Unit::TestCase
+## Pattern
+context do
include SimpleRouter::Engines::SimpleEngine
- test "static pattern matches a path" do
+ # static pattern matches a path
+ test do
path = Path.new('/foo/bar')
pattern = Pattern.new('/foo/bar')
- assert pattern == path
+ assert { pattern == path }
end
- test "variable pattern matches a path" do
+ # variable pattern matches a path
+ test do
path = Path.new('/foo/bar')
pattern = Pattern.new('/:foo/:bar')
- assert pattern == path
+ assert { pattern == path }
end
- test "pattern variables" do
+ # pattern variables
+ test do
path = Path.new('/foo/bar/baz')
pattern = Pattern.new('/:a/:b/:c')
- assert pattern == path
- pattern.vars.should be(%w( foo bar baz ))
+ assert { pattern == path }
+ pattern.vars.must == %w( foo bar baz )
end
- test "pattern variables with extension" do
+ # pattern variables with extension
+ test do
path = Path.new('/foo/bar/baz.xml')
pattern = Pattern.new('/:a/:b/:c.:type')
- assert pattern == path
- pattern.vars.should be(%w( foo bar baz xml ))
+ assert { pattern == path }
+ pattern.vars.must == %w( foo bar baz xml )
end
- test "variable pattern matches a path with static extension" do
+ # variable pattern matches a path with static extension
+ test do
path = Path.new('/foo/bar.xml')
pattern = Pattern.new('/:foo/:bar.xml')
- assert pattern == path
+ assert { pattern == path }
end
- test "variable pattern matches a path with variable extension" do
+ # variable pattern matches a path with variable extension
+ test do
path = Path.new('/foo/bar.xml')
pattern = Pattern.new('/:foo/:bar.:type')
- assert pattern == path
+ assert { pattern == path }
end
- test "pattern without extension doesn't match path with extension" do
+ # pattern without extension doesn't match path with extension
+ test do
path = Path.new('/foo/bar.xml')
pattern = Pattern.new('/:foo/:bar')
- assert pattern != path
+ assert { pattern != path }
end
- test "pattern with static extension doesn't match path without extension" do
+ # pattern with static extension doesn't match path without extension
+ test do
path = Path.new('/foo/bar')
pattern = Pattern.new('/:foo/:bar.xml')
- assert pattern != path
+ assert { pattern != path }
end
- test "pattern with variable extension doesn't match path without extension" do
+ # pattern with variable extension doesn't match path without extension
+ test do
path = Path.new('/foo/bar')
pattern = Pattern.new('/:foo/:bar.:type')
- assert pattern != path
+ assert { pattern != path }
end
- test "doesn't ignore dots in path parts" do
+ # doesn't ignore dots in path parts
+ test do
path = Path.new('/foo/bar.baz/abc')
pattern = Pattern.new('/:a/:b/:c')
- assert pattern == path
- pattern.variables.should be(%w( foo bar.baz abc ))
+ assert { pattern == path }
+ pattern.variables.must == %w( foo bar.baz abc )
end
- test "doesn't get confused with extension when path contains other dots" do
+ # doesn't get confused with extension when path contains other dots
+ test do
path = Path.new('/foo/bar.baz/abc.xml')
pattern = Pattern.new('/:a/:b/:c.:type')
- assert pattern == path
- pattern.variables.should be(%w( foo bar.baz abc xml ))
+ assert { pattern == path }
+ pattern.variables.must == %w( foo bar.baz abc xml )
end
end
View
27 test/test_dsl.rb
@@ -4,35 +4,42 @@ class App
include SimpleRouter::DSL
end
-class DslTest < Test::Unit::TestCase
+context do
- def setup
+ setup do
+ SimpleRouter.engine = SimpleRouter::Engines::SimpleEngine
+ end
+
+ teardown do
App.routes.clear
end
## API
- test "provides action verb methods" do
+ # provides action verb methods
+ test do
App.get( '/foo') {}
App.post( '/foo') {}
App.put( '/foo') {}
App.delete('/foo') {}
- App.routes.size.should be(4)
+ App.routes.size.must == 4
end
- test "provides routes object" do
- App.respond_to?(:routes).should be(true)
- App.routes.should be_kind_of(SimpleRouter::Routes)
+ # provides routes object
+ test do
+ App.respond_to?(:routes).must == true
+ App.routes.must.kind_of?(SimpleRouter::Routes)
end
## matching
- test "matching routes" do
+ # matching routes
+ test do
App.get('/foo') { 'foo' }
App.get('/bar') { 'bar' }
- App.routes.match(:get, '/foo').should_not be( nil )
- App.routes.match(:get, '/foo').action.call.should be('foo')
+ App.routes.match(:get, '/foo').wont == nil
+ App.routes.match(:get, '/foo').action.call.must == 'foo'
end
end
View
22 test/test_helper.rb
@@ -1,21 +1,17 @@
require 'pathname'
-require 'test/unit'
-require 'rubygems'
-require 'matchy'
-require 'pending'
+require 'nanotest'
+require 'nanotest/spec'
+require 'nanotest/contexts'
begin
require 'ruby-debug'
+ require 'redgreen' # gem install mynyml-redgreen
+ require 'nanotest/stats'
+ require 'nanotest/focus'
rescue LoadError, RuntimeError
end
-root = Pathname(__FILE__).dirname.parent.expand_path
-$:.unshift(root.join('lib'))
-
+$:.unshift Pathname(__FILE__).dirname.parent + 'lib'
require 'simple_router'
-class Test::Unit::TestCase
- def self.test(name, &block)
- name = :"test_#{name.gsub(/\s/,'_')}"
- define_method(name, &block)
- end
-end
+include Nanotest
+include Nanotest::Contexts
View
51 test/test_routes.rb
@@ -1,56 +1,63 @@
require 'test/test_helper'
-Routes = SimpleRouter::Routes
+## Routes
+context do
+ Routes = SimpleRouter::Routes
-class RoutesTest < Test::Unit::TestCase
-
- def setup
+ setup do
@routes = Routes.new
@action = lambda {}
end
- test "stores route definitions" do
+ # stores route definitions
+ test do
@routes.add(:get, '/foo', {}, &@action)
- @routes.first.path.should be('/foo')
+ @routes.first.path.must == '/foo'
end
## matching
- test "matches a path" do
+ # matches a path
+ test do
@routes.add(:get, '/foo', {}, &@action)
@routes.add(:get, '/bar', {}, &@action)
- @routes.match(:get, '/bar').should_not be(nil)
- @routes.match(:get, '/bar').path.should be('/bar')
+ @routes.match(:get, '/bar').wont == nil
+ @routes.match(:get, '/bar').path.must == '/bar'
end
- test "returns nil when no route matches" do
+ # returns nil when no route matches
+ test do
@routes.add(:get, '/foo', {}, &@action)
@routes.add(:get, '/bar', {}, &@action)
- @routes.match('/baz', :get).should be(nil)
+ @routes.match('/baz', :get).must == nil
end
- test "normalizes passed in verb string" do
+ # normalizes passed in verb string
+ test do
@routes.add(:get, '/foo', {}, &@action)
@routes.add(:get, '/bar', {}, &@action)
- @routes.match('get', '/bar').path.should be('/bar')
- @routes.match('GET', '/bar').path.should be('/bar')
- @routes.match(' GET ','/bar').path.should be('/bar')
+ @routes.match('get', '/bar').path.must == '/bar'
+ @routes.match('GET', '/bar').path.must == '/bar'
+ @routes.match(' GET ','/bar').path.must == '/bar'
end
end
-class RouteTest < Test::Unit::TestCase
+## Route
+context do
- test "internal API" do
+ # internal API
+ test do
verb, path, options, action = :get, '/foo', {}, lambda {}
route = SimpleRouter::Routes::Route.new(verb, path, options, &action)
- route.verb .should be(verb)
- route.path .should be(path)
- route.options .should be(options)
- route.action .should be(action)
- route.values .should be(nil)
+ route.verb .must == verb
+ route.path .must == path
+ route.options .must == options
+ route.action .must == action
+ route.values .must == nil
end
end
+
View
14 test/test_simple_router.rb
@@ -4,20 +4,22 @@ class App
include SimpleRouter::DSL
end
-class SimpleRouterTest < Test::Unit::TestCase
+context do
- def setup
+ setup do
SimpleRouter.engine = nil
end
## engine
- test "default engine" do
- SimpleRouter.engine.name.split('::').last.should be('SimpleEngine')
+ # default engine
+ test do
+ SimpleRouter.engine.name.split('::').last.must == 'SimpleEngine'
end
- test "custom engine" do
+ # custom engine
+ test do
SimpleRouter.engine = ::Object
- SimpleRouter.engine.name.should be('Object')
+ SimpleRouter.engine.name.must == 'Object'
end
end

0 comments on commit dc7dddc

Please sign in to comment.
Something went wrong with that request. Please try again.