chicago 0.3.4 → 0.3.5
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +0 -2
- data/chicago.gemspec +9 -5
- data/lib/chicago/riot.rb +1 -0
- data/lib/chicago/{protest → riot}/macros.rb +3 -3
- data/test/protest_macros_test.rb +1 -1
- data/test/shoulda_tests/application_test.rb +48 -0
- data/test/shoulda_tests/helpers_test.rb +125 -0
- data/test/shoulda_tests/responders_test.rb +28 -0
- data/test/shoulda_tests/test_helper.rb +21 -0
- data/test/test_helper.rb +4 -2
- metadata +8 -4
- data/lib/chicago/protest.rb +0 -1
data/Rakefile
CHANGED
@@ -9,10 +9,8 @@ task(:set_test_env) { ENV['RACK_ENV'] ||= 'test' }
|
|
9
9
|
|
10
10
|
desc "Run all tests"
|
11
11
|
task :test => [:set_test_env] do
|
12
|
-
require 'protest'
|
13
12
|
$:.concat ['./lib', './test']
|
14
13
|
Dir.glob("./test/*_test.rb").each { |test| require test }
|
15
|
-
Protest.report
|
16
14
|
end
|
17
15
|
|
18
16
|
task "test:shoulda" => [:set_test_env]
|
data/chicago.gemspec
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = "chicago"
|
3
|
-
s.version = "0.3.
|
4
|
-
s.date = "2009-10-
|
3
|
+
s.version = "0.3.5"
|
4
|
+
s.date = "2009-10-04"
|
5
5
|
s.summary = "Sinatra runtime and testing extensions used commonly by Thumblemonks"
|
6
6
|
s.email = %w[gus@gusg.us gabriel.gironda@gmail.com]
|
7
7
|
s.homepage = "http://github.com/thumblemonks/chicago/tree/master"
|
8
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
9
|
s.authors = %w[Justin\ Knowlden Gabriel\ Gironda]
|
10
10
|
|
11
|
-
s.has_rdoc =
|
11
|
+
s.has_rdoc = true
|
12
12
|
s.rdoc_options = ["--main", "README.markdown"]
|
13
13
|
s.extra_rdoc_files = ["README.markdown"]
|
14
14
|
|
@@ -20,9 +20,9 @@ Gem::Specification.new do |s|
|
|
20
20
|
lib/chicago.rb
|
21
21
|
lib/chicago/application.rb
|
22
22
|
lib/chicago/helpers.rb
|
23
|
-
lib/chicago/protest.rb
|
24
|
-
lib/chicago/protest/macros.rb
|
25
23
|
lib/chicago/responders.rb
|
24
|
+
lib/chicago/riot.rb
|
25
|
+
lib/chicago/riot/macros.rb
|
26
26
|
lib/chicago/shoulda.rb
|
27
27
|
lib/chicago/shoulda/sinatra.rb
|
28
28
|
]
|
@@ -33,6 +33,10 @@ Gem::Specification.new do |s|
|
|
33
33
|
test/helpers_test.rb
|
34
34
|
test/protest_macros_test.rb
|
35
35
|
test/responders_test.rb
|
36
|
+
test/shoulda_tests/application_test.rb
|
37
|
+
test/shoulda_tests/helpers_test.rb
|
38
|
+
test/shoulda_tests/responders_test.rb
|
39
|
+
test/shoulda_tests/test_helper.rb
|
36
40
|
test/test_helper.rb
|
37
41
|
]
|
38
42
|
end
|
data/lib/chicago/riot.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'chicago/riot/macros'
|
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'json'
|
2
2
|
|
3
3
|
module Chicago
|
4
|
-
module
|
4
|
+
module Riot
|
5
5
|
module Macros
|
6
6
|
def asserts_response_status(expected)
|
7
7
|
asserts("response status is #{expected}") { last_response.status }.equals(expected)
|
@@ -39,7 +39,7 @@ module Chicago
|
|
39
39
|
asserts_location expected_path
|
40
40
|
end
|
41
41
|
end # Macros
|
42
|
-
end #
|
42
|
+
end # Riot
|
43
43
|
end # Chicago
|
44
44
|
|
45
|
-
|
45
|
+
Riot::Context.instance_eval { include Chicago::Riot::Macros }
|
data/test/protest_macros_test.rb
CHANGED
@@ -0,0 +1,48 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class ApplicationTest < Test::Unit::TestCase
|
4
|
+
|
5
|
+
def app
|
6
|
+
@app = 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
|
+
should_have_response_status 200
|
25
|
+
should_have_content_type 'text/css'
|
26
|
+
should_have_response_body %r[.bar \{\s+display: none; \}\s]
|
27
|
+
end
|
28
|
+
|
29
|
+
context "with specified path" do
|
30
|
+
setup { get '/css/goo.css' }
|
31
|
+
should_have_response_status 200
|
32
|
+
should_have_content_type 'text/css'
|
33
|
+
should_have_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
|
+
should_have_response_status 404
|
39
|
+
should_have_content_type 'text/css'
|
40
|
+
end
|
41
|
+
end # catching all css
|
42
|
+
|
43
|
+
context "getting obvious views" do
|
44
|
+
setup { get '/baz' }
|
45
|
+
should_have_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
|
+
class HelpersTest < Test::Unit::TestCase
|
4
|
+
def app
|
5
|
+
@app = 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
|
+
should_have_response_body %r[^<link( \w+=".+"){4}/>$]
|
21
|
+
should_have_response_body %r[href="/stylesheets/foo\.css"]
|
22
|
+
should_have_response_body %r[media="screen"]
|
23
|
+
should_have_response_body %r[rel="stylesheet"]
|
24
|
+
should_have_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
|
+
should_have_response_body %r[^<link( \w+=".+"){5}/>$]
|
37
|
+
should_have_response_body %r[href="/stylesheets/bar\.css"]
|
38
|
+
should_have_response_body %r[media="print"]
|
39
|
+
should_have_response_body %r[rel="stylesheet"]
|
40
|
+
should_have_response_body %r[type="text/css"]
|
41
|
+
should_have_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
|
+
should_have_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
|
+
should_have_response_body %r[^<script( \w+=".+"){2}></script>$]
|
67
|
+
should_have_response_body %r[src="/javascripts/foo\.js"]
|
68
|
+
should_have_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
|
+
should_have_response_body %r[^<script( \w+=".+"){3}></script>$]
|
81
|
+
should_have_response_body %r[src="/javascripts/foo\.js"]
|
82
|
+
should_have_response_body %r[type="text/blarg"]
|
83
|
+
should_have_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
|
+
should_have_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
|
+
should_have_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
|
+
should_have_response_body %r[^<a( \w+=".+"){2}>foo bear</a>$]
|
121
|
+
should_have_response_body %r[href="/bar/ler"]
|
122
|
+
should_have_response_body %r[title="gus is nice"]
|
123
|
+
end # with options
|
124
|
+
end # using an anchor
|
125
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class RespondersTest < Test::Unit::TestCase
|
4
|
+
def app
|
5
|
+
@app = mock_app {
|
6
|
+
helpers Sinatra::Chicago::Responders
|
7
|
+
get "/json_bait" do
|
8
|
+
status(201)
|
9
|
+
json_response({:foo => "bar"})
|
10
|
+
end
|
11
|
+
|
12
|
+
get "/no_bait" do
|
13
|
+
status(200)
|
14
|
+
json_response(nil)
|
15
|
+
end
|
16
|
+
}
|
17
|
+
end
|
18
|
+
|
19
|
+
context "json response" do
|
20
|
+
setup { get "/json_bait" }
|
21
|
+
should_have_json_response({:foo => :bar})
|
22
|
+
end # json response
|
23
|
+
|
24
|
+
context "json response with null data" do
|
25
|
+
setup { get "/no_bait" }
|
26
|
+
should_have_json_response(/^$/)
|
27
|
+
end # json response
|
28
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
%w[ rubygems test/unit shoulda haml sass chicago rack/test chicago/shoulda ].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
|
+
end
|
18
|
+
|
19
|
+
class Test::Unit::TestCase
|
20
|
+
include Rack::Test::Methods
|
21
|
+
end
|
data/test/test_helper.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
%w[ rubygems
|
1
|
+
%w[ rubygems riot haml sass chicago rack/test chicago/riot ].each do |lib|
|
2
2
|
require lib
|
3
3
|
end
|
4
4
|
|
@@ -20,6 +20,8 @@ module Rack::Test::Methods
|
|
20
20
|
end
|
21
21
|
end
|
22
22
|
|
23
|
-
class
|
23
|
+
class Riot::Situation
|
24
24
|
include Rack::Test::Methods
|
25
25
|
end
|
26
|
+
|
27
|
+
at_exit { Riot.report }
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: chicago
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Justin Knowlden
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2009-10-
|
13
|
+
date: 2009-10-04 00:00:00 -05:00
|
14
14
|
default_executable:
|
15
15
|
dependencies: []
|
16
16
|
|
@@ -31,9 +31,9 @@ files:
|
|
31
31
|
- lib/chicago.rb
|
32
32
|
- lib/chicago/application.rb
|
33
33
|
- lib/chicago/helpers.rb
|
34
|
-
- lib/chicago/protest.rb
|
35
|
-
- lib/chicago/protest/macros.rb
|
36
34
|
- lib/chicago/responders.rb
|
35
|
+
- lib/chicago/riot.rb
|
36
|
+
- lib/chicago/riot/macros.rb
|
37
37
|
- lib/chicago/shoulda.rb
|
38
38
|
- lib/chicago/shoulda/sinatra.rb
|
39
39
|
has_rdoc: true
|
@@ -71,4 +71,8 @@ test_files:
|
|
71
71
|
- test/helpers_test.rb
|
72
72
|
- test/protest_macros_test.rb
|
73
73
|
- test/responders_test.rb
|
74
|
+
- test/shoulda_tests/application_test.rb
|
75
|
+
- test/shoulda_tests/helpers_test.rb
|
76
|
+
- test/shoulda_tests/responders_test.rb
|
77
|
+
- test/shoulda_tests/test_helper.rb
|
74
78
|
- test/test_helper.rb
|
data/lib/chicago/protest.rb
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
require 'chicago/protest/macros'
|