Class: MinitestToRspec::Model::Klass
- Defined in:
- lib/minitest_to_rspec/model/klass.rb
Overview
Data object. Represents a ‘:class` S-expression.
Instance Method Summary collapse
- #action_controller_test_case? ⇒ Boolean
- #action_mailer_test_case? ⇒ Boolean
- #active_support_test_case? ⇒ Boolean
-
#assert_valid_name ⇒ Object
Raise an error if we don’t know now to process the name of this class.
- #block ⇒ Object
- #block? ⇒ Boolean
- #draper_test_case? ⇒ Boolean
-
#initialize(exp) ⇒ Klass
constructor
A new instance of Klass.
-
#name ⇒ Object
Returns the name of the class.
-
#parent ⇒ Object
Returns the “inheritance”.
-
#test_case? ⇒ Boolean
Returns true if ‘@exp` inherits from, e.g.
Methods included from SexpAssertions
#assert_sexp_type, #assert_sexp_type_array, #sexp_type?
Constructor Details
#initialize(exp) ⇒ Klass
Returns a new instance of Klass.
9 10 11 12 13 |
# File 'lib/minitest_to_rspec/model/klass.rb', line 9 def initialize(exp) assert_sexp_type(:class, exp) @exp = exp.dup assert_valid_name end |
Instance Method Details
#action_controller_test_case? ⇒ Boolean
15 16 17 |
# File 'lib/minitest_to_rspec/model/klass.rb', line 15 def action_controller_test_case? lineage?(parent, [:ActionController, :TestCase]) end |
#action_mailer_test_case? ⇒ Boolean
19 20 21 |
# File 'lib/minitest_to_rspec/model/klass.rb', line 19 def action_mailer_test_case? lineage?(parent, [:ActionMailer, :TestCase]) end |
#active_support_test_case? ⇒ Boolean
23 24 25 |
# File 'lib/minitest_to_rspec/model/klass.rb', line 23 def active_support_test_case? lineage?(parent, [:ActiveSupport, :TestCase]) end |
#assert_valid_name ⇒ Object
Raise an error if we don’t know now to process the name of this class. Specifically, classes with module-shorthand.
29 30 31 32 33 34 35 36 37 |
# File 'lib/minitest_to_rspec/model/klass.rb', line 29 def assert_valid_name if name.is_a?(Symbol) # Valid elsif name.respond_to?(:sexp_type) && name.sexp_type == :colon2 raise ModuleShorthandError else raise ProcessingError, "Unexpected class expression: #{name}" end end |
#block ⇒ Object
43 44 45 |
# File 'lib/minitest_to_rspec/model/klass.rb', line 43 def block @_block ||= @exp[3..-1] || [] end |
#block? ⇒ Boolean
39 40 41 |
# File 'lib/minitest_to_rspec/model/klass.rb', line 39 def block? !block.empty? end |
#draper_test_case? ⇒ Boolean
47 48 49 |
# File 'lib/minitest_to_rspec/model/klass.rb', line 47 def draper_test_case? lineage?(parent, [:Draper, :TestCase]) end |
#name ⇒ Object
Returns the name of the class. Examples:
-
Banana #=> :Banana
-
Fruit::Banana #=> s(:colon2, s(:const, :Fruit), :Banana)
Note that the latter (module shorthand) is not supported by MinitestToRspec. See ‘#assert_valid_name`.
59 60 61 |
# File 'lib/minitest_to_rspec/model/klass.rb', line 59 def name @exp[1] end |
#parent ⇒ Object
Returns the “inheritance”. Examples:
-
Inherit nothing #=> nil
-
Inherit Foo #=> s(:const, :Foo)
-
Inherit Bar::Foo #=> s(:colon2, s(:const, :Bar), :Foo)
69 70 71 |
# File 'lib/minitest_to_rspec/model/klass.rb', line 69 def parent @_parent ||= @exp[2] end |
#test_case? ⇒ Boolean
Returns true if ‘@exp` inherits from, e.g. ActiveSupport::TestCase. TODO: Other test case parent classes.
75 76 77 78 79 80 81 |
# File 'lib/minitest_to_rspec/model/klass.rb', line 75 def test_case? return false unless sexp_type?(:colon2, parent) active_support_test_case? || action_controller_test_case? || action_mailer_test_case? || draper_test_case? end |