Skip to content

Commit

Permalink
Update deprecation warning for should_change and should_not_change ma…
Browse files Browse the repository at this point in the history
…cros
  • Loading branch information
joshuaclayton committed Jun 22, 2010
1 parent 0d1827a commit 226f5b8
Showing 1 changed file with 32 additions and 2 deletions.
34 changes: 32 additions & 2 deletions lib/shoulda/macros.rb
Expand Up @@ -36,8 +36,23 @@ module Macros
#
# # Assert the value changed to "new:"
# should_change("the post title", :to => "new") { @post.title }
#
# This macro was deprecated because these tests aren't as valuable as
# alternative tests that explicitly test the final state.
#
# Consider an alternative:
#
# context "updating a post" do
# setup do
# @post = Post.create(:title => "old")
# put :update, :post => {:title => "new"}, :id => @post.to_param
# end
# should "update the title" do
# assert_equal "new", @post.reload.title
# end
# end
def should_change(description, options = {}, &block)
::ActiveSupport::Deprecation.warn
::ActiveSupport::Deprecation.warn("Not considered a useful test. Instead, test the end state explicitly.")
by, from, to = get_options!([options], :by, :from, :to)
stmt = "change #{description}"
stmt << " from #{from.inspect}" if from
Expand Down Expand Up @@ -69,8 +84,23 @@ def should_change(description, options = {}, &block)
# setup { @post.update_attributes(:title => "new") }
# should_not_change("the number of posts") { Post.count }
# end
#
# This macro was deprecated because these tests aren't as valuable as
# alternative tests that explicitly test the final state.
#
# Consider an alternative:
#
# context "updating a post" do
# setup do
# @post = Post.create(:title => "old")
# put :update, :post => {:title => ""}, :id => @post.to_param
# end
# should "not update the title" do
# assert_equal "old", @post.reload.title
# end
# end
def should_not_change(description, &block)
::ActiveSupport::Deprecation.warn
::ActiveSupport::Deprecation.warn("Not considered a useful test. Instead, test the end state explicitly.")
before = lambda { @_before_should_not_change = block.bind(self).call }
should "not change #{description}", :before => before do
new_value = block.bind(self).call
Expand Down

0 comments on commit 226f5b8

Please sign in to comment.