public
Description: A Ruby web application framework
Homepage: http://www.mackframework.com
Clone URL: git://github.com/markbates/mack.git
Click here to lend your support to: mack and make a donation at www.pledgie.com !
ControllerGenerator now generates 'good' default tests. [#25]
markbates (author)
Tue Aug 05 10:35:48 -0700 2008
commit  fc72954d683d67e43c90c66274ba4d2ef77de7dd
tree    ea39bad5c28cfbcad8d88a17143c83aa90faedc3
parent  9502e60855e78a9c9319e45ce7a75162a92d7cb1
...
32
33
34
35
36
 
 
37
38
 
39
40
41
...
32
33
34
 
 
35
36
37
 
38
39
40
41
0
@@ -32,10 +32,10 @@ class ControllerGenerator < Genosaurus
0
         rf.each do |line|
0
           if line.match("Mack::Routes.build")
0
             x = line.match(/\|(.+)\|/).captures
0
-            line << "\n  # Added by rake generate:controller name=#{param(:name)} actions=#{param(:actions)}\n"
0
-            line << "\n  r.with_options(:controller => :#{@name_plural}) do |map|\n"
0
+            line << "\n  # Added by rake generate:controller name=#{param(:name)} actions=#{param(:actions)}"
0
+            line << "\n  r.with_options(:controller => :#{@name_plural}) do |map|"
0
             @actions.each do |action|
0
-              line << "\n    map.#{@name_plural}_#{action}_url \"/#{@name_plural}#{action == "index" ? "" : "/#{action}"}\", :action => :#{action}"
0
+              line << "\n    map.#{@name_plural}_#{action} \"/#{@name_plural}#{action == "index" ? "" : "/#{action}"}\", :action => :#{action}"
0
             end
0
             line << "\n  end # #{@name_plural}\n"
0
           end
...
4
5
6
7
 
 
 
 
 
8
9
10
...
4
5
6
 
7
8
9
10
11
12
13
14
0
@@ -4,7 +4,11 @@ describe <%= @name_plural_camel %>Controller do
0
   <% @actions.each do |action| %>
0
   describe "<%= action %>" do
0
     
0
-    it "should do something :)"
0
+    it "should get the <%= action %> action" do
0
+      get <%= @name_plural %>_<%= action %>_url
0
+      response.should be_successful
0
+      response.body.should match(/<%= @name_plural_camel %>Controller#<%= action %>/)
0
+    end
0
     
0
   end
0
   <% end %>
...
7
8
9
10
 
 
 
11
12
13
14
...
7
8
9
 
10
11
12
13
14
15
16
0
@@ -7,7 +7,9 @@ class <%= @name_plural_camel %>ControllerTest < Test::Unit::TestCase
0
   end
0
   <% @actions.each do |action| %>
0
   def test_<%= action %>
0
-    assert true
0
+    get <%= @name_plural %>_<%= action %>_url
0
+    assert response.successful?
0
+    assert_match /<%= @name_plural_camel %>Controller#<%= action %>/, response.body
0
   end
0
   <% end %>
0
 end
0
\ No newline at end of file
...
4
5
6
7
 
 
 
 
 
8
9
10
11
12
13
 
 
 
 
 
14
15
16
...
4
5
6
 
7
8
9
10
11
12
13
14
15
16
 
17
18
19
20
21
22
23
24
0
@@ -4,13 +4,21 @@ describe ZoosController do
0
   
0
   describe "index" do
0
     
0
-    it "should do something :)"
0
+    it "should get the index action" do
0
+      get zoos_index_url
0
+      response.should be_successful
0
+      response.body.should match(/ZoosController#index/)
0
+    end
0
     
0
   end
0
   
0
   describe "show" do
0
     
0
-    it "should do something :)"
0
+    it "should get the show action" do
0
+      get zoos_show_url
0
+      response.should be_successful
0
+      response.body.should match(/ZoosController#show/)
0
+    end
0
     
0
   end
0
   
...
7
8
9
10
 
 
 
11
12
13
14
 
 
 
15
16
17
...
7
8
9
 
10
11
12
13
14
15
 
16
17
18
19
20
21
0
@@ -7,11 +7,15 @@ class ZoosControllerTest < Test::Unit::TestCase
0
   end
0
   
0
   def test_index
0
-    assert true
0
+    get zoos_index_url
0
+    assert response.successful?
0
+    assert_match /ZoosController#index/, response.body
0
   end
0
   
0
   def test_show
0
-    assert true
0
+    get zoos_show_url
0
+    assert response.successful?
0
+    assert_match /ZoosController#show/, response.body
0
   end
0
   
0
 end
...
45
46
47
48
49
 
 
50
51
52
...
45
46
47
 
 
48
49
50
51
52
0
@@ -45,8 +45,8 @@ describe ControllerGenerator do
0
     ControllerGenerator.run("name" => "zoo", "actions" => "index,show")
0
     File.read(@route_file_loc).should match(/  # Added by rake generate:controller name=zoo actions=index,show/)
0
     File.read(@route_file_loc).should match(/  r.with_options\(:controller => :zoos\) do \|map\|/)
0
-    File.read(@route_file_loc).should match(/    map.zoos_index_url "\/zoos", :action => :index/)
0
-    File.read(@route_file_loc).should match(/    map.zoos_show_url "\/zoos\/show", :action => :show/)
0
+    File.read(@route_file_loc).should match(/    map.zoos_index "\/zoos", :action => :index/)
0
+    File.read(@route_file_loc).should match(/    map.zoos_show "\/zoos\/show", :action => :show/)
0
     File.read(@route_file_loc).should match(/  end # zoos/)
0
   end
0
   

Comments