Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

[PATCH] visibility of fixture accssor methods

#2992

Hello,

this is similar to #1708, but including another problem,
so I attached the same patch again. If there are the ways to
tell of updating the ticket that was marked as "incomplete" or
"invalid", please let met know.

Well, the teardown method is invoked even when the test method
comes from outside of the test script.

$ cat test/unit/test_result_test.rb 
require 'test_helper'

class TestResultTest < ActiveSupport::TestCase
  def teardown
    p @method_name
  end
end
$ ruby -Itest test/unit/test_result_test.rb -v
Loaded suite test/unit/test_result_test
Started
test_results(ActionController::IntegrationTest): .
test_results(ActionController::TestCase): .
test_results(ActionMailer::TestCase): .
test_results(ActionView::TestCase): .
test_results(ActiveRecord::TestCase): .
test_results(ActiveSupport::TestCase): .
test_results(TestResultTest): "test_results"
.

Finished in 0.233754 seconds.

7 tests, 0 assertions, 0 failures, 0 errors

Actually, I'm very annoyed the following case:

require 'test_helper'

class TestResultTest < ActiveSupport::TestCase
  def setup
    File.unlink(logfile)
  rescue Errno::ENOENT
  end

  def teardown
    assert_equal 1, File.unlink(logfile)
  end

  def logfile
    @logfile ||= Rails.root + "tmp/logfile"
  end

  test "create log 1" do
    File.open(logfile, "w"){|f| f.puts("log 1")}
  end

  test "create log 2" do
    File.open(logfile, "w"){|f| f.puts("log 2")}
  end
end

the result of above test is:

$ ruby -Itest test/unit/test_result_test.rb -v
Loaded suite test/unit/test_result_test
Started
test_results(ActionController::IntegrationTest): .
test_results(ActionController::TestCase): .
test_results(ActionMailer::TestCase): .
test_results(ActionView::TestCase): .
test_results(ActiveRecord::TestCase): .
test_results(ActiveSupport::TestCase): .
test_create_log_1(TestResultTest): .
test_create_log_2(TestResultTest): .
test_results(TestResultTest): E

Finished in 0.220522 seconds.

  1) Error:
test_results(TestResultTest):
Errno::ENOENT: No such file or directory - /tmp/233/tmp/logfile
    test/unit/test_result_test.rb:10:in `unlink'
    test/unit/test_result_test.rb:10:in `teardown'

9 tests, 2 assertions, 0 failures, 1 errors

Hmm, I don't know about the test_results method,
at least in my test/unit/test_result_test.rb.

After patching,

$ ruby -Itest test/unit/test_result_test.rb -v
Loaded suite test/unit/test_result_test
Started
test_create_log_1(TestResultTest): .
test_create_log_2(TestResultTest): .

Finished in 0.202083 seconds.

2 tests, 2 assertions, 0 failures, 0 errors

the result is quite simple and this is what I want :-).

Thanks,

Reported by Nobuhiro IMAI · August 4th, 2009 @ 07:16 AM

State: resolved
Milestone: 3.0.2
Assigned to: José Valim José Valim
Importance: High

Activity

  1. Nobuhiro IMAI
    Nobuhiro IMAI
    • Title changed from visibility of fixture accssor methods to [PATCH] visibility of fixture accssor methods
    • Assigned user set to Pratik

    How about to include this patch into the next release? 2.3.5?

    Thanks,

    September 12th, 2009 @ 12:20 AM

  2. CancelProfileIsBroken
    CancelProfileIsBroken
    • Tag changed from 2.3.3, 2.3.4, activerecord, fixtures, patch to 2.3.3, 2.3.4, activerecord, bugmash, fixtures, patch
    • Assigned user cleared.

    September 25th, 2009 @ 12:59 PM

  3. Elad Meidar
    Elad Meidar

    +1 on the patch, applies cleanly on 2-3-stable and Master. @Nobuhiro: although it's all seems like the correct way to go, are you sure this won't backfire on something ?

    September 26th, 2009 @ 03:01 AM

  4. Elad Meidar
    Elad Meidar
    • Tag changed from 2.3.3, 2.3.4, activerecord, bugmash, fixtures, patch to 2.3.3, 2.3.4, activerecord, bugmash, bugmash-review, fixtures, patch

    September 26th, 2009 @ 03:03 AM

  5. Nobuhiro IMAI
    Nobuhiro IMAI

    @Elad: Fixture accessor methods are only used in test scripts, so that it's ok even if the visibility is private, I guess. Thanks.

    September 26th, 2009 @ 03:32 AM

  6. sr.iniv.t
    sr.iniv.t

    +1 verified. Patch applies cleanly.

    September 27th, 2009 @ 05:34 AM

  7. CancelProfileIsBroken
    CancelProfileIsBroken
    • Tag changed from 2.3.3, 2.3.4, activerecord, bugmash, bugmash-review, fixtures, patch to 2.3.3, 2.3.4, activerecord, bugmash-review, fixtures, patch

    September 27th, 2009 @ 11:47 AM

  8. CancelProfileIsBroken
    CancelProfileIsBroken
    • Tag changed from 2.3.3, 2.3.4, activerecord, bugmash-review, fixtures, patch to 2.3.3, 2.3.4, activerecord, bugmash-review, fixtures, patch

    September 27th, 2009 @ 12:33 PM

  9. Nobuhiro IMAI
    Nobuhiro IMAI
    • Tag changed from 2.3.3, 2.3.4, activerecord, bugmash-review, fixtures, patch to 2.3.6, activerecord, bugmash-review, fixtures, patch

    With Rails 2.3.5, the situation seems to have deteriorated.

    $ ruby -Itest test/unit/test_result_test.rb -v
    Loaded suite test/unit/test_result_test
    Started
    test_results(ActionController::IntegrationTest): .
    test_results(ActionController::TestCase): .
    test_results(ActionMailer::TestCase): .
    test_results(ActionView::TestCase): E
    test_results(ActiveRecord::TestCase): .
    test_results(ActiveSupport::TestCase): .
    test_results(TestResultTest): .
    test_the_truth(TestResultTest): .
    
    Finished in 0.356134 seconds.
    
      1) Error:
    test_results(ActionView::TestCase):
    TypeError: wrong argument type Class (expected Module)
        
    
    8 tests, 1 assertions, 0 failures, 1 errors
    

    This is because the hook, setup_with_controller(), is added to ActionView::TestCase.

    .../actionpack-2.3.5/lib/action_view/test_case.rb:81:in `helper_class'
    .../actionpack-2.3.5/lib/action_view/test_case.rb:106:in `include_helper_modules!'
    .../actionpack-2.3.5/lib/action_view/test_case.rb:59:in `send'
    .../actionpack-2.3.5/lib/action_view/test_case.rb:59:in `setup_with_controller'
    (snip)
    

    and in determine_default_helper_class(), trying to include ActionView::TestCase itself as a helper module, then raises TypeError.
    At this point, determine_default_helper_class should be as follow:

           def determine_default_helper_class(name)
    -        name.sub(/Test$/, '').constantize
    +        name.sub!(/Test\z/, '').try(:constantize)
           rescue NameError
             nil
           end
    

    Anyway, it's no problem if the fixtures accessor methods are private.
    Attached patch is cleanly applied even now, at least using git-apply. Thanks.

    December 23rd, 2009 @ 07:46 AM

  10. Rizwan Reza
    Rizwan Reza
    • Tag changed from 2.3.6, activerecord, bugmash-review, fixtures, patch to 2.3.6, activerecord, bugmash, fixtures, patch

    May 15th, 2010 @ 06:45 PM

  11. Casey Dreier
    Casey Dreier

    +1 Verified that patch applies cleanly for 2.3-stable branch.

    May 15th, 2010 @ 09:04 PM

  12. Rizwan Reza
    Rizwan Reza
    • Milestone set to 2.3.6
    • State changed from new to open

    Casey, also update us if the tests pass.

    May 15th, 2010 @ 09:13 PM

  13. Rizwan Reza
    Rizwan Reza
    • Tag changed from 2.3.6, activerecord, bugmash, fixtures, patch to 2.3.6, activerecord, bugmash-review, fixtures, patch

    May 15th, 2010 @ 09:15 PM

  14. Casey Dreier
    Casey Dreier

    Yes, all tests on master pass with this patch applied.

    May 16th, 2010 @ 12:38 AM

  15. Rizwan Reza
    Rizwan Reza
    • Tag changed from 2.3.6, activerecord, bugmash-review, fixtures, patch to 2.3.6, activerecord, bugmash, bugmash-review, fixtures, patch

    May 16th, 2010 @ 02:41 AM

  16. Rizwan Reza
    Rizwan Reza
    • Milestone cleared.
    • Tag changed from 2.3.6, activerecord, bugmash, bugmash-review, fixtures, patch to 2.3.6, 3.0, activerecord, bugmash, bugmash-review, fixtures, patch
    • State changed from open to verified

    The patch above is for both: master and 2-3-stable.

    May 16th, 2010 @ 02:58 AM

  17. Rizwan Reza
    Rizwan Reza
    • Tag changed from 2.3.6, 3.0, activerecord, bugmash, bugmash-review, fixtures, patch to 2.3.6, 3.0, activerecord, bugmash, fixtures, patch

    May 16th, 2010 @ 02:58 AM

  18. Rizwan Reza
    Rizwan Reza
    • Tag changed from 2.3.6, 3.0, activerecord, bugmash, fixtures, patch to 2.3.6, 3.0, activerecord, bugmash-review, fixtures, patch

    May 16th, 2010 @ 02:58 AM

  19. Rizwan Reza
    Rizwan Reza
    • No changes were found…

    May 16th, 2010 @ 02:58 AM

  20. José Valim
    José Valim
    • Milestone cleared.
    • Tag changed from 2.3.6, 3.0, activerecord, bugmash-review, fixtures, patch to 2.3.6, 3.0, activerecord, bugmash, fixtures, patch
    • State changed from verified to open
    • Assigned user set to José Valim

    The patch does not apply on master anymore. Can anyone rebase please?

    May 16th, 2010 @ 09:51 AM

  21. Wijnand Wiersma
  22. Casey Dreier
    Casey Dreier

    +1 Verified that new patches apply cleanly to both master and 2.3-stable branch.
    Does not cause any failing tests on either branch.

    May 16th, 2010 @ 06:25 PM

  23. Repository
    Repository
    • State changed from open to resolved

    (from [5d0afe75ebd7d88f982a57af84dba1ef62b14c0c]) prevent to run fixture accessor (e.g. test_foos for TestFoo model) as a test case [#2992 state:resolved]

    Signed-off-by: Wijnand Wiersma wijnand@videre.net
    Signed-off-by: José Valim jose.valim@gmail.com
    http://github.com/rails/rails/commit/5d0afe75ebd7d88f982a57af84dba1...

    May 16th, 2010 @ 07:16 PM

  24. José Valim
    José Valim
    • Tag changed from 2.3.6, 3.0, activerecord, bugmash, fixtures, patch to 2.3.6, 3.0, activerecord, fixtures, patch

    May 16th, 2010 @ 07:23 PM

  25. Jeremy Kemper
    Jeremy Kemper
    • Milestone set to 3.0.2
    • Importance changed from to High

    October 15th, 2010 @ 11:01 PM