Skip to content

Instantly share code, notes, and snippets.

@bjhess
Created October 2, 2008 17:53
Show Gist options
  • Save bjhess/14410 to your computer and use it in GitHub Desktop.
Save bjhess/14410 to your computer and use it in GitHub Desktop.
# Is there a way to combine the should_redirect_to and
# should_set_the_flash_to tests since they are repeated
# in multiple contexts?
context "when valid email addresses passed" do
setup do
Group.any_instance.expects(:notify_new_memberships).once
end
context "when separated by commas" do
setup do
post :create, :group_id => @group.id, :pending_membership_emails => 'basil@fawlty.com,polly@fawlty.com'
end
should_redirect_to "edit_group_path(@group)"
should_set_the_flash_to(/notification.+sent/i)
end
context "when separated by commas and newlines" do
setup do
post :create, :group_id => @group.id, :pending_membership_emails => "basil@fawlty.com,\r\npolly@fawlty.com"
end
should_redirect_to "edit_group_path(@group)"
should_set_the_flash_to(/notification.+sent/i)
end
context "when separated by spaces" do
setup do
post :create, :group_id => @group.id, :pending_membership_emails => "basil@fawlty.com polly@fawlty.com"
end
should_redirect_to "edit_group_path(@group)"
should_set_the_flash_to(/notification.+sent/i)
end
context "when separated by newlines" do
setup do
post :create, :group_id => @group.id, :pending_membership_emails => "basil@fawlty.com\r\npolly@fawlty.com"
end
should_redirect_to "edit_group_path(@group)"
should_set_the_flash_to(/notification.+sent/i)
end
context "when separated by multiple newlines" do
setup do
post :create, :group_id => @group.id, :pending_membership_emails => "basil@fawlty.com\r\n\r\n\r\npolly@fawlty.com"
end
should_redirect_to "edit_group_path(@group)"
should_set_the_flash_to(/notification.+sent/i)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment