rspec-rails 1.1.11 → 1.1.12

Sign up to get free protection for your applications and to get access to all the features.
Files changed (140) hide show
  1. data/History.txt +29 -0
  2. data/Manifest.txt +94 -94
  3. data/README.txt +5 -7
  4. data/Rakefile +14 -2
  5. data/{spec_resources/views/controller_spec/_partial.rhtml → TODO.txt} +0 -0
  6. data/features/step_definitions/people.rb +6 -0
  7. data/features/support/env.rb +13 -0
  8. data/{stories/transactions_should_rollback → features/transactions/transactions_should_rollback.feature} +4 -3
  9. data/generators/rspec/rspec_generator.rb +0 -4
  10. data/generators/rspec/templates/rspec.rake +130 -104
  11. data/generators/rspec/templates/script/spec_server +17 -8
  12. data/generators/rspec/templates/spec_helper.rb +1 -1
  13. data/generators/rspec_default_values.rb +3 -3
  14. data/generators/rspec_scaffold/templates/edit_erb_spec.rb +7 -6
  15. data/generators/rspec_scaffold/templates/index_erb_spec.rb +9 -8
  16. data/generators/rspec_scaffold/templates/new_erb_spec.rb +7 -6
  17. data/generators/rspec_scaffold/templates/show_erb_spec.rb +9 -9
  18. data/lib/spec/rails.rb +14 -2
  19. data/lib/spec/rails/example/controller_example_group.rb +16 -23
  20. data/lib/spec/rails/example/cookies_proxy.rb +5 -1
  21. data/lib/spec/rails/example/functional_example_group.rb +17 -5
  22. data/lib/spec/rails/example/helper_example_group.rb +5 -4
  23. data/lib/spec/rails/example/rails_example_group.rb +10 -15
  24. data/lib/spec/rails/example/view_example_group.rb +5 -5
  25. data/lib/spec/rails/extensions.rb +1 -3
  26. data/lib/spec/rails/extensions/action_controller/base.rb +1 -1
  27. data/lib/spec/rails/extensions/action_controller/rescue.rb +9 -5
  28. data/lib/spec/rails/extensions/action_controller/test_response.rb +11 -2
  29. data/lib/spec/rails/extensions/action_view/base.rb +4 -2
  30. data/lib/spec/rails/extensions/active_record/base.rb +1 -2
  31. data/lib/spec/rails/extensions/spec/{example → runner}/configuration.rb +12 -7
  32. data/lib/spec/rails/matchers.rb +1 -0
  33. data/lib/spec/rails/matchers/ar_be_valid.rb +41 -0
  34. data/lib/spec/rails/matchers/redirect_to.rb +4 -2
  35. data/lib/spec/rails/matchers/render_template.rb +30 -10
  36. data/lib/spec/rails/mocks.rb +11 -8
  37. data/lib/spec/rails/version.rb +3 -2
  38. data/rspec-rails.gemspec +16 -8
  39. data/spec/{rails/autotest → autotest}/mappings_spec.rb +3 -3
  40. data/{spec_resources → spec/resources}/controllers/action_view_base_spec_controller.rb +0 -0
  41. data/spec/resources/controllers/application.rb +9 -0
  42. data/{spec_resources → spec/resources}/controllers/controller_spec_controller.rb +19 -6
  43. data/{spec_resources → spec/resources}/controllers/redirect_spec_controller.rb +7 -0
  44. data/{spec_resources → spec/resources}/controllers/render_spec_controller.rb +0 -0
  45. data/{spec_resources → spec/resources}/controllers/rjs_spec_controller.rb +0 -0
  46. data/{spec_resources → spec/resources}/helpers/addition_helper.rb +0 -0
  47. data/{spec_resources → spec/resources}/helpers/explicit_helper.rb +8 -0
  48. data/{spec_resources → spec/resources}/helpers/more_explicit_helper.rb +0 -0
  49. data/{spec_resources → spec/resources}/helpers/plugin_application_helper.rb +0 -0
  50. data/{spec_resources → spec/resources}/helpers/view_spec_helper.rb +0 -0
  51. data/spec/resources/models/animal.rb +4 -0
  52. data/spec/resources/models/person.rb +18 -0
  53. data/spec/resources/models/thing.rb +3 -0
  54. data/{spec_resources/views/controller_spec/action_setting_the_assigns_hash.rhtml → spec/resources/views/controller_spec/_partial.rhtml} +0 -0
  55. data/{spec_resources → spec/resources}/views/controller_spec/action_setting_flash_after_session_reset.rhtml +0 -0
  56. data/{spec_resources → spec/resources}/views/controller_spec/action_setting_flash_before_session_reset.rhtml +0 -0
  57. data/{spec_resources/views/layouts/application.rhtml → spec/resources/views/controller_spec/action_setting_the_assigns_hash.rhtml} +0 -0
  58. data/{spec_resources → spec/resources}/views/controller_spec/action_with_errors_in_template.rhtml +0 -0
  59. data/{spec_resources → spec/resources}/views/controller_spec/action_with_template.rhtml +0 -0
  60. data/{spec_resources/views/layouts/simple.rhtml → spec/resources/views/layouts/application.rhtml} +0 -0
  61. data/{spec_resources/views/render_spec/_a_partial.rhtml → spec/resources/views/layouts/simple.rhtml} +0 -0
  62. data/{spec_resources → spec/resources}/views/objects/_object.html.erb +0 -0
  63. data/{spec_resources/views/render_spec/action_with_alternate_layout.rhtml → spec/resources/views/render_spec/_a_partial.rhtml} +0 -0
  64. data/{spec_resources/views/render_spec/some_action.rhtml → spec/resources/views/render_spec/action_with_alternate_layout.rhtml} +0 -0
  65. data/{spec_resources/views/view_spec/_partial_used_twice.rhtml → spec/resources/views/render_spec/some_action.html.erb} +0 -0
  66. data/{spec_resources → spec/resources}/views/render_spec/some_action.js.rjs +0 -0
  67. data/{spec_resources → spec/resources}/views/render_spec/some_action.rjs +0 -0
  68. data/{spec_resources → spec/resources}/views/rjs_spec/_replacement_partial.rhtml +0 -0
  69. data/{spec_resources → spec/resources}/views/rjs_spec/hide_div.rjs +0 -0
  70. data/{spec_resources → spec/resources}/views/rjs_spec/hide_page_element.rjs +0 -0
  71. data/{spec_resources → spec/resources}/views/rjs_spec/insert_html.rjs +0 -0
  72. data/{spec_resources → spec/resources}/views/rjs_spec/replace.rjs +0 -0
  73. data/{spec_resources → spec/resources}/views/rjs_spec/replace_html.rjs +0 -0
  74. data/{spec_resources → spec/resources}/views/rjs_spec/replace_html_with_partial.rjs +0 -0
  75. data/{spec_resources → spec/resources}/views/rjs_spec/visual_effect.rjs +0 -0
  76. data/{spec_resources → spec/resources}/views/rjs_spec/visual_toggle_effect.rjs +0 -0
  77. data/{spec_resources → spec/resources}/views/tag_spec/no_tags.rhtml +0 -0
  78. data/{spec_resources → spec/resources}/views/tag_spec/single_div_with_no_attributes.rhtml +0 -0
  79. data/{spec_resources → spec/resources}/views/tag_spec/single_div_with_one_attribute.rhtml +0 -0
  80. data/{spec_resources → spec/resources}/views/view_spec/_partial.rhtml +0 -0
  81. data/spec/resources/views/view_spec/_partial_used_twice.rhtml +0 -0
  82. data/{spec_resources → spec/resources}/views/view_spec/_partial_with_local_variable.rhtml +0 -0
  83. data/{spec_resources → spec/resources}/views/view_spec/_partial_with_sub_partial.rhtml +0 -0
  84. data/{spec_resources → spec/resources}/views/view_spec/_spacer.rhtml +0 -0
  85. data/{spec_resources → spec/resources}/views/view_spec/accessor.rhtml +0 -0
  86. data/{spec_resources → spec/resources}/views/view_spec/block_helper.rhtml +0 -0
  87. data/{spec_resources → spec/resources}/views/view_spec/entry_form.rhtml +0 -0
  88. data/{spec_resources → spec/resources}/views/view_spec/explicit_helper.rhtml +0 -0
  89. data/{spec_resources → spec/resources}/views/view_spec/foo/show.rhtml +0 -0
  90. data/{spec_resources → spec/resources}/views/view_spec/implicit_helper.rhtml +0 -0
  91. data/{spec_resources → spec/resources}/views/view_spec/multiple_helpers.rhtml +0 -0
  92. data/spec/resources/views/view_spec/path_params.html.erb +1 -0
  93. data/{spec_resources → spec/resources}/views/view_spec/should_not_receive.rhtml +0 -0
  94. data/{spec_resources → spec/resources}/views/view_spec/template_with_partial.rhtml +0 -0
  95. data/{spec_resources → spec/resources}/views/view_spec/template_with_partial_using_collection.rhtml +0 -0
  96. data/{spec_resources → spec/resources}/views/view_spec/template_with_partial_with_array.rhtml +0 -0
  97. data/spec/{rails → spec/rails}/example/assigns_hash_proxy_spec.rb +1 -1
  98. data/spec/spec/rails/example/configuration_spec.rb +79 -0
  99. data/spec/{rails → spec/rails}/example/controller_isolation_spec.rb +1 -7
  100. data/spec/{rails → spec/rails}/example/controller_spec_spec.rb +63 -6
  101. data/spec/{rails → spec/rails}/example/cookies_proxy_spec.rb +30 -13
  102. data/spec/{rails → spec/rails}/example/example_group_factory_spec.rb +1 -1
  103. data/spec/{rails → spec/rails}/example/helper_spec_spec.rb +28 -1
  104. data/spec/{rails → spec/rails}/example/model_spec_spec.rb +1 -1
  105. data/spec/{rails → spec/rails}/example/shared_behaviour_spec.rb +1 -1
  106. data/spec/{rails → spec/rails}/example/test_unit_assertion_accessibility_spec.rb +1 -1
  107. data/spec/{rails → spec/rails}/example/view_spec_spec.rb +22 -1
  108. data/spec/{rails → spec/rails}/extensions/action_controller_rescue_action_spec.rb +4 -1
  109. data/spec/{rails → spec/rails}/extensions/action_view_base_spec.rb +1 -1
  110. data/spec/{rails → spec/rails}/extensions/active_record_spec.rb +1 -1
  111. data/spec/{rails → spec/rails}/interop/testcase_spec.rb +6 -2
  112. data/spec/spec/rails/matchers/ar_be_valid_spec.rb +35 -0
  113. data/spec/{rails → spec/rails}/matchers/assert_select_spec.rb +1 -5
  114. data/spec/{rails → spec/rails}/matchers/errors_on_spec.rb +1 -1
  115. data/spec/{rails → spec/rails}/matchers/have_text_spec.rb +1 -1
  116. data/spec/{rails → spec/rails}/matchers/include_text_spec.rb +1 -1
  117. data/spec/{rails → spec/rails}/matchers/redirect_to_spec.rb +11 -2
  118. data/spec/{rails → spec/rails}/matchers/render_template_spec.rb +8 -4
  119. data/spec/{rails → spec/rails}/matchers/should_change_spec.rb +1 -1
  120. data/spec/{rails → spec/rails}/mocks/ar_classes.rb +0 -0
  121. data/spec/{rails → spec/rails}/mocks/mock_model_spec.rb +1 -1
  122. data/spec/{rails → spec/rails}/mocks/stub_model_spec.rb +1 -1
  123. data/spec/{rails → spec/rails}/sample_modified_fixture.rb +1 -1
  124. data/spec/{rails → spec/rails}/sample_spec.rb +1 -1
  125. data/spec/spec/rails/spec_server_spec.rb +96 -0
  126. data/spec/{rails → spec/rails}/spec_spec.rb +1 -1
  127. data/spec/spec_helper.rb +23 -14
  128. metadata +111 -100
  129. data/UPGRADE +0 -7
  130. data/generators/rspec/templates/all_stories.rb +0 -4
  131. data/generators/rspec/templates/stories_helper.rb +0 -3
  132. data/lib/spec/rails/extensions/object.rb +0 -5
  133. data/spec/rails/example/configuration_spec.rb +0 -83
  134. data/spec/rails/matchers/description_generation_spec.rb +0 -37
  135. data/spec/rails/spec_server_spec.rb +0 -96
  136. data/stories/all.rb +0 -10
  137. data/stories/configuration/stories.rb +0 -5
  138. data/stories/helper.rb +0 -6
  139. data/stories/steps/people.rb +0 -8
  140. data/stories/transactions_should_rollback.rb +0 -25
@@ -13,17 +13,21 @@ module Spec
13
13
  def run(argv, stderr, stdout)
14
14
  $stdout = stdout
15
15
  $stderr = stderr
16
-
17
- base = ActiveRecord::Base
18
- def base.clear_reloadable_connections!
19
- active_connections.each do |name, conn|
20
- if conn.requires_reloading?
21
- conn.disconnect!
22
- active_connections.delete(name)
16
+
17
+ unless ActiveRecord::Base.respond_to?(:clear_reloadable_connections!)
18
+ base = ActiveRecord::Base
19
+ def base.clear_reloadable_connections!
20
+ active_connections.each do |name, conn|
21
+ if conn.requires_reloading?
22
+ conn.disconnect!
23
+ active_connections.delete(name)
24
+ end
23
25
  end
24
26
  end
25
27
  end
26
28
 
29
+ ActiveRecord::Base.clear_reloadable_connections!
30
+
27
31
  if ActionController.const_defined?(:Dispatcher)
28
32
  dispatcher = ::ActionController::Dispatcher.new($stdout)
29
33
  dispatcher.cleanup_application
@@ -35,8 +39,13 @@ module Spec
35
39
  if Object.const_defined?(:Fixtures) && Fixtures.respond_to?(:reset_cache)
36
40
  Fixtures.reset_cache
37
41
  end
42
+
43
+ if ::ActiveSupport.const_defined?(:Dependencies)
44
+ ::ActiveSupport::Dependencies.mechanism = :load
45
+ else
46
+ ::Dependencies.mechanism = :load
47
+ end
38
48
 
39
- ::Dependencies.mechanism = :load
40
49
  require_dependency('application.rb') unless Object.const_defined?(:ApplicationController)
41
50
  load File.dirname(__FILE__) + '/../spec/spec_helper.rb'
42
51
 
@@ -43,5 +43,5 @@ Spec::Runner.configure do |config|
43
43
  #
44
44
  # == Notes
45
45
  #
46
- # For more information take a look at Spec::Example::Configuration and Spec::Runner
46
+ # For more information take a look at Spec::Runner::Configuration and Spec::Runner
47
47
  end
@@ -3,9 +3,9 @@ module Rails
3
3
  class GeneratedAttribute
4
4
  def default_value
5
5
  @default_value ||= case type
6
- when :int, :integer then "\"1\""
7
- when :float then "\"1.5\""
8
- when :decimal then "\"9.99\""
6
+ when :int, :integer then "1"
7
+ when :float then "1.5"
8
+ when :decimal then "9.99"
9
9
  when :datetime, :timestamp, :time then "Time.now"
10
10
  when :date then "Date.today"
11
11
  when :string, :text then "\"value for #{@name}\""
@@ -1,14 +1,15 @@
1
1
  require File.expand_path(File.dirname(__FILE__) + '<%= '/..' * class_nesting_depth %>/../../spec_helper')
2
2
 
3
+ <% output_attributes = attributes.reject{|attribute| [:datetime, :timestamp, :time, :date].index(attribute.type) } -%>
3
4
  describe "/<%= table_name %>/edit.<%= default_file_extension %>" do
4
5
  include <%= controller_class_name %>Helper
5
6
 
6
7
  before(:each) do
7
8
  assigns[:<%= file_name %>] = @<%= file_name %> = stub_model(<%= class_name %>,
8
- :new_record? => false<%= attributes.empty? ? '' : ',' %>
9
- <% attributes.each_with_index do |attribute, attribute_index| -%><% unless attribute.name =~ /_id/ || [:datetime, :timestamp, :time, :date].index(attribute.type) -%>
10
- :<%= attribute.name %> => <%= attribute.default_value %><%= attribute_index == attributes.length - 1 ? '' : ','%>
11
- <% end -%><% end -%>
9
+ :new_record? => false<%= output_attributes.empty? ? '' : ',' %>
10
+ <% output_attributes.each_with_index do |attribute, attribute_index| -%>
11
+ :<%= attribute.name %> => <%= attribute.default_value %><%= attribute_index == output_attributes.length - 1 ? '' : ','%>
12
+ <% end -%>
12
13
  )
13
14
  end
14
15
 
@@ -16,9 +17,9 @@ describe "/<%= table_name %>/edit.<%= default_file_extension %>" do
16
17
  render "/<%= table_name %>/edit.<%= default_file_extension %>"
17
18
 
18
19
  response.should have_tag("form[action=#{<%= file_name %>_path(@<%= file_name %>)}][method=post]") do
19
- <% for attribute in attributes -%><% unless attribute.name =~ /_id/ || [:datetime, :timestamp, :time, :date].index(attribute.type) -%>
20
+ <% for attribute in output_attributes -%>
20
21
  with_tag('<%= attribute.input_type -%>#<%= file_name %>_<%= attribute.name %>[name=?]', "<%= file_name %>[<%= attribute.name %>]")
21
- <% end -%><% end -%>
22
+ <% end -%>
22
23
  end
23
24
  end
24
25
  end
@@ -1,16 +1,17 @@
1
1
  require File.expand_path(File.dirname(__FILE__) + '<%= '/..' * class_nesting_depth %>/../../spec_helper')
2
2
 
3
+ <% output_attributes = attributes.reject{|attribute| [:datetime, :timestamp, :time, :date].index(attribute.type) } -%>
3
4
  describe "/<%= table_name %>/index.<%= default_file_extension %>" do
4
5
  include <%= controller_class_name %>Helper
5
6
 
6
7
  before(:each) do
7
8
  assigns[:<%= table_name %>] = [
8
9
  <% [1,2].each_with_index do |id, model_index| -%>
9
- stub_model(<%= class_name %><%= attributes.empty? ? (model_index == 1 ? ')' : '),') : ',' %>
10
- <% attributes.each_with_index do |attribute, attribute_index| -%><% unless attribute.name =~ /_id/ || [:datetime, :timestamp, :time, :date].index(attribute.type) -%>
11
- :<%= attribute.name %> => <%= attribute.default_value %><%= attribute_index == attributes.length - 1 ? '' : ','%>
12
- <% end -%><% end -%>
13
- <% if !attributes.empty? -%>
10
+ stub_model(<%= class_name %><%= output_attributes.empty? ? (model_index == 1 ? ')' : '),') : ',' %>
11
+ <% output_attributes.each_with_index do |attribute, attribute_index| -%>
12
+ :<%= attribute.name %> => <%= attribute.default_value %><%= attribute_index == output_attributes.length - 1 ? '' : ','%>
13
+ <% end -%>
14
+ <% if !output_attributes.empty? -%>
14
15
  <%= model_index == 1 ? ')' : '),' %>
15
16
  <% end -%>
16
17
  <% end -%>
@@ -19,9 +20,9 @@ describe "/<%= table_name %>/index.<%= default_file_extension %>" do
19
20
 
20
21
  it "should render list of <%= table_name %>" do
21
22
  render "/<%= table_name %>/index.<%= default_file_extension %>"
22
- <% for attribute in attributes -%><% unless attribute.name =~ /_id/ || [:datetime, :timestamp, :time, :date].index(attribute.type) -%>
23
- response.should have_tag("tr>td", <%= attribute.default_value %>, 2)
24
- <% end -%><% end -%>
23
+ <% for attribute in output_attributes -%>
24
+ response.should have_tag("tr>td", <%= attribute.default_value %>.to_s, 2)
25
+ <% end -%>
25
26
  end
26
27
  end
27
28
 
@@ -1,14 +1,15 @@
1
1
  require File.expand_path(File.dirname(__FILE__) + '<%= '/..' * class_nesting_depth %>/../../spec_helper')
2
2
 
3
+ <% output_attributes = attributes.reject{|attribute| [:datetime, :timestamp, :time, :date].index(attribute.type) } -%>
3
4
  describe "/<%= table_name %>/new.<%= default_file_extension %>" do
4
5
  include <%= controller_class_name %>Helper
5
6
 
6
7
  before(:each) do
7
8
  assigns[:<%= file_name %>] = stub_model(<%= class_name %>,
8
- :new_record? => true<%= attributes.empty? ? '' : ',' %>
9
- <% attributes.each_with_index do |attribute, attribute_index| -%><% unless attribute.name =~ /_id/ || [:datetime, :timestamp, :time, :date].index(attribute.type) -%>
10
- :<%= attribute.name %> => <%= attribute.default_value %><%= attribute_index == attributes.length - 1 ? '' : ','%>
11
- <% end -%><% end -%>
9
+ :new_record? => true<%= output_attributes.empty? ? '' : ',' %>
10
+ <% output_attributes.each_with_index do |attribute, attribute_index| -%>
11
+ :<%= attribute.name %> => <%= attribute.default_value %><%= attribute_index == output_attributes.length - 1 ? '' : ','%>
12
+ <% end -%>
12
13
  )
13
14
  end
14
15
 
@@ -16,9 +17,9 @@ describe "/<%= table_name %>/new.<%= default_file_extension %>" do
16
17
  render "/<%= table_name %>/new.<%= default_file_extension %>"
17
18
 
18
19
  response.should have_tag("form[action=?][method=post]", <%= table_name %>_path) do
19
- <% for attribute in attributes -%><% unless attribute.name =~ /_id/ || [:datetime, :timestamp, :time, :date].index(attribute.type) -%>
20
+ <% for attribute in output_attributes -%>
20
21
  with_tag("<%= attribute.input_type -%>#<%= file_name %>_<%= attribute.name %>[name=?]", "<%= file_name %>[<%= attribute.name %>]")
21
- <% end -%><% end -%>
22
+ <% end -%>
22
23
  end
23
24
  end
24
25
  end
@@ -1,23 +1,23 @@
1
1
  require File.expand_path(File.dirname(__FILE__) + '<%= '/..' * class_nesting_depth %>/../../spec_helper')
2
2
 
3
+ <% output_attributes = attributes.reject{|attribute| [:datetime, :timestamp, :time, :date].index(attribute.type) } -%>
3
4
  describe "/<%= table_name %>/show.<%= default_file_extension %>" do
4
5
  include <%= controller_class_name %>Helper
5
-
6
6
  before(:each) do
7
- assigns[:<%= file_name %>] = @<%= file_name %> = stub_model(<%= class_name %><%= attributes.empty? ? ')' : ',' %>
8
- <% attributes.each_with_index do |attribute, attribute_index| -%><% unless attribute.name =~ /_id/ || [:datetime, :timestamp, :time, :date].index(attribute.type) -%>
9
- :<%= attribute.name %> => <%= attribute.default_value %><%= attribute_index == attributes.length - 1 ? '' : ','%>
10
- <% end -%><% end -%>
11
- <% if !attributes.empty? -%>
7
+ assigns[:<%= file_name %>] = @<%= file_name %> = stub_model(<%= class_name %><%= output_attributes.empty? ? ')' : ',' %>
8
+ <% output_attributes.each_with_index do |attribute, attribute_index| -%>
9
+ :<%= attribute.name %> => <%= attribute.default_value %><%= attribute_index == output_attributes.length - 1 ? '' : ','%>
10
+ <% end -%>
11
+ <% if !output_attributes.empty? -%>
12
12
  )
13
13
  <% end -%>
14
14
  end
15
15
 
16
16
  it "should render attributes in <p>" do
17
17
  render "/<%= table_name %>/show.<%= default_file_extension %>"
18
- <% for attribute in attributes -%><% unless attribute.name =~ /_id/ || [:datetime, :timestamp, :time, :date].index(attribute.type) -%>
19
- response.should have_text(/<%= Regexp.escape(attribute.default_value)[1..-2]%>/)
20
- <% end -%><% end -%>
18
+ <% for attribute in output_attributes -%>
19
+ response.should have_text(/<%= Regexp.escape(attribute.default_value).gsub(/^"|"$/, '')%>/)
20
+ <% end -%>
21
21
  end
22
22
  end
23
23
 
@@ -1,6 +1,11 @@
1
1
  silence_warnings { RAILS_ENV = "test" }
2
2
 
3
- require_dependency 'application'
3
+ begin
4
+ require_dependency 'application_controller'
5
+ rescue MissingSourceFile
6
+ require_dependency 'application'
7
+ end
8
+
4
9
  require 'action_controller/test_process'
5
10
  require 'action_controller/integration'
6
11
  require 'active_record/fixtures' if defined?(ActiveRecord::Base)
@@ -12,4 +17,11 @@ require 'spec/rails/matchers'
12
17
  require 'spec/rails/mocks'
13
18
  require 'spec/rails/example'
14
19
  require 'spec/rails/extensions'
15
- require 'spec/rails/interop/testcase'
20
+ require 'spec/rails/interop/testcase'
21
+
22
+ if Rails::VERSION::STRING >= "2.0"
23
+ # This is a temporary hack to get rspec's auto-runner functionality to not consider
24
+ # ActionMailer::TestCase to be a spec waiting to run.
25
+ require 'action_mailer/test_case'
26
+ Spec::Example::ExampleGroupFactory.register(:ignore_for_now, ActionMailer::TestCase)
27
+ end
@@ -38,29 +38,9 @@ module Spec
38
38
  #
39
39
  # == Expecting Errors
40
40
  #
41
- # Rspec on Rails will raise errors that occur in controller actions.
42
- # In contrast, Rails will swallow errors that are raised in controller
43
- # actions and return an error code in the header. If you wish to override
44
- # Rspec and have Rail's default behaviour,tell the controller to use
45
- # rails error handling ...
41
+ # Rspec on Rails will raise errors that occur in controller actions and
42
+ # are not rescued or handeled with rescue_from.
46
43
  #
47
- # before(:each) do
48
- # controller.use_rails_error_handling!
49
- # end
50
- #
51
- # When using Rail's error handling, you can expect error codes in headers ...
52
- #
53
- # it "should return an error in the header" do
54
- # response.should be_error
55
- # end
56
- #
57
- # it "should return a 501" do
58
- # response.response_code.should == 501
59
- # end
60
- #
61
- # it "should return a 501" do
62
- # response.code.should == "501"
63
- # end
64
44
  class ControllerExampleGroup < FunctionalExampleGroup
65
45
  class << self
66
46
 
@@ -202,6 +182,16 @@ module Spec
202
182
  @_first_render ||= args[0] unless args[0] =~ /^layouts/
203
183
  PickedTemplate.new
204
184
  end
185
+
186
+ define_method :render do |*args|
187
+ if @_rendered
188
+ opts = args[0]
189
+ (@_rendered[:template] ||= opts[:file]) if opts[:file]
190
+ (@_rendered[:partials][opts[:partial]] += 1) if opts[:partial]
191
+ else
192
+ super
193
+ end
194
+ end
205
195
  end
206
196
  end
207
197
  end
@@ -247,8 +237,11 @@ module Spec
247
237
  Spec::Example::ExampleGroupFactory.register(:controller, self)
248
238
  end
249
239
 
250
- class PickedTemplate
240
+ # Returned by _pick_template when running controller examples in isolation mode.
241
+ class PickedTemplate
242
+ # Do nothing when running controller examples in isolation mode.
251
243
  def render_template(*ignore_args); end
244
+ # Do nothing when running controller examples in isolation mode.
252
245
  def render_partial(*ignore_args); end
253
246
  end
254
247
  end
@@ -9,7 +9,11 @@ module Spec
9
9
  end
10
10
 
11
11
  def[]=(name, value)
12
- @example.request.cookies[name.to_s] = CGI::Cookie.new(name.to_s, value)
12
+ if ::Rails::VERSION::STRING >= '2.3'
13
+ @example.request.cookies[name.to_s] = value
14
+ else
15
+ @example.request.cookies[name.to_s] = CGI::Cookie.new(name.to_s, value)
16
+ end
13
17
  end
14
18
 
15
19
  def [](name)
@@ -7,7 +7,7 @@ module Spec
7
7
 
8
8
  attr_reader :request, :response
9
9
  before(:each) do
10
- @controller_class = Object.path2class @controller_class_name
10
+ @controller_class = @controller_class_name.split('::').inject(Object) { |k,n| k.const_get n }
11
11
  raise "Can't determine controller class for #{@controller_class_name}" if @controller_class.nil?
12
12
 
13
13
  @controller = @controller_class.new
@@ -15,13 +15,13 @@ module Spec
15
15
  @response = ActionController::TestResponse.new
16
16
  @response.session = @request.session
17
17
  end
18
-
18
+
19
19
  def params
20
20
  request.parameters
21
21
  end
22
22
 
23
23
  def flash
24
- response.flash
24
+ @controller.__send__ :flash
25
25
  end
26
26
 
27
27
  def session
@@ -44,11 +44,23 @@ module Spec
44
44
  # post :login
45
45
  # cookies[:login].expires.should == 1.week.from_now
46
46
  #
47
- # == Examples (Rails >= 2.0.0 only)
47
+ # == Examples (Rails 2.0 > 2.2)
48
48
  #
49
49
  # cookies[:user_id] = {:value => '1234', :expires => 1.minute.ago}
50
50
  # get :index
51
51
  # response.should be_redirect
52
+ #
53
+ # == Examples (Rails 2.3)
54
+ #
55
+ # Rails 2.3 changes the way cookies are made available to functional
56
+ # tests (and therefore rspec controller specs), only making single
57
+ # values available with no access to other aspects of the cookie. This
58
+ # is backwards-incompatible, so you have to change your examples to
59
+ # look like this:
60
+ #
61
+ # cookies[:foo] = 'bar'
62
+ # get :index
63
+ # cookies[:foo].should == 'bar'
52
64
  def cookies
53
65
  @cookies ||= Spec::Rails::Example::CookiesProxy.new(self)
54
66
  end
@@ -71,7 +83,7 @@ module Spec
71
83
  # assigns[:registration].should == Thing.new
72
84
  #--
73
85
  # NOTE - Even though docs only use assigns[:key] format, this supports
74
- # assigns(:key) in order to avoid breaking old specs.
86
+ # assigns(:key) for backwards compatibility.
75
87
  #++
76
88
  def assigns(key = nil)
77
89
  if key.nil?
@@ -26,6 +26,8 @@ module Spec
26
26
  # end
27
27
  # end
28
28
  class HelperExampleGroup < FunctionalExampleGroup
29
+ attr_accessor :output_buffer
30
+
29
31
  class HelperObject < ActionView::Base
30
32
  def protect_against_forgery?
31
33
  false
@@ -117,7 +119,9 @@ module Spec
117
119
 
118
120
  @flash = ActionController::Flash::FlashHash.new
119
121
  session['flash'] = @flash
120
-
122
+
123
+ @output_buffer = ""
124
+ @template = helper
121
125
  ActionView::Helpers::AssetTagHelper::reset_javascript_include_default
122
126
 
123
127
  helper.session = session
@@ -161,9 +165,6 @@ module Spec
161
165
 
162
166
  class HelperExampleGroupController < ApplicationController #:nodoc:
163
167
  attr_accessor :request, :url
164
-
165
- # Re-raise errors
166
- def rescue_action(e); raise e; end
167
168
  end
168
169
  end
169
170
  end
@@ -8,26 +8,21 @@ module Spec
8
8
  module Rails
9
9
 
10
10
  module Example
11
- class RailsExampleGroup < Test::Unit::TestCase
12
-
13
- # Rails >= r8570 uses setup/teardown_fixtures explicitly
14
- # However, Rails >= r8664 extracted these out to use ActiveSupport::Callbacks.
15
- # The latter case is handled at the TestCase level, in interop/testcase.rb
16
- unless ActiveSupport.const_defined?(:Callbacks) and self.include?(ActiveSupport::Callbacks)
17
- before(:each) do
18
- setup_fixtures if self.respond_to?(:setup_fixtures)
19
- end
20
- after(:each) do
21
- teardown_fixtures if self.respond_to?(:teardown_fixtures)
22
- end
11
+ if ActiveSupport.const_defined?(:TestCase)
12
+ class RailsExampleGroup < ActiveSupport::TestCase
13
+ include ActionController::Assertions::SelectorAssertions
23
14
  end
24
-
15
+ else
16
+ class RailsExampleGroup < Test::Unit::TestCase
17
+ end
18
+ end
19
+
20
+ class RailsExampleGroup
25
21
  include Spec::Rails::Matchers
26
22
  include Spec::Rails::Mocks
27
-
28
23
  Spec::Example::ExampleGroupFactory.default(self)
29
-
30
24
  end
25
+
31
26
  end
32
27
  end
33
28
  end
@@ -103,11 +103,11 @@ module Spec
103
103
  add_helpers(options)
104
104
 
105
105
  assigns[:action_name] = @action_name
106
-
107
- @request.path_parameters = {
108
- :controller => derived_controller_name(options),
109
- :action => derived_action_name(options)
110
- }
106
+
107
+ @request.path_parameters = @request.path_parameters.merge(
108
+ :controller => derived_controller_name(options),
109
+ :action => derived_action_name(options)
110
+ ).merge(options[:path_parameters] || {})
111
111
 
112
112
  defaults = { :layout => false }
113
113
  options = defaults.merge options
@@ -1,8 +1,6 @@
1
1
  require 'spec'
2
2
 
3
- require 'spec/rails/extensions/object'
4
-
5
- require 'spec/rails/extensions/spec/example/configuration'
3
+ require 'spec/rails/extensions/spec/runner/configuration'
6
4
  require 'spec/rails/extensions/spec/matchers/have'
7
5
 
8
6
  require 'spec/rails/extensions/active_record/base'