public
Fork of vigetlabs/helper_me_test
Description: Providing quick and easy ways to create and write tests for your Rails helpers.
Clone URL: git://github.com/brianjlandau/helper_me_test.git
Add helper generator and flesh out helper test generator
brianjlandau (author)
Fri Jun 20 12:35:26 -0700 2008
commit  8c28c056828d6ff974a94231cb7a560bc0940ac4
tree    d17ec3f2b0bda8c9f8b1bcb826508e491fede829
parent  7d7b8a5e8044d18ce6c6b8e644718147866e69b1
...
1
2
 
 
3
4
5
 
 
 
 
 
 
 
6
7
8
...
1
 
2
3
4
5
 
6
7
8
9
10
11
12
13
 
 
0
@@ -1,8 +1,13 @@
0
 Description:
0
- Explain the generator
0
+ Creates helper tests for each helper you currently have,
0
+ creating one test for each public method in the module.
0
 
0
 Example:
0
- ./script/generate helper_tests [Helpers]
0
+ ./script/generate helper_tests
0
+
0
+ This will create tests for all helpers that currently exist:
0
+ test/helpers/foo_helper_test.rb
0
+ test/helpers/bar_helper_test.rb
0
+ test/helpers/admin/posts_helper_test.rb
0
+ ...
0
 
0
- This will create:
0
- what/will/it/create
...
1
 
2
3
4
5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6
7
8
...
 
1
2
3
 
 
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
0
@@ -1,8 +1,30 @@
0
-class HelperTestsGenerator < Rails::Generator::NamedBase
0
+class HelperTestsGenerator < Rails::Generator::Base
0
   def manifest
0
     record do |m|
0
- # m.directory "lib"
0
- # m.template 'README', "README"
0
+ Dir.glob(File.expand_path(File.join(RAILS_ROOT, 'app', 'helpers/**/*_helper.rb'))) do |helper_file|
0
+
0
+ helper_file_name = File.base_name(helepr_file, '.rb')
0
+ helper_class_name = helper_file_name.camelcase
0
+
0
+ helper_path = File.dirname(helper_file).
0
+ helper_relative_path = helper_path.gsub(/^#{Regexp.escape(File.expand_path(File.join(RAILS_ROOT, 'app', 'helpers')))}/, '')
0
+ module_names = helper_relative_path.split('/')
0
+ module_names.collect! {|mod| mod.camelcase }
0
+ helper_full_name = module_names.join('::') + '::' + helper_class_name
0
+
0
+ helper_methods = helper_full_name.constantize.public_instance_methods
0
+
0
+ m.class_collisions "#{helper_full_name}Test"
0
+
0
+ m.directory File.join('test/helpers', helper_relative_path)
0
+
0
+ m.template 'helper_test.rb',
0
+ File.join('test/helpers',
0
+ helper_relative_path,
0
+ "#{helper_file_name}_test.rb"),
0
+ :assigns => { :helper_full_name => helper_full_name,
0
+ :helper_methods => helper_methods }
0
+ end
0
     end
0
   end
0
 end
...
1
2
3
4
 
 
5
6
 
7
8
...
1
2
 
 
3
4
5
 
6
7
8
0
@@ -1,8 +1,8 @@
0
 require 'helper_me_test'
0
 
0
-ActionView::TestCase.send :include, HelperMeTest.TagAssertions
0
-ActionView::TestCase.send :include, HelperMeTest.SelectorAssertions
0
+ActionView::TestCase.send :include, HelperMeTest::Assertions::TagAssertions
0
+ActionView::TestCase.send :include, HelperMeTest::Assertions::SelectorAssertions
0
 if defined? Hpricot
0
- ActionView::TestCase.send :include, HelperMeTest.HpricotAssertions
0
+ ActionView::TestCase.send :include, HelperMeTest::Assertions::HpricotAssertions
0
 end
0
 
...
1
2
3
 
4
5
6
...
363
364
365
366
367
 
...
1
2
3
4
5
6
7
...
364
365
366
 
367
368
0
@@ -1,6 +1,7 @@
0
 require 'active_support'
0
 require 'action_controller'
0
 require 'action_view'
0
+require 'action_view/test_case'
0
 require 'rexml/document'
0
 require 'html/document'
0
 
0
@@ -363,4 +364,4 @@ module HelperMeTest
0
     end
0
     
0
   end
0
-end
0
\ No newline at end of file
0
+end

Comments

    No one has commented yet.