thumblemonks-chicago 0.3.1 → 0.3.2

Sign up to get free protection for your applications and to get access to all the features.
data/README.markdown CHANGED
@@ -31,7 +31,13 @@ Assuming you have required 'rack/test', like so:
31
31
 
32
32
  require 'rack/test'
33
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:
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:
35
41
 
36
42
  require 'chicago/shoulda'
37
43
 
data/Rakefile CHANGED
@@ -1,6 +1,5 @@
1
1
  require 'rubygems'
2
2
  require 'rake'
3
- require 'rake/testtask'
4
3
 
5
4
  desc 'Default task: run all tests'
6
5
  task :default => [:test]
@@ -11,11 +10,12 @@ task :environment do
11
10
  # Nothing yet
12
11
  end
13
12
 
14
- task :test => [:set_test_env, :environment]
15
- desc 'Run all tests'
16
- Rake::TestTask.new do |t|
17
- t.test_files = FileList['test/*_test.rb']
18
- t.verbose = true
13
+ desc "Run all tests"
14
+ task :test => [:set_test_env, :environment] do
15
+ require 'protest'
16
+ $:.concat ['./lib', './test']
17
+ Dir.glob("./test/*_test.rb").each { |test| require test }
18
+ Protest.run
19
19
  end
20
20
 
21
21
  desc "Open an irb session preloaded with this library"
data/chicago.gemspec CHANGED
@@ -1,7 +1,7 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = "chicago"
3
- s.version = "0.3.1"
4
- s.date = "2009-06-10"
3
+ s.version = "0.3.2"
4
+ s.date = "2009-06-28"
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"
@@ -22,6 +22,8 @@ Gem::Specification.new do |s|
22
22
  lib/chicago.rb
23
23
  lib/chicago/application.rb
24
24
  lib/chicago/helpers.rb
25
+ lib/chicago/protest.rb
26
+ lib/chicago/protest/macros.rb
25
27
  lib/chicago/responders.rb
26
28
  lib/chicago/shoulda.rb
27
29
  lib/chicago/shoulda/sinatra.rb
@@ -0,0 +1,34 @@
1
+ require 'json'
2
+
3
+ module Chicago
4
+ module Protest
5
+ module Macros
6
+ def asserts_response_status(expected)
7
+ asserts("response status").equals(expected) { last_response.status }
8
+ end
9
+
10
+ def asserts_content_type(expected)
11
+ asserts("content type").equals(expected) { last_response.headers['Content-type'] }
12
+ end
13
+
14
+ def asserts_response_body(expected)
15
+ # TODO: implement a matches operator
16
+ asserts("response body").not do
17
+ expected = %r[#{expected}] if expected.kind_of?(String)
18
+ expected.match(last_response.body).nil?
19
+ end
20
+ end
21
+
22
+ def asserts_json_response(json, &block)
23
+ asserts_content_type 'application/json'
24
+ asserts("response body has JSON") do
25
+ json = json.to_json unless json.instance_of?(String)
26
+ last_response.body == json
27
+ end
28
+ end
29
+
30
+ end # Macros
31
+ end # Protest
32
+ end # Chicago
33
+
34
+ Protest::Context.instance_eval { include Chicago::Protest::Macros }
@@ -0,0 +1 @@
1
+ require 'chicago/protest/macros'
@@ -1,8 +1,8 @@
1
1
  require File.join(File.dirname(__FILE__), 'test_helper')
2
2
 
3
- class ApplicationTest < Test::Unit::TestCase
3
+ context "ApplicationTest:" do
4
4
 
5
- def app
5
+ setup do
6
6
  mock_app {
7
7
  register Sinatra::Chicago
8
8
 
@@ -17,15 +17,16 @@ class ApplicationTest < Test::Unit::TestCase
17
17
  }
18
18
  end
19
19
 
20
+ # TODO: change to namespace
20
21
  context "catching all css" do
21
22
  context "with default path" do
22
23
  setup do
23
24
  get '/stylesheets/foo.css'
24
25
  end
25
26
 
26
- should_have_response_status 200
27
- should_have_content_type 'text/css'
28
- should_have_response_body %r[.bar \{\s+display: none; \}\s]
27
+ asserts_response_status 200
28
+ asserts_content_type 'text/css'
29
+ asserts_response_body %r[.bar \{\s+display: none; \}\s]
29
30
  end
30
31
 
31
32
  context "with specified path" do
@@ -33,9 +34,9 @@ class ApplicationTest < Test::Unit::TestCase
33
34
  get '/css/goo.css'
34
35
  end
35
36
 
36
- should_have_response_status 200
37
- should_have_content_type 'text/css'
38
- should_have_response_body %r[.car \{\s+display: some; \}\s]
37
+ asserts_response_status 200
38
+ asserts_content_type 'text/css'
39
+ asserts_response_body %r[.car \{\s+display: some; \}\s]
39
40
  end
40
41
 
41
42
  context "with path that's not a defined a sass file" do
@@ -43,17 +44,14 @@ class ApplicationTest < Test::Unit::TestCase
43
44
  get '/stylesheets/zoo.css'
44
45
  end
45
46
 
46
- should_have_response_status 404
47
- should_have_content_type 'text/html'
47
+ asserts_response_status 404
48
+ asserts_content_type 'text/html'
48
49
  end
49
50
  end # catching all css
50
51
 
51
52
  context "getting obvious views" do
52
- setup do
53
- get '/baz'
54
- end
55
-
56
- should_have_response_body "Whatever man. That's just like, your opinion."
57
- end
53
+ setup { get '/baz' }
54
+ asserts_response_body "Whatever man. That's just like, your opinion."
55
+ end # getting obvious views
58
56
 
59
57
  end
data/test/helpers_test.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  require File.join(File.dirname(__FILE__), 'test_helper')
2
2
 
3
- class HelpersTest < Test::Unit::TestCase
4
- def app
3
+ context "HelpersTest:" do
4
+ setup do
5
5
  mock_app {
6
6
  helpers Sinatra::Chicago::Helpers
7
7
  }
@@ -17,11 +17,11 @@ class HelpersTest < Test::Unit::TestCase
17
17
  get '/foo'
18
18
  end
19
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"]
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
25
  end # for plain old foo
26
26
 
27
27
  context "for bar with options" do
@@ -33,12 +33,12 @@ class HelpersTest < Test::Unit::TestCase
33
33
  get '/foo'
34
34
  end
35
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"]
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
42
  end # for bar with options
43
43
 
44
44
  context "with a specific href" do
@@ -49,7 +49,7 @@ class HelpersTest < Test::Unit::TestCase
49
49
  }
50
50
  get '/foo'
51
51
  end
52
- should_have_response_body %r[href="http://example.com"]
52
+ asserts_response_body %r[href="http://example.com"]
53
53
  end # with a specific href
54
54
  end # including stylesheets
55
55
 
@@ -63,9 +63,9 @@ class HelpersTest < Test::Unit::TestCase
63
63
  get '/foo'
64
64
  end
65
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"]
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
69
  end # for plain old foo
70
70
 
71
71
  context "for foo with options" do
@@ -77,10 +77,10 @@ class HelpersTest < Test::Unit::TestCase
77
77
  get '/foo'
78
78
  end
79
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"]
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
84
  end # for foo with options
85
85
 
86
86
  context "with a specific src" do
@@ -91,7 +91,7 @@ class HelpersTest < Test::Unit::TestCase
91
91
  }
92
92
  get '/foo'
93
93
  end
94
- should_have_response_body %r[src="http://example.com"]
94
+ asserts_response_body %r[src="http://example.com"]
95
95
  end # with a specific src
96
96
  end # including javascript
97
97
 
@@ -105,7 +105,7 @@ class HelpersTest < Test::Unit::TestCase
105
105
  get '/foo'
106
106
  end
107
107
 
108
- should_have_response_body %Q[<a href="/bar">foo</a>]
108
+ asserts_response_body %Q[<a href="/bar">foo</a>]
109
109
  end # for plain old foo
110
110
 
111
111
  context "with options" do
@@ -117,9 +117,9 @@ class HelpersTest < Test::Unit::TestCase
117
117
  get '/foo'
118
118
  end
119
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"]
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
123
  end # with options
124
124
  end # using an anchor
125
125
  end
@@ -1,8 +1,8 @@
1
1
  require File.join(File.dirname(__FILE__), 'test_helper')
2
2
 
3
- class RespondersTest < Test::Unit::TestCase
3
+ context "RespondersTest" do
4
4
 
5
- def app
5
+ setup do
6
6
  mock_app {
7
7
  helpers Sinatra::Chicago::Responders
8
8
  get "/json_bait" do
@@ -17,8 +17,8 @@ class RespondersTest < Test::Unit::TestCase
17
17
  get "/json_bait"
18
18
  end
19
19
 
20
- should_have_response_status 201
21
- should_have_json_response({:foo => :bar})
20
+ asserts_response_status 201
21
+ asserts_json_response({:foo => :bar})
22
22
  end # json response
23
23
 
24
24
  end
data/test/test_helper.rb CHANGED
@@ -1,4 +1,4 @@
1
- %w[ rubygems haml sass chicago test/unit rack/test shoulda chicago/shoulda ].each do |lib|
1
+ %w[ rubygems protest haml sass chicago rack/test chicago/protest ].each do |lib|
2
2
  require lib
3
3
  end
4
4
 
@@ -14,8 +14,12 @@ module Rack::Test::Methods
14
14
  @_rack_test_session ||= Rack::Test::Session.new(app)
15
15
  @app.instance_eval(&block)
16
16
  end
17
+
18
+ def app
19
+ @app
20
+ end
17
21
  end
18
22
 
19
- class Test::Unit::TestCase
23
+ class Protest::Context
20
24
  include Rack::Test::Methods
21
25
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: thumblemonks-chicago
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.3.2
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-06-10 00:00:00 -07:00
13
+ date: 2009-06-28 00:00:00 -07:00
14
14
  default_executable:
15
15
  dependencies: []
16
16
 
@@ -34,6 +34,8 @@ files:
34
34
  - lib/chicago.rb
35
35
  - lib/chicago/application.rb
36
36
  - lib/chicago/helpers.rb
37
+ - lib/chicago/protest.rb
38
+ - lib/chicago/protest/macros.rb
37
39
  - lib/chicago/responders.rb
38
40
  - lib/chicago/shoulda.rb
39
41
  - lib/chicago/shoulda/sinatra.rb