rspec-rails 1.1.12 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (124) hide show
  1. data/.document +7 -0
  2. data/History.txt +55 -0
  3. data/License.txt +1 -1
  4. data/Manifest.txt +53 -48
  5. data/README.txt +5 -4
  6. data/Rakefile +9 -2
  7. data/TODO.txt +1 -0
  8. data/Upgrade.markdown +103 -0
  9. data/generators/rspec/rspec_generator.rb +1 -0
  10. data/generators/rspec/templates/rspec.rake +134 -111
  11. data/generators/rspec/templates/script/autospec +1 -0
  12. data/generators/rspec/templates/script/spec +21 -4
  13. data/generators/rspec/templates/script/spec_server +34 -107
  14. data/generators/rspec/templates/spec_helper.rb +1 -1
  15. data/generators/rspec_controller/rspec_controller_generator.rb +1 -5
  16. data/generators/rspec_scaffold/rspec_scaffold_generator.rb +13 -17
  17. data/generators/rspec_scaffold/templates/controller_spec.rb +27 -29
  18. data/generators/rspec_scaffold/templates/edit_erb_spec.rb +2 -2
  19. data/generators/rspec_scaffold/templates/helper_spec.rb +1 -1
  20. data/generators/rspec_scaffold/templates/index_erb_spec.rb +2 -2
  21. data/generators/rspec_scaffold/templates/new_erb_spec.rb +2 -2
  22. data/generators/rspec_scaffold/templates/routing_spec.rb +24 -20
  23. data/generators/rspec_scaffold/templates/show_erb_spec.rb +2 -2
  24. data/lib/spec/rails.rb +10 -9
  25. data/lib/spec/rails/example.rb +2 -2
  26. data/lib/spec/rails/example/assigns_hash_proxy.rb +1 -2
  27. data/lib/spec/rails/example/controller_example_group.rb +117 -123
  28. data/lib/spec/rails/example/functional_example_group.rb +7 -22
  29. data/lib/spec/rails/example/helper_example_group.rb +15 -33
  30. data/lib/spec/rails/example/model_example_group.rb +1 -1
  31. data/lib/spec/rails/example/render_observer.rb +0 -26
  32. data/lib/spec/rails/example/routing_example_group.rb +13 -0
  33. data/lib/spec/rails/example/routing_helpers.rb +68 -0
  34. data/lib/spec/rails/example/view_example_group.rb +50 -47
  35. data/lib/spec/rails/extensions.rb +2 -1
  36. data/lib/spec/rails/extensions/action_controller/rescue.rb +25 -8
  37. data/lib/spec/rails/extensions/action_controller/test_case.rb +16 -0
  38. data/lib/spec/rails/extensions/action_controller/test_response.rb +4 -3
  39. data/lib/spec/rails/extensions/action_view/base.rb +9 -9
  40. data/lib/spec/rails/extensions/active_record/base.rb +39 -23
  41. data/lib/spec/rails/extensions/active_support/test_case.rb +7 -0
  42. data/lib/spec/rails/extensions/spec/matchers/have.rb +8 -6
  43. data/lib/spec/rails/extensions/spec/runner/configuration.rb +12 -44
  44. data/lib/spec/rails/matchers/ar_be_valid.rb +8 -5
  45. data/lib/spec/rails/matchers/assert_select.rb +36 -21
  46. data/lib/spec/rails/matchers/have_text.rb +3 -3
  47. data/lib/spec/rails/matchers/include_text.rb +4 -4
  48. data/lib/spec/rails/matchers/redirect_to.rb +30 -19
  49. data/lib/spec/rails/matchers/render_template.rb +7 -3
  50. data/lib/spec/rails/mocks.rb +1 -1
  51. data/lib/spec/rails/spec_server.rb +97 -0
  52. data/lib/spec/rails/story_adapter.rb +4 -4
  53. data/lib/spec/rails/version.rb +2 -2
  54. data/spec/resources/controllers/controller_spec_controller.rb +14 -6
  55. data/spec/resources/controllers/example.txt +1 -0
  56. data/spec/resources/controllers/redirect_spec_controller.rb +4 -0
  57. data/spec/resources/controllers/render_spec_controller.rb +1 -1
  58. data/spec/resources/controllers/rjs_spec_controller.rb +1 -1
  59. data/spec/resources/helpers/explicit_helper.rb +1 -1
  60. data/spec/resources/views/controller_spec/{_partial.rhtml → _partial.html.erb} +0 -0
  61. data/spec/resources/views/controller_spec/{action_setting_flash_after_session_reset.rhtml → action_setting_flash_after_session_reset.html.erb} +0 -0
  62. data/spec/resources/views/controller_spec/{action_setting_flash_before_session_reset.rhtml → action_setting_flash_before_session_reset.html.erb} +0 -0
  63. data/spec/resources/views/controller_spec/{action_setting_the_assigns_hash.rhtml → action_setting_the_assigns_hash.html.erb} +0 -0
  64. data/spec/resources/views/controller_spec/{action_with_errors_in_template.rhtml → action_with_errors_in_template.html.erb} +0 -0
  65. data/spec/resources/views/controller_spec/{action_with_template.rhtml → action_with_template.html.erb} +0 -0
  66. data/spec/resources/views/layouts/{application.rhtml → application.html.erb} +0 -0
  67. data/spec/resources/views/layouts/{simple.rhtml → simple.html.erb} +0 -0
  68. data/spec/resources/views/render_spec/{_a_partial.rhtml → _a_partial.html.erb} +0 -0
  69. data/spec/resources/views/render_spec/{action_with_alternate_layout.rhtml → action_with_alternate_layout.html.erb} +0 -0
  70. data/spec/resources/views/rjs_spec/{_replacement_partial.rhtml → _replacement_partial.html.erb} +0 -0
  71. data/spec/resources/views/rjs_spec/{hide_div.rjs → hide_div.js.rjs} +0 -0
  72. data/spec/resources/views/rjs_spec/{hide_page_element.rjs → hide_page_element.js.rjs} +0 -0
  73. data/spec/resources/views/rjs_spec/{insert_html.rjs → insert_html.js.rjs} +0 -0
  74. data/spec/resources/views/rjs_spec/{replace.rjs → replace.js.rjs} +0 -0
  75. data/spec/resources/views/rjs_spec/{replace_html.rjs → replace_html.js.rjs} +0 -0
  76. data/spec/resources/views/rjs_spec/{replace_html_with_partial.rjs → replace_html_with_partial.js.rjs} +0 -0
  77. data/spec/resources/views/rjs_spec/{visual_effect.rjs → visual_effect.js.rjs} +0 -0
  78. data/spec/resources/views/rjs_spec/{visual_toggle_effect.rjs → visual_toggle_effect.js.rjs} +0 -0
  79. data/spec/resources/views/tag_spec/{no_tags.rhtml → no_tags.html.erb} +0 -0
  80. data/spec/resources/views/tag_spec/{single_div_with_no_attributes.rhtml → single_div_with_no_attributes.html.erb} +0 -0
  81. data/spec/resources/views/tag_spec/{single_div_with_one_attribute.rhtml → single_div_with_one_attribute.html.erb} +0 -0
  82. data/spec/resources/views/view_spec/{_partial.rhtml → _partial.html.erb} +0 -0
  83. data/spec/resources/views/view_spec/{_partial_used_twice.rhtml → _partial_used_twice.html.erb} +0 -0
  84. data/spec/resources/views/view_spec/{_partial_with_local_variable.rhtml → _partial_with_local_variable.html.erb} +0 -0
  85. data/spec/resources/views/view_spec/{_partial_with_sub_partial.rhtml → _partial_with_sub_partial.html.erb} +0 -0
  86. data/spec/resources/views/view_spec/{_spacer.rhtml → _spacer.html.erb} +0 -0
  87. data/spec/resources/views/view_spec/{accessor.rhtml → accessor.html.erb} +0 -0
  88. data/spec/resources/views/view_spec/{block_helper.rhtml → block_helper.html.erb} +0 -0
  89. data/spec/resources/views/view_spec/{entry_form.rhtml → entry_form.html.erb} +0 -0
  90. data/spec/resources/views/view_spec/{explicit_helper.rhtml → explicit_helper.html.erb} +0 -0
  91. data/spec/resources/views/view_spec/foo/{show.rhtml → show.html.erb} +0 -0
  92. data/spec/resources/views/view_spec/{implicit_helper.rhtml → implicit_helper.html.erb} +0 -0
  93. data/spec/resources/views/view_spec/{multiple_helpers.rhtml → multiple_helpers.html.erb} +0 -0
  94. data/spec/resources/views/view_spec/{should_not_receive.rhtml → should_not_receive.html.erb} +0 -0
  95. data/spec/resources/views/view_spec/{template_with_partial.rhtml → template_with_partial.html.erb} +0 -0
  96. data/spec/resources/views/view_spec/{template_with_partial_using_collection.rhtml → template_with_partial_using_collection.html.erb} +0 -0
  97. data/spec/resources/views/view_spec/{template_with_partial_with_array.rhtml → template_with_partial_with_array.html.erb} +0 -0
  98. data/spec/spec/rails/example/assigns_hash_proxy_spec.rb +18 -5
  99. data/spec/spec/rails/example/configuration_spec.rb +15 -29
  100. data/spec/spec/rails/example/{controller_spec_spec.rb → controller_example_group_spec.rb} +40 -96
  101. data/spec/spec/rails/example/cookies_proxy_spec.rb +32 -36
  102. data/spec/spec/rails/example/error_handling_spec.rb +90 -0
  103. data/spec/spec/rails/example/example_group_factory_spec.rb +5 -5
  104. data/spec/spec/rails/example/{helper_spec_spec.rb → helper_example_group_spec.rb} +45 -13
  105. data/spec/spec/rails/example/{model_spec_spec.rb → model_example_group_spec.rb} +3 -1
  106. data/spec/spec/rails/example/routing_example_group_spec.rb +9 -0
  107. data/spec/spec/rails/example/shared_routing_example_group_examples.rb +45 -0
  108. data/spec/spec/rails/example/test_unit_assertion_accessibility_spec.rb +1 -1
  109. data/spec/spec/rails/example/{view_spec_spec.rb → view_example_group_spec.rb} +44 -17
  110. data/spec/spec/rails/matchers/ar_be_valid_spec.rb +10 -0
  111. data/spec/spec/rails/matchers/assert_select_spec.rb +59 -60
  112. data/spec/spec/rails/matchers/have_text_spec.rb +12 -4
  113. data/spec/spec/rails/matchers/include_text_spec.rb +11 -13
  114. data/spec/spec/rails/matchers/redirect_to_spec.rb +224 -189
  115. data/spec/spec/rails/matchers/render_template_spec.rb +169 -158
  116. data/spec/spec/rails/spec_server_spec.rb +18 -7
  117. data/spec/spec_helper.rb +21 -9
  118. metadata +68 -53
  119. data/lib/spec/rails/example/rails_example_group.rb +0 -28
  120. data/lib/spec/rails/extensions/action_controller/base.rb +0 -14
  121. data/rspec-rails.gemspec +0 -36
  122. data/spec/resources/views/render_spec/some_action.rjs +0 -1
  123. data/spec/spec/rails/example/shared_behaviour_spec.rb +0 -16
  124. data/spec/spec/rails/extensions/action_controller_rescue_action_spec.rb +0 -57
@@ -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
@@ -9,9 +9,10 @@ module ActionController #:nodoc:
9
9
  if ::Rails::VERSION::STRING < "2.3"
10
10
  def [](name)
11
11
  Kernel.warn <<-WARNING
12
- [](name) as an alias for capture(name) (TestResponse extension in rspec-rails)
13
- is deprecated and will be removed in the rspec-rails release that follows the
14
- rails-2.3.0 release.
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.
15
16
  WARNING
16
17
  capture(name)
17
18
  end
@@ -3,8 +3,7 @@ module ActionView #:nodoc:
3
3
  include Spec::Rails::Example::RenderObserver
4
4
  cattr_accessor :base_view_path
5
5
 
6
- alias_method :orig_render_partial, :render_partial
7
- def render_partial(partial_path, local_assigns = nil, deprecated_local_assigns = nil) #:nodoc:
6
+ def render_partial_with_base_view_path_handling(partial_path, local_assigns = nil, deprecated_local_assigns = nil) #:nodoc:
8
7
  if partial_path.is_a?(String)
9
8
  unless partial_path.include?("/")
10
9
  unless self.class.base_view_path.nil?
@@ -13,21 +12,22 @@ module ActionView #:nodoc:
13
12
  end
14
13
  end
15
14
  begin
16
- orig_render_partial(partial_path, local_assigns, deprecated_local_assigns)
15
+ render_partial_without_base_view_path_handling(partial_path, local_assigns, deprecated_local_assigns)
17
16
  rescue ArgumentError # edge rails > 2.1 changed render_partial to accept only one arg
18
- orig_render_partial(partial_path)
17
+ render_partial_without_base_view_path_handling(partial_path)
19
18
  end
20
19
  end
20
+ alias_method_chain :render_partial, :base_view_path_handling
21
21
 
22
- alias_method :orig_render, :render
23
- def render(options = {}, old_local_assigns = {}, &block)
24
- if render_proxy.send(:__mock_proxy).send(:find_matching_expectation, :render, options)
22
+ def render_with_mock_proxy(options = {}, old_local_assigns = {}, &block)
23
+ if render_proxy.__send__(:__mock_proxy).__send__(:find_matching_expectation, :render, options)
25
24
  render_proxy.render(options)
26
25
  else
27
- unless render_proxy.send(:__mock_proxy).send(:find_matching_method_stub, :render, options)
28
- orig_render(options, old_local_assigns, &block)
26
+ unless render_proxy.__send__(:__mock_proxy).__send__(:find_matching_method_stub, :render, options)
27
+ render_without_mock_proxy(options, old_local_assigns, &block)
29
28
  end
30
29
  end
31
30
  end
31
+ alias_method_chain :render, :mock_proxy
32
32
  end
33
33
  end
@@ -1,29 +1,45 @@
1
1
  if defined?(ActiveRecord::Base)
2
- module ActiveRecord #:nodoc:
3
- class Base
4
- class << self
5
- # Extension for <tt>should have</tt> on AR Model classes
6
- #
7
- # ModelClass.should have(:no).records
8
- # ModelClass.should have(1).record
9
- # ModelClass.should have(n).records
10
- def records
11
- find(:all)
12
- end
13
- alias :record :records
14
- end
2
+ module Spec
3
+ module Rails
4
+ module Extensions
5
+ module ActiveRecord
6
+ module ClassMethods
7
+ # :call-seq:
8
+ # ModelClass.should have(:no).records
9
+ # ModelClass.should have(1).record
10
+ # ModelClass.should have(n).records
11
+ #
12
+ # Extension to enhance <tt>should have</tt> on AR Model classes
13
+ def records
14
+ find(:all)
15
+ end
16
+ alias :record :records
17
+ end
15
18
 
16
- # Extension for <tt>should have</tt> on AR Model instances
17
- #
18
- # model.should have(:no).errors_on(:attribute)
19
- # model.should have(1).error_on(:attribute)
20
- # model.should have(n).errors_on(:attribute)
21
- def errors_on(attribute)
22
- self.valid?
23
- [self.errors.on(attribute)].flatten.compact
19
+ module InstanceMethods
20
+ # :call-seq:
21
+ # model.should have(:no).errors_on(:attribute)
22
+ # model.should have(1).error_on(:attribute)
23
+ # model.should have(n).errors_on(:attribute)
24
+ #
25
+ # Extension to enhance <tt>should have</tt> on AR Model instances.
26
+ # Calls model.valid? in order to prepare the object's errors
27
+ # object.
28
+ def errors_on(attribute)
29
+ self.valid?
30
+ [self.errors.on(attribute)].flatten.compact
31
+ end
32
+ alias :error_on :errors_on
33
+ end
34
+ end
24
35
  end
25
- alias :error_on :errors_on
26
-
36
+ end
37
+ end
38
+
39
+ module ActiveRecord #:nodoc:
40
+ class Base
41
+ extend Spec::Rails::Extensions::ActiveRecord::ClassMethods
42
+ include Spec::Rails::Extensions::ActiveRecord::InstanceMethods
27
43
  end
28
44
  end
29
45
  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
+
@@ -3,19 +3,21 @@ require 'spec/matchers/have'
3
3
  module Spec #:nodoc:
4
4
  module Matchers #:nodoc:
5
5
  class Have #:nodoc:
6
- alias_method :__original_failure_message, :failure_message
7
- def failure_message
6
+
7
+ def failure_message_for_should_with_errors_on_extensions
8
8
  return "expected #{relativities[@relativity]}#{@expected} errors on :#{@args[0]}, got #{@given}" if @collection_name == :errors_on
9
9
  return "expected #{relativities[@relativity]}#{@expected} error on :#{@args[0]}, got #{@given}" if @collection_name == :error_on
10
- return __original_failure_message
10
+ return failure_message_without_errors_on_extensions
11
11
  end
12
+ alias_method_chain :failure_message_for_should, :errors_on_extensions
12
13
 
13
- alias_method :__original_description, :description
14
- def description
14
+ def description_with_errors_on_extensions
15
15
  return "should have #{relativities[@relativity]}#{@expected} errors on :#{@args[0]}" if @collection_name == :errors_on
16
16
  return "should have #{relativities[@relativity]}#{@expected} error on :#{@args[0]}" if @collection_name == :error_on
17
- return __original_description
17
+ return description_without_errors_on_extensions
18
18
  end
19
+ alias_method_chain :description, :errors_on_extensions
20
+
19
21
  end
20
22
  end
21
23
  end
@@ -1,76 +1,44 @@
1
1
  require 'spec/runner/configuration'
2
2
  require 'test_help'
3
3
 
4
- begin
5
- module Spec
6
- module Runner
7
- class Configuration
4
+ if defined?(ActiveRecord::Base)
5
+ module Spec
6
+ module Runner
7
+ class Configuration
8
8
 
9
- TEST_CASE = ActiveSupport.const_defined?(:TestCase) ? ActiveSupport::TestCase : Test::Unit::TestCase
10
-
11
- # Rails 1.2.3 does a copy of the @inheritable_attributes to the subclass when the subclass is
12
- # created. This causes an ordering issue when setting state on Configuration because the data is
13
- # already copied.
14
- # Iterating over EXAMPLE_GROUP_CLASSES causes the base ExampleGroup classes to have their
15
- # @inheritable_attributes updated.
16
- # TODO: BT - When we no longer support Rails 1.2.3, we can remove this functionality
17
- EXAMPLE_GROUP_CLASSES = [
18
- TEST_CASE,
19
- ::Spec::Rails::Example::RailsExampleGroup,
20
- ::Spec::Rails::Example::FunctionalExampleGroup,
21
- ::Spec::Rails::Example::ControllerExampleGroup,
22
- ::Spec::Rails::Example::ViewExampleGroup,
23
- ::Spec::Rails::Example::HelperExampleGroup,
24
- ::Spec::Rails::Example::ModelExampleGroup
25
- ]
26
- # All of this is ActiveRecord related and makes no sense if it's not used by the app
27
- if defined?(ActiveRecord::Base)
28
9
  def initialize
29
10
  super
30
11
  self.fixture_path = RAILS_ROOT + '/spec/fixtures'
31
12
  end
32
13
 
33
14
  def use_transactional_fixtures
34
- TEST_CASE.use_transactional_fixtures
15
+ ActiveSupport::TestCase.use_transactional_fixtures
35
16
  end
36
17
  def use_transactional_fixtures=(value)
37
- EXAMPLE_GROUP_CLASSES.each do |example_group|
38
- example_group.use_transactional_fixtures = value
39
- end
18
+ ActiveSupport::TestCase.use_transactional_fixtures = value
40
19
  end
41
20
 
42
21
  def use_instantiated_fixtures
43
- TEST_CASE.use_instantiated_fixtures
22
+ ActiveSupport::TestCase.use_instantiated_fixtures
44
23
  end
45
24
  def use_instantiated_fixtures=(value)
46
- EXAMPLE_GROUP_CLASSES.each do |example_group|
47
- example_group.use_instantiated_fixtures = value
48
- end
25
+ ActiveSupport::TestCase.use_instantiated_fixtures = value
49
26
  end
50
27
 
51
28
  def fixture_path
52
- TEST_CASE.fixture_path
29
+ ActiveSupport::TestCase.fixture_path
53
30
  end
54
31
  def fixture_path=(path)
55
- EXAMPLE_GROUP_CLASSES.each do |example_group|
56
- example_group.fixture_path = path
57
- end
32
+ ActiveSupport::TestCase.fixture_path = path
58
33
  end
59
34
 
60
35
  def global_fixtures
61
- TEST_CASE.fixture_table_names
36
+ ActiveSupport::TestCase.fixture_table_names
62
37
  end
63
38
  def global_fixtures=(fixtures)
64
- EXAMPLE_GROUP_CLASSES.each do |example_group|
65
- example_group.fixtures(*fixtures)
66
- end
39
+ ActiveSupport::TestCase.fixtures(*fixtures)
67
40
  end
68
41
  end
69
42
  end
70
43
  end
71
44
  end
72
- rescue Exception => e
73
- puts e.message
74
- puts e.backtrace
75
- raise e
76
- end
@@ -6,7 +6,7 @@ module Spec
6
6
 
7
7
  def initialize
8
8
  @matcher = Spec::Matchers::Be.new :be_valid
9
- @matcher.send :handling_predicate!
9
+ @matcher.__send__ :handling_predicate!
10
10
  end
11
11
 
12
12
  def matches?(actual)
@@ -14,19 +14,22 @@ module Spec
14
14
  @matcher.matches? @actual
15
15
  end
16
16
 
17
- def failure_message
17
+ def failure_message_for_should
18
18
  if @actual.respond_to?(:errors) &&
19
19
  ActiveRecord::Errors === @actual.errors
20
20
  "Expected #{@actual.inspect} to be valid, but it was not\nErrors: " + @actual.errors.full_messages.join(", ")
21
21
  else
22
- @matcher.failure_message
22
+ @matcher.failure_message_for_should
23
23
  end
24
24
  end
25
25
 
26
- def negative_failure_message
27
- @matcher.negative_failure_message
26
+ def failure_message_for_should_not
27
+ @matcher.failure_message_for_should_not
28
28
  end
29
29
 
30
+ def description
31
+ "be valid"
32
+ end
30
33
  end
31
34
 
32
35
  # :call-seq:
@@ -5,7 +5,7 @@ module Spec # :nodoc:
5
5
  module Matchers
6
6
 
7
7
  class AssertSelect #:nodoc:
8
-
8
+
9
9
  def initialize(assertion, spec_scope, *args, &block)
10
10
  @assertion = assertion
11
11
  @spec_scope = spec_scope
@@ -14,25 +14,22 @@ module Spec # :nodoc:
14
14
  end
15
15
 
16
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
17
  @block = block if block
18
+
19
+ if doc = doc_from(response_or_text)
20
+ @args.unshift(doc)
21
+ end
22
+
26
23
  begin
27
- @spec_scope.send(@assertion, *@args, &@block)
24
+ @spec_scope.__send__(@assertion, *@args, &@block)
25
+ true
28
26
  rescue ::Test::Unit::AssertionFailedError => @error
27
+ false
29
28
  end
30
-
31
- @error.nil?
32
29
  end
33
-
34
- def failure_message; @error.message; end
35
- def negative_failure_message; "should not #{description}, but did"; end
30
+
31
+ def failure_message_for_should; @error.message; end
32
+ def failure_message_for_should_not; "should not #{description}, but did"; end
36
33
 
37
34
  def description
38
35
  {
@@ -43,13 +40,31 @@ module Spec # :nodoc:
43
40
 
44
41
  private
45
42
 
43
+ module TestResponseOrString
44
+ def test_response?
45
+ ActionController::TestResponse === self and
46
+ !self.headers['Content-Type'].blank? and
47
+ self.headers['Content-Type'].to_sym == :xml
48
+ end
49
+
50
+ def string?
51
+ String === self
52
+ end
53
+ end
54
+
55
+ def doc_from(response_or_text)
56
+ response_or_text.extend TestResponseOrString
57
+ markup = response_or_text.body if response_or_text.test_response?
58
+ markup = response_or_text if response_or_text.string?
59
+ HTML::Document.new(markup, false, true).root if markup
60
+ end
61
+
46
62
  def format_args(*args)
47
- return "" if args.empty?
48
- return "(#{arg_list(*args)})"
63
+ args.empty? ? "" : "(#{arg_list(*args)})"
49
64
  end
50
65
 
51
66
  def arg_list(*args)
52
- args.collect do |arg|
67
+ args.map do |arg|
53
68
  arg.respond_to?(:description) ? arg.description : arg.inspect
54
69
  end.join(", ")
55
70
  end
@@ -75,7 +90,7 @@ module Spec # :nodoc:
75
90
  #
76
91
  # see documentation for assert_select at http://api.rubyonrails.org/
77
92
  def have_tag(*args, &block)
78
- AssertSelect.new(:assert_select, self, *args, &block)
93
+ @__current_scope_for_assert_select = AssertSelect.new(:assert_select, self, *args, &block)
79
94
  end
80
95
 
81
96
  # wrapper for a nested assert_select
@@ -86,7 +101,7 @@ module Spec # :nodoc:
86
101
  #
87
102
  # see documentation for assert_select at http://api.rubyonrails.org/
88
103
  def with_tag(*args, &block)
89
- should have_tag(*args, &block)
104
+ @__current_scope_for_assert_select.should have_tag(*args, &block)
90
105
  end
91
106
 
92
107
  # wrapper for a nested assert_select with false
@@ -97,7 +112,7 @@ module Spec # :nodoc:
97
112
  #
98
113
  # see documentation for assert_select at http://api.rubyonrails.org/
99
114
  def without_tag(*args, &block)
100
- should_not have_tag(*args, &block)
115
+ @__current_scope_for_assert_select.should_not have_tag(*args, &block)
101
116
  end
102
117
 
103
118
  # :call-seq:
@@ -14,15 +14,15 @@ module Spec
14
14
  return actual == expected unless Regexp === expected
15
15
  end
16
16
 
17
- def failure_message
17
+ def failure_message_for_should
18
18
  "expected #{expected.inspect}, got #{actual.inspect}"
19
19
  end
20
20
 
21
- def negative_failure_message
21
+ def failure_message_for_should_not
22
22
  "expected not to have text #{expected.inspect}"
23
23
  end
24
24
 
25
- def to_s
25
+ def description
26
26
  "have text #{expected.inspect}"
27
27
  end
28
28
 
@@ -13,15 +13,15 @@ module Spec
13
13
  return actual.include?(expected)
14
14
  end
15
15
 
16
- def failure_message
16
+ def failure_message_for_should
17
17
  "expected to find #{expected.inspect} in #{actual.inspect}"
18
18
  end
19
19
 
20
- def negative_failure_message
20
+ def failure_message_for_should_not
21
21
  "expected not to include text #{expected.inspect}"
22
22
  end
23
23
 
24
- def to_s
24
+ def description
25
25
  "include text #{expected.inspect}"
26
26
  end
27
27
 
@@ -51,4 +51,4 @@ module Spec
51
51
 
52
52
  end
53
53
  end
54
- end
54
+ end