Permalink
Browse files

Merge branch 'master' of git://github.com/thoughtbot/shoulda

  • Loading branch information...
2 parents 5dfc3bf + ebd37ea commit 49a2f5e8e7d4a191a8b3a084c369d14e75bbff5b @mjankowski mjankowski committed Sep 15, 2008
View
1 .gitignore
@@ -2,3 +2,4 @@ test/rails_root/log/*.log
doc
coverage
.svn/
+pkg
View
37 Rakefile
@@ -1,6 +1,9 @@
require 'rake'
require 'rake/testtask'
require 'rake/rdoctask'
+require 'rake/gempackagetask'
+require 'lib/shoulda/context'
+require 'lib/shoulda/tasks'
# Test::Unit::UI::VERBOSE
test_files_pattern = 'test/{unit,functional,other}/**/*_test.rb'
@@ -33,7 +36,37 @@ end
desc 'Default: run tests.'
task :default => ['test']
-Dir['tasks/*.rake'].each do |f|
- load f
+spec = Gem::Specification.new do |s|
+ s.name = "shoulda"
+ s.version = Thoughtbot::Shoulda::VERSION
+ s.summary = "Making tests easy on the fingers and eyes"
+ s.homepage = "http://thoughtbot.com/projects/shoulda"
+ s.rubyforge_project = "shoulda"
+
+ s.files = FileList["[A-Z]*", "{bin,lib,test}/**/*"]
+ s.executables = s.files.grep(/^bin/) { |f| File.basename(f) }
+
+ s.has_rdoc = true
+ s.extra_rdoc_files = ["README.rdoc", "CONTRIBUTION_GUIDELINES.rdoc"]
+ s.rdoc_options = ["--line-numbers", "--inline-source", "--main", "README.rdoc"]
+
+ s.authors = ["Tammer Saleh"]
+ s.email = "tsaleh@thoughtbot.com"
+
+ s.add_dependency "activesupport", ">= 2.0"
end
+Rake::GemPackageTask.new spec do |pkg|
+ pkg.need_tar = true
+ pkg.need_zip = true
+end
+
+desc "Clean files generated by rake tasks"
+task :clobber => [:clobber_rdoc, :clobber_package]
+
+desc "Generate a gemspec file for GitHub"
+task :gemspec do
+ File.open("#{spec.name}.gemspec", 'w') do |f|
+ f.write spec.to_ruby
+ end
+end
View
19 init.rb
@@ -1,18 +1 @@
-require 'rubygems'
-require 'active_support'
-require 'shoulda'
-require 'shoulda/active_record'
-require 'shoulda/controller'
-require 'shoulda/action_mailer'
-
-if defined?(RAILS_ROOT)
- # load in the 3rd party macros from vendorized plugins and gems
- Dir[File.join(RAILS_ROOT, "vendor", "{plugins,gems}", "*", "shoulda_macros", "*.rb")].each do |macro_file_path|
- require macro_file_path
- end
-
- # load in the local application specific macros
- Dir[File.join(RAILS_ROOT, "test", "shoulda_macros", "*.rb")].each do |macro_file_path|
- require macro_file_path
- end
-end
+require 'shoulda/rails'
View
2 lib/shoulda/context.rb
@@ -1,6 +1,6 @@
module Thoughtbot # :nodoc:
module Shoulda
- VERSION = '1.1.1'
+ VERSION = '2.0.0'
class << self
attr_accessor :contexts
View
1 lib/shoulda/controller.rb
@@ -2,6 +2,7 @@
require 'shoulda/controller/helpers'
require 'shoulda/controller/resource_options'
require 'shoulda/controller/macros'
+require 'shoulda/controller/routing'
module Test # :nodoc: all
module Unit
View
10 lib/shoulda/controller/routing.rb
@@ -0,0 +1,10 @@
+require 'shoulda'
+require 'shoulda/controller/routing/macros'
+
+module Test # :nodoc: all
+ module Unit
+ class TestCase
+ extend ThoughtBot::Shoulda::Controller::Routing::Macros
+ end
+ end
+end
View
47 lib/shoulda/controller/routing/macros.rb
@@ -0,0 +1,47 @@
+module ThoughtBot
+ module Shoulda
+ module Controller
+ module Routing
+ module Macros
+ # Macro that creates a routing test. It tries to use the given HTTP
+ # +method+ on the given +path+, and asserts that it routes to the
+ # given +options+.
+ #
+ # If you don't specify a :controller, it will try to guess the controller
+ # based on the current test.
+ #
+ # +to_param+ is called on the +options+ given.
+ #
+ # Examples:
+ #
+ # should_route :get, '/posts', :action => :index
+ # should_route :post, '/posts', :controller => :posts, :action => :create
+ # should_route :get, '/posts/1', :action => :show, :id => 1
+ # should_route :put, '/posts/1', :action => :update, :id => "1"
+ # should_route :delete, '/posts/1', :action => :destroy, :id => 1
+ # should_route :get, '/posts/new', :action => :new
+ #
+ def should_route(method, path, options)
+ unless options[:controller]
+ options[:controller] = self.name.gsub(/ControllerTest$/, '').tableize
+ end
+ options[:controller] = options[:controller].to_s
+ options[:action] = options[:action].to_s
+
+ populated_path = path.dup
+ options.each do |key, value|
+ options[key] = value.to_param if value.respond_to? :to_param
+ populated_path.gsub!(key.inspect, value.to_s)
+ end
+
+ should_name = "route #{method.to_s.upcase} #{populated_path} to/from #{options.inspect}"
+
+ should should_name do
+ assert_routing({:method => method, :path => populated_path}, options)
+ end
+ end
+ end
+ end
+ end
+ end
+end
View
19 lib/shoulda/rails.rb
@@ -0,0 +1,19 @@
+require 'rubygems'
+require 'active_support'
+require 'shoulda'
+
+require 'shoulda/active_record' if defined? ActiveRecord::Base
+require 'shoulda/controller' if defined? ActionController::Base
+require 'shoulda/action_mailer' if defined? ActionMailer::Base
+
+if defined?(RAILS_ROOT)
+ # load in the 3rd party macros from vendorized plugins and gems
+ Dir[File.join(RAILS_ROOT, "vendor", "{plugins,gems}", "*", "shoulda_macros", "*.rb")].each do |macro_file_path|
+ require macro_file_path
+ end
+
+ # load in the local application specific macros
+ Dir[File.join(RAILS_ROOT, "test", "shoulda_macros", "*.rb")].each do |macro_file_path|
+ require macro_file_path
+ end
+end
View
3 lib/shoulda/tasks.rb
@@ -0,0 +1,3 @@
+Dir[File.join(File.dirname(__FILE__), 'tasks', '*.rake')].each do |f|
+ load f
+end
View
0 tasks/list_tests.rake → lib/shoulda/tasks/list_tests.rake
File renamed without changes.
View
0 tasks/yaml_to_shoulda.rake → lib/shoulda/tasks/yaml_to_shoulda.rake
File renamed without changes.
View
33 shoulda.gemspec
@@ -0,0 +1,33 @@
+Gem::Specification.new do |s|
+ s.name = %q{shoulda}
+ s.version = "2.0.0"
+
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
+ s.authors = ["Tammer Saleh"]
+ s.date = %q{2008-09-14}
+ s.default_executable = %q{convert_to_should_syntax}
+ s.email = %q{tsaleh@thoughtbot.com}
+ s.executables = ["convert_to_should_syntax"]
+ s.extra_rdoc_files = ["README.rdoc", "CONTRIBUTION_GUIDELINES.rdoc"]
+ s.files = ["CONTRIBUTION_GUIDELINES.rdoc", "MIT-LICENSE", "Rakefile", "README.rdoc", "bin/convert_to_should_syntax", "lib/shoulda", "lib/shoulda/action_mailer", "lib/shoulda/action_mailer/assertions.rb", "lib/shoulda/action_mailer.rb", "lib/shoulda/active_record", "lib/shoulda/active_record/assertions.rb", "lib/shoulda/active_record/macros.rb", "lib/shoulda/active_record.rb", "lib/shoulda/assertions.rb", "lib/shoulda/context.rb", "lib/shoulda/controller", "lib/shoulda/controller/formats", "lib/shoulda/controller/formats/html.rb", "lib/shoulda/controller/formats/xml.rb", "lib/shoulda/controller/helpers.rb", "lib/shoulda/controller/macros.rb", "lib/shoulda/controller/resource_options.rb", "lib/shoulda/controller/routing", "lib/shoulda/controller/routing/macros.rb", "lib/shoulda/controller/routing.rb", "lib/shoulda/controller.rb", "lib/shoulda/helpers.rb", "lib/shoulda/macros.rb", "lib/shoulda/private_helpers.rb", "lib/shoulda/proc_extensions.rb", "lib/shoulda/rails.rb", "lib/shoulda/tasks", "lib/shoulda/tasks/list_tests.rake", "lib/shoulda/tasks/yaml_to_shoulda.rake", "lib/shoulda/tasks.rb", "lib/shoulda.rb", "test/fixtures", "test/fixtures/addresses.yml", "test/fixtures/friendships.yml", "test/fixtures/posts.yml", "test/fixtures/products.yml", "test/fixtures/taggings.yml", "test/fixtures/tags.yml", "test/fixtures/users.yml", "test/functional", "test/functional/posts_controller_test.rb", "test/functional/users_controller_test.rb", "test/other", "test/other/context_test.rb", "test/other/convert_to_should_syntax_test.rb", "test/other/helpers_test.rb", "test/other/private_helpers_test.rb", "test/other/should_test.rb", "test/rails_root", "test/rails_root/app", "test/rails_root/app/controllers", "test/rails_root/app/controllers/application.rb", "test/rails_root/app/controllers/posts_controller.rb", "test/rails_root/app/controllers/users_controller.rb", "test/rails_root/app/helpers", "test/rails_root/app/helpers/application_helper.rb", "test/rails_root/app/helpers/posts_helper.rb", "test/rails_root/app/helpers/users_helper.rb", "test/rails_root/app/models", "test/rails_root/app/models/address.rb", "test/rails_root/app/models/dog.rb", "test/rails_root/app/models/flea.rb", "test/rails_root/app/models/friendship.rb", "test/rails_root/app/models/post.rb", "test/rails_root/app/models/product.rb", "test/rails_root/app/models/tag.rb", "test/rails_root/app/models/tagging.rb", "test/rails_root/app/models/user.rb", "test/rails_root/app/views", "test/rails_root/app/views/layouts", "test/rails_root/app/views/layouts/posts.rhtml", "test/rails_root/app/views/layouts/users.rhtml", "test/rails_root/app/views/posts", "test/rails_root/app/views/posts/edit.rhtml", "test/rails_root/app/views/posts/index.rhtml", "test/rails_root/app/views/posts/new.rhtml", "test/rails_root/app/views/posts/show.rhtml", "test/rails_root/app/views/users", "test/rails_root/app/views/users/edit.rhtml", "test/rails_root/app/views/users/index.rhtml", "test/rails_root/app/views/users/new.rhtml", "test/rails_root/app/views/users/show.rhtml", "test/rails_root/config", "test/rails_root/config/boot.rb", "test/rails_root/config/database.yml", "test/rails_root/config/environment.rb", "test/rails_root/config/environments", "test/rails_root/config/environments/sqlite3.rb", "test/rails_root/config/initializers", "test/rails_root/config/initializers/new_rails_defaults.rb", "test/rails_root/config/initializers/shoulda.rb", "test/rails_root/config/routes.rb", "test/rails_root/db", "test/rails_root/db/migrate", "test/rails_root/db/migrate/001_create_users.rb", "test/rails_root/db/migrate/002_create_posts.rb", "test/rails_root/db/migrate/003_create_taggings.rb", "test/rails_root/db/migrate/004_create_tags.rb", "test/rails_root/db/migrate/005_create_dogs.rb", "test/rails_root/db/migrate/006_create_addresses.rb", "test/rails_root/db/migrate/007_create_fleas.rb", "test/rails_root/db/migrate/008_create_dogs_fleas.rb", "test/rails_root/db/migrate/009_create_products.rb", "test/rails_root/db/migrate/010_create_friendships.rb", "test/rails_root/db/schema.rb", "test/rails_root/log", "test/rails_root/log/sqlite3.log", "test/rails_root/public", "test/rails_root/public/404.html", "test/rails_root/public/422.html", "test/rails_root/public/500.html", "test/rails_root/script", "test/rails_root/script/console", "test/rails_root/script/generate", "test/rails_root/vendor", "test/rails_root/vendor/plugins", "test/README", "test/test_helper.rb", "test/unit", "test/unit/address_test.rb", "test/unit/dog_test.rb", "test/unit/flea_test.rb", "test/unit/friendship_test.rb", "test/unit/post_test.rb", "test/unit/product_test.rb", "test/unit/tag_test.rb", "test/unit/tagging_test.rb", "test/unit/user_test.rb"]
+ s.has_rdoc = true
+ s.homepage = %q{http://thoughtbot.com/projects/shoulda}
+ s.rdoc_options = ["--line-numbers", "--inline-source", "--main", "README.rdoc"]
+ s.require_paths = ["lib"]
+ s.rubyforge_project = %q{shoulda}
+ s.rubygems_version = %q{1.2.0}
+ s.summary = %q{Making tests easy on the fingers and eyes}
+
+ if s.respond_to? :specification_version then
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
+ s.specification_version = 2
+
+ if current_version >= 3 then
+ s.add_runtime_dependency(%q<activesupport>, [">= 2.0"])
+ else
+ s.add_dependency(%q<activesupport>, [">= 2.0"])
+ end
+ else
+ s.add_dependency(%q<activesupport>, [">= 2.0"])
+ end
+end
View
1 tasks/shoulda.rake
@@ -0,0 +1 @@
+require 'shoulda/tasks'
View
19 test/functional/posts_controller_test.rb
@@ -13,6 +13,25 @@ def setup
@response = ActionController::TestResponse.new
@post = Post.find(:first)
end
+
+ # autodetects the :controller
+ should_route :get, '/posts', :action => :index
+ # explicitly specify :controller
+ should_route :post, '/posts', :controller => :posts, :action => :create
+ # non-string parameter
+ should_route :get, '/posts/1', :action => :show, :id => 1
+ # string-parameter
+ should_route :put, '/posts/1', :action => :update, :id => "1"
+ should_route :delete, '/posts/1', :action => :destroy, :id => 1
+ should_route :get, '/posts/new', :action => :new
+
+ # Test the nested routes
+ should_route :get, '/users/5/posts', :action => :index, :user_id => 5
+ should_route :post, '/users/5/posts', :action => :create, :user_id => 5
+ should_route :get, '/users/5/posts/1', :action => :show, :id => 1, :user_id => 5
+ should_route :delete, '/users/5/posts/1', :action => :destroy, :id => 1, :user_id => 5
+ should_route :get, '/users/5/posts/new', :action => :new, :user_id => 5
+ should_route :put, '/users/5/posts/1', :action => :update, :id => 1, :user_id => 5
context "The public" do
setup do

0 comments on commit 49a2f5e

Please sign in to comment.