Change should_assign_to and should_not_assign_to to allow multiple names (#22)

This commit is contained in:
Bob Showalter 2008-07-31 11:26:27 -04:00
parent 0de2794be2
commit cefcfe1205
2 changed files with 26 additions and 10 deletions

View File

@ -336,25 +336,31 @@ module ThoughtBot # :nodoc:
should_set_the_flash_to nil
end
# Macro that creates a test asserting that the controller assigned to @name
# Macro that creates a test asserting that the controller assigned to
# each of the named instance variable(s).
#
# Example:
#
# should_assign_to :user
def should_assign_to(name)
should "assign @#{name}" do
assert assigns(name.to_sym), "The action isn't assigning to @#{name}"
# should_assign_to :user, :posts
def should_assign_to(*names)
names.each do |name|
should "assign @#{name}" do
assert assigns(name.to_sym), "The action isn't assigning to @#{name}"
end
end
end
# Macro that creates a test asserting that the controller did not assign to @name
# 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
def should_not_assign_to(name)
should "not assign to @#{name}" do
assert !assigns(name.to_sym), "@#{name} was visible"
# should_not_assign_to :user, :posts
def should_not_assign_to(*names)
names.each do |name|
should "not assign to @#{name}" do
assert !assigns(name.to_sym), "@#{name} was visible"
end
end
end

View File

@ -39,5 +39,15 @@ class PostsControllerTest < Test::Unit::TestCase
resource.create.params = { :title => "first post", :body => 'blah blah blah'}
resource.update.params = { :title => "changed" }
end
context "viewing posts for a user" do
setup do
get :index, :user_id => users(:first)
end
should_respond_with :success
should_assign_to :user, :posts
should_not_assign_to :foo, :bar
end
end
end