The "test" method copied below complains when another test of the same name if found in another test file. The following doesn''t work... test/integration/users_test.rb test "this is a test" do ... end test/integration/forums_test.rb test "this is a test" do ... end but this does work... test/integration/users_test.rb def this_is_a_test ... end test/integration/forums_test.rb def this_is_a_test ... end What''s the purpose for "test" working this way? # File vendor/rails/activesupport/lib/active_support/testing/declarative.rb, line 7 7: def test(name, &block) 8: test_name = "test_#{name.gsub(/\s+/,''_'')}".to_sym 9: defined = instance_method(test_name) rescue false 10: raise "#{test_name} is already defined in #{self}" if defined 11: if block_given? 12: define_method(test_name, &block) 13: else 14: define_method(test_name) do 15: flunk "No implementation provided for #{name}" 16: end 17: end 18: end -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To post to this group, send email to rubyonrails-core@googlegroups.com. To unsubscribe from this group, send email to rubyonrails-core+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en.
Michael Koziarski
2009-Dec-18 08:57 UTC
Re: test "this is a test" do vs def this_is_a_test
> What''s the purpose for "test" working this way?It should only be doing this if the method you''re defining would be *replacing* another test, it shouldn''t matter if you have test with the same name in different classes. The warning''s saved me a few times before, but it''s possible that there''s a bug that''s causing the behaviour that you''re seeing. If you can reproduce it in a new app we could have a bug, but I don''t think that''s too likely given every newly generated unit test does: test "the truth" do assert true end -- Cheers Koz -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To post to this group, send email to rubyonrails-core@googlegroups.com. To unsubscribe from this group, send email to rubyonrails-core+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en.
Good point with... test "the truth"... I''ll have to dig a bit more because my test didn''t seem to be replacing anything in the current class. Thanks On Thu, Dec 17, 2009 at 10:57 PM, Michael Koziarski <michael@koziarski.com> wrote:>> What''s the purpose for "test" working this way? > > It should only be doing this if the method you''re defining would be > *replacing* another test, it shouldn''t matter if you have test with > the same name in different classes. The warning''s saved me a few > times before, but it''s possible that there''s a bug that''s causing the > behaviour that you''re seeing. If you can reproduce it in a new app we > could have a bug, but I don''t think that''s too likely given every > newly generated unit test does: > > test "the truth" do > assert true > end > > > > > > -- > Cheers > > Koz > > -- > > You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. > To post to this group, send email to rubyonrails-core@googlegroups.com. > To unsubscribe from this group, send email to rubyonrails-core+unsubscribe@googlegroups.com. > For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en. > > >-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To post to this group, send email to rubyonrails-core@googlegroups.com. To unsubscribe from this group, send email to rubyonrails-core+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en.
On Dec 17, 2009, at 2:56 AM, Andrew Kaspick wrote:> The "test" method copied below complains when another test of the same > name if found in another test file. > > The following doesn''t work... > > test/integration/users_test.rb > test "this is a test" do > ... > end > > test/integration/forums_test.rb > test "this is a test" do > ... > end > > but this does work... > > test/integration/users_test.rb > def this_is_a_test > ... > end > > test/integration/forums_test.rb > def this_is_a_test > ... > end > > What''s the purpose for "test" working this way? >I''ve run into the opposite situation, where I was writing vanilla "def test_" stuff and trying to debug a particular case. Unfortunately, *somebody* had copied the whole header / setup from another test, so the test method was stomping on an identically named test... I''d recommend that you double-check the declarations in users_test.rb and forums_test.rb, as something weird is going on... --Matt Jones -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To post to this group, send email to rubyonrails-core@googlegroups.com. To unsubscribe from this group, send email to rubyonrails-core+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en.
I''ve only experienced this issue when I made the mistake of copying the class name from one test to another, and forgot to change it. e.g. # file users_test.rb class UsersTest < ActionController::IntegrationTest ... end #file forums_test.rb class UsersTest < ActionController::IntegrationTest ... end When this mistake is made, it won''t matter which form of test definition you have. The testing framework will complain. The other possibility is plugins/gems messing with your class names. I can''t think of any exact examples though. Module inclusion should also NOT cause this. On Dec 18, 9:27 am, Matt Jones <al2o...@gmail.com> wrote:> On Dec 17, 2009, at 2:56 AM, Andrew Kaspick wrote: > > > The "test" method copied below complains when another test of the same > > name if found in another test file. > > > The following doesn''t work... > > > test/integration/users_test.rb > > test "this is a test" do > > ... > > end > > > test/integration/forums_test.rb > > test "this is a test" do > > ... > > end > > > but this does work... > > > test/integration/users_test.rb > > def this_is_a_test > > ... > > end > > > test/integration/forums_test.rb > > def this_is_a_test > > ... > > end > > > What''s the purpose for "test" working this way? > > I''ve run into the opposite situation, where I was writing vanilla "def > test_" stuff and trying to debug a particular case. Unfortunately, > *somebody* had copied the whole header / setup from another test, so > the test method was stomping on an identically named test... I''d > recommend that you double-check the declarations in users_test.rb and > forums_test.rb, as something weird is going on... > > --Matt Jones-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To post to this group, send email to rubyonrails-core@googlegroups.com. To unsubscribe from this group, send email to rubyonrails-core+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en.