Permalink
Browse files

Added shoulda_macros directory support as per http://thoughtbot.light…

  • Loading branch information...
1 parent 2cb29f5 commit 56a3f432b274b1762b26ba9516762c4cdc27dd17 Tammer Saleh committed Aug 4, 2008
Showing with 26 additions and 2 deletions.
  1. +13 −1 README.rdoc
  2. +13 −1 init.rb
View
14 README.rdoc
@@ -114,10 +114,22 @@ More to come here, but have fun with what's there.
assert_contains(['a', '1'], /\d/)
assert_contains(['a', '1'], 'a')
+=== 3rd Party and Application Specific Macros
+
+Any *.rb file under RAILS_ROOT/test/shoulda_macros/ or vendor/(plugins|gems)/gem_name/shoulda_macros/ will be automatically required when you run your tests. This allows you to distribute macros with your plugins, or to organize the macros inside your application. Remember to add your macro to Test::Unit::TestCase in the macro file:
+
+ # test/shoulda_macros/security.rb
+ class Test::Unit::TestCase
+ def self.should_be_denied(opts = {})
+ should_set_the_flash_to(opts[:flash] || /Please log in/i)
+ should_redirect_to(opts[:redirect] || 'login_url')
+ end
+ end
+
= Credits
Shoulda is maintained by {Tammer Saleh}[mailto:tsaleh@thoughtbot.com], and is funded by Thoughtbot[http://www.thoughtbot.com], inc.
= License
-Shoulda is Copyright © 2006-2007 Tammer Saleh, Thoughtbot. It is free software, and may be redistributed under the terms specified in the MIT-LICENSE file.
+Shoulda is Copyright © 2006-2008 Tammer Saleh, Thoughtbot. It is free software, and may be redistributed under the terms specified in the MIT-LICENSE file.
View
14 init.rb
@@ -1,3 +1,15 @@
require 'rubygems'
require 'active_support'
-require 'shoulda'
+require 'shoulda'
+
+if defined?(RAILS_ROOT)
+ # load in the 3rd party macros from vendorized plugins and gems
+ Dir[File.join(RAILS_ROOT, "vendor", "{plugin,gem}", "*", "shoulda_macros", "*.rb")].each do |macro_file_path|
@rmm5t
rmm5t Aug 4, 2008

Tammer,
Shouldn’t {plugin,gem} be {plugins,gems} ?

+ 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

0 comments on commit 56a3f43

Please sign in to comment.