Class: MinitestToRspec::CLI
- Inherits:
-
Object
- Object
- MinitestToRspec::CLI
- Defined in:
- lib/minitest_to_rspec/cli.rb
Overview
Command-Line Interface (CLI) instantiated by ‘bin/mt2rspec`
Constant Summary collapse
- E_USAGE =
1.freeze
- E_FILE_NOT_FOUND =
2.freeze
- E_FILE_ALREADY_EXISTS =
3.freeze
- E_CONVERT_FAIL =
4.freeze
- E_CANNOT_CREATE_TARGET_DIR =
5.freeze
- BANNER =
<<~EOS.freeze Usage: mt2rspec [--rails] [--mocha] source_file [target_file] Reads source_file, writes target_file. If target_file is omitted, its location will be inferred. For example, test/fruit/banana_test.rb implies spec/fruit/banana_spec.rb. If the target directory doesn't exist, it will be created. Options: EOS
- OPT_MOCHA =
"Convert mocha to rspec-mocks. (Experimental)"- OPT_RAILS =
<<~EOS.tr("\n", " ").freeze Requires rails_helper instead of spec_helper. Passes :type metadatum to RSpec.describe. EOS
Instance Attribute Summary collapse
-
#source ⇒ Object
readonly
Returns the value of attribute source.
-
#target ⇒ Object
readonly
Returns the value of attribute target.
Instance Method Summary collapse
-
#initialize(args) ⇒ CLI
constructor
A new instance of CLI.
- #run ⇒ Object
Constructor Details
#initialize(args) ⇒ CLI
Returns a new instance of CLI.
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/minitest_to_rspec/cli.rb', line 34 def initialize(args) opts = Trollop.(args) do version MinitestToRspec::VERSION BANNER opt :rails, OPT_RAILS, short: :none opt :mocha, OPT_MOCHA, short: :none end @rails = opts[:rails] @mocha = opts[:mocha] case args.length when 2 @source, @target = args when 1 @source = args[0] @target = infer_target_from @source else warn "Please specify source file" exit E_USAGE end end |
Instance Attribute Details
#source ⇒ Object (readonly)
Returns the value of attribute source.
32 33 34 |
# File 'lib/minitest_to_rspec/cli.rb', line 32 def source @source end |
#target ⇒ Object (readonly)
Returns the value of attribute target.
32 33 34 |
# File 'lib/minitest_to_rspec/cli.rb', line 32 def target @target end |
Instance Method Details
#run ⇒ Object
56 57 58 59 60 61 62 63 64 |
# File 'lib/minitest_to_rspec/cli.rb', line 56 def run assert_file_exists(source) assert_file_does_not_exist(target) ensure_target_directory(target) write_target(converter.convert(read_source, source)) rescue Error => e $stderr.puts "Failed to convert: #{e}" exit E_CONVERT_FAIL end |