Permalink
Browse files

Added asserts_redirected_to protest macro

  • Loading branch information...
1 parent 7546953 commit cea0114577b93e96493e00cf98f05d5a6f0b7f9f @gus gus committed Jun 28, 2009
Showing with 42 additions and 36 deletions.
  1. +0 −8 HISTORY.txt
  2. +4 −4 chicago.gemspec
  3. +13 −0 lib/chicago/protest/macros.rb
  4. +5 −14 test/application_test.rb
  5. +2 −2 test/helpers_test.rb
  6. +15 −0 test/protest_macros_test.rb
  7. +3 −8 test/responders_test.rb
View
@@ -1,8 +0,0 @@
-0.2
-
-* Updated to work with the latest Sinatra (0.9.1) and use proper extension nomenclature
-* Fixed catch_all_css to punt on stylesheets that are not defined as SASS files
-
-0.1.2.4
-
-* Updated to work with Sinatra 0.9
View
@@ -1,6 +1,6 @@
Gem::Specification.new do |s|
s.name = "chicago"
- s.version = "0.3.2"
+ s.version = "0.3.2.1"
s.date = "2009-06-28"
s.summary = "Sinatra runtime and testing extensions used commonly by Thumblemonks"
s.email = %w[gus@gusg.us gabriel.gironda@gmail.com]
@@ -10,14 +10,12 @@ Gem::Specification.new do |s|
s.has_rdoc = false
s.rdoc_options = ["--main", "README.markdown"]
- s.extra_rdoc_files = ["HISTORY.txt", "README.markdown"]
+ s.extra_rdoc_files = ["README.markdown"]
# run git ls-files to get an updated list
s.files = %w[
- HISTORY.txt
MIT-LICENSE
README.markdown
- Rakefile
chicago.gemspec
lib/chicago.rb
lib/chicago/application.rb
@@ -30,8 +28,10 @@ Gem::Specification.new do |s|
]
s.test_files = %w[
+ Rakefile
test/application_test.rb
test/helpers_test.rb
+ test/protest_macros_test.rb
test/responders_test.rb
test/test_helper.rb
]
@@ -27,6 +27,19 @@ def asserts_json_response(json, &block)
end
end
+ # Usage:
+ # assert_redirected_to '/foo/bar'
+ def asserts_redirected_to(expected_path)
+ asserts_response_status 302
+ asserts_location expected_path
+ # TODO: implement a matches operator
+ # action = expected_path.kind_of?(Regexp) ? 'match' : 'equal'
+ # send("assert_#{action}", expected_path, last_response.headers["Location"])
+ end
+
+ def asserts_location(expected_path)
+ asserts("location header").equals(expected_path) { last_response.headers["Location"] }
+ end
end # Macros
end # Protest
end # Chicago
View
@@ -1,6 +1,6 @@
-require File.join(File.dirname(__FILE__), 'test_helper')
+require 'test_helper'
-context "ApplicationTest:" do
+context "Application Test:" do
setup do
mock_app {
@@ -20,30 +20,21 @@
# TODO: change to namespace
context "catching all css" do
context "with default path" do
- setup do
- get '/stylesheets/foo.css'
- end
-
+ setup { get '/stylesheets/foo.css' }
asserts_response_status 200
asserts_content_type 'text/css'
asserts_response_body %r[.bar \{\s+display: none; \}\s]
end
context "with specified path" do
- setup do
- get '/css/goo.css'
- end
-
+ setup { get '/css/goo.css' }
asserts_response_status 200
asserts_content_type 'text/css'
asserts_response_body %r[.car \{\s+display: some; \}\s]
end
context "with path that's not a defined a sass file" do
- setup do
- get '/stylesheets/zoo.css'
- end
-
+ setup { get '/stylesheets/zoo.css' }
asserts_response_status 404
asserts_content_type 'text/html'
end
View
@@ -1,6 +1,6 @@
-require File.join(File.dirname(__FILE__), 'test_helper')
+require 'test_helper'
-context "HelpersTest:" do
+context "Helpers Test:" do
setup do
mock_app {
helpers Sinatra::Chicago::Helpers
@@ -0,0 +1,15 @@
+require 'test_helper'
+
+context "Protest Macros Test:" do
+ setup do
+ mock_app {
+ helpers Sinatra::Chicago::Responders
+ get("/redirecter") { redirect '/foo/bar' }
+ }
+ end
+
+ context "asserts redirected to" do
+ setup { get('/redirecter') }
+ asserts_redirected_to('/foo/bar')
+ end # asserts redirected to
+end
View
@@ -1,7 +1,6 @@
-require File.join(File.dirname(__FILE__), 'test_helper')
-
-context "RespondersTest" do
+require 'test_helper'
+context "Responders Test:" do
setup do
mock_app {
helpers Sinatra::Chicago::Responders
@@ -13,12 +12,8 @@
end
context "json response" do
- setup do
- get "/json_bait"
- end
-
+ setup { get "/json_bait" }
asserts_response_status 201
asserts_json_response({:foo => :bar})
end # json response
-
end

0 comments on commit cea0114

Please sign in to comment.