rspec-rails-w-factory_girl 1.3.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (167) hide show
  1. data/.document +7 -0
  2. data/Contribute.rdoc +4 -0
  3. data/History.rdoc +310 -0
  4. data/License.txt +33 -0
  5. data/Manifest.txt +166 -0
  6. data/README.rdoc +45 -0
  7. data/Rakefile +72 -0
  8. data/TODO.txt +17 -0
  9. data/Upgrade.rdoc +148 -0
  10. data/generators/integration_spec/integration_spec_generator.rb +10 -0
  11. data/generators/integration_spec/templates/integration_spec.rb +4 -0
  12. data/generators/rspec/CHANGES +1 -0
  13. data/generators/rspec/rspec_generator.rb +73 -0
  14. data/generators/rspec/templates/previous_failures.txt +0 -0
  15. data/generators/rspec/templates/rcov.opts +2 -0
  16. data/generators/rspec/templates/rspec.rake +144 -0
  17. data/generators/rspec/templates/script/autospec +6 -0
  18. data/generators/rspec/templates/script/spec +10 -0
  19. data/generators/rspec/templates/spec.opts +4 -0
  20. data/generators/rspec/templates/spec_helper.rb +54 -0
  21. data/generators/rspec_controller/USAGE +33 -0
  22. data/generators/rspec_controller/rspec_controller_generator.rb +47 -0
  23. data/generators/rspec_controller/templates/controller_spec.rb +25 -0
  24. data/generators/rspec_controller/templates/helper_spec.rb +11 -0
  25. data/generators/rspec_controller/templates/view_spec.rb +12 -0
  26. data/generators/rspec_default_values.rb +28 -0
  27. data/generators/rspec_model/USAGE +18 -0
  28. data/generators/rspec_model/rspec_model_generator.rb +34 -0
  29. data/generators/rspec_model/templates/factories.rb +8 -0
  30. data/generators/rspec_model/templates/model_spec.rb +13 -0
  31. data/generators/rspec_scaffold/rspec_scaffold_generator.rb +154 -0
  32. data/generators/rspec_scaffold/templates/controller_spec.rb +131 -0
  33. data/generators/rspec_scaffold/templates/edit_erb_spec.rb +25 -0
  34. data/generators/rspec_scaffold/templates/helper_spec.rb +11 -0
  35. data/generators/rspec_scaffold/templates/index_erb_spec.rb +27 -0
  36. data/generators/rspec_scaffold/templates/new_erb_spec.rb +25 -0
  37. data/generators/rspec_scaffold/templates/routing_spec.rb +33 -0
  38. data/generators/rspec_scaffold/templates/show_erb_spec.rb +22 -0
  39. data/init.rb +9 -0
  40. data/lib/autotest/discover.rb +5 -0
  41. data/lib/autotest/rails_rspec.rb +76 -0
  42. data/lib/spec/rails/example/assigns_hash_proxy.rb +39 -0
  43. data/lib/spec/rails/example/controller_example_group.rb +285 -0
  44. data/lib/spec/rails/example/cookies_proxy.rb +29 -0
  45. data/lib/spec/rails/example/functional_example_group.rb +106 -0
  46. data/lib/spec/rails/example/helper_example_group.rb +153 -0
  47. data/lib/spec/rails/example/integration_example_group.rb +16 -0
  48. data/lib/spec/rails/example/model_example_group.rb +15 -0
  49. data/lib/spec/rails/example/render_observer.rb +80 -0
  50. data/lib/spec/rails/example/routing_example_group.rb +13 -0
  51. data/lib/spec/rails/example/routing_helpers.rb +66 -0
  52. data/lib/spec/rails/example/view_example_group.rb +199 -0
  53. data/lib/spec/rails/example.rb +48 -0
  54. data/lib/spec/rails/extensions/action_controller/rescue.rb +42 -0
  55. data/lib/spec/rails/extensions/action_controller/test_case.rb +16 -0
  56. data/lib/spec/rails/extensions/action_controller/test_response.rb +21 -0
  57. data/lib/spec/rails/extensions/action_view/base.rb +35 -0
  58. data/lib/spec/rails/extensions/active_record/base.rb +45 -0
  59. data/lib/spec/rails/extensions/active_support/test_case.rb +7 -0
  60. data/lib/spec/rails/extensions/spec/matchers/have.rb +23 -0
  61. data/lib/spec/rails/extensions/spec/runner/configuration.rb +44 -0
  62. data/lib/spec/rails/extensions.rb +11 -0
  63. data/lib/spec/rails/interop/testcase.rb +14 -0
  64. data/lib/spec/rails/matchers/ar_be_valid.rb +27 -0
  65. data/lib/spec/rails/matchers/assert_select.rb +180 -0
  66. data/lib/spec/rails/matchers/change.rb +13 -0
  67. data/lib/spec/rails/matchers/have_text.rb +57 -0
  68. data/lib/spec/rails/matchers/include_text.rb +54 -0
  69. data/lib/spec/rails/matchers/redirect_to.rb +126 -0
  70. data/lib/spec/rails/matchers/render_template.rb +129 -0
  71. data/lib/spec/rails/matchers/route_to.rb +149 -0
  72. data/lib/spec/rails/matchers.rb +32 -0
  73. data/lib/spec/rails/mocks.rb +136 -0
  74. data/lib/spec/rails/version.rb +16 -0
  75. data/lib/spec/rails.rb +26 -0
  76. data/spec/autotest/mappings_spec.rb +86 -0
  77. data/spec/rails_suite.rb +7 -0
  78. data/spec/resources/controllers/action_view_base_spec_controller.rb +2 -0
  79. data/spec/resources/controllers/application.rb +9 -0
  80. data/spec/resources/controllers/controller_spec_controller.rb +127 -0
  81. data/spec/resources/controllers/example.txt +1 -0
  82. data/spec/resources/controllers/redirect_spec_controller.rb +70 -0
  83. data/spec/resources/controllers/render_spec_controller.rb +34 -0
  84. data/spec/resources/controllers/rjs_spec_controller.rb +58 -0
  85. data/spec/resources/helpers/addition_helper.rb +5 -0
  86. data/spec/resources/helpers/explicit_helper.rb +46 -0
  87. data/spec/resources/helpers/more_explicit_helper.rb +5 -0
  88. data/spec/resources/helpers/plugin_application_helper.rb +6 -0
  89. data/spec/resources/helpers/view_spec_helper.rb +13 -0
  90. data/spec/resources/models/animal.rb +4 -0
  91. data/spec/resources/models/person.rb +18 -0
  92. data/spec/resources/models/thing.rb +3 -0
  93. data/spec/resources/views/controller_spec/_partial.html.erb +0 -0
  94. data/spec/resources/views/controller_spec/action_setting_flash_after_session_reset.html.erb +1 -0
  95. data/spec/resources/views/controller_spec/action_setting_flash_before_session_reset.html.erb +1 -0
  96. data/spec/resources/views/controller_spec/action_setting_the_assigns_hash.html.erb +0 -0
  97. data/spec/resources/views/controller_spec/action_with_errors_in_template.html.erb +1 -0
  98. data/spec/resources/views/controller_spec/action_with_template.html.erb +1 -0
  99. data/spec/resources/views/layouts/application.html.erb +0 -0
  100. data/spec/resources/views/layouts/simple.html.erb +0 -0
  101. data/spec/resources/views/objects/_object.html.erb +1 -0
  102. data/spec/resources/views/render_spec/_a_partial.html.erb +0 -0
  103. data/spec/resources/views/render_spec/action_with_alternate_layout.html.erb +0 -0
  104. data/spec/resources/views/render_spec/some_action.html.erb +0 -0
  105. data/spec/resources/views/render_spec/some_action.js.rjs +1 -0
  106. data/spec/resources/views/rjs_spec/_replacement_partial.html.erb +1 -0
  107. data/spec/resources/views/rjs_spec/hide_div.js.rjs +1 -0
  108. data/spec/resources/views/rjs_spec/hide_page_element.js.rjs +1 -0
  109. data/spec/resources/views/rjs_spec/insert_html.js.rjs +1 -0
  110. data/spec/resources/views/rjs_spec/replace.js.rjs +1 -0
  111. data/spec/resources/views/rjs_spec/replace_html.js.rjs +1 -0
  112. data/spec/resources/views/rjs_spec/replace_html_with_partial.js.rjs +1 -0
  113. data/spec/resources/views/rjs_spec/visual_effect.js.rjs +1 -0
  114. data/spec/resources/views/rjs_spec/visual_toggle_effect.js.rjs +1 -0
  115. data/spec/resources/views/tag_spec/no_tags.html.erb +1 -0
  116. data/spec/resources/views/tag_spec/single_div_with_no_attributes.html.erb +1 -0
  117. data/spec/resources/views/tag_spec/single_div_with_one_attribute.html.erb +1 -0
  118. data/spec/resources/views/view_spec/_partial.html.erb +2 -0
  119. data/spec/resources/views/view_spec/_partial_used_twice.html.erb +0 -0
  120. data/spec/resources/views/view_spec/_partial_with_local_variable.html.erb +1 -0
  121. data/spec/resources/views/view_spec/_partial_with_sub_partial.html.erb +1 -0
  122. data/spec/resources/views/view_spec/_spacer.html.erb +1 -0
  123. data/spec/resources/views/view_spec/accessor.html.erb +6 -0
  124. data/spec/resources/views/view_spec/block_helper.html.erb +3 -0
  125. data/spec/resources/views/view_spec/entry_form.html.erb +2 -0
  126. data/spec/resources/views/view_spec/explicit_helper.html.erb +2 -0
  127. data/spec/resources/views/view_spec/foo/show.html.erb +1 -0
  128. data/spec/resources/views/view_spec/implicit_helper.html.erb +2 -0
  129. data/spec/resources/views/view_spec/multiple_helpers.html.erb +3 -0
  130. data/spec/resources/views/view_spec/path_params.html.erb +1 -0
  131. data/spec/resources/views/view_spec/should_not_receive.html.erb +3 -0
  132. data/spec/resources/views/view_spec/template_with_partial.html.erb +5 -0
  133. data/spec/resources/views/view_spec/template_with_partial_using_collection.html.erb +3 -0
  134. data/spec/resources/views/view_spec/template_with_partial_with_array.html.erb +1 -0
  135. data/spec/resources/views/view_spec/view_helpers.html.erb +1 -0
  136. data/spec/spec/rails/example/assigns_hash_proxy_spec.rb +109 -0
  137. data/spec/spec/rails/example/configuration_spec.rb +65 -0
  138. data/spec/spec/rails/example/controller_example_group_spec.rb +307 -0
  139. data/spec/spec/rails/example/controller_isolation_spec.rb +75 -0
  140. data/spec/spec/rails/example/cookies_proxy_spec.rb +87 -0
  141. data/spec/spec/rails/example/error_handling_spec.rb +90 -0
  142. data/spec/spec/rails/example/example_group_factory_spec.rb +112 -0
  143. data/spec/spec/rails/example/helper_example_group_spec.rb +247 -0
  144. data/spec/spec/rails/example/model_example_group_spec.rb +32 -0
  145. data/spec/spec/rails/example/routing_example_group_spec.rb +10 -0
  146. data/spec/spec/rails/example/shared_routing_example_group_examples.rb +237 -0
  147. data/spec/spec/rails/example/test_unit_assertion_accessibility_spec.rb +33 -0
  148. data/spec/spec/rails/example/view_example_group_spec.rb +346 -0
  149. data/spec/spec/rails/extensions/action_view_base_spec.rb +79 -0
  150. data/spec/spec/rails/extensions/active_record_spec.rb +14 -0
  151. data/spec/spec/rails/interop/testcase_spec.rb +70 -0
  152. data/spec/spec/rails/matchers/ar_be_valid_spec.rb +19 -0
  153. data/spec/spec/rails/matchers/assert_select_spec.rb +835 -0
  154. data/spec/spec/rails/matchers/errors_on_spec.rb +37 -0
  155. data/spec/spec/rails/matchers/have_text_spec.rb +69 -0
  156. data/spec/spec/rails/matchers/include_text_spec.rb +62 -0
  157. data/spec/spec/rails/matchers/redirect_to_spec.rb +253 -0
  158. data/spec/spec/rails/matchers/render_template_spec.rb +208 -0
  159. data/spec/spec/rails/matchers/should_change_spec.rb +15 -0
  160. data/spec/spec/rails/mocks/ar_classes.rb +10 -0
  161. data/spec/spec/rails/mocks/mock_model_spec.rb +109 -0
  162. data/spec/spec/rails/mocks/stub_model_spec.rb +80 -0
  163. data/spec/spec/rails/sample_modified_fixture.rb +8 -0
  164. data/spec/spec/rails/sample_spec.rb +8 -0
  165. data/spec/spec/rails/spec_spec.rb +11 -0
  166. data/spec/spec_helper.rb +78 -0
  167. metadata +301 -0
data/Upgrade.rdoc ADDED
@@ -0,0 +1,148 @@
1
+ = Upgrade to 1.2.8 - 1.3.2
2
+
3
+ == What's new
4
+
5
+ === route_to and be_routable matchers
6
+
7
+ Stop using route_for and params_from today! These new matchers from Randy
8
+ Harmon are more expressive and more reliable. Here's how you use them:
9
+
10
+ { :put => "/projects/37" }.should route_to(:controller => 'projects', :action => 'update', :id => '37')
11
+
12
+ { :get => "/nonexisting_route" }.should_not be_routable
13
+
14
+ == What's changed
15
+
16
+ === spec_server has been removed
17
+
18
+ spec_server was deprecated in 1.2.7 and has now been removed. Admittedly, this
19
+ was a short deprecation cycle, but spec server never quite worked right in all
20
+ situations and spork is a great solution that you can use today! This is all
21
+ you need to do:
22
+
23
+ [sudo] gem install spork
24
+ cd path/to/project
25
+ spork --bootsrap
26
+
27
+ Now open up spec/spec_helper.rb and follow the directions at the top. You'll
28
+ be up and running in no time.
29
+
30
+ For more info:
31
+
32
+ * http://github.com/timcharper/spork
33
+ * http://groups.google.com/group/sporkgem
34
+
35
+ = Upgrade to 1.2.7
36
+
37
+ == What's changed
38
+
39
+ === spec_server is deprecated
40
+
41
+ spec_server is deprecated in favor of Tim Harper's new spork library
42
+ (http://github.com/timcharper/spork). Get it. Use it. Love it.
43
+
44
+ gem install spork
45
+
46
+ = Upgrade to 1.2.0-1.2.6
47
+
48
+ == What's changed
49
+
50
+ === Supported Rails Versions
51
+
52
+ This release supports the following versions of rails:
53
+
54
+ * 2.0.5
55
+ * 2.1.2
56
+ * 2.2.2
57
+ * 2.3.2
58
+
59
+ === update generated files
60
+
61
+ Be sure to run "script/generate rspec" and allow the following files to be overwritten:
62
+
63
+ * lib/tasks/rspec.rake
64
+ * script/spec
65
+ * script/spec_server
66
+
67
+ === controller.use_rails_error_handling! is deprecated
68
+
69
+ Use <tt>rescue_action_in_public!</tt> instead. It comes directly from rails and does
70
+ exactly the same thing
71
+
72
+ === route_for
73
+
74
+ After a change to edge rails broke our monkey-patched <tt>route_for</tt> method, I
75
+ decided to just delegate to rails' <tt>assert_generates</tt> method. For most cases,
76
+ this will not present a problem, but for some it might. You'll know if you
77
+ upgrade and see any newly failing, route-related examples. Here are the things
78
+ that you might need to change.
79
+
80
+ ==== Make sure IDs are strings
81
+
82
+ If you had :id => 1 before, you need to change that to :id => "1"
83
+
84
+ #old
85
+ route_for(:controller => 'things', :action => 'show', :id => 1).should == "/things/1"
86
+
87
+ #new
88
+ route_for(:controller => 'things', :action => 'show', :id => "1").should == "/things/1"
89
+
90
+ ==== Convert paths for non-get methods to hashes
91
+
92
+ If you had an example with a route that requires post, put, or delete, you'll
93
+ need to declare that explicitly.
94
+
95
+ #old
96
+ route_for(:controller => 'things', :action => 'create').should == "/things"
97
+
98
+ #new
99
+ route_for(:controller => 'things', :action => 'create').should == {:path => "/things", :method => :post}
100
+
101
+ === Controller/template isolation
102
+
103
+ Even though controller specs do not render views by default (use
104
+ <tt>integrate_views</tt> to get them to render views), the way this works has
105
+ changed in this version.
106
+
107
+ It used to be that the view template need not even exist, but due to changes
108
+ in rails it became much more difficult to manage that for all the different
109
+ versions of rails that rspec-rails supports. So now the template must exist,
110
+ but it still won't be rendered unless you declare <tt>integrate_views</tt>.
111
+
112
+ == What's new
113
+
114
+ === render no longer requires a path
115
+
116
+ The <tt>render()</tt> method in view specs will infer the path from the
117
+ first argument passed to <tt>describe()</tt>.
118
+
119
+ describe "players/show" do
120
+ it "does something" do
121
+ render
122
+ response.should have_tag("....")
123
+ end
124
+ end
125
+
126
+ === routing specs live in spec/routing
127
+
128
+ <tt>script/generate rspec_scaffold</tt> now generates its routing spec in
129
+ <tt>spec/routing/</tt>.
130
+
131
+ === bypass_rescue
132
+
133
+ Added a new <tt>bypass_rescue()</tt> declaration for controller specs. Use this
134
+ when you want to specify that an error is raised by an action, even if that
135
+ error is later captured by a <tt>rescue_from()</tt> declaration.
136
+
137
+ describe AccountController do
138
+ describe "GET @account" do
139
+ context "requested by anonymous user" do
140
+ it "denies access" do
141
+ bypass_rescue
142
+ lambda do
143
+ get :show, :id => "37"
144
+ end.should raise_error(AccessDenied)
145
+ end
146
+ end
147
+ end
148
+ end
@@ -0,0 +1,10 @@
1
+ require File.dirname(__FILE__) + '/../rspec_default_values'
2
+
3
+ class IntegrationSpecGenerator < ModelGenerator
4
+ def manifest
5
+ record do |m|
6
+ m.class_collisions class_path, class_name
7
+ m.template 'integration_spec.rb', File.join('spec/integration', class_path, "#{class_name.tableize}_spec.rb")
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,4 @@
1
+ require 'spec_helper'
2
+
3
+ describe "<%= class_name.pluralize %>" do
4
+ end
@@ -0,0 +1 @@
1
+ Please refer to the CHANGES file for RSpec's core
@@ -0,0 +1,73 @@
1
+ require 'rbconfig'
2
+
3
+ # This generator bootstraps a Rails project for use with RSpec
4
+ class RspecGenerator < Rails::Generator::Base
5
+ DEFAULT_SHEBANG = File.join(Config::CONFIG['bindir'],
6
+ Config::CONFIG['ruby_install_name'])
7
+
8
+ def initialize(runtime_args, runtime_options = {})
9
+ if test ?f, 'spec/spec_helper.rb'
10
+
11
+ puts <<-HELPFUL_INSTRUCTIONS
12
+
13
+ It looks like you are upgrading rspec-rails in this application. Please let
14
+ this script overwrite everything it wants to with the following exceptions,
15
+ *if* you have customized any of these files:
16
+
17
+ * spec/spec.opts
18
+ * spec/rcov.opts
19
+ * spec/spec_helper.rb
20
+
21
+ If you have customized spec/spec_helper.rb, please set aside a copy of that
22
+ file so that it can be updated and you can manually restore your changes.
23
+
24
+ HELPFUL_INSTRUCTIONS
25
+ end
26
+ Dir.mkdir('lib/tasks') unless File.directory?('lib/tasks')
27
+
28
+ if Rails::VERSION::STRING >= '2.1'
29
+ test_env = 'config/environments/test.rb'
30
+ contents = File.read(test_env)
31
+ unless contents =~ /config\.gem\s+(\"|\')rspec/m
32
+ puts "Configuring rspec and rspec-rails and factory_girl gems in #{test_env} ..."
33
+ puts
34
+ require File.expand_path('../../../lib/spec/rails/version.rb', __FILE__)
35
+ rspec_config = <<-EOF
36
+ config.gem 'rspec-rails', :version => '>= #{Spec::Rails::VERSION::STRING}', :lib => false unless File.directory?(File.join(Rails.root, 'vendor/plugins/rspec-rails'))
37
+ config.gem 'factory_girl', lib => false unless File.directory?(File.join(Rails.root, 'vendor/plugins/factory_girl'))
38
+ EOF
39
+ File.open(test_env, "wb") do |f|
40
+ f.puts contents
41
+ f.puts
42
+ f.puts rspec_config
43
+ end
44
+ end
45
+ end
46
+
47
+ super
48
+ end
49
+
50
+ def manifest
51
+ record do |m|
52
+ script_options = { :chmod => 0755, :shebang => options[:shebang] == DEFAULT_SHEBANG ? nil : options[:shebang] }
53
+
54
+ m.directory 'lib/tasks'
55
+ m.file 'rspec.rake', 'lib/tasks/rspec.rake'
56
+
57
+ m.file 'script/autospec', 'script/autospec', script_options
58
+ m.file 'script/spec', 'script/spec', script_options
59
+
60
+ m.directory 'spec'
61
+ m.file 'rcov.opts', 'spec/rcov.opts'
62
+ m.file 'spec.opts', 'spec/spec.opts'
63
+ m.template 'spec_helper.rb', 'spec/spec_helper.rb'
64
+ end
65
+ end
66
+
67
+ protected
68
+
69
+ def banner
70
+ "Usage: #{$0} rspec"
71
+ end
72
+
73
+ end
File without changes
@@ -0,0 +1,2 @@
1
+ --exclude "spec/*,gems/*"
2
+ --rails
@@ -0,0 +1,144 @@
1
+ gem 'test-unit', '1.2.3' if RUBY_VERSION.to_f >= 1.9
2
+ rspec_gem_dir = nil
3
+ Dir["#{RAILS_ROOT}/vendor/gems/*"].each do |subdir|
4
+ rspec_gem_dir = subdir if subdir.gsub("#{RAILS_ROOT}/vendor/gems/","") =~ /^(\w+-)?rspec-(\d+)/ && File.exist?("#{subdir}/lib/spec/rake/spectask.rb")
5
+ end
6
+ rspec_plugin_dir = File.expand_path(File.dirname(__FILE__) + '/../../vendor/plugins/rspec')
7
+
8
+ if rspec_gem_dir && (test ?d, rspec_plugin_dir)
9
+ raise "\n#{'*'*50}\nYou have rspec installed in both vendor/gems and vendor/plugins\nPlease pick one and dispose of the other.\n#{'*'*50}\n\n"
10
+ end
11
+
12
+ if rspec_gem_dir
13
+ $LOAD_PATH.unshift("#{rspec_gem_dir}/lib")
14
+ elsif File.exist?(rspec_plugin_dir)
15
+ $LOAD_PATH.unshift("#{rspec_plugin_dir}/lib")
16
+ end
17
+
18
+ # Don't load rspec if running "rake gems:*"
19
+ unless ARGV.any? {|a| a =~ /^gems/}
20
+
21
+ begin
22
+ require 'spec/rake/spectask'
23
+ rescue MissingSourceFile
24
+ module Spec
25
+ module Rake
26
+ class SpecTask
27
+ def initialize(name)
28
+ task name do
29
+ # if rspec-rails is a configured gem, this will output helpful material and exit ...
30
+ require File.expand_path(File.join(File.dirname(__FILE__),"..","..","config","environment"))
31
+
32
+ # ... otherwise, do this:
33
+ raise <<-MSG
34
+
35
+ #{"*" * 80}
36
+ * You are trying to run an rspec rake task defined in
37
+ * #{__FILE__},
38
+ * but rspec can not be found in vendor/gems, vendor/plugins or system gems.
39
+ #{"*" * 80}
40
+ MSG
41
+ end
42
+ end
43
+ end
44
+ end
45
+ end
46
+ end
47
+
48
+ Rake.application.instance_variable_get('@tasks').delete('default')
49
+
50
+ spec_prereq = File.exist?(File.join(RAILS_ROOT, 'config', 'database.yml')) ? "db:test:prepare" : :noop
51
+ task :noop do
52
+ end
53
+
54
+ task :default => :spec
55
+ task :stats => "spec:statsetup"
56
+
57
+ desc "Run all specs in spec directory (excluding plugin specs)"
58
+ Spec::Rake::SpecTask.new(:spec => spec_prereq) do |t|
59
+ t.spec_opts = ['--options', "\"#{RAILS_ROOT}/spec/spec.opts\""]
60
+ t.spec_files = FileList['spec/**/*_spec.rb']
61
+ end
62
+
63
+ namespace :spec do
64
+ desc "Run all specs in spec directory with RCov (excluding plugin specs)"
65
+ Spec::Rake::SpecTask.new(:rcov) do |t|
66
+ t.spec_opts = ['--options', "\"#{RAILS_ROOT}/spec/spec.opts\""]
67
+ t.spec_files = FileList['spec/**/*_spec.rb']
68
+ t.rcov = true
69
+ t.rcov_opts = lambda do
70
+ IO.readlines("#{RAILS_ROOT}/spec/rcov.opts").map {|l| l.chomp.split " "}.flatten
71
+ end
72
+ end
73
+
74
+ desc "Print Specdoc for all specs (excluding plugin specs)"
75
+ Spec::Rake::SpecTask.new(:doc) do |t|
76
+ t.spec_opts = ["--format", "specdoc", "--dry-run"]
77
+ t.spec_files = FileList['spec/**/*_spec.rb']
78
+ end
79
+
80
+ desc "Print Specdoc for all plugin examples"
81
+ Spec::Rake::SpecTask.new(:plugin_doc) do |t|
82
+ t.spec_opts = ["--format", "specdoc", "--dry-run"]
83
+ t.spec_files = FileList['vendor/plugins/**/spec/**/*_spec.rb'].exclude('vendor/plugins/rspec/*')
84
+ end
85
+
86
+ [:models, :controllers, :views, :helpers, :lib, :integration].each do |sub|
87
+ desc "Run the code examples in spec/#{sub}"
88
+ Spec::Rake::SpecTask.new(sub => spec_prereq) do |t|
89
+ t.spec_opts = ['--options', "\"#{RAILS_ROOT}/spec/spec.opts\""]
90
+ t.spec_files = FileList["spec/#{sub}/**/*_spec.rb"]
91
+ end
92
+ end
93
+
94
+ desc "Run the code examples in vendor/plugins (except RSpec's own)"
95
+ Spec::Rake::SpecTask.new(:plugins => spec_prereq) do |t|
96
+ t.spec_opts = ['--options', "\"#{RAILS_ROOT}/spec/spec.opts\""]
97
+ t.spec_files = FileList['vendor/plugins/**/spec/**/*_spec.rb'].exclude('vendor/plugins/rspec/*').exclude("vendor/plugins/rspec-rails/*")
98
+ end
99
+
100
+ namespace :plugins do
101
+ desc "Runs the examples for rspec_on_rails"
102
+ Spec::Rake::SpecTask.new(:rspec_on_rails) do |t|
103
+ t.spec_opts = ['--options', "\"#{RAILS_ROOT}/spec/spec.opts\""]
104
+ t.spec_files = FileList['vendor/plugins/rspec-rails/spec/**/*_spec.rb']
105
+ end
106
+ end
107
+
108
+ # Setup specs for stats
109
+ task :statsetup do
110
+ require 'code_statistics'
111
+ ::STATS_DIRECTORIES << %w(Model\ specs spec/models) if File.exist?('spec/models')
112
+ ::STATS_DIRECTORIES << %w(View\ specs spec/views) if File.exist?('spec/views')
113
+ ::STATS_DIRECTORIES << %w(Controller\ specs spec/controllers) if File.exist?('spec/controllers')
114
+ ::STATS_DIRECTORIES << %w(Helper\ specs spec/helpers) if File.exist?('spec/helpers')
115
+ ::STATS_DIRECTORIES << %w(Library\ specs spec/lib) if File.exist?('spec/lib')
116
+ ::STATS_DIRECTORIES << %w(Routing\ specs spec/routing) if File.exist?('spec/routing')
117
+ ::STATS_DIRECTORIES << %w(Integration\ specs spec/integration) if File.exist?('spec/integration')
118
+ ::CodeStatistics::TEST_TYPES << "Model specs" if File.exist?('spec/models')
119
+ ::CodeStatistics::TEST_TYPES << "View specs" if File.exist?('spec/views')
120
+ ::CodeStatistics::TEST_TYPES << "Controller specs" if File.exist?('spec/controllers')
121
+ ::CodeStatistics::TEST_TYPES << "Helper specs" if File.exist?('spec/helpers')
122
+ ::CodeStatistics::TEST_TYPES << "Library specs" if File.exist?('spec/lib')
123
+ ::CodeStatistics::TEST_TYPES << "Routing specs" if File.exist?('spec/routing')
124
+ ::CodeStatistics::TEST_TYPES << "Integration specs" if File.exist?('spec/integration')
125
+ end
126
+
127
+ namespace :db do
128
+ namespace :fixtures do
129
+ desc "Load fixtures (from spec/fixtures) into the current environment's database. Load specific fixtures using FIXTURES=x,y. Load from subdirectory in test/fixtures using FIXTURES_DIR=z."
130
+ task :load => :environment do
131
+ ActiveRecord::Base.establish_connection(Rails.env)
132
+ base_dir = File.join(Rails.root, 'spec', 'fixtures')
133
+ fixtures_dir = ENV['FIXTURES_DIR'] ? File.join(base_dir, ENV['FIXTURES_DIR']) : base_dir
134
+
135
+ require 'active_record/fixtures'
136
+ (ENV['FIXTURES'] ? ENV['FIXTURES'].split(/,/).map {|f| File.join(fixtures_dir, f) } : Dir.glob(File.join(fixtures_dir, '*.{yml,csv}'))).each do |fixture_file|
137
+ Fixtures.create_fixtures(File.dirname(fixture_file), File.basename(fixture_file, '.*'))
138
+ end
139
+ end
140
+ end
141
+ end
142
+ end
143
+
144
+ end
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+ gem 'test-unit', '1.2.3' if RUBY_VERSION.to_f >= 1.9
3
+ ENV['RSPEC'] = 'true' # allows autotest to discover rspec
4
+ ENV['AUTOTEST'] = 'true' # allows autotest to run w/ color on linux
5
+ system((RUBY_PLATFORM =~ /mswin|mingw/ ? 'autotest.bat' : 'autotest'), *ARGV) ||
6
+ $stderr.puts("Unable to find autotest. Please install ZenTest or fix your PATH")
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env ruby
2
+ if ARGV.any? {|arg| %w[--drb -X --generate-options -G --help -h --version -v].include?(arg)}
3
+ require 'rubygems' unless ENV['NO_RUBYGEMS']
4
+ else
5
+ gem 'test-unit', '1.2.3' if RUBY_VERSION.to_f >= 1.9
6
+ ENV["RAILS_ENV"] ||= 'test'
7
+ require File.expand_path(File.dirname(__FILE__) + "/../config/environment") unless defined?(RAILS_ROOT)
8
+ end
9
+ require 'spec/autorun'
10
+ exit ::Spec::Runner::CommandLine.run
@@ -0,0 +1,4 @@
1
+ --colour
2
+ --format progress
3
+ --loadby mtime
4
+ --reverse
@@ -0,0 +1,54 @@
1
+ # This file is copied to ~/spec when you run 'ruby script/generate rspec'
2
+ # from the project root directory.
3
+ ENV["RAILS_ENV"] ||= 'test'
4
+ require File.expand_path(File.join(File.dirname(__FILE__),'..','config','environment'))
5
+ require 'spec/autorun'
6
+ require 'spec/rails'
7
+
8
+ # Uncomment the next line to use webrat's matchers
9
+ #require 'webrat/integrations/rspec-rails'
10
+
11
+ # Requires supporting files with custom matchers and macros, etc,
12
+ # in ./support/ and its subdirectories.
13
+ Dir[File.expand_path(File.join(File.dirname(__FILE__),'support','**','*.rb'))].each {|f| require f}
14
+
15
+ Spec::Runner.configure do |config|
16
+ # If you're not using ActiveRecord you should remove these
17
+ # lines, delete config/database.yml and disable :active_record
18
+ # in your config/boot.rb
19
+ config.use_transactional_fixtures = true
20
+ config.use_instantiated_fixtures = false
21
+ config.fixture_path = RAILS_ROOT + '/spec/fixtures/'
22
+
23
+ # == Fixtures
24
+ #
25
+ # You can declare fixtures for each example_group like this:
26
+ # describe "...." do
27
+ # fixtures :table_a, :table_b
28
+ #
29
+ # Alternatively, if you prefer to declare them only once, you can
30
+ # do so right here. Just uncomment the next line and replace the fixture
31
+ # names with your fixtures.
32
+ #
33
+ # config.global_fixtures = :table_a, :table_b
34
+ #
35
+ # If you declare global fixtures, be aware that they will be declared
36
+ # for all of your examples, even those that don't use them.
37
+ #
38
+ # You can also declare which fixtures to use (for example fixtures for test/fixtures):
39
+ #
40
+ # config.fixture_path = RAILS_ROOT + '/spec/fixtures/'
41
+ #
42
+ # == Mock Framework
43
+ #
44
+ # RSpec uses its own mocking framework by default. If you prefer to
45
+ # use mocha, flexmock or RR, uncomment the appropriate line:
46
+ #
47
+ # config.mock_with :mocha
48
+ # config.mock_with :flexmock
49
+ # config.mock_with :rr
50
+ #
51
+ # == Notes
52
+ #
53
+ # For more information take a look at Spec::Runner::Configuration and Spec::Runner
54
+ end
@@ -0,0 +1,33 @@
1
+ Description:
2
+ The rspec_controller generator creates stub specs and files for a new
3
+ controller and its views.
4
+
5
+ The generator takes a controller name and a list of views as arguments.
6
+ The controller name may be given in CamelCase or under_score and should
7
+ not be suffixed with 'Controller'. To create a controller within a
8
+ module, specify the controller name as 'module/controller'.
9
+
10
+ The generator creates stubs for a controller (and spec), a view (and spec)
11
+ for each view in the argument list, plus a helper.
12
+
13
+ Example:
14
+ ./script/generate rspec_controller dog bark fetch
15
+ ...
16
+ create spec/controllers/dog_controller_spec.rb
17
+ create app/controllers/dog_controller.rb
18
+ create app/helpers/dog_helper.rb
19
+ create spec/views/dog/bark_view_spec.rb
20
+ create app/views/dog/bark.rhtml
21
+ create spec/views/dog/fetch_view_spec.rb
22
+ create app/views/dog/fetch.rhtml
23
+
24
+ Modules Example:
25
+ ./script/generate rspec_controller 'pets/dog' bark fetch
26
+ ...
27
+ create spec/controllers/pets/dog_controller_spec.rb
28
+ create app/controllers/pets/dog_controller.rb
29
+ create app/helpers/pets/dog_helper.rb
30
+ create spec/views/pets/dog/bark_view_spec.rb
31
+ create app/views/pets/dog/bark.rhtml
32
+ create spec/views/pets/dog/fetch_view_spec.rb
33
+ create app/views/pets/dog/fetch.rhtml
@@ -0,0 +1,47 @@
1
+ require 'rails_generator/generators/components/controller/controller_generator'
2
+
3
+ class RspecControllerGenerator < ControllerGenerator
4
+
5
+ def manifest
6
+ record do |m|
7
+ # Check for class naming collisions.
8
+ m.class_collisions class_path, "#{class_name}Controller", "#{class_name}Helper"
9
+
10
+ # Controller, helper, views, and spec directories.
11
+ m.directory File.join('app/controllers', class_path)
12
+ m.directory File.join('app/helpers', class_path)
13
+ m.directory File.join('app/views', class_path, file_name)
14
+ m.directory File.join('spec/controllers', class_path)
15
+ m.directory File.join('spec/helpers', class_path)
16
+ m.directory File.join('spec/views', class_path, file_name)
17
+
18
+ @default_file_extension = "html.erb"
19
+
20
+ # Controller spec, class, and helper.
21
+ m.template 'controller_spec.rb',
22
+ File.join('spec/controllers', class_path, "#{file_name}_controller_spec.rb")
23
+
24
+ m.template 'helper_spec.rb',
25
+ File.join('spec/helpers', class_path, "#{file_name}_helper_spec.rb")
26
+
27
+ m.template 'controller:controller.rb',
28
+ File.join('app/controllers', class_path, "#{file_name}_controller.rb")
29
+
30
+ m.template 'controller:helper.rb',
31
+ File.join('app/helpers', class_path, "#{file_name}_helper.rb")
32
+
33
+
34
+
35
+ # Spec and view template for each action.
36
+ actions.each do |action|
37
+ m.template 'view_spec.rb',
38
+ File.join('spec/views', class_path, file_name, "#{action}.#{@default_file_extension}_spec.rb"),
39
+ :assigns => { :action => action, :model => file_name }
40
+ path = File.join('app/views', class_path, file_name, "#{action}.#{@default_file_extension}")
41
+ m.template "controller:view.#{@default_file_extension}",
42
+ path,
43
+ :assigns => { :action => action, :path => path }
44
+ end
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,25 @@
1
+ require 'spec_helper'
2
+
3
+ describe <%= class_name %>Controller do
4
+
5
+ <% if actions.empty? -%>
6
+ #Delete this example and add some real ones
7
+ <% else -%>
8
+ #Delete these examples and add some real ones
9
+ <% end -%>
10
+ it "should use <%= class_name %>Controller" do
11
+ controller.should be_an_instance_of(<%= class_name %>Controller)
12
+ end
13
+
14
+ <% unless actions.empty? -%>
15
+ <% for action in actions -%>
16
+
17
+ describe "GET '<%= action %>'" do
18
+ it "should be successful" do
19
+ get '<%= action %>'
20
+ response.should be_success
21
+ end
22
+ end
23
+ <% end -%>
24
+ <% end -%>
25
+ end
@@ -0,0 +1,11 @@
1
+ require 'spec_helper'
2
+
3
+ describe <%= class_name %>Helper do
4
+
5
+ #Delete this example and add some real ones or delete this file
6
+ it "should be included in the object returned by #helper" do
7
+ included_modules = (class << helper; self; end).send :included_modules
8
+ included_modules.should include(<%= class_name %>Helper)
9
+ end
10
+
11
+ end
@@ -0,0 +1,12 @@
1
+ require 'spec_helper'
2
+
3
+ describe "/<%= class_name.underscore %>/<%= action %>" do
4
+ before(:each) do
5
+ render '<%= class_name.underscore %>/<%= action %>'
6
+ end
7
+
8
+ #Delete this example and add some real ones or delete this file
9
+ it "should tell you where to find the file" do
10
+ response.should have_tag('p', %r[Find me in app/views/<%= class_name.underscore %>/<%= action %>])
11
+ end
12
+ end
@@ -0,0 +1,28 @@
1
+ module Rails
2
+ module Generator
3
+ class GeneratedAttribute
4
+ def default_value
5
+ @default_value ||= case type
6
+ when :int, :integer then "1"
7
+ when :float then "1.5"
8
+ when :decimal then "9.99"
9
+ when :datetime, :timestamp, :time then "Time.now"
10
+ when :date then "Date.today"
11
+ when :string, :text then "\"value for #{@name}\""
12
+ when :boolean then "false"
13
+ when :belongs_to, :references then "1"
14
+ else
15
+ ""
16
+ end
17
+ end
18
+
19
+ def name_or_reference
20
+ if ::Rails::VERSION::STRING >= '2.2'
21
+ reference? ? :"#{name}_id" : name
22
+ else
23
+ name
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,18 @@
1
+ Description:
2
+ The rspec_model generator creates stubs for a new model.
3
+
4
+ The generator takes a model name as its argument. The model name may be
5
+ given in CamelCase or under_score and should not be suffixed with 'Model'.
6
+
7
+ The generator creates a model class in app/models, an RSpec spec in
8
+ spec/models, database fixtures in spec/fixtures/plural_name.yml, and a migration
9
+ in db/migrate.
10
+
11
+ Example:
12
+ ./script/generate rspec_model Account
13
+
14
+ This will create an Account model:
15
+ Model: app/models/account.rb
16
+ Spec: spec/models/account_spec.rb
17
+ Fixtures: spec/fixtures/accounts.yml
18
+ Migration: db/migrate/XXX_add_accounts.rb