Permalink
Browse files

Split the Controller namespace into ActionController and ActionView

  • Loading branch information...
1 parent a8f0d94 commit 33705c8b05c87526d2a4f37710db2206da532309 @jferris jferris committed Feb 9, 2009
@@ -1,14 +1,14 @@
require 'shoulda'
-require 'shoulda/controller/helpers'
-require 'shoulda/controller/matchers'
-require 'shoulda/controller/macros'
+require 'shoulda/action_controller/helpers'
+require 'shoulda/action_controller/matchers'
+require 'shoulda/action_controller/macros'
module Test # :nodoc: all
module Unit
class TestCase
- include Shoulda::Controller::Matchers
- include Shoulda::Controller::Helpers
- extend Shoulda::Controller::Macros
+ include Shoulda::ActionController::Matchers
+ include Shoulda::ActionController::Helpers
+ extend Shoulda::ActionController::Macros
end
end
end
@@ -1,5 +1,5 @@
module Shoulda # :nodoc:
- module Controller # :nodoc:
+ module ActionController # :nodoc:
module Helpers # :nodoc:
private # :enddoc:
@@ -1,5 +1,5 @@
module Shoulda # :nodoc:
- module Controller # :nodoc:
+ module ActionController # :nodoc:
# = Macro test helpers for your controllers
#
# By using the macro helpers you can quickly and easily create concise and easy to read test suites.
@@ -24,7 +24,6 @@ module Controller # :nodoc:
module Macros
include Matchers
- # :section: Test macros
# Macro that creates a test asserting that the flash contains the given value.
# val can be a String, a Regex, or nil (indicating that the flash should not be set)
#
@@ -235,35 +234,6 @@ def should_redirect_to(description, &block)
end
end
- # Macro that creates a test asserting that the rendered view contains a <form> element.
- def should_render_a_form
- should "display a form" do
- assert_select "form", true, "The template doesn't contain a <form> element"
- end
- end
-
- # Macro that creates a test asserting that the rendered view contains the selected metatags.
- # Values can be string or Regexps.
- # Example:
- #
- # should_render_page_with_metadata :description => "Description of this page", :keywords => /post/
- #
- # You can also use this method to test the rendered views title.
- #
- # Example:
- # should_render_page_with_metadata :title => /index/
- def should_render_page_with_metadata(options)
- options.each do |key, value|
- should "have metatag #{key}" do
- if key.to_sym == :title
- assert_select "title", value
- else
- assert_select "meta[name=?][content#{"*" if value.is_a?(Regexp)}=?]", key, value
- end
- end
- end
- end
-
# Macro that creates a routing test. It tries to use the given HTTP
# +method+ on the given +path+, and asserts that it routes to the
# given +options+.
@@ -1,14 +1,14 @@
-require 'shoulda/controller/matchers/assign_to_matcher'
-require 'shoulda/controller/matchers/filter_param_matcher'
-require 'shoulda/controller/matchers/set_the_flash_matcher'
-require 'shoulda/controller/matchers/render_with_layout_matcher'
-require 'shoulda/controller/matchers/respond_with_matcher'
-require 'shoulda/controller/matchers/respond_with_content_type_matcher'
-require 'shoulda/controller/matchers/set_session_matcher'
-require 'shoulda/controller/matchers/route_matcher'
+require 'shoulda/action_controller/matchers/assign_to_matcher'
+require 'shoulda/action_controller/matchers/filter_param_matcher'
+require 'shoulda/action_controller/matchers/set_the_flash_matcher'
+require 'shoulda/action_controller/matchers/render_with_layout_matcher'
+require 'shoulda/action_controller/matchers/respond_with_matcher'
+require 'shoulda/action_controller/matchers/respond_with_content_type_matcher'
+require 'shoulda/action_controller/matchers/set_session_matcher'
+require 'shoulda/action_controller/matchers/route_matcher'
module Shoulda # :nodoc:
- module Controller # :nodoc:
+ module ActionController # :nodoc:
# By using the macro helpers you can quickly and easily create concise and
# easy to read test suites.
@@ -1,5 +1,5 @@
module Shoulda # :nodoc:
- module Controller # :nodoc:
+ module ActionController # :nodoc:
module Matchers
# Ensures that the controller assigned to the named instance variable.
@@ -1,5 +1,5 @@
module Shoulda # :nodoc:
- module Controller # :nodoc:
+ module ActionController # :nodoc:
module Matchers
# Ensures that filter_parameter_logging is set for the specified key.
@@ -1,5 +1,5 @@
module Shoulda # :nodoc:
- module Controller # :nodoc:
+ module ActionController # :nodoc:
module Matchers
# Ensures that the controller rendered with the given layout.
@@ -1,5 +1,5 @@
module Shoulda # :nodoc:
- module Controller # :nodoc:
+ module ActionController # :nodoc:
module Matchers
# Ensures a controller responded with expected 'response' content type.
@@ -1,5 +1,5 @@
module Shoulda # :nodoc:
- module Controller # :nodoc:
+ module ActionController # :nodoc:
module Matchers
# Ensures a controller responded with expected 'response' status code.
@@ -60,7 +60,7 @@ def symbol_to_status_code(potential_symbol)
when :missing then 404
when :error then 500..599
when Symbol
- ActionController::StatusCodes::SYMBOL_TO_STATUS_CODE[potential_symbol]
+ ::ActionController::StatusCodes::SYMBOL_TO_STATUS_CODE[potential_symbol]
else
potential_symbol
end
@@ -74,4 +74,4 @@ def expectation
end
end
-end
+end
@@ -1,5 +1,5 @@
module Shoulda # :nodoc:
- module Controller # :nodoc:
+ module ActionController # :nodoc:
module Matchers
# Ensures that requesting +path+ using +method+ routes to +options+.
@@ -77,7 +77,7 @@ def route_recognized?
@negative_failure_message = "Didn't expect to #{description}"
true
- rescue ActionController::RoutingError => error
+ rescue ::ActionController::RoutingError => error
@failure_message = error.message
false
rescue Test::Unit::AssertionFailedError => error
@@ -1,5 +1,5 @@
module Shoulda # :nodoc:
- module Controller # :nodoc:
+ module ActionController # :nodoc:
module Matchers
# Ensures that a session key was set to the expected value.
@@ -1,5 +1,5 @@
module Shoulda # :nodoc:
- module Controller # :nodoc:
+ module ActionController # :nodoc:
module Matchers
# Ensures that the flash contains the given value. Can be a String, a
@@ -0,0 +1,10 @@
+require 'shoulda'
+require 'shoulda/action_view/macros'
+
+module Test # :nodoc: all
+ module Unit
+ class TestCase
+ extend Shoulda::ActionView::Macros
+ end
+ end
+end
@@ -0,0 +1,56 @@
+module Shoulda # :nodoc:
+ module ActionView # :nodoc:
+ # = Macro test helpers for your view
+ #
+ # By using the macro helpers you can quickly and easily create concise and
+ # easy to read test suites.
+ #
+ # This code segment:
+ # context "on GET to :new" do
+ # setup do
+ # get :new
+ # end
+ #
+ # should_render_a_form
+ # should_render_page_with_metadata :title => /index/
+ #
+ # should "do something else really cool" do
+ # assert_select '#really_cool'
+ # end
+ # end
+ #
+ # Would produce 3 tests for the +show+ action
+ module Macros
+
+ # Macro that creates a test asserting that the rendered view contains a <form> element.
+ def should_render_a_form
+ should "display a form" do
+ assert_select "form", true, "The template doesn't contain a <form> element"
+ end
+ end
+
+ # Macro that creates a test asserting that the rendered view contains the selected metatags.
+ # Values can be string or Regexps.
+ # Example:
+ #
+ # should_render_page_with_metadata :description => "Description of this page", :keywords => /post/
+ #
+ # You can also use this method to test the rendered views title.
+ #
+ # Example:
+ # should_render_page_with_metadata :title => /index/
+ def should_render_page_with_metadata(options)
+ options.each do |key, value|
+ should "have metatag #{key}" do
+ if key.to_sym == :title
+ assert_select "title", value
+ else
+ assert_select "meta[name=?][content#{"*" if value.is_a?(Regexp)}=?]", key, value
+ end
+ end
+ end
+ end
+ end
+ end
+end
+
@@ -2,9 +2,10 @@
require 'active_support'
require 'shoulda'
-require 'shoulda/active_record' if defined? ActiveRecord::Base
-require 'shoulda/controller' if defined? ActionController::Base
-require 'shoulda/action_mailer' if defined? ActionMailer::Base
+require 'shoulda/active_record' if defined? ActiveRecord::Base
+require 'shoulda/action_controller' if defined? ActionController::Base
+require 'shoulda/action_view' if defined? ActionView::Base
+require 'shoulda/action_mailer' if defined? ActionMailer::Base
if defined?(RAILS_ROOT)
# load in the 3rd party macros from vendorized plugins and gems

0 comments on commit 33705c8

Please sign in to comment.