thumblemonks-chicago 0.2.2 → 0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/README.markdown +8 -4
- data/chicago.gemspec +1 -1
- data/lib/chicago/application.rb +3 -5
- data/lib/chicago/helpers.rb +3 -3
- data/lib/chicago/responders.rb +3 -3
- data/lib/chicago/shoulda/sinatra.rb +9 -9
- data/test/application_test.rb +16 -20
- data/test/helpers_test.rb +14 -8
- data/test/responders_test.rb +10 -6
- data/test/test_helper.rb +11 -15
- metadata +1 -1
data/README.markdown
CHANGED
@@ -18,16 +18,20 @@ And you'll get some helpful Sinatra extensions and helpers.
|
|
18
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
19
|
|
20
20
|
YourApp < Sinatra::Base
|
21
|
-
register Sinatra::
|
22
|
-
helpers Sinatra::
|
23
|
-
helpers Sinatra::
|
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
24
|
end
|
25
25
|
|
26
26
|
You don't necessarily need all of them. You just need to "include" the statements that mix-in the functionality you want.
|
27
27
|
|
28
28
|
### Sinatra testing
|
29
29
|
|
30
|
-
|
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 Shoulda in your tests of your Sinatra app, do this:
|
31
35
|
|
32
36
|
require 'chicago/shoulda'
|
33
37
|
|
data/chicago.gemspec
CHANGED
data/lib/chicago/application.rb
CHANGED
@@ -1,6 +1,5 @@
|
|
1
1
|
module Sinatra
|
2
|
-
module
|
3
|
-
module Base
|
2
|
+
module Chicago
|
4
3
|
|
5
4
|
# Assumes all CSS is SASS and is referenced as being in a directory named stylesheets
|
6
5
|
# If SASS file is not defined, the route will passed on to - theoretically - the real
|
@@ -23,8 +22,7 @@ module Sinatra
|
|
23
22
|
end
|
24
23
|
end
|
25
24
|
|
26
|
-
|
27
|
-
end # ThumbleMonks
|
25
|
+
end # Chicago
|
28
26
|
|
29
|
-
register
|
27
|
+
register Chicago
|
30
28
|
end # Sinatra
|
data/lib/chicago/helpers.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
module Sinatra
|
2
|
-
module
|
2
|
+
module Chicago
|
3
3
|
module Helpers
|
4
4
|
# A basic anchor (link_to) tag
|
5
5
|
#
|
@@ -71,7 +71,7 @@ module Sinatra
|
|
71
71
|
options.map {|k,v| "#{k}=\"#{v}\""}.join(' ')
|
72
72
|
end
|
73
73
|
end # Helpers
|
74
|
-
end #
|
74
|
+
end # Chicago
|
75
75
|
|
76
|
-
helpers
|
76
|
+
helpers Chicago::Helpers
|
77
77
|
end # Sinatra
|
data/lib/chicago/responders.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
module Sinatra
|
2
|
-
module
|
2
|
+
module Chicago
|
3
3
|
module Responders
|
4
4
|
|
5
5
|
# Returns a JSON response for an object
|
@@ -9,7 +9,7 @@ module Sinatra
|
|
9
9
|
end
|
10
10
|
|
11
11
|
end # Responders
|
12
|
-
end #
|
12
|
+
end # Chicago
|
13
13
|
|
14
|
-
helpers
|
14
|
+
helpers Chicago::Responders
|
15
15
|
end # Sinatra
|
@@ -2,8 +2,8 @@ require 'json'
|
|
2
2
|
require 'ostruct'
|
3
3
|
|
4
4
|
module ThumbleMonks
|
5
|
-
module
|
6
|
-
module
|
5
|
+
module Chicago
|
6
|
+
module Shoulda
|
7
7
|
|
8
8
|
def self.included(klass)
|
9
9
|
klass.extend(Macros)
|
@@ -52,15 +52,15 @@ module ThumbleMonks
|
|
52
52
|
end
|
53
53
|
|
54
54
|
def assert_response(status)
|
55
|
-
assert_equal status,
|
55
|
+
assert_equal status, last_response.status
|
56
56
|
end
|
57
57
|
|
58
58
|
def assert_response_body(body)
|
59
|
-
assert_match body,
|
59
|
+
assert_match body, last_response.body
|
60
60
|
end
|
61
61
|
|
62
62
|
def assert_content_type(expected)
|
63
|
-
assert_equal expected,
|
63
|
+
assert_equal expected, last_response.headers['Content-type']
|
64
64
|
end
|
65
65
|
|
66
66
|
# Usage:
|
@@ -72,12 +72,12 @@ module ThumbleMonks
|
|
72
72
|
yield if block_given?
|
73
73
|
assert_response 302
|
74
74
|
action = expected_path.kind_of?(Regexp) ? 'match' : 'equal'
|
75
|
-
send("assert_#{action}", expected_path,
|
75
|
+
send("assert_#{action}", expected_path, last_response.headers["Location"])
|
76
76
|
end
|
77
77
|
end # Helpers
|
78
78
|
|
79
|
-
end #
|
80
|
-
end #
|
79
|
+
end # Shoulda
|
80
|
+
end # Chicago
|
81
81
|
end # ThumbleMonks
|
82
82
|
|
83
|
-
Test::Unit::TestCase.instance_eval { include ThumbleMonks::Shoulda
|
83
|
+
Test::Unit::TestCase.instance_eval { include ThumbleMonks::Chicago::Shoulda }
|
data/test/application_test.rb
CHANGED
@@ -2,15 +2,24 @@ require File.join(File.dirname(__FILE__), 'test_helper')
|
|
2
2
|
|
3
3
|
class ApplicationTest < Test::Unit::TestCase
|
4
4
|
|
5
|
+
def app
|
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
|
+
|
5
20
|
context "catching all css" do
|
6
21
|
context "with default path" do
|
7
22
|
setup do
|
8
|
-
mock_app {
|
9
|
-
catch_all_css
|
10
|
-
template :foo do
|
11
|
-
".bar\n :display none"
|
12
|
-
end
|
13
|
-
}
|
14
23
|
get '/stylesheets/foo.css'
|
15
24
|
end
|
16
25
|
|
@@ -21,12 +30,6 @@ class ApplicationTest < Test::Unit::TestCase
|
|
21
30
|
|
22
31
|
context "with specified path" do
|
23
32
|
setup do
|
24
|
-
mock_app {
|
25
|
-
catch_all_css('/css')
|
26
|
-
template :goo do
|
27
|
-
".car\n :display some"
|
28
|
-
end
|
29
|
-
}
|
30
33
|
get '/css/goo.css'
|
31
34
|
end
|
32
35
|
|
@@ -37,8 +40,7 @@ class ApplicationTest < Test::Unit::TestCase
|
|
37
40
|
|
38
41
|
context "with path that's not a defined a sass file" do
|
39
42
|
setup do
|
40
|
-
|
41
|
-
get '/stylesheets/goo.css'
|
43
|
+
get '/stylesheets/zoo.css'
|
42
44
|
end
|
43
45
|
|
44
46
|
should_have_response_status 404
|
@@ -48,12 +50,6 @@ class ApplicationTest < Test::Unit::TestCase
|
|
48
50
|
|
49
51
|
context "getting obvious views" do
|
50
52
|
setup do
|
51
|
-
mock_app {
|
52
|
-
get_obvious 'baz'
|
53
|
-
template :baz do
|
54
|
-
"Whatever man. That's just like, your opinion."
|
55
|
-
end
|
56
|
-
}
|
57
53
|
get '/baz'
|
58
54
|
end
|
59
55
|
|
data/test/helpers_test.rb
CHANGED
@@ -1,10 +1,16 @@
|
|
1
1
|
require File.join(File.dirname(__FILE__), 'test_helper')
|
2
2
|
|
3
3
|
class HelpersTest < Test::Unit::TestCase
|
4
|
+
def app
|
5
|
+
mock_app {
|
6
|
+
helpers Sinatra::Chicago::Helpers
|
7
|
+
}
|
8
|
+
end
|
9
|
+
|
4
10
|
context "including stylesheet" do
|
5
11
|
context "for plain old foo" do
|
6
12
|
setup do
|
7
|
-
|
13
|
+
extend_mock_app {
|
8
14
|
template(:foo) { "= stylesheet_include('foo')" }
|
9
15
|
get('/foo') { haml :foo }
|
10
16
|
}
|
@@ -20,7 +26,7 @@ class HelpersTest < Test::Unit::TestCase
|
|
20
26
|
|
21
27
|
context "for bar with options" do
|
22
28
|
setup do
|
23
|
-
|
29
|
+
extend_mock_app {
|
24
30
|
template(:foo) { "= stylesheet_include('bar', :media => 'print', :baz => 'boo')" }
|
25
31
|
get('/foo') { haml :foo }
|
26
32
|
}
|
@@ -37,7 +43,7 @@ class HelpersTest < Test::Unit::TestCase
|
|
37
43
|
|
38
44
|
context "with a specific href" do
|
39
45
|
setup do
|
40
|
-
|
46
|
+
extend_mock_app {
|
41
47
|
template(:foo) { "= stylesheet_include('http://example.com')" }
|
42
48
|
get('/foo') { haml :foo }
|
43
49
|
}
|
@@ -50,7 +56,7 @@ class HelpersTest < Test::Unit::TestCase
|
|
50
56
|
context "including javascript" do
|
51
57
|
context "for plain old foo" do
|
52
58
|
setup do
|
53
|
-
|
59
|
+
extend_mock_app {
|
54
60
|
template(:foo) { "= javascript_include('foo')" }
|
55
61
|
get('/foo') { haml :foo }
|
56
62
|
}
|
@@ -64,7 +70,7 @@ class HelpersTest < Test::Unit::TestCase
|
|
64
70
|
|
65
71
|
context "for foo with options" do
|
66
72
|
setup do
|
67
|
-
|
73
|
+
extend_mock_app {
|
68
74
|
template(:foo) { "= javascript_include('foo', :type => 'text/blarg', :gus => 'nice')" }
|
69
75
|
get('/foo') { haml :foo }
|
70
76
|
}
|
@@ -79,7 +85,7 @@ class HelpersTest < Test::Unit::TestCase
|
|
79
85
|
|
80
86
|
context "with a specific src" do
|
81
87
|
setup do
|
82
|
-
|
88
|
+
extend_mock_app {
|
83
89
|
template(:foo) { "= javascript_include('http://example.com')" }
|
84
90
|
get('/foo') { haml :foo }
|
85
91
|
}
|
@@ -92,7 +98,7 @@ class HelpersTest < Test::Unit::TestCase
|
|
92
98
|
context "using an anchor" do
|
93
99
|
context "for plain old foo" do
|
94
100
|
setup do
|
95
|
-
|
101
|
+
extend_mock_app {
|
96
102
|
template(:foo) { "= anchor('foo', '/bar')" }
|
97
103
|
get('/foo') { haml :foo }
|
98
104
|
}
|
@@ -104,7 +110,7 @@ class HelpersTest < Test::Unit::TestCase
|
|
104
110
|
|
105
111
|
context "with options" do
|
106
112
|
setup do
|
107
|
-
|
113
|
+
extend_mock_app {
|
108
114
|
template(:foo) { "= anchor('foo bear', '/bar/ler', :title => 'gus is nice')" }
|
109
115
|
get('/foo') { haml :foo }
|
110
116
|
}
|
data/test/responders_test.rb
CHANGED
@@ -2,14 +2,18 @@ require File.join(File.dirname(__FILE__), 'test_helper')
|
|
2
2
|
|
3
3
|
class RespondersTest < Test::Unit::TestCase
|
4
4
|
|
5
|
+
def app
|
6
|
+
mock_app {
|
7
|
+
helpers Sinatra::Chicago::Responders
|
8
|
+
get "/json_bait" do
|
9
|
+
status(201)
|
10
|
+
json_response({:foo => "bar"})
|
11
|
+
end
|
12
|
+
}
|
13
|
+
end
|
14
|
+
|
5
15
|
context "json response" do
|
6
16
|
setup do
|
7
|
-
mock_app {
|
8
|
-
get "/json_bait" do
|
9
|
-
status(201)
|
10
|
-
json_response({:foo => "bar"})
|
11
|
-
end
|
12
|
-
}
|
13
17
|
get "/json_bait"
|
14
18
|
end
|
15
19
|
|
data/test/test_helper.rb
CHANGED
@@ -1,25 +1,21 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
require 'sass'
|
5
|
-
require 'sinatra'
|
6
|
-
require 'test/unit'
|
7
|
-
require 'sinatra/test'
|
8
|
-
|
9
|
-
require 'shoulda'
|
10
|
-
|
11
|
-
require 'chicago'
|
12
|
-
require 'chicago/shoulda'
|
1
|
+
%w[ rubygems haml sass chicago test/unit rack/test shoulda chicago/shoulda ].each do |lib|
|
2
|
+
require lib
|
3
|
+
end
|
13
4
|
|
14
|
-
module
|
5
|
+
module Rack::Test::Methods
|
15
6
|
# Sets up a Sinatra::Base subclass defined with the block
|
16
7
|
# given. Used in setup or individual spec methods to establish
|
17
8
|
# the application.
|
18
|
-
def mock_app(base=Sinatra::
|
9
|
+
def mock_app(base=Sinatra::Base, &block)
|
19
10
|
@app = Sinatra.new(base, &block)
|
20
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
|
21
17
|
end
|
22
18
|
|
23
19
|
class Test::Unit::TestCase
|
24
|
-
include
|
20
|
+
include Rack::Test::Methods
|
25
21
|
end
|