`attribute` doesn't set attribute for `sub_test_case`
mtsmfm opened this issue ยท 6 comments
I expect following code is passed but failed:
require "test-unit"
require "test/unit/version"
puts "RUBY_VERSION #=> #{RUBY_VERSION}"
puts "Test::Unit::VERSION #=> #{Test::Unit::VERSION}"
class TestAttributeTest < Test::Unit::TestCase
attribute :attr, :value
def test_attribute
assert_equal :value, self[:attr]
end
end
class SubTestCaseAttributeTest < Test::Unit::TestCase
attribute :attr, :value
sub_test_case "sub test case" do
def test_attribute
assert_equal :value, self[:attr]
end
end
end
RUBY_VERSION #=> 2.4.1
Test::Unit::VERSION #=> 3.2.3
Loaded suite -
Started
F
===============================================================================
Failure: test_attribute(SubTestCaseAttributeTest::sub test case)
-:18:in `test_attribute'
<:value> expected but was
<nil>
diff:
? :value
? ni
===============================================================================
.
Finished in 0.005044152 seconds.
------
2 tests, 2 assertions, 1 failures, 0 errors, 0 pendings, 0 omissions, 0 notifications
50% passed
------
396.50 tests/s, 396.50 assertions/s
Is this intentional?
Another Information
I can't find any document for attribute
.
Is there a document?
Can I help to add document if it doesn't exist?
Test case level attribute isn't supported because I didn't think about the use case.
I'll consider whether test-unit should support the feature or not.
I can't find any document for attribute.
Is there a document?
No there isn't.
Can I help to add document if it doesn't exist?
Sure!
Test case level attribute isn't supported because I didn't think about the use case.
I'll consider whether test-unit should support the feature or not.
In my case, honestly I want to set attribute whole of the test class, not sub_test_case
.
For example:
class JavaScriptFormTest < ActionDispatch::IntegrationTest # I'm using test-unit-rails
attribute :js, true
def test_submit
end
attribute :js, true
def test_error
end
...
end
I can't find any document for attribute.
Is there a document?
No there isn't.
Can I help to add document if it doesn't exist?
Sure!
๐
Which document should I edit?
I remember! attribute
has :keep
option. Use the following code for your use case:
class JavaScriptFormTest < ActionDispatch::IntegrationTest # I'm using test-unit-rails
attribute :js, true, :keep => true
def test_submit
p self[:js] # => true
end
def test_error
p self[:js] # => true
end
...
end
Which document should I edit? โ๏ธ
Test::Unit::TestCase
in lib/test/unit/testcase.rb
and
Test::Unit::Attribute::ClassMethods#attribute
in lib/test/unit/attribute.rb
.
It's better that Test::Unit::TestCase
document has summary and Test::Unit::Attribute::ClassMethods#attribute
document has details.
I just noticed following behavior when I tried to write documentation:
require 'test-unit'
class AttrTest < Test::Unit::TestCase
def test_slow_method1
p self[:speed] # => :slow
end
attribute :speed, :slow, {keep: true}, :test_slow_method1
def test_slow_method2
p self[:speed] # => nil
end
end
Is this intentional?
I understand that keep
option is suitable for this case.
I'll close this issue and let's have a discussion about attribute
on #143
Thank you for telling me about the option