lib/shoulda/action_controller/macros.rb in shoulda-2.10.3 vs lib/shoulda/action_controller/macros.rb in shoulda-2.11.0

- old
+ new

@@ -22,56 +22,49 @@ # # Would produce 5 tests for the +show+ action module Macros include Matchers + # Deprecated: use ActionController::Matchers#set_the_flash instead. + # # Macro that creates a test asserting that the flash contains the given # value. Expects a +String+ or +Regexp+. # - # If the argument is +nil+, it will assert that the flash is not set. - # This behavior is deprecated. - # # Example: # # should_set_the_flash_to "Thank you for placing this order." # should_set_the_flash_to /created/i def should_set_the_flash_to(val) - if val - matcher = set_the_flash.to(val) - should matcher.description do - assert_accepts matcher, @controller - end - else - warn "[DEPRECATION] should_set_the_flash_to nil is deprecated. " << - "Use should_not_set_the_flash instead." - should_not_set_the_flash - end + ::ActiveSupport::Deprecation.warn("use: should set_the_flash") + should set_the_flash.to(val) end + # Deprecated: use ActionController::Matchers#set_the_flash instead. + # # Macro that creates a test asserting that the flash is empty. def should_not_set_the_flash - matcher = set_the_flash - should "not #{matcher.description}" do - assert_rejects matcher, @controller - end + ::ActiveSupport::Deprecation.warn("use: should_not set_the_flash") + should_not set_the_flash end + # Deprecated: use ActionController::Matchers#filter_param instead. + # # Macro that creates a test asserting that filter_parameter_logging # is set for the specified keys # # Example: # # should_filter_params :password, :ssn def should_filter_params(*keys) + ::ActiveSupport::Deprecation.warn("use: should filter_param") keys.each do |key| - matcher = filter_param(key) - should matcher.description do - assert_accepts matcher, @controller - end + should filter_param(key) end end + # Deprecated: use ActionController::Matchers#assign_to instead. + # # Macro that creates a test asserting that the controller assigned to # each of the named instance variable(s). # # Options: # * <tt>:class</tt> - The expected class of the instance variable being checked. @@ -83,128 +76,123 @@ # # should_assign_to :user, :posts # should_assign_to :user, :class => User # should_assign_to(:user) { @user } def should_assign_to(*names, &block) + ::ActiveSupport::Deprecation.warn("use: should assign_to") klass = get_options!(names, :class) names.each do |name| matcher = assign_to(name).with_kind_of(klass) - should matcher.description do - if block - expected_value = instance_eval(&block) - matcher = matcher.with(expected_value) - end - - assert_accepts matcher, @controller - end + matcher = matcher.with(&block) if block + should matcher end end + # Deprecated: use ActionController::Matchers#assign_to instead. + # # Macro that creates a test asserting that the controller did not assign to # any of the named instance variable(s). # # Example: # # should_not_assign_to :user, :posts def should_not_assign_to(*names) + ::ActiveSupport::Deprecation.warn("use: should_not assign_to") names.each do |name| - matcher = assign_to(name) - should "not #{matcher.description}" do - assert_rejects matcher, @controller - end + should_not assign_to(name) end end + # Deprecated: use ActionController::Matchers#respond_with instead. + # # Macro that creates a test asserting that the controller responded with a 'response' status code. # Example: # # should_respond_with :success def should_respond_with(response) - should "respond with #{response}" do - matcher = respond_with(response) - assert_accepts matcher, @controller - end + ::ActiveSupport::Deprecation.warn("use: should respond_with") + should respond_with(response) end + # Deprecated: use ActionController::Matchers#respond_with_content_type instead. + # # Macro that creates a test asserting that the response content type was 'content_type'. # Example: # # should_respond_with_content_type 'application/rss+xml' # should_respond_with_content_type :rss # should_respond_with_content_type /rss/ def should_respond_with_content_type(content_type) - matcher = respond_with_content_type(content_type) - should matcher.description do - assert_accepts matcher, @controller - end + ::ActiveSupport::Deprecation.warn("use: should respond_with_content_type") + should respond_with_content_type(content_type) end + # Deprecated: use ActionController::Matchers#set_session instead. + # # Macro that creates a test asserting that a value returned from the # session is correct. Expects the session key as a parameter, and a block # that returns the expected value. # # Example: # # should_set_session(:user_id) { @user.id } # should_set_session(:message) { "Free stuff" } def should_set_session(key, &block) + ::ActiveSupport::Deprecation.warn("use: should set_session") matcher = set_session(key) - should matcher.description do - expected_value = instance_eval(&block) - matcher = matcher.to(expected_value) - assert_accepts matcher, @controller - end + matcher = matcher.to(&block) if block + should matcher end + # Deprecated: use ActionController::Matchers#render_template instead. + # # Macro that creates a test asserting that the controller rendered the given template. # Example: # # should_render_template :new def should_render_template(template) - should "render template #{template.inspect}" do - assert_template template.to_s - end + ::ActiveSupport::Deprecation.warn("use: should render_template") + should render_template(template) end + # Deprecated: use ActionController::Matchers#render_with_layout instead. + # # Macro that creates a test asserting that the controller rendered with the given layout. # Example: # # should_render_with_layout 'special' def should_render_with_layout(expected_layout = 'application') - matcher = render_with_layout(expected_layout) - if expected_layout - should matcher.description do - assert_accepts matcher, @controller - end - else - should "render without layout" do - assert_rejects matcher, @controller - end - end + ::ActiveSupport::Deprecation.warn("use: should render_with_layout") + should render_with_layout(expected_layout) end + # Deprecated: use ActionController::Matchers#render_with_layout instead. + # # Macro that creates a test asserting that the controller rendered without a layout. # Same as @should_render_with_layout false@ def should_render_without_layout - should_render_with_layout nil + ::ActiveSupport::Deprecation.warn("use: should_not render_with_layout") + should_not render_with_layout end + # Deprecated: use ActionController::Matchers#redirect_to instead. + # # Macro that creates a test asserting that the controller returned a # redirect to the given path. The passed description will be used when # generating a test name. Expects a block that returns the expected path # for the redirect. # # Example: # # should_redirect_to("the user's profile") { user_url(@user) } def should_redirect_to(description, &block) - should "redirect to #{description}" do - expected_url = instance_eval(&block) - assert_redirected_to expected_url - end + ::ActiveSupport::Deprecation.warn("use: should redirect_to") + should redirect_to(description, &block) end + # Deprecated: use ActionController::Matchers#route instead. + # # 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+. # # If you don't specify a :controller, it will try to guess the controller @@ -223,18 +211,11 @@ # should_route :delete, "/posts/1", :action => :destroy, :id => 1 # should_route :get, "/users/1/posts/1", # :action => :show, :id => 1, :user_id => 1 # def should_route(method, path, options) - unless options[:controller] - options[:controller] = self.name.gsub(/ControllerTest$/, '').tableize - end - - matcher = route(method, path).to(options) - - should matcher.description do - assert_accepts matcher.in_context(self), self - end + ::ActiveSupport::Deprecation.warn("use: should route") + should route(method, path).to(options) end end end end