merb-gen 0.9.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (100) hide show
  1. data/LICENSE +20 -0
  2. data/README +10 -0
  3. data/Rakefile +47 -0
  4. data/TODO +4 -0
  5. data/app_generators/merb/USAGE +0 -0
  6. data/app_generators/merb/merb_generator.rb +36 -0
  7. data/app_generators/merb/templates/Rakefile +126 -0
  8. data/app_generators/merb/templates/app/controllers/application.rb +2 -0
  9. data/app_generators/merb/templates/app/controllers/exceptions.rb +13 -0
  10. data/app_generators/merb/templates/app/helpers/global_helpers.rb +5 -0
  11. data/app_generators/merb/templates/app/views/exceptions/internal_server_error.html.erb +216 -0
  12. data/app_generators/merb/templates/app/views/exceptions/not_acceptable.html.erb +55 -0
  13. data/app_generators/merb/templates/app/views/exceptions/not_found.html.erb +39 -0
  14. data/app_generators/merb/templates/app/views/layout/application.html.erb +11 -0
  15. data/app_generators/merb/templates/autotest/discover.rb +1 -0
  16. data/app_generators/merb/templates/autotest/merb.rb +149 -0
  17. data/app_generators/merb/templates/autotest/merb_rspec.rb +202 -0
  18. data/app_generators/merb/templates/config/environments/development.rb +6 -0
  19. data/app_generators/merb/templates/config/environments/production.rb +5 -0
  20. data/app_generators/merb/templates/config/environments/rake.rb +7 -0
  21. data/app_generators/merb/templates/config/environments/test.rb +5 -0
  22. data/app_generators/merb/templates/config/init.rb +58 -0
  23. data/app_generators/merb/templates/config/rack.rb +1 -0
  24. data/app_generators/merb/templates/config/router.rb +35 -0
  25. data/app_generators/merb/templates/public/images/merb.jpg +0 -0
  26. data/app_generators/merb/templates/public/merb.fcgi +22 -0
  27. data/app_generators/merb/templates/public/stylesheets/master.css +119 -0
  28. data/app_generators/merb/templates/spec/spec.opts +0 -0
  29. data/app_generators/merb/templates/spec/spec_helper.rb +11 -0
  30. data/app_generators/merb/templates/test/test_helper.rb +14 -0
  31. data/app_generators/merb_flat/merb_flat_generator.rb +22 -0
  32. data/app_generators/merb_flat/templates/README.txt +10 -0
  33. data/app_generators/merb_flat/templates/application.rb +15 -0
  34. data/app_generators/merb_flat/templates/config/framework.rb +5 -0
  35. data/app_generators/merb_flat/templates/config/init.rb +19 -0
  36. data/app_generators/merb_flat/templates/views/foo.html.erb +3 -0
  37. data/app_generators/merb_plugin/merb_plugin_generator.rb +22 -0
  38. data/app_generators/merb_plugin/templates/LICENSE +20 -0
  39. data/app_generators/merb_plugin/templates/README +4 -0
  40. data/app_generators/merb_plugin/templates/Rakefile +44 -0
  41. data/app_generators/merb_plugin/templates/TODO +5 -0
  42. data/app_generators/merb_plugin/templates/lib/%base_name%.rb +18 -0
  43. data/app_generators/merb_plugin/templates/lib/%base_name%/merbtasks.rb +6 -0
  44. data/app_generators/merb_plugin/templates/spec/%base_name%_spec.rb +7 -0
  45. data/app_generators/merb_plugin/templates/spec/spec_helper.rb +2 -0
  46. data/app_generators/merb_plugin/templates/test/%base_name%_test.rb +0 -0
  47. data/app_generators/merb_plugin/templates/test/test_helper.rb +2 -0
  48. data/app_generators/merb_very_flat/merb_very_flat_generator.rb +37 -0
  49. data/app_generators/merb_very_flat/templates/%app_file_name%.rb +15 -0
  50. data/app_generators/merb_very_flat/templates/README.txt +9 -0
  51. data/bin/merb-gen +103 -0
  52. data/lib/merb-gen.rb +38 -0
  53. data/lib/merb-gen/base.rb +62 -0
  54. data/lib/merb-gen/helpers.rb +108 -0
  55. data/merb_default_generators/model/USAGE +0 -0
  56. data/merb_default_generators/model/model_generator.rb +40 -0
  57. data/merb_default_generators/model/templates/app/models/%model_file_name%.rb +5 -0
  58. data/merb_default_generators/resource_controller/USAGE +0 -0
  59. data/merb_default_generators/resource_controller/resource_controller_generator.rb +74 -0
  60. data/merb_default_generators/resource_controller/templates/app/controllers/%controller_file_name%.rb +46 -0
  61. data/merb_default_generators/resource_controller/templates/app/helpers/%controller_file_name%_helper.rb +16 -0
  62. data/merb_default_generators/resource_controller/templates/app/views/%controller_file_name%/delete.html.erb +3 -0
  63. data/merb_default_generators/resource_controller/templates/app/views/%controller_file_name%/edit.html.erb +3 -0
  64. data/merb_default_generators/resource_controller/templates/app/views/%controller_file_name%/index.html.erb +3 -0
  65. data/merb_default_generators/resource_controller/templates/app/views/%controller_file_name%/new.html.erb +3 -0
  66. data/merb_default_generators/resource_controller/templates/app/views/%controller_file_name%/show.html.erb +3 -0
  67. data/merb_generators/controller/USAGE +0 -0
  68. data/merb_generators/controller/controller_generator.rb +59 -0
  69. data/merb_generators/controller/templates/app/controllers/%controller_file_name%.rb +18 -0
  70. data/merb_generators/controller/templates/app/helpers/%controller_file_name%_helper.rb +16 -0
  71. data/merb_generators/controller/templates/app/views/%controller_file_name%/index.html.erb +1 -0
  72. data/merb_generators/freezer/USAGE +0 -0
  73. data/merb_generators/freezer/freezer_generator.rb +25 -0
  74. data/merb_generators/freezer/templates/script/frozen-merb +43 -0
  75. data/merb_generators/part_controller/USAGE +0 -0
  76. data/merb_generators/part_controller/part_controller_generator.rb +58 -0
  77. data/merb_generators/part_controller/templates/app/helpers/%controller_file_name%_part_helper.rb +16 -0
  78. data/merb_generators/part_controller/templates/app/parts/%controller_file_name%_part.rb +18 -0
  79. data/merb_generators/part_controller/templates/app/parts/views/%controller_file_name%_part/index.html.erb +3 -0
  80. data/merb_generators/resource/USAGE +0 -0
  81. data/merb_generators/resource/resource_generator.rb +48 -0
  82. data/rspec_generators/merb_controller_test/merb_controller_test_generator.rb +49 -0
  83. data/rspec_generators/merb_controller_test/templates/spec/controllers/%controller_full_file_path%_spec.rb +7 -0
  84. data/rspec_generators/merb_controller_test/templates/spec/helpers/%controller_full_file_path%_helper_spec.rb +5 -0
  85. data/rspec_generators/merb_model_test/merb_model_test_generator.rb +35 -0
  86. data/rspec_generators/merb_model_test/templates/spec/models/%model_file_name%_spec.rb +7 -0
  87. data/rspec_generators/merb_resource_controller_test/merb_resource_controller_test_generator.rb +49 -0
  88. data/rspec_generators/merb_resource_controller_test/templates/spec/controllers/%controller_full_file_path%_spec.rb +7 -0
  89. data/rspec_generators/merb_resource_controller_test/templates/spec/helpers/%controller_full_file_path%_helpers.rb +5 -0
  90. data/rspec_generators/merb_resource_controller_test/templates/spec/views/%controller_full_file_path%/delete.html.erb_spec.rb +1 -0
  91. data/rspec_generators/merb_resource_controller_test/templates/spec/views/%controller_full_file_path%/edit.html.erb_spec.rb +1 -0
  92. data/rspec_generators/merb_resource_controller_test/templates/spec/views/%controller_full_file_path%/index.html.erb_spec.rb +1 -0
  93. data/rspec_generators/merb_resource_controller_test/templates/spec/views/%controller_full_file_path%/new.html.erb_spec.rb +1 -0
  94. data/rspec_generators/merb_resource_controller_test/templates/spec/views/%controller_full_file_path%/show.html.erb_spec.rb +1 -0
  95. data/test_unit_generators/merb_controller_test/merb_controller_test_generator.rb +47 -0
  96. data/test_unit_generators/merb_controller_test/templates/test/functional/%controller_full_file_path%_test.rb +17 -0
  97. data/test_unit_generators/merb_model_test/merb_model_test_generator.rb +34 -0
  98. data/test_unit_generators/merb_model_test/templates/test/unit/%model_file_name%_test.rb +9 -0
  99. data/test_unit_generators/merb_resource_controller_test/merb_resource_controller_test_generator.rb +31 -0
  100. metadata +253 -0
@@ -0,0 +1,55 @@
1
+ <div id="container">
2
+ <div id="header-container">
3
+ <img src="/images/merb.jpg" />
4
+ <!-- <h1>Mongrel + Erb</h1> -->
5
+ <h2>pocket rocket web framework</h2>
6
+ <hr />
7
+ </div>
8
+
9
+ <div id="left-container">
10
+ <h3>Exception:</h3>
11
+ <p><%%= params[:exception] %></p>
12
+ </div>
13
+
14
+ <div id="main-container">
15
+ <h3>Why am I seeing this page?</h3>
16
+ <p>Merb couldn't find an appropriate content_type to return,
17
+ based on what you said was available via provides() and
18
+ what the client requested.</p>
19
+
20
+ <h3>How to add a mime-type</h3>
21
+ <pre><code>
22
+ Merb.add_mime_type :pdf, :to_pdf, %w[application/pdf], &quot;Content-Encoding&quot; =&gt; &quot;gzip&quot;
23
+ </code></pre>
24
+ <h3>What this means is:</h3>
25
+ <ul>
26
+ <li>Add a mime-type for :pdf</li>
27
+ <li>Register the method for converting objects to PDF as <code>#to_pdf</code>.</li>
28
+ <li>Register the incoming mime-type "Accept" header as <code>application/pdf</code>.</li>
29
+ <li>Specify a new header for PDF types so it will set <code>Content-Encoding</code> to gzip.</li>
30
+ </ul>
31
+
32
+ <h3>You can then do:</h3>
33
+ <pre><code>
34
+ class Foo &lt; Application
35
+ provides :pdf
36
+ end
37
+ </code></pre>
38
+
39
+ <h3>Where can I find help?</h3>
40
+ <p>If you have any questions or if you can't figure something out, please take a
41
+ look at our <a href="http://merb.devjavu.com/"> project development page</a> or,
42
+ feel free to come chat at irc.freenode.net, channel #merb.</p>
43
+
44
+ <h3>How do I edit this page?</h3>
45
+ <p>You can change what people see when this happens byy editing <tt>app/views/exceptions/not_found.html.erb</tt>.</p>
46
+
47
+ </div>
48
+
49
+ <div id="footer-container">
50
+ <hr />
51
+ <div class="left"></div>
52
+ <div class="right">&copy; 2007 the merb dev team</div>
53
+ <p>&nbsp;</p>
54
+ </div>
55
+ </div>
@@ -0,0 +1,39 @@
1
+ <div id="container">
2
+ <div id="header-container">
3
+ <img src="/images/merb.jpg" />
4
+ <!-- <h1>Mongrel + Erb</h1> -->
5
+ <h2>pocket rocket web framework</h2>
6
+ <hr />
7
+ </div>
8
+
9
+ <div id="left-container">
10
+ <h3>Exception:</h3>
11
+ <p><%%= params[:exception] %></p>
12
+ </div>
13
+
14
+ <div id="main-container">
15
+ <h3>Welcome to Merb!</h3>
16
+ <p>Merb is a light-weight MVC framework written in Ruby. We hope you enjoy it.</p>
17
+
18
+ <h3>Where can I find help?</h3>
19
+ <p>If you have any questions or if you can't figure something out, please take a
20
+ look at our <a href="http://merb.devjavu.com/"> project development page</a> or,
21
+ feel free to come chat at irc.freenode.net, channel #merb.</p>
22
+
23
+ <h3>How do I edit this page?</h3>
24
+ <p>You're seeing this page because you need to edit the following files:
25
+ <ul>
26
+ <li>config/router.rb <strong><em>(recommended)</em></strong></li>
27
+ <li>app/views/exceptions/not_found.html.erb <strong><em>(recommended)</em></strong></li>
28
+ <li>app/views/layout/application.html.erb <strong><em>(change this layout)</em></strong></li>
29
+ </ul>
30
+ </p>
31
+ </div>
32
+
33
+ <div id="footer-container">
34
+ <hr />
35
+ <div class="left"></div>
36
+ <div class="right">&copy; 2007 the merb dev team</div>
37
+ <p>&nbsp;</p>
38
+ </div>
39
+ </div>
@@ -0,0 +1,11 @@
1
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
2
+ <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-us" lang="en-us">
3
+ <head>
4
+ <title>Fresh Merb App</title>
5
+ <meta http-equiv="content-type" content="text/html; charset=utf-8" />
6
+ <link rel="stylesheet" href="/stylesheets/master.css" type="text/css" media="screen" charset="utf-8" />
7
+ </head>
8
+ <body>
9
+ <%%= catch_content :for_layout %>
10
+ </body>
11
+ </html>
@@ -0,0 +1 @@
1
+ Autotest.add_discovery { "merb" }
@@ -0,0 +1,149 @@
1
+ # Adapted from Autotest::Rails
2
+ require 'autotest'
3
+
4
+ class Autotest::Merb < Autotest
5
+
6
+ # +model_tests_dir+:: the directory to find model-centric tests
7
+ # +controller_tests_dir+:: the directory to find controller-centric tests
8
+ # +view_tests_dir+:: the directory to find view-centric tests
9
+ # +fixtures_dir+:: the directory to find fixtures in
10
+ attr_accessor :model_tests_dir, :controller_tests_dir, :view_tests_dir, :fixtures_dir
11
+
12
+ def initialize # :nodoc:
13
+ super
14
+
15
+ initialize_test_layout
16
+
17
+ # Ignore any happenings in these directories
18
+ add_exception %r%^\./(?:doc|log|public|tmp)%
19
+
20
+ # Ignore any mappings that Autotest may have already set up
21
+ clear_mappings
22
+
23
+ # Any changes to a file in the root of the 'lib' directory will run any
24
+ # model test with a corresponding name.
25
+ add_mapping %r%^lib\/.*\.rb% do |filename, _|
26
+ files_matching Regexp.new(["^#{model_test_for(filename)}$"])
27
+ end
28
+
29
+ # Any changes to a fixture will run corresponding view, controller and
30
+ # model tests
31
+ add_mapping %r%^#{fixtures_dir}/(.*)s.yml% do |_, m|
32
+ [
33
+ model_test_for(m[1]),
34
+ controller_test_for(m[1]),
35
+ view_test_for(m[1])
36
+ ]
37
+ end
38
+
39
+ # Any change to a test or test will cause it to be run
40
+ add_mapping %r%^test/(unit|models|integration|controllers|views|functional)/.*rb$% do |filename, _|
41
+ filename
42
+ end
43
+
44
+ # Any change to a model will cause it's corresponding test to be run
45
+ add_mapping %r%^app/models/(.*)\.rb$% do |_, m|
46
+ model_test_for(m[1])
47
+ end
48
+
49
+ # Any change to the global helper will result in all view and controller
50
+ # tests being run
51
+ add_mapping %r%^app/helpers/global_helpers.rb% do
52
+ files_matching %r%^test/(views|functional|controllers)/.*_test\.rb$%
53
+ end
54
+
55
+ # Any change to a helper will run it's corresponding view and controller
56
+ # tests, unless the helper is the global helper. Changes to the global
57
+ # helper run all view and controller tests.
58
+ add_mapping %r%^app/helpers/(.*)_helper(s)?.rb% do |_, m|
59
+ if m[1] == "global" then
60
+ files_matching %r%^test/(views|functional|controllers)/.*_test\.rb$%
61
+ else
62
+ [
63
+ view_test_for(m[1]),
64
+ controller_test_for(m[1])
65
+ ]
66
+ end
67
+ end
68
+
69
+ # Changes to views result in their corresponding view and controller test
70
+ # being run
71
+ add_mapping %r%^app/views/(.*)/% do |_, m|
72
+ [
73
+ view_test_for(m[1]),
74
+ controller_test_for(m[1])
75
+ ]
76
+ end
77
+
78
+ # Changes to a controller result in its corresponding test being run. If
79
+ # the controller is the exception or application controller, all
80
+ # controller tests are run.
81
+ add_mapping %r%^app/controllers/(.*)\.rb$% do |_, m|
82
+ if ["application", "exception"].include?(m[1])
83
+ files_matching %r%^test/(controllers|views|functional)/.*_test\.rb$%
84
+ else
85
+ controller_test_for(m[1])
86
+ end
87
+ end
88
+
89
+ # If a change is made to the router, run all controller and view tests
90
+ add_mapping %r%^config/router.rb$% do # FIX
91
+ files_matching %r%^test/(controllers|views|functional)/.*_test\.rb$%
92
+ end
93
+
94
+ # If any of the major files governing the environment are altered, run
95
+ # everything
96
+ add_mapping %r%^test/test_helper.rb|config/(init|rack|environments/test.rb|database.yml)% do # FIX
97
+ files_matching %r%^test/(unit|models|controllers|views|functional)/.*_test\.rb$%
98
+ end
99
+ end
100
+
101
+ private
102
+
103
+ # Determines the paths we can expect tests or specs to reside, as well as
104
+ # corresponding fixtures.
105
+ def initialize_test_layout
106
+ self.model_tests_dir = "test/unit"
107
+ self.controller_tests_dir = "test/functional"
108
+ self.view_tests_dir = "test/views"
109
+ self.fixtures_dir = "test/fixtures"
110
+ end
111
+
112
+ # Given a filename and the test type, this method will return the
113
+ # corresponding test's or spec's name.
114
+ #
115
+ # ==== Arguments
116
+ # +filename+<String>:: the file name of the model, view, or controller
117
+ # +kind_of_test+<Symbol>:: the type of test we that we should run
118
+ #
119
+ # ==== Returns
120
+ # String:: the name of the corresponding test or spec
121
+ #
122
+ # ==== Example
123
+ #
124
+ # > test_for("user", :model)
125
+ # => "user_test.rb"
126
+ # > test_for("login", :controller)
127
+ # => "login_controller_test.rb"
128
+ # > test_for("form", :view)
129
+ # => "form_view_spec.rb" # If you're running a RSpec-like suite
130
+ def test_for(filename, kind_of_test) # :nodoc:
131
+ name = [filename]
132
+ name << kind_of_test.to_s if kind_of_test == :view
133
+ name << "test"
134
+ return name.join("_") + ".rb"
135
+ end
136
+
137
+ def model_test_for(filename)
138
+ [model_tests_dir, test_for(filename, :model)].join("/")
139
+ end
140
+
141
+ def controller_test_for(filename)
142
+ [controller_tests_dir, test_for(filename, :controller)].join("/")
143
+ end
144
+
145
+ def view_test_for(filename)
146
+ [view_tests_dir, test_for(filename, :view)].join("/")
147
+ end
148
+
149
+ end
@@ -0,0 +1,202 @@
1
+ # Adapted from Autotest::Rails
2
+ require 'autotest'
3
+
4
+ class Autotest::MerbRspec < Autotest
5
+
6
+ # +model_tests_dir+:: the directory to find model-centric tests
7
+ # +controller_tests_dir+:: the directory to find controller-centric tests
8
+ # +view_tests_dir+:: the directory to find view-centric tests
9
+ # +fixtures_dir+:: the directory to find fixtures in
10
+ attr_accessor :model_tests_dir, :controller_tests_dir, :view_tests_dir, :fixtures_dir
11
+
12
+ def initialize # :nodoc:
13
+ super
14
+
15
+ initialize_test_layout
16
+
17
+ # Ignore any happenings in these directories
18
+ add_exception %r%^\./(?:doc|log|public|tmp)%
19
+
20
+ # Ignore any mappings that Autotest may have already set up
21
+ clear_mappings
22
+
23
+ # Any changes to a file in the root of the 'lib' directory will run any
24
+ # model test with a corresponding name.
25
+ add_mapping %r%^lib\/.*\.rb% do |filename, _|
26
+ files_matching Regexp.new("^#{model_test_for(filename)}$")
27
+ end
28
+
29
+ add_mapping %r%^spec/(spec_helper|shared/.*)\.rb$% do
30
+ files_matching %r%^spec/.*_spec\.rb$%
31
+ end
32
+
33
+ # Any changes to a fixture will run corresponding view, controller and
34
+ # model tests
35
+ add_mapping %r%^#{fixtures_dir}/(.*)s.yml% do |_, m|
36
+ [
37
+ model_test_for(m[1]),
38
+ controller_test_for(m[1]),
39
+ view_test_for(m[1])
40
+ ]
41
+ end
42
+
43
+ # Any change to a test or spec will cause it to be run
44
+ add_mapping %r%^spec/(unit|models|integration|controllers|views|functional)/.*rb$% do |filename, _|
45
+ filename
46
+ end
47
+
48
+ # Any change to a model will cause it's corresponding test to be run
49
+ add_mapping %r%^app/models/(.*)\.rb$% do |_, m|
50
+ model_test_for(m[1])
51
+ end
52
+
53
+ # Any change to the global helper will result in all view and controller
54
+ # tests being run
55
+ add_mapping %r%^app/helpers/global_helpers.rb% do
56
+ files_matching %r%^spec/(views|functional|controllers)/.*_spec\.rb$%
57
+ end
58
+
59
+ # Any change to a helper will run it's corresponding view and controller
60
+ # tests, unless the helper is the global helper. Changes to the global
61
+ # helper run all view and controller tests.
62
+ add_mapping %r%^app/helpers/(.*)_helper(s)?.rb% do |_, m|
63
+ if m[1] == "global" then
64
+ files_matching %r%^spec/(views|functional|controllers)/.*_spec\.rb$%
65
+ else
66
+ [
67
+ view_test_for(m[1]),
68
+ controller_test_for(m[1])
69
+ ]
70
+ end
71
+ end
72
+
73
+ # Changes to views result in their corresponding view and controller test
74
+ # being run
75
+ add_mapping %r%^app/views/(.*)/% do |_, m|
76
+ [
77
+ view_test_for(m[1]),
78
+ controller_test_for(m[1])
79
+ ]
80
+ end
81
+
82
+ # Changes to a controller result in its corresponding test being run. If
83
+ # the controller is the exception or application controller, all
84
+ # controller tests are run.
85
+ add_mapping %r%^app/controllers/(.*)\.rb$% do |_, m|
86
+ if ["application", "exception"].include?(m[1])
87
+ files_matching %r%^spec/(controllers|views|functional)/.*_spec\.rb$%
88
+ else
89
+ controller_test_for(m[1])
90
+ end
91
+ end
92
+
93
+ # If a change is made to the router, run all controller and view tests
94
+ add_mapping %r%^config/router.rb$% do # FIX
95
+ files_matching %r%^spec/(controllers|views|functional)/.*_spec\.rb$%
96
+ end
97
+
98
+ # If any of the major files governing the environment are altered, run
99
+ # everything
100
+ add_mapping %r%^spec/spec_helper.rb|config/(init|rack|environments/test.rb|database.yml)% do # FIX
101
+ files_matching %r%^spec/(unit|models|controllers|views|functional)/.*_spec\.rb$%
102
+ end
103
+ end
104
+
105
+ ##
106
+ # Methods below this point are adapted from Auotest::Rspec
107
+
108
+ def consolidate_failures(failed)
109
+ filters = Hash.new { |h,k| h[k] = [] }
110
+ failed.each do |spec, failed_trace|
111
+ if f = test_files_for(failed).find { |f| failed_trace =~ Regexp.new(f) } then
112
+ filters[f] << spec
113
+ break
114
+ end
115
+ end
116
+ return filters
117
+ end
118
+
119
+ def make_test_cmd(files_to_test)
120
+ return "#{ruby} -S #{spec_command} #{add_options_if_present} #{files_to_test.keys.flatten.join(' ')}"
121
+ end
122
+
123
+ def add_options_if_present
124
+ File.exist?("spec/spec.opts") ? "-O spec/spec.opts " : ""
125
+ end
126
+
127
+ # Finds the proper spec command to use. Precendence is set in the
128
+ # lazily-evaluated method spec_commands. Alias + Override that in
129
+ # ~/.autotest to provide a different spec command then the default
130
+ # paths provided.
131
+ def spec_command(separator=File::ALT_SEPARATOR)
132
+ unless defined? @spec_command then
133
+ @spec_command = spec_commands.find { |cmd| File.exists? cmd }
134
+
135
+ raise RspecCommandError, "No spec command could be found!" unless @spec_command
136
+
137
+ @spec_command.gsub! File::SEPARATOR, separator if separator
138
+ end
139
+ @spec_command
140
+ end
141
+
142
+ # Autotest will look for spec commands in the following
143
+ # locations, in this order:
144
+ #
145
+ # * bin/spec
146
+ # * default spec bin/loader installed in Rubygems
147
+ def spec_commands
148
+ [
149
+ File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'bin', 'spec')),
150
+ File.join(Config::CONFIG['bindir'], 'spec')
151
+ ]
152
+ end
153
+
154
+ private
155
+
156
+ # Determines the paths we can expect tests or specs to reside, as well as
157
+ # corresponding fixtures.
158
+ def initialize_test_layout
159
+ self.model_tests_dir = "spec/models"
160
+ self.controller_tests_dir = "spec/controllers"
161
+ self.view_tests_dir = "spec/views"
162
+ self.fixtures_dir = "spec/fixtures"
163
+ end
164
+
165
+ # Given a filename and the test type, this method will return the
166
+ # corresponding test's or spec's name.
167
+ #
168
+ # ==== Arguments
169
+ # +filename+<String>:: the file name of the model, view, or controller
170
+ # +kind_of_test+<Symbol>:: the type of test we that we should run
171
+ #
172
+ # ==== Returns
173
+ # String:: the name of the corresponding test or spec
174
+ #
175
+ # ==== Example
176
+ #
177
+ # > test_for("user", :model)
178
+ # => "user_test.rb"
179
+ # > test_for("login", :controller)
180
+ # => "login_controller_test.rb"
181
+ # > test_for("form", :view)
182
+ # => "form_view_spec.rb" # If you're running a RSpec-like suite
183
+ def test_for(filename, kind_of_test) # :nodoc:
184
+ name = [filename]
185
+ name << kind_of_test.to_s unless if == :view
186
+ name << "spec"
187
+ return name.join("_") + ".rb"
188
+ end
189
+
190
+ def model_test_for(filename)
191
+ [model_tests_dir, test_for(filename, :model)].join("/")
192
+ end
193
+
194
+ def controller_test_for(filename)
195
+ [controller_tests_dir, test_for(filename, :controller)].join("/")
196
+ end
197
+
198
+ def view_test_for(filename)
199
+ [view_tests_dir, test_for(filename, :view)].join("/")
200
+ end
201
+
202
+ end