class MinitestToRspec::Input::Subprocessors::Klass
Processes `s(:class, ..)` expressions.
Public Class Methods
Takes `sexp`, a `:class` s-expression, and `rails`, a boolean indicating that `rspec-rails` conventions (like `:type` metadata) should be used.
MinitestToRspec::Input::Subprocessors::Base::new
# File lib/minitest_to_rspec/input/subprocessors/klass.rb, line 15 def initialize(sexp, rails, mocha) super(rails, mocha) @exp = Model::Klass.new(sexp) sexp.clear end
Public Instance Methods
# File lib/minitest_to_rspec/input/subprocessors/klass.rb, line 21 def process sexp = head ebk = @exp.block if ebk.length > 1 sexp << block elsif ebk.length == 1 sexp << full_process(ebk[0]) end sexp end
Private Instance Methods
Returns a :block S-expression, the contents of the class.
# File lib/minitest_to_rspec/input/subprocessors/klass.rb, line 35 def block processed = @exp.block.map { |line| full_process(line) } s(:block, *processed) end
Given a `test_class_name` like `BananaTest`, returns the described class, like `Banana`.
# File lib/minitest_to_rspec/input/subprocessors/klass.rb, line 42 def described_class(test_class_name) test_class_name.to_s.gsub(/Test\Z/, '').to_sym end
Returns the head of the output Sexp. If it's a test case, an :iter representing an `RSpec.describe`. Otherwise, a :class.
# File lib/minitest_to_rspec/input/subprocessors/klass.rb, line 48 def head if @exp.test_case? rspec_describe_block else s(:class, @exp.name, @exp.parent) end end
Returns an S-expression representing the RDM (RSpec Describe Metadata) hash
# File lib/minitest_to_rspec/input/subprocessors/klass.rb, line 58 def rdm s(:hash, s(:lit, :type), s(:lit, rdm_type)) end
Returns the RDM (RSpec Describe Metadata) type.
> Model
specs: type: :model > Controller specs: type: :controller > Request specs: type: :request > Feature specs: type: :feature > View specs: type: :view > Helper specs: type: :helper > Mailer specs: type: :mailer > Routing specs: type: :routing > bit.ly/1G5w7CJ
TODO: Obviously, they're not all supported yet.
# File lib/minitest_to_rspec/input/subprocessors/klass.rb, line 75 def rdm_type if @exp.action_controller_test_case? :controller elsif @exp.draper_test_case? :decorator elsif @exp.action_mailer_test_case? :mailer else :model end end
# File lib/minitest_to_rspec/input/subprocessors/klass.rb, line 87 def rspec_describe const = s(:const, described_class(@exp.name)) call = s(:call, s(:const, :RSpec), :describe, const) call << rdm if @rails call end
Returns a S-expression representing a call to RSpec.describe
# File lib/minitest_to_rspec/input/subprocessors/klass.rb, line 95 def rspec_describe_block s(:iter, rspec_describe, 0) end