chicago 0.3.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/MIT-LICENSE +20 -0
- data/README.markdown +44 -0
- data/Rakefile +34 -0
- data/chicago.gemspec +38 -0
- data/lib/chicago.rb +4 -0
- data/lib/chicago/application.rb +28 -0
- data/lib/chicago/helpers.rb +77 -0
- data/lib/chicago/protest.rb +1 -0
- data/lib/chicago/protest/macros.rb +45 -0
- data/lib/chicago/responders.rb +15 -0
- data/lib/chicago/shoulda.rb +1 -0
- data/lib/chicago/shoulda/sinatra.rb +83 -0
- data/test/application_test.rb +48 -0
- data/test/helpers_test.rb +125 -0
- data/test/protest_macros_test.rb +15 -0
- data/test/responders_test.rb +19 -0
- data/test/test_helper.rb +25 -0
- metadata +74 -0
data/MIT-LICENSE
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
Copyright (c) 2008 Justin Knowlden, Gabriel Gironda, Dan Hodos, Thumble Monks
|
|
2
|
+
|
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
|
4
|
+
a copy of this software and associated documentation files (the
|
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
|
9
|
+
the following conditions:
|
|
10
|
+
|
|
11
|
+
The above copyright notice and this permission notice shall be
|
|
12
|
+
included in all copies or substantial portions of the Software.
|
|
13
|
+
|
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.markdown
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
# Chicago
|
|
2
|
+
|
|
3
|
+
It's my kind of town!
|
|
4
|
+
- Sinatra
|
|
5
|
+
|
|
6
|
+
Yeah, we're real clever. We're also from ["The city in mid-west best city in the whole wide wide world"](http://www.azlyrics.com/lyrics/lupefiasco/gogogadgetflow.html) ... which makes us double the clever.
|
|
7
|
+
|
|
8
|
+
## What what?
|
|
9
|
+
|
|
10
|
+
### Sinatra runtime app
|
|
11
|
+
|
|
12
|
+
In your Sinatra app, do this:
|
|
13
|
+
|
|
14
|
+
require 'chicago'
|
|
15
|
+
|
|
16
|
+
And you'll get some helpful Sinatra extensions and helpers.
|
|
17
|
+
|
|
18
|
+
If you're Sinatra app is considered modular - as in, you are not using the `Sinatra::Default` app - you will want to add the following in your app:
|
|
19
|
+
|
|
20
|
+
YourApp < Sinatra::Base
|
|
21
|
+
register Sinatra::Chicago # for some DSL helpers
|
|
22
|
+
helpers Sinatra::Chicago::Helpers # for standard helpers
|
|
23
|
+
helpers Sinatra::Chicago::Responders # for JSON assistance
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
You don't necessarily need all of them. You just need to "include" the statements that mix-in the functionality you want.
|
|
27
|
+
|
|
28
|
+
### Sinatra testing
|
|
29
|
+
|
|
30
|
+
Assuming you have required 'rack/test', like so:
|
|
31
|
+
|
|
32
|
+
require 'rack/test'
|
|
33
|
+
|
|
34
|
+
This is because these macros use last_request defined by the Rack/Test library. If you're using [Protest](http://github.com/thumblemonks/protest) in your tests of your Sinatra app, do this:
|
|
35
|
+
|
|
36
|
+
require 'chicago/protest'
|
|
37
|
+
|
|
38
|
+
... and you'll get a bunch of cool Protest macros for testing specific Sinatra stuff.
|
|
39
|
+
|
|
40
|
+
If you're using Shoulda in your tests of your Sinatra app, do this:
|
|
41
|
+
|
|
42
|
+
require 'chicago/shoulda'
|
|
43
|
+
|
|
44
|
+
... and you'll get a bunch of cool Shoulda macros for testing specific Sinatra stuff.
|
data/Rakefile
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
require 'rubygems'
|
|
2
|
+
require 'rake'
|
|
3
|
+
require 'rake/testtask'
|
|
4
|
+
|
|
5
|
+
desc 'Default task: run all tests'
|
|
6
|
+
task :default => [:test]
|
|
7
|
+
|
|
8
|
+
task(:set_test_env) { ENV['RACK_ENV'] ||= 'test' }
|
|
9
|
+
|
|
10
|
+
desc "Run all tests"
|
|
11
|
+
task :test => [:set_test_env] do
|
|
12
|
+
require 'protest'
|
|
13
|
+
$:.concat ['./lib', './test']
|
|
14
|
+
Dir.glob("./test/*_test.rb").each { |test| require test }
|
|
15
|
+
Protest.report
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
task "test:shoulda" => [:set_test_env]
|
|
19
|
+
desc "Run all Shoulda based tests"
|
|
20
|
+
Rake::TestTask.new("test:shoulda") do |t|
|
|
21
|
+
t.libs << "test/shoulda_tests"
|
|
22
|
+
t.test_files = FileList['test/shoulda_tests/*_test.rb']
|
|
23
|
+
t.verbose = true
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
# task :test => [:set_test_env] do
|
|
27
|
+
# $:.concat ['./lib', './test/shoulda_tests']
|
|
28
|
+
# Dir.glob("./test/shoulda_tests/*_test.rb").each { |test| require test }
|
|
29
|
+
# end
|
|
30
|
+
|
|
31
|
+
desc "Open an irb session preloaded with this library"
|
|
32
|
+
task :console do
|
|
33
|
+
exec "irb -rubygems"
|
|
34
|
+
end
|
data/chicago.gemspec
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
Gem::Specification.new do |s|
|
|
2
|
+
s.name = "chicago"
|
|
3
|
+
s.version = "0.3.4"
|
|
4
|
+
s.date = "2009-10-02"
|
|
5
|
+
s.summary = "Sinatra runtime and testing extensions used commonly by Thumblemonks"
|
|
6
|
+
s.email = %w[gus@gusg.us gabriel.gironda@gmail.com]
|
|
7
|
+
s.homepage = "http://github.com/thumblemonks/chicago/tree/master"
|
|
8
|
+
s.description = "Sinatra runtime and testing extensions used commonly by Thumblemonks. For example, :json_response, which turns an object into JSON and sets the content-type appropriately."
|
|
9
|
+
s.authors = %w[Justin\ Knowlden Gabriel\ Gironda]
|
|
10
|
+
|
|
11
|
+
s.has_rdoc = false
|
|
12
|
+
s.rdoc_options = ["--main", "README.markdown"]
|
|
13
|
+
s.extra_rdoc_files = ["README.markdown"]
|
|
14
|
+
|
|
15
|
+
# run git ls-files to get an updated list
|
|
16
|
+
s.files = %w[
|
|
17
|
+
MIT-LICENSE
|
|
18
|
+
README.markdown
|
|
19
|
+
chicago.gemspec
|
|
20
|
+
lib/chicago.rb
|
|
21
|
+
lib/chicago/application.rb
|
|
22
|
+
lib/chicago/helpers.rb
|
|
23
|
+
lib/chicago/protest.rb
|
|
24
|
+
lib/chicago/protest/macros.rb
|
|
25
|
+
lib/chicago/responders.rb
|
|
26
|
+
lib/chicago/shoulda.rb
|
|
27
|
+
lib/chicago/shoulda/sinatra.rb
|
|
28
|
+
]
|
|
29
|
+
|
|
30
|
+
s.test_files = %w[
|
|
31
|
+
Rakefile
|
|
32
|
+
test/application_test.rb
|
|
33
|
+
test/helpers_test.rb
|
|
34
|
+
test/protest_macros_test.rb
|
|
35
|
+
test/responders_test.rb
|
|
36
|
+
test/test_helper.rb
|
|
37
|
+
]
|
|
38
|
+
end
|
data/lib/chicago.rb
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
module Sinatra
|
|
2
|
+
module Chicago
|
|
3
|
+
|
|
4
|
+
# Assumes all CSS is SASS and is referenced as being in a directory named stylesheets
|
|
5
|
+
# If SASS file is not defined, the route will passed on to - theoretically - the real
|
|
6
|
+
# CSS in the public directory.
|
|
7
|
+
def catch_all_css(path='/stylesheets')
|
|
8
|
+
get("#{path}/*.css") do
|
|
9
|
+
begin
|
|
10
|
+
content_type 'text/css'
|
|
11
|
+
sass params["splat"].first.to_sym
|
|
12
|
+
rescue Errno::ENOENT
|
|
13
|
+
pass
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
# When you don't want anything special, but to load a named view as HAML.
|
|
19
|
+
def get_obvious(name)
|
|
20
|
+
get "/#{name}" do
|
|
21
|
+
haml name.to_sym
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
end # Chicago
|
|
26
|
+
|
|
27
|
+
register Chicago
|
|
28
|
+
end # Sinatra
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
module Sinatra
|
|
2
|
+
module Chicago
|
|
3
|
+
module Helpers
|
|
4
|
+
# A basic anchor (link_to) tag
|
|
5
|
+
#
|
|
6
|
+
# Exmaples:
|
|
7
|
+
#
|
|
8
|
+
# anchor('GusGus', 'http://gusg.us')
|
|
9
|
+
# => <a href="http://gusg.us">GusG.us</a>
|
|
10
|
+
#
|
|
11
|
+
# anchor('GusGus', 'http://gusg.us', :title => 'You know who!')
|
|
12
|
+
# => <a href="http://gusg.us" title="You know who!">GusG.us</a>
|
|
13
|
+
def anchor(name, url, options={})
|
|
14
|
+
defaults = {:href => url}
|
|
15
|
+
options_str = hash_to_attributes(defaults.merge(options))
|
|
16
|
+
%Q[<a #{options_str}>#{name}</a>]
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
# A helper to include stylesheet links. Currently defaults everything to
|
|
20
|
+
# load from a /stylesheets directory.
|
|
21
|
+
#
|
|
22
|
+
# Exmaples:
|
|
23
|
+
#
|
|
24
|
+
# stylesheet_include('foo')
|
|
25
|
+
# => <link href="/stylsheets/foo.css" media="screen" rel="stylesheet" type="text/css" />
|
|
26
|
+
#
|
|
27
|
+
# stylesheet_include('foo/bar')
|
|
28
|
+
# => <link href="/stylsheets/foo/bar.css" media="screen" rel="stylesheet" type="text/css" />
|
|
29
|
+
#
|
|
30
|
+
# stylesheet_include('foo', :media => "print")
|
|
31
|
+
# => <link href="/stylsheets/foo.css" media="print" rel="stylesheet" type="text/css" />
|
|
32
|
+
#
|
|
33
|
+
# stylesheet_include('http://example.com/foo.css')
|
|
34
|
+
# => <link href="http://example.com/foo.css" media="print" rel="stylesheet" type="text/css" />
|
|
35
|
+
def stylesheet_include(name, options={})
|
|
36
|
+
name = "/stylesheets/#{name}.css" unless remote_asset?(name)
|
|
37
|
+
defaults = {:href => name, :media => "screen",
|
|
38
|
+
:rel => "stylesheet", :type => "text/css"}
|
|
39
|
+
options_str = hash_to_attributes(defaults.merge(options))
|
|
40
|
+
%Q[<link #{options_str}/>]
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
# A helper to include javascript source tags. Currently defaults everything
|
|
44
|
+
# to load from a /javascripts directory.
|
|
45
|
+
#
|
|
46
|
+
# Exmaples:
|
|
47
|
+
#
|
|
48
|
+
# javascript_include('foo')
|
|
49
|
+
# => <javascript src="/javascripts/foo.js" type="text/javascript"></script>
|
|
50
|
+
#
|
|
51
|
+
# javascript_include('foo/bar')
|
|
52
|
+
# => <javascript src="/javascripts/foo/bar.js" type="text/javascript"></script>
|
|
53
|
+
#
|
|
54
|
+
# javascript_include('foo', :something => "great")
|
|
55
|
+
# => <javascript src="/javascripts/foo.js" type="text/javascript" something="great"></script>
|
|
56
|
+
#
|
|
57
|
+
# javascript_include('http://example.com/foo.js')
|
|
58
|
+
# => <javascript src="http://example.com/foo.js" type="text/javascript"></script>
|
|
59
|
+
def javascript_include(name, options={})
|
|
60
|
+
name = "/javascripts/#{name}.js" unless remote_asset?(name)
|
|
61
|
+
defaults = {:src => name, :type => "text/javascript"}
|
|
62
|
+
options_str = hash_to_attributes(defaults.merge(options))
|
|
63
|
+
%Q[<script #{options_str}></script>]
|
|
64
|
+
end
|
|
65
|
+
private
|
|
66
|
+
def remote_asset?(uri)
|
|
67
|
+
uri =~ %r[^\w+://.+]
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
def hash_to_attributes(options)
|
|
71
|
+
options.map {|k,v| "#{k}=\"#{v}\""}.join(' ')
|
|
72
|
+
end
|
|
73
|
+
end # Helpers
|
|
74
|
+
end # Chicago
|
|
75
|
+
|
|
76
|
+
helpers Chicago::Helpers
|
|
77
|
+
end # Sinatra
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
require 'chicago/protest/macros'
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
require 'json'
|
|
2
|
+
|
|
3
|
+
module Chicago
|
|
4
|
+
module Protest
|
|
5
|
+
module Macros
|
|
6
|
+
def asserts_response_status(expected)
|
|
7
|
+
asserts("response status is #{expected}") { last_response.status }.equals(expected)
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def asserts_content_type(expected)
|
|
11
|
+
asserts("content type is #{expected}") { last_response.headers['Content-type'] }.equals(expected)
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def asserts_response_body(expected)
|
|
15
|
+
asserts("response body matches #{expected.inspect}") { last_response.body }.matches(expected)
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def asserts_location(expected_path)
|
|
19
|
+
asserts("location matches #{expected_path}") do
|
|
20
|
+
last_response.headers["Location"]
|
|
21
|
+
end.matches(expected_path)
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def asserts_json_response(json, &block)
|
|
25
|
+
asserts_content_type 'application/json'
|
|
26
|
+
asserts("response body has JSON") do
|
|
27
|
+
json = json.to_json unless json.instance_of?(String)
|
|
28
|
+
json
|
|
29
|
+
end.equals(situation.last_response.body)
|
|
30
|
+
# Calling situation is kind of yucky, but maybe not. The maybe not is because of how explicit it is
|
|
31
|
+
# to say "situation" (gus)
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
# Usage:
|
|
35
|
+
# assert_redirected_to '/foo/bar'
|
|
36
|
+
# assert_redirected_to %r[foo/bar]
|
|
37
|
+
def asserts_redirected_to(expected_path)
|
|
38
|
+
asserts_response_status 302
|
|
39
|
+
asserts_location expected_path
|
|
40
|
+
end
|
|
41
|
+
end # Macros
|
|
42
|
+
end # Protest
|
|
43
|
+
end # Chicago
|
|
44
|
+
|
|
45
|
+
Protest::Context.instance_eval { include Chicago::Protest::Macros }
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
module Sinatra
|
|
2
|
+
module Chicago
|
|
3
|
+
module Responders
|
|
4
|
+
|
|
5
|
+
# Returns a JSON response for an object. Will return an empty string if the provided object is nil.
|
|
6
|
+
def json_response(object)
|
|
7
|
+
content_type 'application/json'
|
|
8
|
+
object ? object.to_json : ""
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
end # Responders
|
|
12
|
+
end # Chicago
|
|
13
|
+
|
|
14
|
+
helpers Chicago::Responders
|
|
15
|
+
end # Sinatra
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
require 'chicago/shoulda/sinatra'
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
require 'json'
|
|
2
|
+
require 'ostruct'
|
|
3
|
+
|
|
4
|
+
module ThumbleMonks
|
|
5
|
+
module Chicago
|
|
6
|
+
module Shoulda
|
|
7
|
+
|
|
8
|
+
def self.included(klass)
|
|
9
|
+
klass.extend(Macros)
|
|
10
|
+
klass.send(:include, Helpers)
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
module Macros
|
|
14
|
+
def should_have_response_status(expected)
|
|
15
|
+
should("have response status") { assert_response expected }
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def should_have_response_body(expected)
|
|
19
|
+
name = expected.is_a?(String) ? expected[0...15] : expected.to_s
|
|
20
|
+
should("have response body like #{name}") { assert_response_body expected }
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def should_have_content_type(expected)
|
|
24
|
+
should("have content_type") { assert_content_type expected }
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def should_have_json_response(json={}, &block)
|
|
28
|
+
should_have_content_type 'application/json'
|
|
29
|
+
should "have JSON response in the body" do
|
|
30
|
+
json = self.instance_eval(&block) if block_given?
|
|
31
|
+
json = json.to_json unless json.instance_of?(String) || json.instance_of?(Regexp)
|
|
32
|
+
assert_response_body json
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
# Checks to see if there is a redirect in play and the path the redirect goes to
|
|
37
|
+
#
|
|
38
|
+
# Example:
|
|
39
|
+
# should_be_redirected_to { "/users/@user.id" }
|
|
40
|
+
# should_be_redirected_to "/home"
|
|
41
|
+
def should_be_redirected_to(expected_path=nil, &block)
|
|
42
|
+
should "be redirected to #{expected_path || 'a url'}" do
|
|
43
|
+
expected_path = self.instance_eval(&block) if block_given?
|
|
44
|
+
assert_redirected_to expected_path
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
end # Macros
|
|
48
|
+
|
|
49
|
+
module Helpers
|
|
50
|
+
def deny(check, message=nil)
|
|
51
|
+
assert(!check, message)
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
def assert_response(status)
|
|
55
|
+
assert_equal status, last_response.status
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
def assert_response_body(body)
|
|
59
|
+
assert_match body, last_response.body
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
def assert_content_type(expected)
|
|
63
|
+
assert_equal expected, last_response.headers['Content-type']
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
# Usage:
|
|
67
|
+
#
|
|
68
|
+
# assert_redirected_to '/foo/bar'
|
|
69
|
+
# or
|
|
70
|
+
# assert_redirected_to %r[foo.bar]
|
|
71
|
+
def assert_redirected_to(expected_path)
|
|
72
|
+
yield if block_given?
|
|
73
|
+
assert_response 302
|
|
74
|
+
action = expected_path.kind_of?(Regexp) ? 'match' : 'equal'
|
|
75
|
+
send("assert_#{action}", expected_path, last_response.headers["Location"])
|
|
76
|
+
end
|
|
77
|
+
end # Helpers
|
|
78
|
+
|
|
79
|
+
end # Shoulda
|
|
80
|
+
end # Chicago
|
|
81
|
+
end # ThumbleMonks
|
|
82
|
+
|
|
83
|
+
Test::Unit::TestCase.instance_eval { include ThumbleMonks::Chicago::Shoulda }
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
require 'test_helper'
|
|
2
|
+
|
|
3
|
+
context "Application Test:" do
|
|
4
|
+
|
|
5
|
+
setup do
|
|
6
|
+
mock_app {
|
|
7
|
+
register Sinatra::Chicago
|
|
8
|
+
|
|
9
|
+
template(:foo) { ".bar\n :display none" }
|
|
10
|
+
template(:goo) { ".car\n :display some" }
|
|
11
|
+
template(:baz) { "Whatever man. That's just like, your opinion." }
|
|
12
|
+
|
|
13
|
+
catch_all_css
|
|
14
|
+
catch_all_css('/css')
|
|
15
|
+
|
|
16
|
+
get_obvious 'baz'
|
|
17
|
+
}
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
# TODO: change to namespace
|
|
21
|
+
context "catching all css" do
|
|
22
|
+
context "with default path" do
|
|
23
|
+
setup { get '/stylesheets/foo.css' }
|
|
24
|
+
asserts_response_status 200
|
|
25
|
+
asserts_content_type 'text/css'
|
|
26
|
+
asserts_response_body %r[.bar \{\s+display: none; \}\s]
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
context "with specified path" do
|
|
30
|
+
setup { get '/css/goo.css' }
|
|
31
|
+
asserts_response_status 200
|
|
32
|
+
asserts_content_type 'text/css'
|
|
33
|
+
asserts_response_body %r[.car \{\s+display: some; \}\s]
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
context "with path that's not a defined a sass file" do
|
|
37
|
+
setup { get '/stylesheets/zoo.css' }
|
|
38
|
+
asserts_response_status 404
|
|
39
|
+
asserts_content_type 'text/css'
|
|
40
|
+
end
|
|
41
|
+
end # catching all css
|
|
42
|
+
|
|
43
|
+
context "getting obvious views" do
|
|
44
|
+
setup { get '/baz' }
|
|
45
|
+
asserts_response_body "Whatever man. That's just like, your opinion."
|
|
46
|
+
end # getting obvious views
|
|
47
|
+
|
|
48
|
+
end
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
require 'test_helper'
|
|
2
|
+
|
|
3
|
+
context "Helpers Test:" do
|
|
4
|
+
setup do
|
|
5
|
+
mock_app {
|
|
6
|
+
helpers Sinatra::Chicago::Helpers
|
|
7
|
+
}
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
context "including stylesheet" do
|
|
11
|
+
context "for plain old foo" do
|
|
12
|
+
setup do
|
|
13
|
+
extend_mock_app {
|
|
14
|
+
template(:foo) { "= stylesheet_include('foo')" }
|
|
15
|
+
get('/foo') { haml :foo }
|
|
16
|
+
}
|
|
17
|
+
get '/foo'
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
asserts_response_body %r[^<link( \w+=".+"){4}/>$]
|
|
21
|
+
asserts_response_body %r[href="/stylesheets/foo\.css"]
|
|
22
|
+
asserts_response_body %r[media="screen"]
|
|
23
|
+
asserts_response_body %r[rel="stylesheet"]
|
|
24
|
+
asserts_response_body %r[type="text/css"]
|
|
25
|
+
end # for plain old foo
|
|
26
|
+
|
|
27
|
+
context "for bar with options" do
|
|
28
|
+
setup do
|
|
29
|
+
extend_mock_app {
|
|
30
|
+
template(:foo) { "= stylesheet_include('bar', :media => 'print', :baz => 'boo')" }
|
|
31
|
+
get('/foo') { haml :foo }
|
|
32
|
+
}
|
|
33
|
+
get '/foo'
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
asserts_response_body %r[^<link( \w+=".+"){5}/>$]
|
|
37
|
+
asserts_response_body %r[href="/stylesheets/bar\.css"]
|
|
38
|
+
asserts_response_body %r[media="print"]
|
|
39
|
+
asserts_response_body %r[rel="stylesheet"]
|
|
40
|
+
asserts_response_body %r[type="text/css"]
|
|
41
|
+
asserts_response_body %r[baz="boo"]
|
|
42
|
+
end # for bar with options
|
|
43
|
+
|
|
44
|
+
context "with a specific href" do
|
|
45
|
+
setup do
|
|
46
|
+
extend_mock_app {
|
|
47
|
+
template(:foo) { "= stylesheet_include('http://example.com')" }
|
|
48
|
+
get('/foo') { haml :foo }
|
|
49
|
+
}
|
|
50
|
+
get '/foo'
|
|
51
|
+
end
|
|
52
|
+
asserts_response_body %r[href="http://example.com"]
|
|
53
|
+
end # with a specific href
|
|
54
|
+
end # including stylesheets
|
|
55
|
+
|
|
56
|
+
context "including javascript" do
|
|
57
|
+
context "for plain old foo" do
|
|
58
|
+
setup do
|
|
59
|
+
extend_mock_app {
|
|
60
|
+
template(:foo) { "= javascript_include('foo')" }
|
|
61
|
+
get('/foo') { haml :foo }
|
|
62
|
+
}
|
|
63
|
+
get '/foo'
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
asserts_response_body %r[^<script( \w+=".+"){2}></script>$]
|
|
67
|
+
asserts_response_body %r[src="/javascripts/foo\.js"]
|
|
68
|
+
asserts_response_body %r[type="text/javascript"]
|
|
69
|
+
end # for plain old foo
|
|
70
|
+
|
|
71
|
+
context "for foo with options" do
|
|
72
|
+
setup do
|
|
73
|
+
extend_mock_app {
|
|
74
|
+
template(:foo) { "= javascript_include('foo', :type => 'text/blarg', :gus => 'nice')" }
|
|
75
|
+
get('/foo') { haml :foo }
|
|
76
|
+
}
|
|
77
|
+
get '/foo'
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
asserts_response_body %r[^<script( \w+=".+"){3}></script>$]
|
|
81
|
+
asserts_response_body %r[src="/javascripts/foo\.js"]
|
|
82
|
+
asserts_response_body %r[type="text/blarg"]
|
|
83
|
+
asserts_response_body %r[gus="nice"]
|
|
84
|
+
end # for foo with options
|
|
85
|
+
|
|
86
|
+
context "with a specific src" do
|
|
87
|
+
setup do
|
|
88
|
+
extend_mock_app {
|
|
89
|
+
template(:foo) { "= javascript_include('http://example.com')" }
|
|
90
|
+
get('/foo') { haml :foo }
|
|
91
|
+
}
|
|
92
|
+
get '/foo'
|
|
93
|
+
end
|
|
94
|
+
asserts_response_body %r[src="http://example.com"]
|
|
95
|
+
end # with a specific src
|
|
96
|
+
end # including javascript
|
|
97
|
+
|
|
98
|
+
context "using an anchor" do
|
|
99
|
+
context "for plain old foo" do
|
|
100
|
+
setup do
|
|
101
|
+
extend_mock_app {
|
|
102
|
+
template(:foo) { "= anchor('foo', '/bar')" }
|
|
103
|
+
get('/foo') { haml :foo }
|
|
104
|
+
}
|
|
105
|
+
get '/foo'
|
|
106
|
+
end
|
|
107
|
+
|
|
108
|
+
asserts_response_body %Q[<a href="/bar">foo</a>]
|
|
109
|
+
end # for plain old foo
|
|
110
|
+
|
|
111
|
+
context "with options" do
|
|
112
|
+
setup do
|
|
113
|
+
extend_mock_app {
|
|
114
|
+
template(:foo) { "= anchor('foo bear', '/bar/ler', :title => 'gus is nice')" }
|
|
115
|
+
get('/foo') { haml :foo }
|
|
116
|
+
}
|
|
117
|
+
get '/foo'
|
|
118
|
+
end
|
|
119
|
+
|
|
120
|
+
asserts_response_body %r[^<a( \w+=".+"){2}>foo bear</a>$]
|
|
121
|
+
asserts_response_body %r[href="/bar/ler"]
|
|
122
|
+
asserts_response_body %r[title="gus is nice"]
|
|
123
|
+
end # with options
|
|
124
|
+
end # using an anchor
|
|
125
|
+
end
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
require 'test_helper'
|
|
2
|
+
|
|
3
|
+
context "Protest Macros Test:" do
|
|
4
|
+
setup do
|
|
5
|
+
mock_app {
|
|
6
|
+
helpers Sinatra::Chicago::Responders
|
|
7
|
+
get("/redirecter") { redirect '/foo/bar' }
|
|
8
|
+
}
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
context "asserts redirected to" do
|
|
12
|
+
setup { get('/redirecter') }
|
|
13
|
+
asserts_redirected_to('/foo/bar')
|
|
14
|
+
end # asserts redirected to
|
|
15
|
+
end
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
require 'test_helper'
|
|
2
|
+
|
|
3
|
+
context "Responders Test:" do
|
|
4
|
+
setup do
|
|
5
|
+
mock_app {
|
|
6
|
+
helpers Sinatra::Chicago::Responders
|
|
7
|
+
get "/json_bait" do
|
|
8
|
+
status(201)
|
|
9
|
+
json_response({:foo => "bar"})
|
|
10
|
+
end
|
|
11
|
+
}
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
context "json response" do
|
|
15
|
+
setup { get "/json_bait" }
|
|
16
|
+
asserts_response_status 201
|
|
17
|
+
asserts_json_response({:foo => :bar})
|
|
18
|
+
end # json response
|
|
19
|
+
end
|
data/test/test_helper.rb
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
%w[ rubygems protest haml sass chicago rack/test chicago/protest ].each do |lib|
|
|
2
|
+
require lib
|
|
3
|
+
end
|
|
4
|
+
|
|
5
|
+
module Rack::Test::Methods
|
|
6
|
+
# Sets up a Sinatra::Base subclass defined with the block
|
|
7
|
+
# given. Used in setup or individual spec methods to establish
|
|
8
|
+
# the application.
|
|
9
|
+
def mock_app(base=Sinatra::Base, &block)
|
|
10
|
+
@app = Sinatra.new(base, &block)
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def extend_mock_app(&block)
|
|
14
|
+
@_rack_test_session ||= Rack::Test::Session.new(app)
|
|
15
|
+
@app.instance_eval(&block)
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def app
|
|
19
|
+
@app
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
class Protest::Situation
|
|
24
|
+
include Rack::Test::Methods
|
|
25
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: chicago
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.3.4
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Justin Knowlden
|
|
8
|
+
- Gabriel Gironda
|
|
9
|
+
autorequire:
|
|
10
|
+
bindir: bin
|
|
11
|
+
cert_chain: []
|
|
12
|
+
|
|
13
|
+
date: 2009-10-02 00:00:00 -05:00
|
|
14
|
+
default_executable:
|
|
15
|
+
dependencies: []
|
|
16
|
+
|
|
17
|
+
description: Sinatra runtime and testing extensions used commonly by Thumblemonks. For example, :json_response, which turns an object into JSON and sets the content-type appropriately.
|
|
18
|
+
email:
|
|
19
|
+
- gus@gusg.us
|
|
20
|
+
- gabriel.gironda@gmail.com
|
|
21
|
+
executables: []
|
|
22
|
+
|
|
23
|
+
extensions: []
|
|
24
|
+
|
|
25
|
+
extra_rdoc_files:
|
|
26
|
+
- README.markdown
|
|
27
|
+
files:
|
|
28
|
+
- MIT-LICENSE
|
|
29
|
+
- README.markdown
|
|
30
|
+
- chicago.gemspec
|
|
31
|
+
- lib/chicago.rb
|
|
32
|
+
- lib/chicago/application.rb
|
|
33
|
+
- lib/chicago/helpers.rb
|
|
34
|
+
- lib/chicago/protest.rb
|
|
35
|
+
- lib/chicago/protest/macros.rb
|
|
36
|
+
- lib/chicago/responders.rb
|
|
37
|
+
- lib/chicago/shoulda.rb
|
|
38
|
+
- lib/chicago/shoulda/sinatra.rb
|
|
39
|
+
has_rdoc: true
|
|
40
|
+
homepage: http://github.com/thumblemonks/chicago/tree/master
|
|
41
|
+
licenses: []
|
|
42
|
+
|
|
43
|
+
post_install_message:
|
|
44
|
+
rdoc_options:
|
|
45
|
+
- --main
|
|
46
|
+
- README.markdown
|
|
47
|
+
require_paths:
|
|
48
|
+
- lib
|
|
49
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
50
|
+
requirements:
|
|
51
|
+
- - ">="
|
|
52
|
+
- !ruby/object:Gem::Version
|
|
53
|
+
version: "0"
|
|
54
|
+
version:
|
|
55
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
56
|
+
requirements:
|
|
57
|
+
- - ">="
|
|
58
|
+
- !ruby/object:Gem::Version
|
|
59
|
+
version: "0"
|
|
60
|
+
version:
|
|
61
|
+
requirements: []
|
|
62
|
+
|
|
63
|
+
rubyforge_project:
|
|
64
|
+
rubygems_version: 1.3.5
|
|
65
|
+
signing_key:
|
|
66
|
+
specification_version: 3
|
|
67
|
+
summary: Sinatra runtime and testing extensions used commonly by Thumblemonks
|
|
68
|
+
test_files:
|
|
69
|
+
- Rakefile
|
|
70
|
+
- test/application_test.rb
|
|
71
|
+
- test/helpers_test.rb
|
|
72
|
+
- test/protest_macros_test.rb
|
|
73
|
+
- test/responders_test.rb
|
|
74
|
+
- test/test_helper.rb
|