Permalink
Browse files

Removed deprecated functionality

  • Loading branch information...
1 parent 975bf8a commit 324bbe99a0ab3761b2c34c0623cac637523ca030 @jferris jferris committed Feb 13, 2010
@@ -27,23 +27,14 @@ module Macros
# 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
+ matcher = set_the_flash.to(val)
+ should matcher.description do
+ assert_accepts matcher, @controller
end
end
View
@@ -1,10 +0,0 @@
-require 'shoulda'
-require 'shoulda/action_view/macros'
-
-module Test # :nodoc: all
- module Unit
- class TestCase
- extend Shoulda::ActionView::Macros
- end
- end
-end
@@ -1,61 +0,0 @@
-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_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.
- #
- # Deprecated.
- def should_render_a_form
- warn "[DEPRECATION] should_render_a_form is deprecated."
- should "display a form" do
- assert_select "form", true, "The template doesn't contain a <form> element"
- end
- end
-
- # Deprecated.
- #
- # 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)
- warn "[DEPRECATION] should_render_page_with_metadata is deprecated."
- 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
-
@@ -430,20 +430,6 @@ def should_have_db_indices(*columns)
alias_method :should_have_db_index, :should_have_db_indices
- # Deprecated. See should_have_db_index
- def should_have_index(*args)
- warn "[DEPRECATION] should_have_index is deprecated. " <<
- "Use should_have_db_index instead."
- should_have_db_index(*args)
- end
-
- # Deprecated. See should_have_db_indices
- def should_have_indices(*args)
- warn "[DEPRECATION] should_have_indices is deprecated. " <<
- "Use should_have_db_indices instead."
- should_have_db_indices(*args)
- end
-
# Ensures that the model cannot be saved if one of the attributes listed is not accepted.
#
# Options:
@@ -463,50 +449,6 @@ def should_validate_acceptance_of(*attributes)
end
end
end
-
- # Deprecated.
- #
- # Ensures that the model has a method named scope_name that returns a NamedScope object with the
- # proxy options set to the options you supply. scope_name can be either a symbol, or a method
- # call which will be evaled against the model. The eval'd method call has access to all the same
- # instance variables that a should statement would.
- #
- # Options: Any of the options that the named scope would pass on to find.
- #
- # Example:
- #
- # should_have_named_scope :visible, :conditions => {:visible => true}
- #
- # Passes for
- #
- # named_scope :visible, :conditions => {:visible => true}
- #
- # Or for
- #
- # def self.visible
- # scoped(:conditions => {:visible => true})
- # end
- #
- # You can test lambdas or methods that return ActiveRecord#scoped calls:
- #
- # should_have_named_scope 'recent(5)', :limit => 5
- # should_have_named_scope 'recent(1)', :limit => 1
- #
- # Passes for
- # named_scope :recent, lambda {|c| {:limit => c}}
- #
- # Or for
- #
- # def self.recent(c)
- # scoped(:limit => c)
- # end
- #
- def should_have_named_scope(scope_call, find_options = nil)
- matcher = have_named_scope(scope_call).finding(find_options)
- should matcher.description do
- assert_accepts matcher.in_context(self), subject
- end
- end
end
end
end
@@ -13,7 +13,6 @@
require 'shoulda/active_record/matchers/have_db_index_matcher'
require 'shoulda/active_record/matchers/have_readonly_attribute_matcher'
require 'shoulda/active_record/matchers/allow_mass_assignment_of_matcher'
-require 'shoulda/active_record/matchers/have_named_scope_matcher'
module Shoulda # :nodoc:
@@ -1,128 +0,0 @@
-module Shoulda # :nodoc:
- module ActiveRecord # :nodoc:
- module Matchers
-
- # Deprecated.
- #
- # Ensures that the model has a method named scope_call that returns a
- # NamedScope object with the proxy options set to the options you supply.
- # scope_call can be either a symbol, or a Ruby expression in a String
- # which will be evaled. The eval'd method call has access to all the same
- # instance variables that an example would.
- #
- # Options:
- #
- # * <tt>in_context</tt> - Any of the options that the named scope would
- # pass on to find.
- #
- # Example:
- #
- # it { should have_named_scope(:visible).
- # finding(:conditions => {:visible => true}) }
- #
- # Passes for
- #
- # named_scope :visible, :conditions => {:visible => true}
- #
- # Or for
- #
- # def self.visible
- # scoped(:conditions => {:visible => true})
- # end
- #
- # You can test lambdas or methods that return ActiveRecord#scoped calls:
- #
- # it { should have_named_scope('recent(5)').finding(:limit => 5) }
- # it { should have_named_scope('recent(1)').finding(:limit => 1) }
- #
- # Passes for
- # named_scope :recent, lambda {|c| {:limit => c}}
- #
- # Or for
- #
- # def self.recent(c)
- # scoped(:limit => c)
- # end
- #
- def have_named_scope(scope_call)
- warn "[DEPRECATION] should_have_named_scope is deprecated."
- HaveNamedScopeMatcher.new(scope_call).in_context(self)
- end
-
- class HaveNamedScopeMatcher # :nodoc:
-
- def initialize(scope_call)
- @scope_call = scope_call.to_s
- end
-
- def finding(finding)
- @finding = finding
- self
- end
-
- def in_context(context)
- @context = context
- self
- end
-
- def matches?(subject)
- @subject = subject
- call_succeeds? && returns_scope? && finds_correct_scope?
- end
-
- def failure_message
- "Expected #{@missing_expectation}"
- end
-
- def negative_failure_message
- "Didn't expect a named scope for #{@scope_call}"
- end
-
- def description
- result = "have a named scope for #{@scope_call}"
- result << " finding #{@finding.inspect}" unless @finding.nil?
- result
- end
-
- private
-
- def call_succeeds?
- scope
- true
- rescue Exception => exception
- @missing_expectation = "#{@subject.class.name} " <<
- "to respond to #{@scope_call} " <<
- "but raised error: #{exception.inspect}"
- false
- end
-
- def scope
- @scope ||= @context.instance_eval("#{@subject.class.name}.#{@scope_call}")
- end
-
- def returns_scope?
- if ::ActiveRecord::NamedScope::Scope === scope
- true
- else
- @missing_expectation = "#{@scope_call} to return a scope"
- false
- end
- end
-
- def finds_correct_scope?
- return true if @finding.nil?
- if @finding == scope.proxy_options
- true
- else
- @missing_expectation = "#{@scope_call} to return results scoped to "
- @missing_expectation << "#{@finding.inspect} but was scoped to "
- @missing_expectation << scope.proxy_options.inspect
- false
- end
- end
-
- end
-
- end
- end
-end
View
@@ -214,19 +214,6 @@ module InstanceMethods
# end
# end
#
- # If an instance variable exists named after the described class, that
- # instance variable will be used as the subject. This behavior is
- # deprecated, and will be removed in a future version of Shoulda. The
- # recommended approach for using a different subject is to use the subject
- # class method.
- #
- # class UserTest
- # should "be the existing user" do
- # @user = User.new
- # assert_equal @user, subject # passes
- # end
- # end
- #
# The subject is used by all macros that require an instance of the class
# being tested.
def subject
@@ -239,17 +226,7 @@ def subject_block # :nodoc:
def get_instance_of(object_or_klass) # :nodoc:
if object_or_klass.is_a?(Class)
- klass = object_or_klass
- ivar = "@#{instance_variable_name_for(klass)}"
- if instance = instance_variable_get(ivar)
- warn "[WARNING] Using #{ivar} as the subject. Future versions " <<
- "of Shoulda will require an explicit subject using the " <<
- "subject class method. Add this after your setup to avoid " <<
- "this warning: subject { #{ivar} }"
- instance
- else
- klass.new
- end
+ object_or_klass.new
else
object_or_klass
end
View
@@ -41,17 +41,10 @@ def should_change(description, options = {}, &block)
stmt << " to #{to.inspect}" if to
stmt << " by #{by.inspect}" if by
- if block_given?
- code = block
- else
- warn "[DEPRECATION] should_change(expression, options) is deprecated. " <<
- "Use should_change(description, options) { code } instead."
- code = lambda { eval(description) }
- end
- before = lambda { @_before_should_change = code.bind(self).call }
+ before = lambda { @_before_should_change = block.bind(self).call }
should stmt, :before => before do
old_value = @_before_should_change
- new_value = code.bind(self).call
+ new_value = block.bind(self).call
assert_operator from, :===, old_value, "#{description} did not originally match #{from.inspect}" if from
assert_not_equal old_value, new_value, "#{description} did not change" unless by == 0
assert_operator to, :===, new_value, "#{description} was not changed to match #{to.inspect}" if to
@@ -72,16 +65,9 @@ def should_change(description, options = {}, &block)
# should_not_change("the number of posts") { Post.count }
# end
def should_not_change(description, &block)
- if block_given?
- code = block
- else
- warn "[DEPRECATION] should_not_change(expression) is deprecated. " <<
- "Use should_not_change(description) { code } instead."
- code = lambda { eval(description) }
- end
- before = lambda { @_before_should_not_change = code.bind(self).call }
+ before = lambda { @_before_should_not_change = block.bind(self).call }
should "not change #{description}", :before => before do
- new_value = code.bind(self).call
+ new_value = block.bind(self).call
assert_equal @_before_should_not_change, new_value, "#{description} changed"
end
end
View
@@ -4,7 +4,6 @@
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)
Oops, something went wrong.

0 comments on commit 324bbe9

Please sign in to comment.