Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Created separate rake task for running shoulda tests

  • Loading branch information...
commit 7002b4a8ead52aa9f7584baceb18f95c1b131484 1 parent 495b7bb
@gus gus authored
View
22 Rakefile
@@ -1,23 +1,33 @@
require 'rubygems'
require 'rake'
+require 'rake/testtask'
desc 'Default task: run all tests'
task :default => [:test]
-task(:set_test_env) { ENV['SINATRA_ENV'] ||= 'test' }
-
-task :environment do
- # Nothing yet
-end
+task(:set_test_env) { ENV['RACK_ENV'] ||= 'test' }
desc "Run all tests"
-task :test => [:set_test_env, :environment] do
+task :test => [:set_test_env] do
require 'protest'
$:.concat ['./lib', './test']
Dir.glob("./test/*_test.rb").each { |test| require test }
Protest.report
end
+task "test:shoulda" => [:set_test_env]
+desc "Run all Shoulda based tests"
+Rake::TestTask.new("test:shoulda") do |t|
+ t.libs << "test/shoulda_tests"
+ t.test_files = FileList['test/shoulda_tests/*_test.rb']
+ t.verbose = true
+end
+
+# task :test => [:set_test_env] do
+# $:.concat ['./lib', './test/shoulda_tests']
+# Dir.glob("./test/shoulda_tests/*_test.rb").each { |test| require test }
+# end
+
desc "Open an irb session preloaded with this library"
task :console do
exec "irb -rubygems"
View
4 chicago.gemspec
@@ -1,7 +1,7 @@
Gem::Specification.new do |s|
s.name = "chicago"
- s.version = "0.3.2.2"
- s.date = "2009-06-28"
+ s.version = "0.3.3"
+ s.date = "2009-07-05"
s.summary = "Sinatra runtime and testing extensions used commonly by Thumblemonks"
s.email = %w[gus@gusg.us gabriel.gironda@gmail.com]
s.homepage = "http://github.com/thumblemonks/chicago/tree/master"
View
2  lib/chicago/shoulda/sinatra.rb
@@ -80,4 +80,4 @@ def assert_redirected_to(expected_path)
end # Chicago
end # ThumbleMonks
-Test::Unit::TestCase.instance_eval { include ThumbleMonks::Chicago::Shoulda }
+Test::Unit::TestCase.instance_eval { include ThumbleMonks::Chicago::Shoulda }
View
2  test/application_test.rb
@@ -36,7 +36,7 @@
context "with path that's not a defined a sass file" do
setup { get '/stylesheets/zoo.css' }
asserts_response_status 404
- asserts_content_type 'text/html'
+ asserts_content_type 'text/css'
end
end # catching all css
View
48 test/shoulda_tests/application_test.rb
@@ -0,0 +1,48 @@
+require 'test_helper'
+
+class ApplicationTest < Test::Unit::TestCase
+
+ def app
+ @app = mock_app {
+ register Sinatra::Chicago
+
+ template(:foo) { ".bar\n :display none" }
+ template(:goo) { ".car\n :display some" }
+ template(:baz) { "Whatever man. That's just like, your opinion." }
+
+ catch_all_css
+ catch_all_css('/css')
+
+ get_obvious 'baz'
+ }
+ end
+
+ # TODO: change to namespace
+ context "catching all css" do
+ context "with default path" do
+ setup { get '/stylesheets/foo.css' }
+ should_have_response_status 200
+ should_have_content_type 'text/css'
+ should_have_response_body %r[.bar \{\s+display: none; \}\s]
+ end
+
+ context "with specified path" do
+ setup { get '/css/goo.css' }
+ should_have_response_status 200
+ should_have_content_type 'text/css'
+ should_have_response_body %r[.car \{\s+display: some; \}\s]
+ end
+
+ context "with path that's not a defined a sass file" do
+ setup { get '/stylesheets/zoo.css' }
+ should_have_response_status 404
+ should_have_content_type 'text/css'
+ end
+ end # catching all css
+
+ context "getting obvious views" do
+ setup { get '/baz' }
+ should_have_response_body "Whatever man. That's just like, your opinion."
+ end # getting obvious views
+
+end
View
125 test/shoulda_tests/helpers_test.rb
@@ -0,0 +1,125 @@
+require 'test_helper'
+
+class HelpersTest < Test::Unit::TestCase
+ def app
+ @app = mock_app {
+ helpers Sinatra::Chicago::Helpers
+ }
+ end
+
+ context "including stylesheet" do
+ context "for plain old foo" do
+ setup do
+ extend_mock_app {
+ template(:foo) { "= stylesheet_include('foo')" }
+ get('/foo') { haml :foo }
+ }
+ get '/foo'
+ end
+
+ should_have_response_body %r[^<link( \w+=".+"){4}/>$]
+ should_have_response_body %r[href="/stylesheets/foo\.css"]
+ should_have_response_body %r[media="screen"]
+ should_have_response_body %r[rel="stylesheet"]
+ should_have_response_body %r[type="text/css"]
+ end # for plain old foo
+
+ context "for bar with options" do
+ setup do
+ extend_mock_app {
+ template(:foo) { "= stylesheet_include('bar', :media => 'print', :baz => 'boo')" }
+ get('/foo') { haml :foo }
+ }
+ get '/foo'
+ end
+
+ should_have_response_body %r[^<link( \w+=".+"){5}/>$]
+ should_have_response_body %r[href="/stylesheets/bar\.css"]
+ should_have_response_body %r[media="print"]
+ should_have_response_body %r[rel="stylesheet"]
+ should_have_response_body %r[type="text/css"]
+ should_have_response_body %r[baz="boo"]
+ end # for bar with options
+
+ context "with a specific href" do
+ setup do
+ extend_mock_app {
+ template(:foo) { "= stylesheet_include('http://example.com')" }
+ get('/foo') { haml :foo }
+ }
+ get '/foo'
+ end
+ should_have_response_body %r[href="http://example.com"]
+ end # with a specific href
+ end # including stylesheets
+
+ context "including javascript" do
+ context "for plain old foo" do
+ setup do
+ extend_mock_app {
+ template(:foo) { "= javascript_include('foo')" }
+ get('/foo') { haml :foo }
+ }
+ get '/foo'
+ end
+
+ should_have_response_body %r[^<script( \w+=".+"){2}></script>$]
+ should_have_response_body %r[src="/javascripts/foo\.js"]
+ should_have_response_body %r[type="text/javascript"]
+ end # for plain old foo
+
+ context "for foo with options" do
+ setup do
+ extend_mock_app {
+ template(:foo) { "= javascript_include('foo', :type => 'text/blarg', :gus => 'nice')" }
+ get('/foo') { haml :foo }
+ }
+ get '/foo'
+ end
+
+ should_have_response_body %r[^<script( \w+=".+"){3}></script>$]
+ should_have_response_body %r[src="/javascripts/foo\.js"]
+ should_have_response_body %r[type="text/blarg"]
+ should_have_response_body %r[gus="nice"]
+ end # for foo with options
+
+ context "with a specific src" do
+ setup do
+ extend_mock_app {
+ template(:foo) { "= javascript_include('http://example.com')" }
+ get('/foo') { haml :foo }
+ }
+ get '/foo'
+ end
+ should_have_response_body %r[src="http://example.com"]
+ end # with a specific src
+ end # including javascript
+
+ context "using an anchor" do
+ context "for plain old foo" do
+ setup do
+ extend_mock_app {
+ template(:foo) { "= anchor('foo', '/bar')" }
+ get('/foo') { haml :foo }
+ }
+ get '/foo'
+ end
+
+ should_have_response_body %Q[<a href="/bar">foo</a>]
+ end # for plain old foo
+
+ context "with options" do
+ setup do
+ extend_mock_app {
+ template(:foo) { "= anchor('foo bear', '/bar/ler', :title => 'gus is nice')" }
+ get('/foo') { haml :foo }
+ }
+ get '/foo'
+ end
+
+ should_have_response_body %r[^<a( \w+=".+"){2}>foo bear</a>$]
+ should_have_response_body %r[href="/bar/ler"]
+ should_have_response_body %r[title="gus is nice"]
+ end # with options
+ end # using an anchor
+end
View
19 test/shoulda_tests/responders_test.rb
@@ -0,0 +1,19 @@
+require 'test_helper'
+
+class RespondersTest < Test::Unit::TestCase
+ def app
+ @app = mock_app {
+ helpers Sinatra::Chicago::Responders
+ get "/json_bait" do
+ status(201)
+ json_response({:foo => "bar"})
+ end
+ }
+ end
+
+ context "json response" do
+ setup { get "/json_bait" }
+ should_have_response_status 201
+ should_have_json_response({:foo => :bar})
+ end # json response
+end
View
21 test/shoulda_tests/test_helper.rb
@@ -0,0 +1,21 @@
+%w[ rubygems test/unit shoulda haml sass chicago rack/test chicago/shoulda ].each do |lib|
+ require lib
+end
+
+module Rack::Test::Methods
+ # Sets up a Sinatra::Base subclass defined with the block
+ # given. Used in setup or individual spec methods to establish
+ # the application.
+ def mock_app(base=Sinatra::Base, &block)
+ @app = Sinatra.new(base, &block)
+ end
+
+ def extend_mock_app(&block)
+ @_rack_test_session ||= Rack::Test::Session.new(app)
+ @app.instance_eval(&block)
+ end
+end
+
+class Test::Unit::TestCase
+ include Rack::Test::Methods
+end

0 comments on commit 7002b4a

Please sign in to comment.
Something went wrong with that request. Please try again.