mcmire-rspec-rails 1.1.99.9

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 (164) hide show
  1. data/History.txt +174 -0
  2. data/License.txt +33 -0
  3. data/Manifest.txt +164 -0
  4. data/README.txt +45 -0
  5. data/Rakefile +63 -0
  6. data/TODO.txt +1 -0
  7. data/Upgrade.markdown +52 -0
  8. data/features/step_definitions/people.rb +6 -0
  9. data/features/support/env.rb +13 -0
  10. data/features/transactions/transactions_should_rollback.feature +16 -0
  11. data/generators/rspec/CHANGES +1 -0
  12. data/generators/rspec/rspec_generator.rb +37 -0
  13. data/generators/rspec/templates/previous_failures.txt +0 -0
  14. data/generators/rspec/templates/rcov.opts +2 -0
  15. data/generators/rspec/templates/rspec.rake +177 -0
  16. data/generators/rspec/templates/script/autospec +5 -0
  17. data/generators/rspec/templates/script/spec +4 -0
  18. data/generators/rspec/templates/script/spec_server +37 -0
  19. data/generators/rspec/templates/spec.opts +4 -0
  20. data/generators/rspec/templates/spec_helper.rb +47 -0
  21. data/generators/rspec_controller/USAGE +33 -0
  22. data/generators/rspec_controller/rspec_controller_generator.rb +45 -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 +19 -0
  27. data/generators/rspec_model/USAGE +18 -0
  28. data/generators/rspec_model/rspec_model_generator.rb +35 -0
  29. data/generators/rspec_model/templates/model_spec.rb +15 -0
  30. data/generators/rspec_scaffold/rspec_scaffold_generator.rb +150 -0
  31. data/generators/rspec_scaffold/templates/controller_spec.rb +171 -0
  32. data/generators/rspec_scaffold/templates/edit_erb_spec.rb +27 -0
  33. data/generators/rspec_scaffold/templates/helper_spec.rb +11 -0
  34. data/generators/rspec_scaffold/templates/index_erb_spec.rb +28 -0
  35. data/generators/rspec_scaffold/templates/new_erb_spec.rb +27 -0
  36. data/generators/rspec_scaffold/templates/routing_spec.rb +63 -0
  37. data/generators/rspec_scaffold/templates/show_erb_spec.rb +23 -0
  38. data/init.rb +9 -0
  39. data/lib/autotest/discover.rb +1 -0
  40. data/lib/autotest/rails_rspec.rb +76 -0
  41. data/lib/spec/rails.rb +37 -0
  42. data/lib/spec/rails/example.rb +53 -0
  43. data/lib/spec/rails/example/assigns_hash_proxy.rb +39 -0
  44. data/lib/spec/rails/example/controller_example_group.rb +242 -0
  45. data/lib/spec/rails/example/cookies_proxy.rb +29 -0
  46. data/lib/spec/rails/example/functional_example_group.rb +84 -0
  47. data/lib/spec/rails/example/helper_example_group.rb +167 -0
  48. data/lib/spec/rails/example/model_example_group.rb +14 -0
  49. data/lib/spec/rails/example/render_observer.rb +67 -0
  50. data/lib/spec/rails/example/routing_helpers.rb +68 -0
  51. data/lib/spec/rails/example/view_example_group.rb +186 -0
  52. data/lib/spec/rails/extensions.rb +15 -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 +43 -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 +48 -0
  61. data/lib/spec/rails/interop/testcase.rb +14 -0
  62. data/lib/spec/rails/matchers.rb +40 -0
  63. data/lib/spec/rails/matchers/ar_be_valid.rb +44 -0
  64. data/lib/spec/rails/matchers/assert_select.rb +131 -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/mocks.rb +135 -0
  71. data/lib/spec/rails/spec_server.rb +97 -0
  72. data/lib/spec/rails/story_adapter.rb +79 -0
  73. data/lib/spec/rails/version.rb +16 -0
  74. data/rspec-rails.gemspec +39 -0
  75. data/spec/autotest/mappings_spec.rb +36 -0
  76. data/spec/rails_suite.rb +7 -0
  77. data/spec/resources/controllers/action_view_base_spec_controller.rb +2 -0
  78. data/spec/resources/controllers/application.rb +9 -0
  79. data/spec/resources/controllers/controller_spec_controller.rb +116 -0
  80. data/spec/resources/controllers/redirect_spec_controller.rb +70 -0
  81. data/spec/resources/controllers/render_spec_controller.rb +30 -0
  82. data/spec/resources/controllers/rjs_spec_controller.rb +58 -0
  83. data/spec/resources/helpers/addition_helper.rb +5 -0
  84. data/spec/resources/helpers/explicit_helper.rb +46 -0
  85. data/spec/resources/helpers/more_explicit_helper.rb +5 -0
  86. data/spec/resources/helpers/plugin_application_helper.rb +6 -0
  87. data/spec/resources/helpers/view_spec_helper.rb +13 -0
  88. data/spec/resources/models/animal.rb +4 -0
  89. data/spec/resources/models/person.rb +18 -0
  90. data/spec/resources/models/thing.rb +3 -0
  91. data/spec/resources/views/controller_spec/_partial.rhtml +0 -0
  92. data/spec/resources/views/controller_spec/action_setting_flash_after_session_reset.rhtml +1 -0
  93. data/spec/resources/views/controller_spec/action_setting_flash_before_session_reset.rhtml +1 -0
  94. data/spec/resources/views/controller_spec/action_setting_the_assigns_hash.rhtml +0 -0
  95. data/spec/resources/views/controller_spec/action_with_errors_in_template.rhtml +1 -0
  96. data/spec/resources/views/controller_spec/action_with_template.rhtml +1 -0
  97. data/spec/resources/views/layouts/application.rhtml +0 -0
  98. data/spec/resources/views/layouts/simple.rhtml +0 -0
  99. data/spec/resources/views/objects/_object.html.erb +1 -0
  100. data/spec/resources/views/render_spec/_a_partial.rhtml +0 -0
  101. data/spec/resources/views/render_spec/action_with_alternate_layout.rhtml +0 -0
  102. data/spec/resources/views/render_spec/some_action.html.erb +0 -0
  103. data/spec/resources/views/render_spec/some_action.js.rjs +1 -0
  104. data/spec/resources/views/render_spec/some_action.rjs +1 -0
  105. data/spec/resources/views/rjs_spec/_replacement_partial.rhtml +1 -0
  106. data/spec/resources/views/rjs_spec/hide_div.rjs +1 -0
  107. data/spec/resources/views/rjs_spec/hide_page_element.rjs +1 -0
  108. data/spec/resources/views/rjs_spec/insert_html.rjs +1 -0
  109. data/spec/resources/views/rjs_spec/replace.rjs +1 -0
  110. data/spec/resources/views/rjs_spec/replace_html.rjs +1 -0
  111. data/spec/resources/views/rjs_spec/replace_html_with_partial.rjs +1 -0
  112. data/spec/resources/views/rjs_spec/visual_effect.rjs +1 -0
  113. data/spec/resources/views/rjs_spec/visual_toggle_effect.rjs +1 -0
  114. data/spec/resources/views/tag_spec/no_tags.rhtml +1 -0
  115. data/spec/resources/views/tag_spec/single_div_with_no_attributes.rhtml +1 -0
  116. data/spec/resources/views/tag_spec/single_div_with_one_attribute.rhtml +1 -0
  117. data/spec/resources/views/view_spec/_partial.rhtml +2 -0
  118. data/spec/resources/views/view_spec/_partial_used_twice.rhtml +0 -0
  119. data/spec/resources/views/view_spec/_partial_with_local_variable.rhtml +1 -0
  120. data/spec/resources/views/view_spec/_partial_with_sub_partial.rhtml +1 -0
  121. data/spec/resources/views/view_spec/_spacer.rhtml +1 -0
  122. data/spec/resources/views/view_spec/accessor.rhtml +5 -0
  123. data/spec/resources/views/view_spec/block_helper.rhtml +3 -0
  124. data/spec/resources/views/view_spec/entry_form.rhtml +2 -0
  125. data/spec/resources/views/view_spec/explicit_helper.rhtml +2 -0
  126. data/spec/resources/views/view_spec/foo/show.rhtml +1 -0
  127. data/spec/resources/views/view_spec/implicit_helper.rhtml +2 -0
  128. data/spec/resources/views/view_spec/multiple_helpers.rhtml +3 -0
  129. data/spec/resources/views/view_spec/path_params.html.erb +1 -0
  130. data/spec/resources/views/view_spec/should_not_receive.rhtml +3 -0
  131. data/spec/resources/views/view_spec/template_with_partial.rhtml +5 -0
  132. data/spec/resources/views/view_spec/template_with_partial_using_collection.rhtml +3 -0
  133. data/spec/resources/views/view_spec/template_with_partial_with_array.rhtml +1 -0
  134. data/spec/spec/rails/example/assigns_hash_proxy_spec.rb +109 -0
  135. data/spec/spec/rails/example/configuration_spec.rb +65 -0
  136. data/spec/spec/rails/example/controller_example_group_spec.rb +275 -0
  137. data/spec/spec/rails/example/controller_isolation_spec.rb +56 -0
  138. data/spec/spec/rails/example/cookies_proxy_spec.rb +87 -0
  139. data/spec/spec/rails/example/error_handling_spec.rb +90 -0
  140. data/spec/spec/rails/example/example_group_factory_spec.rb +112 -0
  141. data/spec/spec/rails/example/helper_example_group_spec.rb +206 -0
  142. data/spec/spec/rails/example/model_example_group_spec.rb +20 -0
  143. data/spec/spec/rails/example/test_unit_assertion_accessibility_spec.rb +33 -0
  144. data/spec/spec/rails/example/view_example_group_spec.rb +335 -0
  145. data/spec/spec/rails/extensions/action_view_base_spec.rb +48 -0
  146. data/spec/spec/rails/extensions/active_record_spec.rb +14 -0
  147. data/spec/spec/rails/interop/testcase_spec.rb +70 -0
  148. data/spec/spec/rails/matchers/ar_be_valid_spec.rb +45 -0
  149. data/spec/spec/rails/matchers/assert_select_spec.rb +811 -0
  150. data/spec/spec/rails/matchers/errors_on_spec.rb +25 -0
  151. data/spec/spec/rails/matchers/have_text_spec.rb +70 -0
  152. data/spec/spec/rails/matchers/include_text_spec.rb +62 -0
  153. data/spec/spec/rails/matchers/redirect_to_spec.rb +253 -0
  154. data/spec/spec/rails/matchers/render_template_spec.rb +183 -0
  155. data/spec/spec/rails/matchers/should_change_spec.rb +15 -0
  156. data/spec/spec/rails/mocks/ar_classes.rb +10 -0
  157. data/spec/spec/rails/mocks/mock_model_spec.rb +106 -0
  158. data/spec/spec/rails/mocks/stub_model_spec.rb +80 -0
  159. data/spec/spec/rails/sample_modified_fixture.rb +8 -0
  160. data/spec/spec/rails/sample_spec.rb +8 -0
  161. data/spec/spec/rails/spec_server_spec.rb +107 -0
  162. data/spec/spec/rails/spec_spec.rb +11 -0
  163. data/spec/spec_helper.rb +78 -0
  164. metadata +262 -0
@@ -0,0 +1,15 @@
1
+ require 'spec'
2
+
3
+ require 'spec/rails/extensions/spec/runner/configuration'
4
+ require 'spec/rails/extensions/spec/matchers/have'
5
+
6
+ require 'spec/rails/extensions/active_support/test_case'
7
+ if Object.const_defined?(:ActiveRecord) && ActiveRecord.const_defined?(:Base)
8
+ require 'spec/rails/extensions/active_record/base'
9
+ end
10
+ if Object.const_defined?(:ActionController) && ActionController.const_defined?(:Base)
11
+ require 'spec/rails/extensions/action_controller/rescue'
12
+ require 'spec/rails/extensions/action_controller/test_case'
13
+ require 'spec/rails/extensions/action_controller/test_response'
14
+ require 'spec/rails/extensions/action_view/base'
15
+ end
@@ -0,0 +1,42 @@
1
+ module ActionController
2
+ module Rescue
3
+ def use_rails_error_handling!
4
+ Kernel.warn <<-WARNING
5
+ DEPRECATION NOTICE: controller.use_rails_error_handling! is
6
+ deprecated and will be removed from a future version of
7
+ rspec-rails.
8
+
9
+ Use rescue_action_in_public!, which is defined directly in
10
+ rails' testing framework, instead.
11
+ WARNING
12
+ if Rails::VERSION::STRING =~ /^2\.0/
13
+ @use_rails_error_handling = true
14
+ else
15
+ # anything but 0.0.0.0 - borrowed from rails own rescue_action_in_public!
16
+ request.remote_addr = '208.77.188.166'
17
+ end
18
+ end
19
+
20
+ def use_rails_error_handling?
21
+ @use_rails_error_handling ||= false
22
+ end
23
+
24
+ protected
25
+
26
+ if Rails::VERSION::STRING =~ /^2\.0/
27
+ def rescue_action_in_public?
28
+ request.respond_to?(:rescue_action_in_public?) and request.rescue_action_in_public?
29
+ end
30
+
31
+ def rescue_action_with_handler_with_fast_errors(exception)
32
+ if (use_rails_error_handling? || rescue_action_in_public?) & !handler_for_rescue(exception)
33
+ rescue_action_in_public(exception)
34
+ else
35
+ rescue_action_with_handler_without_fast_errors(exception)
36
+ end
37
+ end
38
+ alias_method_chain :rescue_action_with_handler, :fast_errors
39
+ end
40
+
41
+ end
42
+ end
@@ -0,0 +1,16 @@
1
+ module ActionController
2
+ class TestCase
3
+ include ::Spec::Rails::Example::RoutingHelpers
4
+
5
+ if Rails::VERSION::STRING =~ /2\.0/
6
+ # Introduced in Rails 2.1, but we need it for 2.0
7
+ def rescue_action_in_public!
8
+ # See rescue.rb in this same directory
9
+ def request.rescue_action_in_public?
10
+ true
11
+ end
12
+ end
13
+
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,21 @@
1
+ module ActionController #:nodoc:
2
+ class TestResponse #:nodoc:
3
+ attr_writer :controller_path
4
+
5
+ def capture(name)
6
+ template.instance_variable_get "@content_for_#{name.to_s}"
7
+ end
8
+
9
+ if ::Rails::VERSION::STRING < "2.3"
10
+ def [](name)
11
+ Kernel.warn <<-WARNING
12
+ DEPRECATION NOTICE: [](name) as an alias for capture(name) (TestResponse
13
+ extension in rspec-rails) is deprecated and will not be defined by rspec-rails
14
+ when working with rails >= 2.3.0. It will also be removed entirely from
15
+ a future version of rspec-rails.
16
+ WARNING
17
+ capture(name)
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,33 @@
1
+ module ActionView #:nodoc:
2
+ class Base #:nodoc:
3
+ include Spec::Rails::Example::RenderObserver
4
+ cattr_accessor :base_view_path
5
+
6
+ def render_partial_with_base_view_path_handling(partial_path, local_assigns = nil, deprecated_local_assigns = nil) #:nodoc:
7
+ if partial_path.is_a?(String)
8
+ unless partial_path.include?("/")
9
+ unless self.class.base_view_path.nil?
10
+ partial_path = "#{self.class.base_view_path}/#{partial_path}"
11
+ end
12
+ end
13
+ end
14
+ begin
15
+ render_partial_without_base_view_path_handling(partial_path, local_assigns, deprecated_local_assigns)
16
+ rescue ArgumentError # edge rails > 2.1 changed render_partial to accept only one arg
17
+ render_partial_without_base_view_path_handling(partial_path)
18
+ end
19
+ end
20
+ alias_method_chain :render_partial, :base_view_path_handling
21
+
22
+ def render_with_mock_proxy(options = {}, old_local_assigns = {}, &block)
23
+ if render_proxy.__send__(:__mock_proxy).__send__(:find_matching_expectation, :render, options)
24
+ render_proxy.render(options)
25
+ else
26
+ unless render_proxy.__send__(:__mock_proxy).__send__(:find_matching_method_stub, :render, options)
27
+ render_without_mock_proxy(options, old_local_assigns, &block)
28
+ end
29
+ end
30
+ end
31
+ alias_method_chain :render, :mock_proxy
32
+ end
33
+ end
@@ -0,0 +1,43 @@
1
+ module Spec
2
+ module Rails
3
+ module Extensions
4
+ module ActiveRecord
5
+ module ClassMethods
6
+ # :call-seq:
7
+ # ModelClass.should have(:no).records
8
+ # ModelClass.should have(1).record
9
+ # ModelClass.should have(n).records
10
+ #
11
+ # Extension to enhance <tt>should have</tt> on AR Model classes
12
+ def records
13
+ find(:all)
14
+ end
15
+ alias :record :records
16
+ end
17
+
18
+ module InstanceMethods
19
+ # :call-seq:
20
+ # model.should have(:no).errors_on(:attribute)
21
+ # model.should have(1).error_on(:attribute)
22
+ # model.should have(n).errors_on(:attribute)
23
+ #
24
+ # Extension to enhance <tt>should have</tt> on AR Model instances.
25
+ # Calls model.valid? in order to prepare the object's errors
26
+ # object.
27
+ def errors_on(attribute)
28
+ self.valid?
29
+ [self.errors.on(attribute)].flatten.compact
30
+ end
31
+ alias :error_on :errors_on
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
37
+
38
+ module ActiveRecord #:nodoc:
39
+ class Base
40
+ extend Spec::Rails::Extensions::ActiveRecord::ClassMethods
41
+ include Spec::Rails::Extensions::ActiveRecord::InstanceMethods
42
+ end
43
+ end
@@ -0,0 +1,7 @@
1
+ module ActiveSupport
2
+ class TestCase
3
+ include ::Spec::Rails::Matchers
4
+ include ::Spec::Rails::Mocks
5
+ end
6
+ end
7
+
@@ -0,0 +1,23 @@
1
+ require 'spec/matchers/have'
2
+
3
+ module Spec #:nodoc:
4
+ module Matchers #:nodoc:
5
+ class Have #:nodoc:
6
+
7
+ def failure_message_with_errors_on_extensions
8
+ return "expected #{relativities[@relativity]}#{@expected} errors on :#{@args[0]}, got #{@given}" if @collection_name == :errors_on
9
+ return "expected #{relativities[@relativity]}#{@expected} error on :#{@args[0]}, got #{@given}" if @collection_name == :error_on
10
+ return failure_message_without_errors_on_extensions
11
+ end
12
+ alias_method_chain :failure_message, :errors_on_extensions
13
+
14
+ def description_with_errors_on_extensions
15
+ return "should have #{relativities[@relativity]}#{@expected} errors on :#{@args[0]}" if @collection_name == :errors_on
16
+ return "should have #{relativities[@relativity]}#{@expected} error on :#{@args[0]}" if @collection_name == :error_on
17
+ return description_without_errors_on_extensions
18
+ end
19
+ alias_method_chain :description, :errors_on_extensions
20
+
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,48 @@
1
+ require 'spec/runner/configuration'
2
+ begin
3
+ require 'test_help'
4
+ rescue MissingSourceFile, NameError
5
+ # probably ApplicationController hasn't been loaded yet, but that probably means we're jimmy rigging this
6
+ end
7
+
8
+ if Object.const_defined?(:ActiveRecord) && ActiveRecord.const_defined?(:Base)
9
+ module Spec
10
+ module Runner
11
+ class Configuration
12
+
13
+ def initialize
14
+ super
15
+ self.fixture_path = RAILS_ROOT + '/spec/fixtures'
16
+ end
17
+
18
+ def use_transactional_fixtures
19
+ ActiveSupport::TestCase.use_transactional_fixtures
20
+ end
21
+ def use_transactional_fixtures=(value)
22
+ ActiveSupport::TestCase.use_transactional_fixtures = value
23
+ end
24
+
25
+ def use_instantiated_fixtures
26
+ ActiveSupport::TestCase.use_instantiated_fixtures
27
+ end
28
+ def use_instantiated_fixtures=(value)
29
+ ActiveSupport::TestCase.use_instantiated_fixtures = value
30
+ end
31
+
32
+ def fixture_path
33
+ ActiveSupport::TestCase.fixture_path
34
+ end
35
+ def fixture_path=(path)
36
+ ActiveSupport::TestCase.fixture_path = path
37
+ end
38
+
39
+ def global_fixtures
40
+ ActiveSupport::TestCase.fixture_table_names
41
+ end
42
+ def global_fixtures=(fixtures)
43
+ ActiveSupport::TestCase.fixtures(*fixtures)
44
+ end
45
+ end
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,14 @@
1
+ module Test
2
+ module Unit
3
+ class TestCase
4
+ # Edge rails (r8664) introduces class-wide setup & teardown callbacks for Test::Unit::TestCase.
5
+ # Make sure these still get run when running TestCases under rspec:
6
+ prepend_before(:each) do
7
+ run_callbacks :setup if respond_to?(:run_callbacks)
8
+ end
9
+ append_after(:each) do
10
+ run_callbacks :teardown if respond_to?(:run_callbacks)
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,40 @@
1
+ dir = File.dirname(__FILE__)
2
+ if Object.const_defined?(:ActiveRecord) && ActiveRecord.const_defined?(:Base)
3
+ require 'spec/rails/matchers/ar_be_valid'
4
+ end
5
+ if Object.const_defined?(:ActionController) && ActionController.const_defined?(:Base)
6
+ require 'spec/rails/matchers/assert_select'
7
+ end
8
+ if Object.const_defined?(:ActiveRecord) && ActiveRecord.const_defined?(:Base)
9
+ require 'spec/rails/matchers/change'
10
+ end
11
+ require 'spec/rails/matchers/have_text'
12
+ require 'spec/rails/matchers/include_text'
13
+ if Object.const_defined?(:ActionController) && ActionController.const_defined?(:Base)
14
+ require 'spec/rails/matchers/redirect_to'
15
+ require 'spec/rails/matchers/render_template'
16
+ end
17
+
18
+ module Spec
19
+ module Rails
20
+ # Spec::Rails::Expectations::Matchers provides several expectation matchers
21
+ # intended to work with Rails components like models and responses. For example:
22
+ #
23
+ # response.should redirect_to("some/url") #redirect_to(url) is the matcher.
24
+ #
25
+ # In addition to those you see below, the arbitrary predicate feature of RSpec
26
+ # makes the following available as well:
27
+ #
28
+ # response.should be_success #passes if response.success?
29
+ # response.should be_redirect #passes if response.redirect?
30
+ #
31
+ # Note that many of these matchers are part of a wrapper of <tt>assert_select</tt>, so
32
+ # the documentation comes straight from that with some slight modifications.
33
+ # <tt>assert_select</tt> is a Test::Unit extension originally contributed to the
34
+ # Rails community as a plugin by Assaf Arkin and eventually shipped as part of Rails.
35
+ #
36
+ # For more info on <tt>assert_select</tt>, see the relevant Rails documentation.
37
+ module Matchers
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,44 @@
1
+ module Spec
2
+ module Rails
3
+ module Matchers
4
+
5
+ class ArBeValid #:nodoc:
6
+
7
+ def initialize
8
+ @matcher = Spec::Matchers::Be.new :be_valid
9
+ @matcher.__send__ :handling_predicate!
10
+ end
11
+
12
+ def matches?(actual)
13
+ @actual = actual
14
+ @matcher.matches? @actual
15
+ end
16
+
17
+ def failure_message
18
+ if @actual.respond_to?(:errors) &&
19
+ ActiveRecord::Errors === @actual.errors
20
+ "Expected #{@actual.inspect} to be valid, but it was not\nErrors: " + @actual.errors.full_messages.join(", ")
21
+ else
22
+ @matcher.failure_message
23
+ end
24
+ end
25
+
26
+ def negative_failure_message
27
+ @matcher.negative_failure_message
28
+ end
29
+
30
+ def description
31
+ "be valid"
32
+ end
33
+ end
34
+
35
+ # :call-seq:
36
+ # response.should be_valid
37
+ # response.should_not be_valid
38
+ def be_valid
39
+ ArBeValid.new
40
+ end
41
+
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,131 @@
1
+ # This is a wrapper of assert_select for rspec.
2
+
3
+ module Spec # :nodoc:
4
+ module Rails
5
+ module Matchers
6
+
7
+ class AssertSelect #:nodoc:
8
+
9
+ def initialize(assertion, spec_scope, *args, &block)
10
+ @assertion = assertion
11
+ @spec_scope = spec_scope
12
+ @args = args
13
+ @block = block
14
+ end
15
+
16
+ def matches?(response_or_text, &block)
17
+ if ActionController::TestResponse === response_or_text and
18
+ response_or_text.headers.key?('Content-Type') and
19
+ !response_or_text.headers['Content-Type'].blank? and
20
+ response_or_text.headers['Content-Type'].to_sym == :xml
21
+ @args.unshift(HTML::Document.new(response_or_text.body, false, true).root)
22
+ elsif String === response_or_text
23
+ @args.unshift(HTML::Document.new(response_or_text).root)
24
+ end
25
+ @block = block if block
26
+ begin
27
+ @spec_scope.__send__(@assertion, *@args, &@block)
28
+ rescue ::Test::Unit::AssertionFailedError => @error
29
+ end
30
+
31
+ @error.nil?
32
+ end
33
+
34
+ def failure_message; @error.message; end
35
+ def negative_failure_message; "should not #{description}, but did"; end
36
+
37
+ def description
38
+ {
39
+ :assert_select => "have tag#{format_args(*@args)}",
40
+ :assert_select_email => "send email#{format_args(*@args)}",
41
+ }[@assertion]
42
+ end
43
+
44
+ private
45
+
46
+ def format_args(*args)
47
+ return "" if args.empty?
48
+ return "(#{arg_list(*args)})"
49
+ end
50
+
51
+ def arg_list(*args)
52
+ args.collect do |arg|
53
+ arg.respond_to?(:description) ? arg.description : arg.inspect
54
+ end.join(", ")
55
+ end
56
+
57
+ end
58
+
59
+ # :call-seq:
60
+ # response.should have_tag(*args, &block)
61
+ # string.should have_tag(*args, &block)
62
+ #
63
+ # wrapper for assert_select with additional support for using
64
+ # css selectors to set expectation on Strings. Use this in
65
+ # helper specs, for example, to set expectations on the results
66
+ # of helper methods.
67
+ #
68
+ # == Examples
69
+ #
70
+ # # in a controller spec
71
+ # response.should have_tag("div", "some text")
72
+ #
73
+ # # in a helper spec (person_address_tag is a method in the helper)
74
+ # person_address_tag.should have_tag("input#person_address")
75
+ #
76
+ # see documentation for assert_select at http://api.rubyonrails.org/
77
+ def have_tag(*args, &block)
78
+ AssertSelect.new(:assert_select, self, *args, &block)
79
+ end
80
+
81
+ # wrapper for a nested assert_select
82
+ #
83
+ # response.should have_tag("div#form") do
84
+ # with_tag("input#person_name[name=?]", "person[name]")
85
+ # end
86
+ #
87
+ # see documentation for assert_select at http://api.rubyonrails.org/
88
+ def with_tag(*args, &block)
89
+ should have_tag(*args, &block)
90
+ end
91
+
92
+ # wrapper for a nested assert_select with false
93
+ #
94
+ # response.should have_tag("div#1") do
95
+ # without_tag("span", "some text that shouldn't be there")
96
+ # end
97
+ #
98
+ # see documentation for assert_select at http://api.rubyonrails.org/
99
+ def without_tag(*args, &block)
100
+ should_not have_tag(*args, &block)
101
+ end
102
+
103
+ # :call-seq:
104
+ # response.should have_rjs(*args, &block)
105
+ #
106
+ # wrapper for assert_select_rjs
107
+ #
108
+ # see documentation for assert_select_rjs at http://api.rubyonrails.org/
109
+ def have_rjs(*args, &block)
110
+ AssertSelect.new(:assert_select_rjs, self, *args, &block)
111
+ end
112
+
113
+ # :call-seq:
114
+ # response.should send_email(*args, &block)
115
+ #
116
+ # wrapper for assert_select_email
117
+ #
118
+ # see documentation for assert_select_email at http://api.rubyonrails.org/
119
+ def send_email(*args, &block)
120
+ AssertSelect.new(:assert_select_email, self, *args, &block)
121
+ end
122
+
123
+ # wrapper for assert_select_encoded
124
+ #
125
+ # see documentation for assert_select_encoded at http://api.rubyonrails.org/
126
+ def with_encoded(*args, &block)
127
+ should AssertSelect.new(:assert_select_encoded, self, *args, &block)
128
+ end
129
+ end
130
+ end
131
+ end