This project is archived and is in readonly mode.
ActionView::TestCase does not initialize helpers contra actual ActionView Behaviour
-
David Chelimsky
- Assigned user set to José Valim
Some background at http://github.com/rspec/rspec-rails/issues#issue/120
-
Rohit Arondekar
- State changed from new to open
- Importance changed from to Low
I was able to reproduce this on Rails 3.0
I also found the following two tests produce strange output.
Two additional tests:
def test_initialization_count_again assert_equal 1, initialized_count end def test_initialization_count_after_foo foo assert_equal 1, initialized_count endOutput:
1) Failure: test_initialization_count(NinjasHelperTest) [test/unit/helpers/ninjas_helper_test.rb:5]: <1> expected but was <nil>. 2) Failure: test_initialization_count_after_foo(NinjasHelperTest) [test/unit/helpers/ninjas_helper_test.rb:14]: <1> expected but was <2>. 3 tests, 3 assertions, 2 failures, 0 errors, 0 skipsNote that the original test fails, however the same test repeated passes and also the method foo has access to @initialized_count (set to 1).
Could this be the result of some kind of lazy loading? I haven't yet dug into the Rails source yet but I thought I should report my findings if somebody else finds them helpful.
-
David Chelimsky
@rohit - I'm confused about the
foomethod in your example. Can you post it (and tell me where it lives)? -
Repository
- State changed from open to resolved
(from [84d0c30cea243f020aa7437a2f0313a9b3f13ec4]) Allow view helper's #initialize method to be called. [#5061 ActionView::TestCase does not initialize helpers contra actual ActionView Beh... state:resolved] http://github.com/rails/rails/commit/84d0c30cea243f020aa7437a2f0313...
-
Repository
(from [b5a17d7648116532805c86d4fe16770da1e616f4]) Allow view helper's #initialize method to be called. [#5061 ActionView::TestCase does not initialize helpers contra actual ActionView Beh... state:resolved] http://github.com/rails/rails/commit/b5a17d7648116532805c86d4fe1677...
-
Rohit Arondekar
Just for completeness...
@David, sorry for not including the module code. The module with the additional foo method is as follows:
module NinjasHelper attr_accessor :initialized_count def initialize( *args, &block ) super *args, &block @initialized_count ||= 0 @initialized_count += 1 end def foo @initialized_count ||= 0 @initialized_count += 1 end endThe tests and result of running tests was same as above.