cavalle-rspec-rails 1.2.2.0.1

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 (168) hide show
  1. data/.document +7 -0
  2. data/History.rdoc +207 -0
  3. data/License.txt +33 -0
  4. data/Manifest.txt +167 -0
  5. data/README.rdoc +45 -0
  6. data/Rakefile +79 -0
  7. data/TODO.txt +1 -0
  8. data/Upgrade.rdoc +103 -0
  9. data/features/step_definitions/people.rb +6 -0
  10. data/features/support/env.rb +13 -0
  11. data/features/transactions/transactions_should_rollback.feature +16 -0
  12. data/generators/rspec/CHANGES +1 -0
  13. data/generators/rspec/rspec_generator.rb +54 -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 +165 -0
  17. data/generators/rspec/templates/script/autospec +6 -0
  18. data/generators/rspec/templates/script/spec +10 -0
  19. data/generators/rspec/templates/script/spec_server +9 -0
  20. data/generators/rspec/templates/spec.opts +4 -0
  21. data/generators/rspec/templates/spec_helper.rb +47 -0
  22. data/generators/rspec_controller/USAGE +33 -0
  23. data/generators/rspec_controller/rspec_controller_generator.rb +45 -0
  24. data/generators/rspec_controller/templates/controller_spec.rb +25 -0
  25. data/generators/rspec_controller/templates/helper_spec.rb +11 -0
  26. data/generators/rspec_controller/templates/view_spec.rb +12 -0
  27. data/generators/rspec_default_values.rb +19 -0
  28. data/generators/rspec_model/USAGE +18 -0
  29. data/generators/rspec_model/rspec_model_generator.rb +35 -0
  30. data/generators/rspec_model/templates/model_spec.rb +15 -0
  31. data/generators/rspec_scaffold/rspec_scaffold_generator.rb +150 -0
  32. data/generators/rspec_scaffold/templates/controller_spec.rb +171 -0
  33. data/generators/rspec_scaffold/templates/edit_erb_spec.rb +27 -0
  34. data/generators/rspec_scaffold/templates/helper_spec.rb +11 -0
  35. data/generators/rspec_scaffold/templates/index_erb_spec.rb +28 -0
  36. data/generators/rspec_scaffold/templates/new_erb_spec.rb +27 -0
  37. data/generators/rspec_scaffold/templates/routing_spec.rb +63 -0
  38. data/generators/rspec_scaffold/templates/show_erb_spec.rb +23 -0
  39. data/init.rb +9 -0
  40. data/lib/autotest/discover.rb +1 -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 +247 -0
  44. data/lib/spec/rails/example/cookies_proxy.rb +29 -0
  45. data/lib/spec/rails/example/functional_example_group.rb +84 -0
  46. data/lib/spec/rails/example/helper_example_group.rb +153 -0
  47. data/lib/spec/rails/example/model_example_group.rb +14 -0
  48. data/lib/spec/rails/example/render_observer.rb +67 -0
  49. data/lib/spec/rails/example/routing_example_group.rb +13 -0
  50. data/lib/spec/rails/example/routing_helpers.rb +70 -0
  51. data/lib/spec/rails/example/view_example_group.rb +186 -0
  52. data/lib/spec/rails/example.rb +47 -0
  53. data/lib/spec/rails/extensions/action_controller/rescue.rb +42 -0
  54. data/lib/spec/rails/extensions/action_controller/test_case.rb +16 -0
  55. data/lib/spec/rails/extensions/action_controller/test_response.rb +21 -0
  56. data/lib/spec/rails/extensions/action_view/base.rb +33 -0
  57. data/lib/spec/rails/extensions/active_record/base.rb +45 -0
  58. data/lib/spec/rails/extensions/active_support/test_case.rb +7 -0
  59. data/lib/spec/rails/extensions/spec/matchers/have.rb +23 -0
  60. data/lib/spec/rails/extensions/spec/runner/configuration.rb +44 -0
  61. data/lib/spec/rails/extensions.rb +11 -0
  62. data/lib/spec/rails/interop/testcase.rb +14 -0
  63. data/lib/spec/rails/matchers/ar_be_valid.rb +44 -0
  64. data/lib/spec/rails/matchers/assert_select.rb +146 -0
  65. data/lib/spec/rails/matchers/change.rb +11 -0
  66. data/lib/spec/rails/matchers/have_text.rb +57 -0
  67. data/lib/spec/rails/matchers/include_text.rb +54 -0
  68. data/lib/spec/rails/matchers/redirect_to.rb +126 -0
  69. data/lib/spec/rails/matchers/render_template.rb +114 -0
  70. data/lib/spec/rails/matchers.rb +32 -0
  71. data/lib/spec/rails/mocks.rb +135 -0
  72. data/lib/spec/rails/spec_server.rb +127 -0
  73. data/lib/spec/rails/story_adapter.rb +79 -0
  74. data/lib/spec/rails/version.rb +15 -0
  75. data/lib/spec/rails.rb +28 -0
  76. data/rspec-rails.gemspec +57 -0
  77. data/spec/autotest/mappings_spec.rb +86 -0
  78. data/spec/rails_suite.rb +7 -0
  79. data/spec/resources/controllers/action_view_base_spec_controller.rb +2 -0
  80. data/spec/resources/controllers/application.rb +9 -0
  81. data/spec/resources/controllers/controller_spec_controller.rb +120 -0
  82. data/spec/resources/controllers/example.txt +1 -0
  83. data/spec/resources/controllers/redirect_spec_controller.rb +70 -0
  84. data/spec/resources/controllers/render_spec_controller.rb +30 -0
  85. data/spec/resources/controllers/rjs_spec_controller.rb +58 -0
  86. data/spec/resources/helpers/addition_helper.rb +5 -0
  87. data/spec/resources/helpers/explicit_helper.rb +46 -0
  88. data/spec/resources/helpers/more_explicit_helper.rb +5 -0
  89. data/spec/resources/helpers/plugin_application_helper.rb +6 -0
  90. data/spec/resources/helpers/view_spec_helper.rb +13 -0
  91. data/spec/resources/models/animal.rb +4 -0
  92. data/spec/resources/models/person.rb +18 -0
  93. data/spec/resources/models/thing.rb +3 -0
  94. data/spec/resources/views/controller_spec/_partial.html.erb +0 -0
  95. data/spec/resources/views/controller_spec/action_setting_flash_after_session_reset.html.erb +1 -0
  96. data/spec/resources/views/controller_spec/action_setting_flash_before_session_reset.html.erb +1 -0
  97. data/spec/resources/views/controller_spec/action_setting_the_assigns_hash.html.erb +0 -0
  98. data/spec/resources/views/controller_spec/action_with_errors_in_template.html.erb +1 -0
  99. data/spec/resources/views/controller_spec/action_with_template.html.erb +1 -0
  100. data/spec/resources/views/layouts/application.html.erb +0 -0
  101. data/spec/resources/views/layouts/simple.html.erb +0 -0
  102. data/spec/resources/views/objects/_object.html.erb +1 -0
  103. data/spec/resources/views/render_spec/_a_partial.html.erb +0 -0
  104. data/spec/resources/views/render_spec/action_with_alternate_layout.html.erb +0 -0
  105. data/spec/resources/views/render_spec/some_action.html.erb +0 -0
  106. data/spec/resources/views/render_spec/some_action.js.rjs +1 -0
  107. data/spec/resources/views/rjs_spec/_replacement_partial.html.erb +1 -0
  108. data/spec/resources/views/rjs_spec/hide_div.js.rjs +1 -0
  109. data/spec/resources/views/rjs_spec/hide_page_element.js.rjs +1 -0
  110. data/spec/resources/views/rjs_spec/insert_html.js.rjs +1 -0
  111. data/spec/resources/views/rjs_spec/replace.js.rjs +1 -0
  112. data/spec/resources/views/rjs_spec/replace_html.js.rjs +1 -0
  113. data/spec/resources/views/rjs_spec/replace_html_with_partial.js.rjs +1 -0
  114. data/spec/resources/views/rjs_spec/visual_effect.js.rjs +1 -0
  115. data/spec/resources/views/rjs_spec/visual_toggle_effect.js.rjs +1 -0
  116. data/spec/resources/views/tag_spec/no_tags.html.erb +1 -0
  117. data/spec/resources/views/tag_spec/single_div_with_no_attributes.html.erb +1 -0
  118. data/spec/resources/views/tag_spec/single_div_with_one_attribute.html.erb +1 -0
  119. data/spec/resources/views/view_spec/_partial.html.erb +2 -0
  120. data/spec/resources/views/view_spec/_partial_used_twice.html.erb +0 -0
  121. data/spec/resources/views/view_spec/_partial_with_local_variable.html.erb +1 -0
  122. data/spec/resources/views/view_spec/_partial_with_sub_partial.html.erb +1 -0
  123. data/spec/resources/views/view_spec/_spacer.html.erb +1 -0
  124. data/spec/resources/views/view_spec/accessor.html.erb +5 -0
  125. data/spec/resources/views/view_spec/block_helper.html.erb +3 -0
  126. data/spec/resources/views/view_spec/entry_form.html.erb +2 -0
  127. data/spec/resources/views/view_spec/explicit_helper.html.erb +2 -0
  128. data/spec/resources/views/view_spec/foo/show.html.erb +1 -0
  129. data/spec/resources/views/view_spec/implicit_helper.html.erb +2 -0
  130. data/spec/resources/views/view_spec/multiple_helpers.html.erb +3 -0
  131. data/spec/resources/views/view_spec/path_params.html.erb +1 -0
  132. data/spec/resources/views/view_spec/should_not_receive.html.erb +3 -0
  133. data/spec/resources/views/view_spec/template_with_partial.html.erb +5 -0
  134. data/spec/resources/views/view_spec/template_with_partial_using_collection.html.erb +3 -0
  135. data/spec/resources/views/view_spec/template_with_partial_with_array.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 +299 -0
  139. data/spec/spec/rails/example/controller_isolation_spec.rb +56 -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 +233 -0
  144. data/spec/spec/rails/example/model_example_group_spec.rb +20 -0
  145. data/spec/spec/rails/example/routing_example_group_spec.rb +9 -0
  146. data/spec/spec/rails/example/shared_routing_example_group_examples.rb +44 -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 +335 -0
  149. data/spec/spec/rails/extensions/action_view_base_spec.rb +48 -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 +45 -0
  153. data/spec/spec/rails/matchers/assert_select_spec.rb +809 -0
  154. data/spec/spec/rails/matchers/errors_on_spec.rb +25 -0
  155. data/spec/spec/rails/matchers/have_text_spec.rb +70 -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 +191 -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 +106 -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_server_spec.rb +107 -0
  166. data/spec/spec/rails/spec_spec.rb +11 -0
  167. data/spec/spec_helper.rb +79 -0
  168. metadata +277 -0
@@ -0,0 +1,16 @@
1
+ Story: transactions should rollback in plain text
2
+ As an RSpec/Rails Story author
3
+ I want transactions to roll back between scenarios in plain text
4
+ So that I can have confidence in the state of the database
5
+
6
+ Scenario: add one Person
7
+ When I add a Person
8
+ Then there should be one person
9
+
10
+ Scenario: add one Person for the second time
11
+ When I add a Person
12
+ Then there should be one person
13
+
14
+ Scenario: add yet another person
15
+ When I add a Person
16
+ Then there should be one person
@@ -0,0 +1 @@
1
+ Please refer to the CHANGES file for RSpec's core
@@ -0,0 +1,54 @@
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
+ super
28
+ end
29
+
30
+ def manifest
31
+ record do |m|
32
+ script_options = { :chmod => 0755, :shebang => options[:shebang] == DEFAULT_SHEBANG ? nil : options[:shebang] }
33
+
34
+ m.directory 'lib/tasks'
35
+ m.file 'rspec.rake', 'lib/tasks/rspec.rake'
36
+
37
+ m.file 'script/autospec', 'script/autospec', script_options
38
+ m.file 'script/spec', 'script/spec', script_options
39
+ m.file 'script/spec_server', 'script/spec_server', script_options
40
+
41
+ m.directory 'spec'
42
+ m.file 'rcov.opts', 'spec/rcov.opts'
43
+ m.file 'spec.opts', 'spec/spec.opts'
44
+ m.template 'spec_helper.rb', 'spec/spec_helper.rb'
45
+ end
46
+ end
47
+
48
+ protected
49
+
50
+ def banner
51
+ "Usage: #{$0} rspec"
52
+ end
53
+
54
+ end
File without changes
@@ -0,0 +1,2 @@
1
+ --exclude "spec/*,gems/*"
2
+ --rails
@@ -0,0 +1,165 @@
1
+ gem 'test-unit', '1.2.3' if RUBY_VERSION.to_f >= 1.9
2
+
3
+ # Don't load rspec if running "rake gems:*"
4
+ unless ARGV.any? {|a| a =~ /^gems/}
5
+
6
+ begin
7
+ require 'spec/rake/spectask'
8
+ rescue MissingSourceFile
9
+ module Spec
10
+ module Rake
11
+ class SpecTask
12
+ def initialize(name)
13
+ task name do
14
+ # if rspec-rails is a configured gem, this will output helpful material and exit ...
15
+ require File.expand_path(File.dirname(__FILE__) + "/../../config/environment")
16
+
17
+ # ... otherwise, do this:
18
+ raise <<-MSG
19
+
20
+ #{"*" * 80}
21
+ * You are trying to run an rspec rake task defined in
22
+ * #{__FILE__},
23
+ * but rspec can not be found in vendor/gems, vendor/plugins or system gems.
24
+ #{"*" * 80}
25
+ MSG
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
32
+
33
+ Rake.application.instance_variable_get('@tasks').delete('default')
34
+
35
+ spec_prereq = File.exist?(File.join(RAILS_ROOT, 'config', 'database.yml')) ? "db:test:prepare" : :noop
36
+ task :noop do
37
+ end
38
+
39
+ task :default => :spec
40
+ task :stats => "spec:statsetup"
41
+
42
+ desc "Run all specs in spec directory (excluding plugin specs)"
43
+ Spec::Rake::SpecTask.new(:spec => spec_prereq) do |t|
44
+ t.spec_opts = ['--options', "\"#{RAILS_ROOT}/spec/spec.opts\""]
45
+ t.spec_files = FileList['spec/**/*/*_spec.rb']
46
+ end
47
+
48
+ namespace :spec do
49
+ desc "Run all specs in spec directory with RCov (excluding plugin specs)"
50
+ Spec::Rake::SpecTask.new(:rcov) do |t|
51
+ t.spec_opts = ['--options', "\"#{RAILS_ROOT}/spec/spec.opts\""]
52
+ t.spec_files = FileList['spec/**/*/*_spec.rb']
53
+ t.rcov = true
54
+ t.rcov_opts = lambda do
55
+ IO.readlines("#{RAILS_ROOT}/spec/rcov.opts").map {|l| l.chomp.split " "}.flatten
56
+ end
57
+ end
58
+
59
+ desc "Print Specdoc for all specs (excluding plugin specs)"
60
+ Spec::Rake::SpecTask.new(:doc) do |t|
61
+ t.spec_opts = ["--format", "specdoc", "--dry-run"]
62
+ t.spec_files = FileList['spec/**/*/*_spec.rb']
63
+ end
64
+
65
+ desc "Print Specdoc for all plugin examples"
66
+ Spec::Rake::SpecTask.new(:plugin_doc) do |t|
67
+ t.spec_opts = ["--format", "specdoc", "--dry-run"]
68
+ t.spec_files = FileList['vendor/plugins/**/spec/**/*/*_spec.rb'].exclude('vendor/plugins/rspec/*')
69
+ end
70
+
71
+ [:models, :controllers, :views, :helpers, :lib].each do |sub|
72
+ desc "Run the code examples in spec/#{sub}"
73
+ Spec::Rake::SpecTask.new(sub => spec_prereq) do |t|
74
+ t.spec_opts = ['--options', "\"#{RAILS_ROOT}/spec/spec.opts\""]
75
+ t.spec_files = FileList["spec/#{sub}/**/*_spec.rb"]
76
+ end
77
+ end
78
+
79
+ desc "Run the code examples in vendor/plugins (except RSpec's own)"
80
+ Spec::Rake::SpecTask.new(:plugins => spec_prereq) do |t|
81
+ t.spec_opts = ['--options', "\"#{RAILS_ROOT}/spec/spec.opts\""]
82
+ t.spec_files = FileList['vendor/plugins/**/spec/**/*/*_spec.rb'].exclude('vendor/plugins/rspec/*').exclude("vendor/plugins/rspec-rails/*")
83
+ end
84
+
85
+ namespace :plugins do
86
+ desc "Runs the examples for rspec_on_rails"
87
+ Spec::Rake::SpecTask.new(:rspec_on_rails) do |t|
88
+ t.spec_opts = ['--options', "\"#{RAILS_ROOT}/spec/spec.opts\""]
89
+ t.spec_files = FileList['vendor/plugins/rspec-rails/spec/**/*/*_spec.rb']
90
+ end
91
+ end
92
+
93
+ # Setup specs for stats
94
+ task :statsetup do
95
+ require 'code_statistics'
96
+ ::STATS_DIRECTORIES << %w(Model\ specs spec/models) if File.exist?('spec/models')
97
+ ::STATS_DIRECTORIES << %w(View\ specs spec/views) if File.exist?('spec/views')
98
+ ::STATS_DIRECTORIES << %w(Controller\ specs spec/controllers) if File.exist?('spec/controllers')
99
+ ::STATS_DIRECTORIES << %w(Helper\ specs spec/helpers) if File.exist?('spec/helpers')
100
+ ::STATS_DIRECTORIES << %w(Library\ specs spec/lib) if File.exist?('spec/lib')
101
+ ::STATS_DIRECTORIES << %w(Routing\ specs spec/lib) if File.exist?('spec/routing')
102
+ ::CodeStatistics::TEST_TYPES << "Model specs" if File.exist?('spec/models')
103
+ ::CodeStatistics::TEST_TYPES << "View specs" if File.exist?('spec/views')
104
+ ::CodeStatistics::TEST_TYPES << "Controller specs" if File.exist?('spec/controllers')
105
+ ::CodeStatistics::TEST_TYPES << "Helper specs" if File.exist?('spec/helpers')
106
+ ::CodeStatistics::TEST_TYPES << "Library specs" if File.exist?('spec/lib')
107
+ ::CodeStatistics::TEST_TYPES << "Routing specs" if File.exist?('spec/routing')
108
+ end
109
+
110
+ namespace :db do
111
+ namespace :fixtures do
112
+ 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."
113
+ task :load => :environment do
114
+ ActiveRecord::Base.establish_connection(Rails.env)
115
+ base_dir = File.join(Rails.root, 'spec', 'fixtures')
116
+ fixtures_dir = ENV['FIXTURES_DIR'] ? File.join(base_dir, ENV['FIXTURES_DIR']) : base_dir
117
+
118
+ require 'active_record/fixtures'
119
+ (ENV['FIXTURES'] ? ENV['FIXTURES'].split(/,/).map {|f| File.join(fixtures_dir, f) } : Dir.glob(File.join(fixtures_dir, '*.{yml,csv}'))).each do |fixture_file|
120
+ Fixtures.create_fixtures(File.dirname(fixture_file), File.basename(fixture_file, '.*'))
121
+ end
122
+ end
123
+ end
124
+ end
125
+
126
+ namespace :server do
127
+ daemonized_server_pid = File.expand_path("#{RAILS_ROOT}/tmp/pids/spec_server.pid")
128
+
129
+ desc "start spec_server."
130
+ task :start do
131
+ if File.exist?(daemonized_server_pid)
132
+ $stderr.puts "spec_server is already running."
133
+ else
134
+ $stderr.puts %Q{Starting up spec_server ...}
135
+ FileUtils.mkdir_p('tmp/pids') unless test ?d, 'tmp/pids'
136
+ system("ruby", "script/spec_server", "--daemon", "--pid", daemonized_server_pid)
137
+ end
138
+ end
139
+
140
+ desc "stop spec_server."
141
+ task :stop do
142
+ unless File.exist?(daemonized_server_pid)
143
+ $stderr.puts "No server running."
144
+ else
145
+ $stderr.puts "Shutting down spec_server ..."
146
+ system("kill", "-s", "TERM", File.read(daemonized_server_pid).strip) &&
147
+ File.delete(daemonized_server_pid)
148
+ end
149
+ end
150
+
151
+ desc "restart spec_server."
152
+ task :restart => [:stop, :start]
153
+
154
+ desc "check if spec server is running"
155
+ task :status do
156
+ if File.exist?(daemonized_server_pid)
157
+ $stderr.puts %Q{spec_server is running (PID: #{File.read(daemonized_server_pid).gsub("\n","")})}
158
+ else
159
+ $stderr.puts "No server running."
160
+ end
161
+ end
162
+ end
163
+ end
164
+
165
+ 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.dirname(__FILE__) + "/../config/environment" unless defined?(RAILS_ROOT)
8
+ end
9
+ require 'spec/autorun'
10
+ exit ::Spec::Runner::CommandLine.run
@@ -0,0 +1,9 @@
1
+ #!/usr/bin/env ruby
2
+ gem 'test-unit', '1.2.3' if RUBY_VERSION.to_f >= 1.9
3
+
4
+ puts "Loading Rails environment"
5
+ ENV["RAILS_ENV"] ||= 'test'
6
+ require File.dirname(__FILE__) + "/../config/environment" unless defined?(RAILS_ROOT)
7
+
8
+ require 'optparse'
9
+ require 'spec/rails/spec_server'
@@ -0,0 +1,4 @@
1
+ --colour
2
+ --format progress
3
+ --loadby mtime
4
+ --reverse
@@ -0,0 +1,47 @@
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.dirname(__FILE__) + "/../config/environment" unless defined?(RAILS_ROOT)
5
+ require 'spec/autorun'
6
+ require 'spec/rails'
7
+
8
+ Spec::Runner.configure do |config|
9
+ # If you're not using ActiveRecord you should remove these
10
+ # lines, delete config/database.yml and disable :active_record
11
+ # in your config/boot.rb
12
+ config.use_transactional_fixtures = true
13
+ config.use_instantiated_fixtures = false
14
+ config.fixture_path = RAILS_ROOT + '/spec/fixtures/'
15
+
16
+ # == Fixtures
17
+ #
18
+ # You can declare fixtures for each example_group like this:
19
+ # describe "...." do
20
+ # fixtures :table_a, :table_b
21
+ #
22
+ # Alternatively, if you prefer to declare them only once, you can
23
+ # do so right here. Just uncomment the next line and replace the fixture
24
+ # names with your fixtures.
25
+ #
26
+ # config.global_fixtures = :table_a, :table_b
27
+ #
28
+ # If you declare global fixtures, be aware that they will be declared
29
+ # for all of your examples, even those that don't use them.
30
+ #
31
+ # You can also declare which fixtures to use (for example fixtures for test/fixtures):
32
+ #
33
+ # config.fixture_path = RAILS_ROOT + '/spec/fixtures/'
34
+ #
35
+ # == Mock Framework
36
+ #
37
+ # RSpec uses it's own mocking framework by default. If you prefer to
38
+ # use mocha, flexmock or RR, uncomment the appropriate line:
39
+ #
40
+ # config.mock_with :mocha
41
+ # config.mock_with :flexmock
42
+ # config.mock_with :rr
43
+ #
44
+ # == Notes
45
+ #
46
+ # For more information take a look at Spec::Runner::Configuration and Spec::Runner
47
+ 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,45 @@
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
+ # Spec and view template for each action.
34
+ actions.each do |action|
35
+ m.template 'view_spec.rb',
36
+ File.join('spec/views', class_path, file_name, "#{action}.#{@default_file_extension}_spec.rb"),
37
+ :assigns => { :action => action, :model => file_name }
38
+ path = File.join('app/views', class_path, file_name, "#{action}.#{@default_file_extension}")
39
+ m.template "controller:view.#{@default_file_extension}",
40
+ path,
41
+ :assigns => { :action => action, :path => path }
42
+ end
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,25 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '<%= '/..' * class_nesting_depth %>/../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 File.expand_path(File.dirname(__FILE__) + '<%= '/..' * class_nesting_depth %>/../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 File.expand_path(File.dirname(__FILE__) + '<%= '/..' * class_nesting_depth %>/../../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,19 @@
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
+ else
14
+ ""
15
+ end
16
+ end
17
+ end
18
+ end
19
+ 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
@@ -0,0 +1,35 @@
1
+ require 'rails_generator/generators/components/model/model_generator'
2
+ require File.dirname(__FILE__) + '/../rspec_default_values'
3
+
4
+ class RspecModelGenerator < ModelGenerator
5
+
6
+ def manifest
7
+
8
+ record do |m|
9
+ # Check for class naming collisions.
10
+ m.class_collisions class_path, class_name
11
+
12
+ # Model, spec, and fixture directories.
13
+ m.directory File.join('app/models', class_path)
14
+ m.directory File.join('spec/models', class_path)
15
+ unless options[:skip_fixture]
16
+ m.directory File.join('spec/fixtures', class_path)
17
+ end
18
+
19
+ # Model class, spec and fixtures.
20
+ m.template 'model:model.rb', File.join('app/models', class_path, "#{file_name}.rb")
21
+ m.template 'model_spec.rb', File.join('spec/models', class_path, "#{file_name}_spec.rb")
22
+ unless options[:skip_fixture]
23
+ m.template 'model:fixtures.yml', File.join('spec/fixtures', "#{table_name}.yml")
24
+ end
25
+
26
+ unless options[:skip_migration]
27
+ m.migration_template 'model:migration.rb', 'db/migrate', :assigns => {
28
+ :migration_name => "Create#{class_name.pluralize.gsub(/::/, '')}"
29
+ }, :migration_file_name => "create_#{file_path.gsub(/\//, '_').pluralize}"
30
+ end
31
+
32
+ end
33
+ end
34
+
35
+ end
@@ -0,0 +1,15 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '<%= '/..' * class_nesting_depth %>/../spec_helper')
2
+
3
+ describe <%= class_name %> do
4
+ before(:each) do
5
+ @valid_attributes = {
6
+ <% attributes.each_with_index do |attribute, attribute_index| -%>
7
+ :<%= attribute.name %> => <%= attribute.default_value %><%= attribute_index == attributes.length - 1 ? '' : ','%>
8
+ <% end -%>
9
+ }
10
+ end
11
+
12
+ it "should create a new instance given valid attributes" do
13
+ <%= class_name %>.create!(@valid_attributes)
14
+ end
15
+ end