From 4ae2cea03674f2d0614a04a55398a68d5fe1dac1 Mon Sep 17 00:00:00 2001 From: tsaleh Date: Mon, 17 Mar 2008 14:03:11 +0000 Subject: [PATCH] small refactorings git-svn-id: https://svn.thoughtbot.com/plugins/shoulda/trunk@389 7bbfaf0e-4d1d-0410-9690-a8bb5f8ef2aa --- lib/shoulda/controller_tests/formats/html.rb | 18 +++++++++++------- lib/shoulda/controller_tests/formats/xml.rb | 10 +++++----- tasks/list_tests.rake | 5 +++-- 3 files changed, 19 insertions(+), 14 deletions(-) diff --git a/lib/shoulda/controller_tests/formats/html.rb b/lib/shoulda/controller_tests/formats/html.rb index 1cc9f727..ba92bba8 100644 --- a/lib/shoulda/controller_tests/formats/html.rb +++ b/lib/shoulda/controller_tests/formats/html.rb @@ -9,8 +9,12 @@ module ThoughtBot # :nodoc: end module ClassMethods + def controller_name_from_class + self.name.gsub(/Test/, '') + end + def make_show_html_tests(res) - context "on GET to :show" do + context "on GET to #{controller_name_from_class}#show" do setup do record = get_existing_record(res) parent_params = make_parent_params(res, record) @@ -31,7 +35,7 @@ module ThoughtBot # :nodoc: end def make_edit_html_tests(res) - context "on GET to :edit" do + context "on GET to #{controller_name_from_class}#edit" do setup do @record = get_existing_record(res) parent_params = make_parent_params(res, @record) @@ -56,7 +60,7 @@ module ThoughtBot # :nodoc: end def make_index_html_tests(res) - context "on GET to :index" do + context "on GET to #{controller_name_from_class}#index" do setup do record = get_existing_record(res) rescue nil parent_params = make_parent_params(res, record) @@ -77,7 +81,7 @@ module ThoughtBot # :nodoc: end def make_new_html_tests(res) - context "on GET to :new" do + context "on GET to #{controller_name_from_class}#new" do setup do record = get_existing_record(res) rescue nil parent_params = make_parent_params(res, record) @@ -99,7 +103,7 @@ module ThoughtBot # :nodoc: end def make_destroy_html_tests(res) - context "on DELETE to :destroy" do + context "on DELETE to #{controller_name_from_class}#destroy" do setup do @record = get_existing_record(res) parent_params = make_parent_params(res, @record) @@ -131,7 +135,7 @@ module ThoughtBot # :nodoc: end def make_create_html_tests(res) - context "on POST to :create with #{res.create.params.inspect}" do + context "on POST to #{controller_name_from_class}#create with #{res.create.params.inspect}" do setup do record = get_existing_record(res) rescue nil parent_params = make_parent_params(res, record) @@ -164,7 +168,7 @@ module ThoughtBot # :nodoc: end def make_update_html_tests(res) - context "on PUT to :update with #{res.create.params.inspect}" do + context "on PUT to #{controller_name_from_class}#update with #{res.create.params.inspect}" do setup do @record = get_existing_record(res) parent_params = make_parent_params(res, @record) diff --git a/lib/shoulda/controller_tests/formats/xml.rb b/lib/shoulda/controller_tests/formats/xml.rb index 8a9bf8a2..f3c16f18 100644 --- a/lib/shoulda/controller_tests/formats/xml.rb +++ b/lib/shoulda/controller_tests/formats/xml.rb @@ -28,7 +28,7 @@ module ThoughtBot # :nodoc: protected def make_show_xml_tests(res) # :nodoc: - context "on GET to :show as xml" do + context "on GET to #{controller_name_from_class}#show as xml" do setup do request_xml record = get_existing_record(res) @@ -56,7 +56,7 @@ module ThoughtBot # :nodoc: end def make_index_xml_tests(res) # :nodoc: - context "on GET to :index as xml" do + context "on GET to #{controller_name_from_class}#index as xml" do setup do request_xml parent_params = make_parent_params(res) @@ -75,7 +75,7 @@ module ThoughtBot # :nodoc: end def make_destroy_xml_tests(res) # :nodoc: - context "on DELETE to :destroy as xml" do + context "on DELETE to #{controller_name_from_class}#destroy as xml" do setup do request_xml @record = get_existing_record(res) @@ -100,7 +100,7 @@ module ThoughtBot # :nodoc: end def make_create_xml_tests(res) # :nodoc: - context "on POST to :create as xml" do + context "on POST to #{controller_name_from_class}#create as xml" do setup do request_xml parent_params = make_parent_params(res) @@ -126,7 +126,7 @@ module ThoughtBot # :nodoc: end def make_update_xml_tests(res) # :nodoc: - context "on PUT to :update as xml" do + context "on PUT to #{controller_name_from_class}#update as xml" do setup do request_xml @record = get_existing_record(res) diff --git a/tasks/list_tests.rake b/tasks/list_tests.rake index ab503eaf..38ce36a9 100644 --- a/tasks/list_tests.rake +++ b/tasks/list_tests.rake @@ -14,9 +14,10 @@ namespace :shoulda do load file klass = File.basename(file, '.rb').classify.constantize - puts + puts klass.name.gsub('Test', '') + test_methods = klass.instance_methods.grep(/^test/).map {|s| s.gsub(/^test: /, '')}.sort - test_methods.each {|m| puts m } + test_methods.each {|m| puts " " + m } end end end