sinatra-spec 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +58 -0
- data/Rakefile +62 -0
- data/lib/sinatra/spec.rb +52 -0
- data/sinatra-spec.gemspec +22 -0
- metadata +81 -0
data/README.md
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
**Sinatra::Spec** is a class for describing [Sinatra](http://www.sinatrarb.com)
|
2
|
+
apps using [MiniTest](https://github.com/seattlerb/minitest), the unit testing
|
3
|
+
framework that ships with Ruby 1.9.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Via [RubyGems](http://rubygems.org):
|
8
|
+
|
9
|
+
$ sudo gem install sinatra-spec
|
10
|
+
|
11
|
+
From a local copy:
|
12
|
+
|
13
|
+
$ git clone git://github.com/mjijackson/sinatra-spec.git
|
14
|
+
$ cd sinatra-session
|
15
|
+
$ rake package && sudo rake install
|
16
|
+
|
17
|
+
## Usage
|
18
|
+
|
19
|
+
To use `Sinatra::Spec` simply use your Sinatra app as the description argument.
|
20
|
+
Inside that `describe` block you have access to all the methods of [Rack::Test](https://github.com/brynary/rack-test/).
|
21
|
+
These methods will be called on a new instance of the app. See the [testing page](http://www.sinatrarb.com/testing.html)
|
22
|
+
in the Sinatra user manual for an explanation of how to test your app using
|
23
|
+
Rack::Test.
|
24
|
+
|
25
|
+
Here is an example:
|
26
|
+
|
27
|
+
```ruby
|
28
|
+
describe MyApp do
|
29
|
+
describe "GET /" do
|
30
|
+
it "should return ok" do
|
31
|
+
get "/"
|
32
|
+
assert last_response.ok?
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
```
|
37
|
+
|
38
|
+
## License
|
39
|
+
|
40
|
+
Copyright 2012 Michael Jackson
|
41
|
+
|
42
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
43
|
+
of this software and associated documentation files (the "Software"), to deal
|
44
|
+
in the Software without restriction, including without limitation the rights
|
45
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
46
|
+
copies of the Software, and to permit persons to whom the Software is
|
47
|
+
furnished to do so, subject to the following conditions:
|
48
|
+
|
49
|
+
The above copyright notice and this permission notice shall be included in
|
50
|
+
all copies or substantial portions of the Software.
|
51
|
+
|
52
|
+
The software is provided "as is", without warranty of any kind, express or
|
53
|
+
implied, including but not limited to the warranties of merchantability,
|
54
|
+
fitness for a particular purpose and non-infringement. In no event shall the
|
55
|
+
authors or copyright holders be liable for any claim, damages or other
|
56
|
+
liability, whether in an action of contract, tort or otherwise, arising from,
|
57
|
+
out of or in connection with the software or the use or other dealings in
|
58
|
+
the software.
|
data/Rakefile
ADDED
@@ -0,0 +1,62 @@
|
|
1
|
+
require 'rake/clean'
|
2
|
+
|
3
|
+
task :default => :package
|
4
|
+
|
5
|
+
# DOCS ########################################################################
|
6
|
+
|
7
|
+
desc "Generate API documentation"
|
8
|
+
task :api => FileList['lib/**/*.rb'] do |t|
|
9
|
+
output_dir = ENV['OUTPUT_DIR'] || 'api'
|
10
|
+
rm_rf output_dir
|
11
|
+
sh((<<-SH).gsub(/[\s\n]+/, ' ').strip)
|
12
|
+
hanna
|
13
|
+
--op #{output_dir}
|
14
|
+
--promiscuous
|
15
|
+
--charset utf8
|
16
|
+
--fmt html
|
17
|
+
--inline-source
|
18
|
+
--line-numbers
|
19
|
+
--accessor option_accessor=RW
|
20
|
+
--main Sinatra::Spec
|
21
|
+
--title 'Sinatra::Spec API Documentation'
|
22
|
+
#{t.prerequisites.join(' ')}
|
23
|
+
SH
|
24
|
+
end
|
25
|
+
|
26
|
+
CLEAN.include 'api'
|
27
|
+
|
28
|
+
# PACKAGING & INSTALLATION ####################################################
|
29
|
+
|
30
|
+
if defined?(Gem)
|
31
|
+
$spec = eval("#{File.read('sinatra-spec.gemspec')}")
|
32
|
+
|
33
|
+
directory 'dist'
|
34
|
+
|
35
|
+
def package(ext='')
|
36
|
+
"dist/#{$spec.name}-#{$spec.version}" + ext
|
37
|
+
end
|
38
|
+
|
39
|
+
file package('.gem') => %w< dist > + $spec.files do |f|
|
40
|
+
sh "gem build sinatra-spec.gemspec"
|
41
|
+
mv File.basename(f.name), f.name
|
42
|
+
end
|
43
|
+
|
44
|
+
file package('.tar.gz') => %w< dist > + $spec.files do |f|
|
45
|
+
sh "git archive --format=tar HEAD | gzip > #{f.name}"
|
46
|
+
end
|
47
|
+
|
48
|
+
desc "Build packages"
|
49
|
+
task :package => %w< .gem .tar.gz >.map {|e| package(e) }
|
50
|
+
|
51
|
+
desc "Build and install as local gem"
|
52
|
+
task :install => package('.gem') do |t|
|
53
|
+
sh "gem install #{package('.gem')}"
|
54
|
+
end
|
55
|
+
|
56
|
+
desc "Upload gem to rubygems.org"
|
57
|
+
task :release => package('.gem') do |t|
|
58
|
+
sh "gem push #{package('.gem')}"
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
CLOBBER.include 'dist'
|
data/lib/sinatra/spec.rb
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
require 'sinatra/base'
|
2
|
+
require 'minitest/spec'
|
3
|
+
require 'rack/test'
|
4
|
+
|
5
|
+
module Sinatra
|
6
|
+
# This spec is a base for specs that describe Sinatra apps. It mixes in
|
7
|
+
# Rack::Test::Methods and provides an #app method that resolves to the app,
|
8
|
+
# so long as the app is used as the spec's +desc+, e.g.:
|
9
|
+
#
|
10
|
+
# describe MyApp do
|
11
|
+
# describe "GET /" do
|
12
|
+
# it "should respond ok" do
|
13
|
+
# get "/"
|
14
|
+
# assert last_response.ok?
|
15
|
+
# end
|
16
|
+
# end
|
17
|
+
# end
|
18
|
+
class Spec < MiniTest::Spec
|
19
|
+
include Rack::Test::Methods
|
20
|
+
|
21
|
+
# Returns +true+ if the given +desc+ is a class that is a descendant of
|
22
|
+
# Sinatra::Base, for which Sinatra::Spec may be used.
|
23
|
+
def self.is_base?(desc)
|
24
|
+
Sinatra::Base > desc
|
25
|
+
rescue TypeError
|
26
|
+
false
|
27
|
+
end
|
28
|
+
|
29
|
+
# Returns an anonymous subclass of this spec's app class. The class is
|
30
|
+
# subclassed so that each spec may modify its own copy of the app without
|
31
|
+
# affecting others.
|
32
|
+
def self.app_class
|
33
|
+
@app_class ||= Class.new(is_base?(desc) ? desc : superclass.app_class)
|
34
|
+
end
|
35
|
+
|
36
|
+
# Returns the subclass of Sinatra::Base this spec describes.
|
37
|
+
def app_class
|
38
|
+
self.class.app_class
|
39
|
+
end
|
40
|
+
|
41
|
+
# Returns an instance of the #app_class fronted by its middleware. Used
|
42
|
+
# by Rack::Test::Methods to call the app.
|
43
|
+
def app
|
44
|
+
app_class.new
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
# Register Sinatra::Spec to be used for all Sinatra::Base apps.
|
50
|
+
MiniTest::Spec.register_spec_type(Sinatra::Spec) do |desc|
|
51
|
+
Sinatra::Spec.is_base?(desc)
|
52
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
Gem::Specification.new do |s|
|
2
|
+
s.name = 'sinatra-spec'
|
3
|
+
s.version = '1.0.0'
|
4
|
+
s.date = Time.now.strftime('%Y-%m-%d')
|
5
|
+
|
6
|
+
s.summary = 'Simple specs for Sinatra apps using MiniTest'
|
7
|
+
s.description = 'Simple specs for Sinatra apps using MiniTest'
|
8
|
+
|
9
|
+
s.author = 'Michael Jackson'
|
10
|
+
s.email = 'mjijackson@gmail.com'
|
11
|
+
|
12
|
+
s.require_paths = %w< lib >
|
13
|
+
|
14
|
+
s.files = Dir['lib/**/*.rb'] +
|
15
|
+
%w< sinatra-spec.gemspec Rakefile README.md >
|
16
|
+
|
17
|
+
s.add_dependency('minitest', '>= 3.1')
|
18
|
+
s.add_dependency('rack-test', '>= 0.6')
|
19
|
+
s.add_development_dependency('rake')
|
20
|
+
|
21
|
+
s.homepage = 'http://mjijackson.github.com/sinatra-spec'
|
22
|
+
end
|
metadata
ADDED
@@ -0,0 +1,81 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: sinatra-spec
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Michael Jackson
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-06-21 00:00:00.000000000Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: minitest
|
16
|
+
requirement: &70140323158460 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '3.1'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *70140323158460
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: rack-test
|
27
|
+
requirement: &70140323157980 !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ! '>='
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0.6'
|
33
|
+
type: :runtime
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *70140323157980
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: rake
|
38
|
+
requirement: &70140323157600 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ! '>='
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: '0'
|
44
|
+
type: :development
|
45
|
+
prerelease: false
|
46
|
+
version_requirements: *70140323157600
|
47
|
+
description: Simple specs for Sinatra apps using MiniTest
|
48
|
+
email: mjijackson@gmail.com
|
49
|
+
executables: []
|
50
|
+
extensions: []
|
51
|
+
extra_rdoc_files: []
|
52
|
+
files:
|
53
|
+
- lib/sinatra/spec.rb
|
54
|
+
- sinatra-spec.gemspec
|
55
|
+
- Rakefile
|
56
|
+
- README.md
|
57
|
+
homepage: http://mjijackson.github.com/sinatra-spec
|
58
|
+
licenses: []
|
59
|
+
post_install_message:
|
60
|
+
rdoc_options: []
|
61
|
+
require_paths:
|
62
|
+
- lib
|
63
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
64
|
+
none: false
|
65
|
+
requirements:
|
66
|
+
- - ! '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
70
|
+
none: false
|
71
|
+
requirements:
|
72
|
+
- - ! '>='
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: '0'
|
75
|
+
requirements: []
|
76
|
+
rubyforge_project:
|
77
|
+
rubygems_version: 1.8.17
|
78
|
+
signing_key:
|
79
|
+
specification_version: 3
|
80
|
+
summary: Simple specs for Sinatra apps using MiniTest
|
81
|
+
test_files: []
|