diff --git a/lib/shoulda/action_controller/macros.rb b/lib/shoulda/action_controller/macros.rb index e9eb6dda..283a340f 100644 --- a/lib/shoulda/action_controller/macros.rb +++ b/lib/shoulda/action_controller/macros.rb @@ -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 diff --git a/lib/shoulda/action_view.rb b/lib/shoulda/action_view.rb deleted file mode 100644 index 2615b637..00000000 --- a/lib/shoulda/action_view.rb +++ /dev/null @@ -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 diff --git a/lib/shoulda/action_view/macros.rb b/lib/shoulda/action_view/macros.rb deleted file mode 100644 index 9a7b4811..00000000 --- a/lib/shoulda/action_view/macros.rb +++ /dev/null @@ -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
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 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 - diff --git a/lib/shoulda/active_record/macros.rb b/lib/shoulda/active_record/macros.rb index ed684dea..4449c7e7 100644 --- a/lib/shoulda/active_record/macros.rb +++ b/lib/shoulda/active_record/macros.rb @@ -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 diff --git a/lib/shoulda/active_record/matchers.rb b/lib/shoulda/active_record/matchers.rb index ed228755..7e0ae4a4 100644 --- a/lib/shoulda/active_record/matchers.rb +++ b/lib/shoulda/active_record/matchers.rb @@ -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: diff --git a/lib/shoulda/active_record/matchers/have_named_scope_matcher.rb b/lib/shoulda/active_record/matchers/have_named_scope_matcher.rb deleted file mode 100644 index 7ead041b..00000000 --- a/lib/shoulda/active_record/matchers/have_named_scope_matcher.rb +++ /dev/null @@ -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: - # - # * in_context - 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 diff --git a/lib/shoulda/context.rb b/lib/shoulda/context.rb index 25606935..36320f3c 100644 --- a/lib/shoulda/context.rb +++ b/lib/shoulda/context.rb @@ -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 diff --git a/lib/shoulda/macros.rb b/lib/shoulda/macros.rb index 4fb764fa..69f002fa 100644 --- a/lib/shoulda/macros.rb +++ b/lib/shoulda/macros.rb @@ -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 diff --git a/lib/shoulda/rails.rb b/lib/shoulda/rails.rb index ddb2fcc2..cd62a208 100644 --- a/lib/shoulda/rails.rb +++ b/lib/shoulda/rails.rb @@ -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) diff --git a/test/functional/posts_controller_test.rb b/test/functional/posts_controller_test.rb index 5dbdff8c..b7020906 100644 --- a/test/functional/posts_controller_test.rb +++ b/test/functional/posts_controller_test.rb @@ -54,8 +54,6 @@ def setup end should_assign_to :posts should_not_assign_to :foo, :bar - should_render_page_with_metadata :description => /Posts/, :title => /index/ - should_render_page_with_metadata :keywords => "posts" end context "viewing posts for a user with rss format" do @@ -65,8 +63,12 @@ def setup end should_respond_with :success should_respond_with_content_type 'application/rss+xml' - should_respond_with_content_type :rss - should_respond_with_content_type /rss/ + context "with a symbol" do + should_respond_with_content_type :rss + end + context "with a regexp" do + should_respond_with_content_type /rss/ + end should_set_session(:mischief) { nil } should_set_session(:special) { '$2 off your next purchase' } should_set_session(:special_user_id) { @user.id } @@ -85,7 +87,6 @@ def setup should_render_with_layout :wide end should_assign_to :false_flag - should_set_the_flash_to nil should_fail do should_set_the_flash_to /.*/ end @@ -95,7 +96,6 @@ def setup setup { get :new, :user_id => users(:first) } should_render_without_layout should_not_set_the_flash - should_render_a_form end context "on POST to #create" do diff --git a/test/matchers/active_record/have_named_scope_matcher_test.rb b/test/matchers/active_record/have_named_scope_matcher_test.rb deleted file mode 100644 index cbf16311..00000000 --- a/test/matchers/active_record/have_named_scope_matcher_test.rb +++ /dev/null @@ -1,65 +0,0 @@ -require File.join(File.dirname(__FILE__), '..', '..', 'test_helper') - -class HaveNamedScopeMatcherTest < ActiveSupport::TestCase # :nodoc: - - context "an attribute with a named scope" do - setup do - define_model :example, :attr => :string do - named_scope :xyz, lambda {|n| - { :order => :attr } - } - end - @model = Example.new - end - - should "accept having a scope with the correct signature" do - assert_accepts have_named_scope("xyz(1)"), @model - end - - should "accept having a scope with the correct signature and find options" do - assert_accepts have_named_scope("xyz(1)").finding(:order => :attr), @model - end - - should "reject having a scope with incorrect find options" do - assert_rejects have_named_scope("xyz(1)"). - finding(:order => 'attr DESC'), - @model - end - - should "reject having a scope with another name" do - assert_rejects have_named_scope("abc(1)"), @model - end - - end - - should "evaluate the scope in the correct context" do - define_model :example, :attr => :string do - named_scope :xyz, lambda {|n| - { :order => n } - } - end - model = Example.new - @order = :attr - assert_accepts have_named_scope("xyz(@order)"). - finding(:order => @order). - in_context(self), - model - end - - context "a method that does not return a scope" do - setup do - klass = Class.new - klass.class_eval do - def self.xyz - 'xyz' - end - end - @model = klass.new - end - - should "reject having a named scope with that name" do - assert_rejects have_named_scope(:xyz), @model - end - end - -end diff --git a/test/other/context_test.rb b/test/other/context_test.rb index 0a5feecf..e89e0c93 100644 --- a/test/other/context_test.rb +++ b/test/other/context_test.rb @@ -158,11 +158,6 @@ class ::SomeModel; end assert_kind_of SomeModel, subject end - should "return an existing instance of the described type as the subject" do - @some_model = SomeModel.new - assert_equal @some_model, subject - end - context "with an explicit subject block" do setup { @expected = SomeModel.new } subject { @expected } diff --git a/test/other/helpers_test.rb b/test/other/helpers_test.rb index 2fe5427e..48d77a00 100644 --- a/test/other/helpers_test.rb +++ b/test/other/helpers_test.rb @@ -93,13 +93,6 @@ class HelpersTest < ActiveSupport::TestCase # :nodoc: should_change("the number of elements", :to => 4) { @a.length } should_change("the first element", :by => 0) { @a[0] } should_not_change("the first element") { @a[0] } - - # tests for deprecated behavior - should_change "@a.length", :by => 1 - should_change "@a.length", :from => 3 - should_change "@a.length", :to => 4 - should_change "@a[0]", :by => 0 - should_not_change "@a[0]" end context "after replacing it with an array of strings" do @@ -113,14 +106,6 @@ class HelpersTest < ActiveSupport::TestCase # :nodoc: should_change("the second element", :from => 2, :to => "b") { @a[1] } should_change("the third element", :from => /\d/, :to => /\w/) { @a[2] } should_change("the last element", :to => String) { @a[3] } - - # tests for deprecated behavior - should_change "@a.length", :by => 3 - should_change "@a.length", :from => 3, :to => 6, :by => 3 - should_change "@a[0]" - should_change "@a[1]", :from => 2, :to => "b" - should_change "@a[2]", :from => /\d/, :to => /\w/ - should_change "@a[3]", :to => String end end @@ -148,16 +133,6 @@ class HelpersTest < ActiveSupport::TestCase # :nodoc: should "accept a class as the first argument" do assert_good_value User, :email, "good@example.com" end - - context "with an instance variable" do - setup do - @product = Product.new(:tangible => true) - end - - should "use that instance variable" do - assert_good_value Product, :price, "9999", /included/ - end - end end context "assert_bad_value" do @@ -184,16 +159,6 @@ class HelpersTest < ActiveSupport::TestCase # :nodoc: should "accept a class as the first argument" do assert_bad_value User, :email, "bad" end - - context "with an instance variable" do - setup do - @product = Product.new(:tangible => true) - end - - should "use that instance variable" do - assert_bad_value Product, :price, "0", /included/ - end - end end context "a matching matcher" do diff --git a/test/rails_root/app/controllers/application_controller.rb b/test/rails_root/app/controllers/application_controller.rb index 10fa9876..feada87d 100644 --- a/test/rails_root/app/controllers/application_controller.rb +++ b/test/rails_root/app/controllers/application_controller.rb @@ -2,9 +2,6 @@ # Likewise, all the methods added will be available for all controllers. class ApplicationController < ActionController::Base - # Pick a unique cookie name to distinguish our session data from others' - session :session_key => '_rails_root_session_id' - def ensure_logged_in unless session[:logged_in] respond_to do |accepts| diff --git a/test/unit/user_test.rb b/test/unit/user_test.rb index 01c86539..3bf2424e 100644 --- a/test/unit/user_test.rb +++ b/test/unit/user_test.rb @@ -14,7 +14,7 @@ class UserTest < ActiveSupport::TestCase should_have_one :address, :dependent => :destroy should_have_db_indices :email, :name - should_have_index :age + should_have_db_index :age should_have_db_index [:email, :name], :unique => true should_have_db_index :age, :unique => false @@ -24,18 +24,6 @@ class UserTest < ActiveSupport::TestCase should_have_db_index :age, :unique => true end - should_have_named_scope :old, :conditions => "age > 50" - should_have_named_scope :eighteen, :conditions => { :age => 18 } - - should_have_named_scope 'recent(5)', :limit => 5 - should_have_named_scope 'recent(1)', :limit => 1 - should_have_named_scope 'recent_via_method(7)', :limit => 7 - - context "when given an instance variable" do - setup { @count = 2 } - should_have_named_scope 'recent(@count)', :limit => 2 - end - should_not_allow_values_for :email, "blah", "b lah" should_allow_values_for :email, "a@b.com", "asdf@asdf.com" should_allow_values_for :age, 1, 10, 99 @@ -44,14 +32,21 @@ class UserTest < ActiveSupport::TestCase should_ensure_length_in_range :email, 1..100 should_ensure_value_in_range :age, 1..100, :low_message => /greater/, :high_message => /less/ - should_fail do - should_ensure_value_in_range :age, 1..100, :low_message => /more/, - :high_message => /less/ + + context "with a different low message" do + should_fail do + should_ensure_value_in_range :age, 1..100, :low_message => /more/, + :high_message => /less/ + end end - should_fail do - should_ensure_value_in_range :age, 1..100, :low_message => /greater/, - :high_message => /fewer/ + + context "with a different high message" do + should_fail do + should_ensure_value_in_range :age, 1..100, :low_message => /greater/, + :high_message => /fewer/ + end end + should_not_allow_mass_assignment_of :password should_have_class_methods :find, :destroy should_have_instance_methods :email, :age, :email=, :valid?