richzhou-rspec-rails 1.3.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (170) hide show
  1. data/.document +7 -0
  2. data/.gitignore +8 -0
  3. data/Contribute.rdoc +4 -0
  4. data/Gemfile +4 -0
  5. data/History.rdoc +321 -0
  6. data/License.txt +33 -0
  7. data/Manifest.txt +165 -0
  8. data/README.rdoc +48 -0
  9. data/Rakefile +12 -0
  10. data/TODO.txt +17 -0
  11. data/Upgrade.rdoc +148 -0
  12. data/generators/integration_spec/integration_spec_generator.rb +10 -0
  13. data/generators/integration_spec/templates/integration_spec.rb +4 -0
  14. data/generators/rspec/CHANGES +1 -0
  15. data/generators/rspec/rspec_generator.rb +72 -0
  16. data/generators/rspec/templates/previous_failures.txt +0 -0
  17. data/generators/rspec/templates/rcov.opts +2 -0
  18. data/generators/rspec/templates/rspec.rake +146 -0
  19. data/generators/rspec/templates/script/autospec +6 -0
  20. data/generators/rspec/templates/script/spec +10 -0
  21. data/generators/rspec/templates/spec.opts +4 -0
  22. data/generators/rspec/templates/spec_helper.rb +54 -0
  23. data/generators/rspec_controller/USAGE +33 -0
  24. data/generators/rspec_controller/rspec_controller_generator.rb +47 -0
  25. data/generators/rspec_controller/templates/controller_spec.rb +25 -0
  26. data/generators/rspec_controller/templates/helper_spec.rb +11 -0
  27. data/generators/rspec_controller/templates/view_spec.rb +12 -0
  28. data/generators/rspec_default_values.rb +28 -0
  29. data/generators/rspec_model/USAGE +18 -0
  30. data/generators/rspec_model/rspec_model_generator.rb +35 -0
  31. data/generators/rspec_model/templates/model_spec.rb +13 -0
  32. data/generators/rspec_scaffold/rspec_scaffold_generator.rb +154 -0
  33. data/generators/rspec_scaffold/templates/controller_spec.rb +131 -0
  34. data/generators/rspec_scaffold/templates/edit_erb_spec.rb +25 -0
  35. data/generators/rspec_scaffold/templates/helper_spec.rb +11 -0
  36. data/generators/rspec_scaffold/templates/index_erb_spec.rb +27 -0
  37. data/generators/rspec_scaffold/templates/new_erb_spec.rb +25 -0
  38. data/generators/rspec_scaffold/templates/routing_spec.rb +33 -0
  39. data/generators/rspec_scaffold/templates/show_erb_spec.rb +22 -0
  40. data/init.rb +9 -0
  41. data/lib/autotest/discover.rb +5 -0
  42. data/lib/autotest/rails_rspec.rb +76 -0
  43. data/lib/spec/rails.rb +26 -0
  44. data/lib/spec/rails/example.rb +48 -0
  45. data/lib/spec/rails/example/assigns_hash_proxy.rb +39 -0
  46. data/lib/spec/rails/example/controller_example_group.rb +285 -0
  47. data/lib/spec/rails/example/cookies_proxy.rb +29 -0
  48. data/lib/spec/rails/example/functional_example_group.rb +106 -0
  49. data/lib/spec/rails/example/helper_example_group.rb +153 -0
  50. data/lib/spec/rails/example/integration_example_group.rb +16 -0
  51. data/lib/spec/rails/example/model_example_group.rb +15 -0
  52. data/lib/spec/rails/example/render_observer.rb +82 -0
  53. data/lib/spec/rails/example/routing_example_group.rb +16 -0
  54. data/lib/spec/rails/example/routing_helpers.rb +66 -0
  55. data/lib/spec/rails/example/view_example_group.rb +203 -0
  56. data/lib/spec/rails/extensions.rb +11 -0
  57. data/lib/spec/rails/extensions/action_controller/rescue.rb +42 -0
  58. data/lib/spec/rails/extensions/action_controller/test_case.rb +16 -0
  59. data/lib/spec/rails/extensions/action_controller/test_response.rb +21 -0
  60. data/lib/spec/rails/extensions/action_view/base.rb +35 -0
  61. data/lib/spec/rails/extensions/active_record/base.rb +45 -0
  62. data/lib/spec/rails/extensions/active_support/test_case.rb +7 -0
  63. data/lib/spec/rails/extensions/spec/matchers/have.rb +23 -0
  64. data/lib/spec/rails/extensions/spec/runner/configuration.rb +45 -0
  65. data/lib/spec/rails/interop/testcase.rb +14 -0
  66. data/lib/spec/rails/matchers.rb +32 -0
  67. data/lib/spec/rails/matchers/ar_be_valid.rb +27 -0
  68. data/lib/spec/rails/matchers/assert_select.rb +180 -0
  69. data/lib/spec/rails/matchers/change.rb +13 -0
  70. data/lib/spec/rails/matchers/have_text.rb +57 -0
  71. data/lib/spec/rails/matchers/include_text.rb +54 -0
  72. data/lib/spec/rails/matchers/redirect_to.rb +126 -0
  73. data/lib/spec/rails/matchers/render_template.rb +129 -0
  74. data/lib/spec/rails/matchers/route_to.rb +149 -0
  75. data/lib/spec/rails/mocks.rb +140 -0
  76. data/lib/spec/rails/version.rb +16 -0
  77. data/rspec-rails.gemspec +25 -0
  78. data/spec/autotest/mappings_spec.rb +86 -0
  79. data/spec/rails_suite.rb +7 -0
  80. data/spec/resources/controllers/action_view_base_spec_controller.rb +2 -0
  81. data/spec/resources/controllers/application.rb +9 -0
  82. data/spec/resources/controllers/controller_spec_controller.rb +127 -0
  83. data/spec/resources/controllers/example.txt +1 -0
  84. data/spec/resources/controllers/redirect_spec_controller.rb +70 -0
  85. data/spec/resources/controllers/render_spec_controller.rb +34 -0
  86. data/spec/resources/controllers/rjs_spec_controller.rb +58 -0
  87. data/spec/resources/helpers/addition_helper.rb +5 -0
  88. data/spec/resources/helpers/explicit_helper.rb +46 -0
  89. data/spec/resources/helpers/more_explicit_helper.rb +5 -0
  90. data/spec/resources/helpers/plugin_application_helper.rb +6 -0
  91. data/spec/resources/helpers/view_spec_helper.rb +13 -0
  92. data/spec/resources/models/animal.rb +4 -0
  93. data/spec/resources/models/person.rb +18 -0
  94. data/spec/resources/models/thing.rb +3 -0
  95. data/spec/resources/views/controller_spec/_partial.html.erb +0 -0
  96. data/spec/resources/views/controller_spec/action_setting_flash_after_session_reset.html.erb +1 -0
  97. data/spec/resources/views/controller_spec/action_setting_flash_before_session_reset.html.erb +1 -0
  98. data/spec/resources/views/controller_spec/action_setting_the_assigns_hash.html.erb +0 -0
  99. data/spec/resources/views/controller_spec/action_with_errors_in_template.html.erb +1 -0
  100. data/spec/resources/views/controller_spec/action_with_template.html.erb +1 -0
  101. data/spec/resources/views/controller_spec/non_existent_action_with_existent_template.html.erb +1 -0
  102. data/spec/resources/views/layouts/application.html.erb +0 -0
  103. data/spec/resources/views/layouts/simple.html.erb +0 -0
  104. data/spec/resources/views/objects/_object.html.erb +1 -0
  105. data/spec/resources/views/render_spec/_a_partial.html.erb +0 -0
  106. data/spec/resources/views/render_spec/action_with_alternate_layout.html.erb +0 -0
  107. data/spec/resources/views/render_spec/some_action.html.erb +0 -0
  108. data/spec/resources/views/render_spec/some_action.js.rjs +1 -0
  109. data/spec/resources/views/rjs_spec/_replacement_partial.html.erb +1 -0
  110. data/spec/resources/views/rjs_spec/hide_div.js.rjs +1 -0
  111. data/spec/resources/views/rjs_spec/hide_page_element.js.rjs +1 -0
  112. data/spec/resources/views/rjs_spec/insert_html.js.rjs +1 -0
  113. data/spec/resources/views/rjs_spec/replace.js.rjs +1 -0
  114. data/spec/resources/views/rjs_spec/replace_html.js.rjs +1 -0
  115. data/spec/resources/views/rjs_spec/replace_html_with_partial.js.rjs +1 -0
  116. data/spec/resources/views/rjs_spec/visual_effect.js.rjs +1 -0
  117. data/spec/resources/views/rjs_spec/visual_toggle_effect.js.rjs +1 -0
  118. data/spec/resources/views/tag_spec/no_tags.html.erb +1 -0
  119. data/spec/resources/views/tag_spec/single_div_with_no_attributes.html.erb +1 -0
  120. data/spec/resources/views/tag_spec/single_div_with_one_attribute.html.erb +1 -0
  121. data/spec/resources/views/view_spec/_partial.html.erb +2 -0
  122. data/spec/resources/views/view_spec/_partial_used_twice.html.erb +0 -0
  123. data/spec/resources/views/view_spec/_partial_with_local_variable.html.erb +1 -0
  124. data/spec/resources/views/view_spec/_partial_with_sub_partial.html.erb +1 -0
  125. data/spec/resources/views/view_spec/_spacer.html.erb +1 -0
  126. data/spec/resources/views/view_spec/accessor.html.erb +6 -0
  127. data/spec/resources/views/view_spec/block_helper.html.erb +3 -0
  128. data/spec/resources/views/view_spec/entry_form.html.erb +2 -0
  129. data/spec/resources/views/view_spec/explicit_helper.html.erb +2 -0
  130. data/spec/resources/views/view_spec/foo/show.html.erb +1 -0
  131. data/spec/resources/views/view_spec/implicit_helper.html.erb +2 -0
  132. data/spec/resources/views/view_spec/multiple_helpers.html.erb +3 -0
  133. data/spec/resources/views/view_spec/path_params.html.erb +1 -0
  134. data/spec/resources/views/view_spec/should_not_receive.html.erb +3 -0
  135. data/spec/resources/views/view_spec/template_with_partial.html.erb +5 -0
  136. data/spec/resources/views/view_spec/template_with_partial_using_collection.html.erb +3 -0
  137. data/spec/resources/views/view_spec/template_with_partial_with_array.html.erb +1 -0
  138. data/spec/resources/views/view_spec/view_helpers.html.erb +1 -0
  139. data/spec/spec/rails/example/assigns_hash_proxy_spec.rb +109 -0
  140. data/spec/spec/rails/example/configuration_spec.rb +67 -0
  141. data/spec/spec/rails/example/controller_example_group_spec.rb +307 -0
  142. data/spec/spec/rails/example/controller_isolation_spec.rb +75 -0
  143. data/spec/spec/rails/example/cookies_proxy_spec.rb +87 -0
  144. data/spec/spec/rails/example/error_handling_spec.rb +90 -0
  145. data/spec/spec/rails/example/example_group_factory_spec.rb +112 -0
  146. data/spec/spec/rails/example/helper_example_group_spec.rb +247 -0
  147. data/spec/spec/rails/example/model_example_group_spec.rb +32 -0
  148. data/spec/spec/rails/example/routing_example_group_spec.rb +9 -0
  149. data/spec/spec/rails/example/shared_routing_example_group_examples.rb +241 -0
  150. data/spec/spec/rails/example/test_unit_assertion_accessibility_spec.rb +33 -0
  151. data/spec/spec/rails/example/view_example_group_spec.rb +346 -0
  152. data/spec/spec/rails/extensions/action_view_base_spec.rb +79 -0
  153. data/spec/spec/rails/extensions/active_record_spec.rb +14 -0
  154. data/spec/spec/rails/interop/testcase_spec.rb +70 -0
  155. data/spec/spec/rails/matchers/ar_be_valid_spec.rb +19 -0
  156. data/spec/spec/rails/matchers/assert_select_spec.rb +835 -0
  157. data/spec/spec/rails/matchers/errors_on_spec.rb +37 -0
  158. data/spec/spec/rails/matchers/have_text_spec.rb +69 -0
  159. data/spec/spec/rails/matchers/include_text_spec.rb +62 -0
  160. data/spec/spec/rails/matchers/redirect_to_spec.rb +253 -0
  161. data/spec/spec/rails/matchers/render_template_spec.rb +208 -0
  162. data/spec/spec/rails/matchers/should_change_spec.rb +15 -0
  163. data/spec/spec/rails/mocks/ar_classes.rb +10 -0
  164. data/spec/spec/rails/mocks/mock_model_spec.rb +112 -0
  165. data/spec/spec/rails/mocks/stub_model_spec.rb +80 -0
  166. data/spec/spec/rails/sample_modified_fixture.rb +8 -0
  167. data/spec/spec/rails/sample_spec.rb +8 -0
  168. data/spec/spec/rails/spec_spec.rb +11 -0
  169. data/spec/spec_helper.rb +78 -0
  170. metadata +363 -0
@@ -0,0 +1,48 @@
1
+ = Spec::Rails
2
+
3
+ * http://rspec.info
4
+ * http://rubyforge.org/projects/rspec
5
+ * http://github.com/dchelimsky/rspec-rails
6
+ * http://wiki.github.com/dchelimsky/rspec/rails
7
+ * mailto:rspec-devel@rubyforge.org
8
+
9
+ == DESCRIPTION:
10
+
11
+ Behaviour Driven Development for Ruby on Rails.
12
+
13
+ rspec-rails is an RSpec extension that allows you to drive the development of
14
+ Ruby on Rails applications with RSpec.
15
+
16
+ This is the repository for rspec-rails-1.x. If you're looking
17
+ for rspec-rails-2 for rails-3, see http://github.com/rspec/rspec-rails.
18
+
19
+ == FEATURES:
20
+
21
+ * Use RSpec to independently specify Rails Models, Views, Controllers and Helpers
22
+ * Integrated fixture loading
23
+ * Special generators for Resources, Models, Views and Controllers that generate RSpec code examples.
24
+
25
+ == VISION:
26
+
27
+ For people for whom TDD is a brand new concept, the testing support built into
28
+ Ruby on Rails is a huge leap forward. The fact that it is built right in is
29
+ fantastic, and Ruby on Rails apps are generally much easier to maintain than
30
+ they might have been without such support.
31
+
32
+ For those of us coming from a history with TDD, and now BDD, the existing
33
+ support presents some problems related to dependencies across examples. To
34
+ that end, RSpec on Rails supports 4 types of examples. We’ve also built in
35
+ first class mocking and stubbing support in order to break dependencies across
36
+ these different concerns.
37
+
38
+ == MORE INFORMATION:
39
+
40
+ See Spec::Rails::Example for information about the different kinds of example
41
+ groups you can use to spec the different Rails components
42
+
43
+ See Spec::Rails::Matchers for information about Rails-specific
44
+ expectations you can set on responses and models, etc.
45
+
46
+ == INSTALL
47
+
48
+ * Visit http://wiki.github.com/dchelimsky/rspec/rails for installation instructions.
@@ -0,0 +1,12 @@
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
3
+
4
+ $:.unshift(File.expand_path(File.join(File.dirname(__FILE__),"..","rspec","lib")))
5
+ $:.unshift(File.expand_path(File.join(File.dirname(__FILE__),"lib")))
6
+
7
+ require 'spec/rails/version'
8
+ require 'spec/rake/spectask'
9
+
10
+ Spec::Rake::SpecTask.new
11
+
12
+ task :default => [:features]
@@ -0,0 +1,17 @@
1
+ * wiki
2
+ * need a matrix of which rspec-rails versions support which rails versions
3
+ * CI
4
+ * need a robust CI setup that runs
5
+ * Multiple rubies
6
+ * MRI: 1.8.6
7
+ * MRI: 1.8.7
8
+ * MRI: 1.9.1
9
+ * JRuby
10
+ * IronRuby??? (perhaps using mono)
11
+ * Multiple rails-es
12
+ * 2.0.5
13
+ * 2.1.2
14
+ * 2.2.2
15
+ * 2.3.4
16
+ * 3.0 (once available)
17
+ * With and without ActiveRecord
@@ -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,72 @@
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 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
+ EOF
38
+ File.open(test_env, "wb") do |f|
39
+ f.puts contents
40
+ f.puts
41
+ f.puts rspec_config
42
+ end
43
+ end
44
+ end
45
+
46
+ super
47
+ end
48
+
49
+ def manifest
50
+ record do |m|
51
+ script_options = { :chmod => 0755, :shebang => options[:shebang] == DEFAULT_SHEBANG ? nil : options[:shebang] }
52
+
53
+ m.directory 'lib/tasks'
54
+ m.file 'rspec.rake', 'lib/tasks/rspec.rake'
55
+
56
+ m.file 'script/autospec', 'script/autospec', script_options
57
+ m.file 'script/spec', 'script/spec', script_options
58
+
59
+ m.directory 'spec'
60
+ m.file 'rcov.opts', 'spec/rcov.opts'
61
+ m.file 'spec.opts', 'spec/spec.opts'
62
+ m.template 'spec_helper.rb', 'spec/spec_helper.rb'
63
+ end
64
+ end
65
+
66
+ protected
67
+
68
+ def banner
69
+ "Usage: #{$0} rspec"
70
+ end
71
+
72
+ end
@@ -0,0 +1,2 @@
1
+ --exclude "spec/*,gems/*"
2
+ --rails
@@ -0,0 +1,146 @@
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
+ include ::Rake::DSL if defined?(::Rake::DSL)
28
+
29
+ def initialize(name)
30
+ task name do
31
+ # if rspec-rails is a configured gem, this will output helpful material and exit ...
32
+ require File.expand_path(File.join(File.dirname(__FILE__),"..","..","config","environment"))
33
+
34
+ # ... otherwise, do this:
35
+ raise <<-MSG
36
+
37
+ #{"*" * 80}
38
+ * You are trying to run an rspec rake task defined in
39
+ * #{__FILE__},
40
+ * but rspec can not be found in vendor/gems, vendor/plugins or system gems.
41
+ #{"*" * 80}
42
+ MSG
43
+ end
44
+ end
45
+ end
46
+ end
47
+ end
48
+ end
49
+
50
+ Rake.application.instance_variable_get('@tasks').delete('default')
51
+
52
+ spec_prereq = File.exist?(File.join(RAILS_ROOT, 'config', 'database.yml')) ? "db:test:prepare" : :noop
53
+ task :noop do
54
+ end
55
+
56
+ task :default => :spec
57
+ task :stats => "spec:statsetup"
58
+
59
+ desc "Run all specs in spec directory (excluding plugin specs)"
60
+ Spec::Rake::SpecTask.new(:spec => spec_prereq) do |t|
61
+ t.spec_opts = ['--options', "\"#{RAILS_ROOT}/spec/spec.opts\""]
62
+ t.spec_files = FileList['spec/**/*_spec.rb']
63
+ end
64
+
65
+ namespace :spec do
66
+ desc "Run all specs in spec directory with RCov (excluding plugin specs)"
67
+ Spec::Rake::SpecTask.new(:rcov) do |t|
68
+ t.spec_opts = ['--options', "\"#{RAILS_ROOT}/spec/spec.opts\""]
69
+ t.spec_files = FileList['spec/**/*_spec.rb']
70
+ t.rcov = true
71
+ t.rcov_opts = lambda do
72
+ IO.readlines("#{RAILS_ROOT}/spec/rcov.opts").map {|l| l.chomp.split " "}.flatten
73
+ end
74
+ end
75
+
76
+ desc "Print Specdoc for all specs (excluding plugin specs)"
77
+ Spec::Rake::SpecTask.new(:doc) do |t|
78
+ t.spec_opts = ["--format", "specdoc", "--dry-run"]
79
+ t.spec_files = FileList['spec/**/*_spec.rb']
80
+ end
81
+
82
+ desc "Print Specdoc for all plugin examples"
83
+ Spec::Rake::SpecTask.new(:plugin_doc) do |t|
84
+ t.spec_opts = ["--format", "specdoc", "--dry-run"]
85
+ t.spec_files = FileList['vendor/plugins/**/spec/**/*_spec.rb'].exclude('vendor/plugins/rspec/*')
86
+ end
87
+
88
+ [:models, :controllers, :views, :helpers, :lib, :integration].each do |sub|
89
+ desc "Run the code examples in spec/#{sub}"
90
+ Spec::Rake::SpecTask.new(sub => spec_prereq) do |t|
91
+ t.spec_opts = ['--options', "\"#{RAILS_ROOT}/spec/spec.opts\""]
92
+ t.spec_files = FileList["spec/#{sub}/**/*_spec.rb"]
93
+ end
94
+ end
95
+
96
+ desc "Run the code examples in vendor/plugins (except RSpec's own)"
97
+ Spec::Rake::SpecTask.new(:plugins => spec_prereq) do |t|
98
+ t.spec_opts = ['--options', "\"#{RAILS_ROOT}/spec/spec.opts\""]
99
+ t.spec_files = FileList['vendor/plugins/**/spec/**/*_spec.rb'].exclude('vendor/plugins/rspec/*').exclude("vendor/plugins/rspec-rails/*")
100
+ end
101
+
102
+ namespace :plugins do
103
+ desc "Runs the examples for rspec_on_rails"
104
+ Spec::Rake::SpecTask.new(:rspec_on_rails) do |t|
105
+ t.spec_opts = ['--options', "\"#{RAILS_ROOT}/spec/spec.opts\""]
106
+ t.spec_files = FileList['vendor/plugins/rspec-rails/spec/**/*_spec.rb']
107
+ end
108
+ end
109
+
110
+ # Setup specs for stats
111
+ task :statsetup do
112
+ require 'code_statistics'
113
+ ::STATS_DIRECTORIES << %w(Model\ specs spec/models) if File.exist?('spec/models')
114
+ ::STATS_DIRECTORIES << %w(View\ specs spec/views) if File.exist?('spec/views')
115
+ ::STATS_DIRECTORIES << %w(Controller\ specs spec/controllers) if File.exist?('spec/controllers')
116
+ ::STATS_DIRECTORIES << %w(Helper\ specs spec/helpers) if File.exist?('spec/helpers')
117
+ ::STATS_DIRECTORIES << %w(Library\ specs spec/lib) if File.exist?('spec/lib')
118
+ ::STATS_DIRECTORIES << %w(Routing\ specs spec/routing) if File.exist?('spec/routing')
119
+ ::STATS_DIRECTORIES << %w(Integration\ specs spec/integration) if File.exist?('spec/integration')
120
+ ::CodeStatistics::TEST_TYPES << "Model specs" if File.exist?('spec/models')
121
+ ::CodeStatistics::TEST_TYPES << "View specs" if File.exist?('spec/views')
122
+ ::CodeStatistics::TEST_TYPES << "Controller specs" if File.exist?('spec/controllers')
123
+ ::CodeStatistics::TEST_TYPES << "Helper specs" if File.exist?('spec/helpers')
124
+ ::CodeStatistics::TEST_TYPES << "Library specs" if File.exist?('spec/lib')
125
+ ::CodeStatistics::TEST_TYPES << "Routing specs" if File.exist?('spec/routing')
126
+ ::CodeStatistics::TEST_TYPES << "Integration specs" if File.exist?('spec/integration')
127
+ end
128
+
129
+ namespace :db do
130
+ namespace :fixtures do
131
+ 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."
132
+ task :load => :environment do
133
+ ActiveRecord::Base.establish_connection(Rails.env)
134
+ base_dir = File.join(Rails.root, 'spec', 'fixtures')
135
+ fixtures_dir = ENV['FIXTURES_DIR'] ? File.join(base_dir, ENV['FIXTURES_DIR']) : base_dir
136
+
137
+ require 'active_record/fixtures'
138
+ (ENV['FIXTURES'] ? ENV['FIXTURES'].split(/,/).map {|f| File.join(fixtures_dir, f) } : Dir.glob(File.join(fixtures_dir, '*.{yml,csv}'))).each do |fixture_file|
139
+ Fixtures.create_fixtures(File.dirname(fixture_file), File.basename(fixture_file, '.*'))
140
+ end
141
+ end
142
+ end
143
+ end
144
+ end
145
+
146
+ end