r2m 0.2.3 → 0.2.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 39cf102836307d757425f6c28d74674bb77001f61f7506ef1babf56b531f0405
4
- data.tar.gz: a481c0b6dd240ea5f908d6481f8cdef1b61fa748bdf83d3c526890b0be9be894
3
+ metadata.gz: 51ea8c25dfef6661109caeee0ca628389434080b154b1beeb1aad1c1515846f7
4
+ data.tar.gz: 4dd1416feddfc8b52e79dfcf4970cdcf3fb8d385885f7f261a8c5e2d0ca23e7c
5
5
  SHA512:
6
- metadata.gz: 26b7a0da0e111484d6fcd55954c9d8efbccfc223279a220abe81b0438225fc868335051e2d77e78542ad8126d75115712a67cf156c927ed9f9402e284c889c84
7
- data.tar.gz: 3db7a67f1bbfef5c88e1a95e942b0b93e37230c9417334a78c56d3fdaacf063c234db93389b17b59feb28ac275c344bc788ca80c7989ee883f091903635e62fd
6
+ metadata.gz: b470cdccf3d24ae191eb6b8b5d956a34f112c297a2be1f1e162ec240cdad5f225ec57df18b056905d8149bd4046f145b1570d563c04ad59a95974b829d0be4a1
7
+ data.tar.gz: f9dd5ca8be65e5ac323fb16f462ca0daa277a4ac059ca8a06cea3e394f22a25140e638d4036131b38dd5a1492c296969d929687293b8e3a315849bbf56a94f9c
data/.github/FUNDING.yml CHANGED
@@ -1,5 +1,5 @@
1
1
  # These are supported funding model platforms
2
2
 
3
- # github: [pftg]
3
+ github: [pftg]
4
4
  patreon: pftg
5
5
  custom: ['https://www.jetthoughts.com', 'https://jtway.co']
data/Gemfile CHANGED
@@ -1,11 +1,11 @@
1
- source "https://rubygems.org"
1
+ source 'https://rubygems.org'
2
2
 
3
3
  # Specify your gem's dependencies in r2m.gemspec
4
4
  gemspec
5
5
 
6
- gem "rake", "~> 12.0"
7
- gem "minitest", "~> 5.0"
6
+ gem 'minitest', '~> 5.0'
7
+ gem 'rake', '~> 12.0'
8
8
 
9
- gem 'rspec'
10
9
  gem 'minitest-around'
11
10
  gem 'minitest-spec-rails'
11
+ gem 'rspec'
data/README.md CHANGED
@@ -1,8 +1,6 @@
1
- # R2m
1
+ # RSpec To minitest
2
2
 
3
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/r2m`. To experiment with that code, run `bin/console` for an interactive prompt.
4
-
5
- TODO: Delete this and the text above, and describe your gem
3
+ * Support Rails Matchers
6
4
 
7
5
  ## Installation
8
6
 
@@ -22,7 +20,7 @@ Or install it yourself as:
22
20
 
23
21
  ## Usage
24
22
 
25
- $ r2m convert test/system/**/*_spec.rb
23
+ $ r2m convert "test/system/**/*_spec.rb"
26
24
 
27
25
  ## Development
28
26
 
data/Rakefile CHANGED
@@ -1,10 +1,10 @@
1
- require "bundler/gem_tasks"
2
- require "rake/testtask"
1
+ require 'bundler/gem_tasks'
2
+ require 'rake/testtask'
3
3
 
4
4
  Rake::TestTask.new(:test) do |t|
5
- t.libs << "test"
6
- t.libs << "lib"
7
- t.test_files = FileList["test/**/*_test.rb"]
5
+ t.libs << 'test'
6
+ t.libs << 'lib'
7
+ t.test_files = FileList['test/**/*_test.rb']
8
8
  end
9
9
 
10
- task :default => :test
10
+ task default: :test
data/bin/console CHANGED
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- require "bundler/setup"
4
- require "r2m"
3
+ require 'bundler/setup'
4
+ require 'r2m'
5
5
 
6
6
  # You can add fixtures and/or initialization code here to make experimenting
7
7
  # with your gem easier. You can also use a different console, if you like.
@@ -10,5 +10,5 @@ require "r2m"
10
10
  # require "pry"
11
11
  # Pry.start
12
12
 
13
- require "irb"
13
+ require 'irb'
14
14
  IRB.start(__FILE__)
data/lib/r2m/command.rb CHANGED
@@ -1,7 +1,10 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'thor'
4
- require_relative './processor'
4
+ require 'pathname'
5
+
6
+ require_relative './spec_convector'
7
+ require_relative './spec_migration'
5
8
 
6
9
  module R2M
7
10
  # Adds CLI commands convert and migrate
@@ -15,30 +18,43 @@ module R2M
15
18
  true
16
19
  end
17
20
 
18
- desc 'convert [path...]', 'Convert Rspec to minitest'
19
- def convert(pathes)
20
- files(pathes).each { |file| process file }
21
+ desc 'convert [path1 path2 ...]', 'Convert Rspec to minitest'
22
+ def convert(*paths)
23
+ files(paths.flatten).each { |path| run_convert path }
21
24
  end
22
25
 
23
- desc 'migrate [path...]', 'Move found specs to test folder and convert them'
24
- method_option :replace_suffix,
26
+ desc 'migrate [path1 path2 ...]', 'Move found specs to test folder and convert them'
27
+ method_option(
28
+ :replace_suffix,
25
29
  desc: 'Renames *_spec.rb to *_test.rb',
26
30
  default: true,
27
31
  aliases: ['s'],
28
32
  type: :boolean
29
- def migrate(pathes)
30
- pp files(pathes)
33
+ )
34
+ def migrate(*paths)
35
+ files(paths.flatten).each do |path|
36
+ say "Processing #{path}"
37
+ run_migrate(path)
38
+ run_convert(path)
39
+ end
31
40
  end
32
41
 
33
42
  private
34
43
 
35
- def process(file)
36
- Processor.new(self).process(file)
44
+ def run_migrate(path)
45
+ SpecMigration.new(Pathname.pwd).migrate(File.realpath(path))
46
+ end
47
+
48
+ def run_convert(file)
49
+ say "Processing #{file}"
50
+ SpecConvector.new(self).process(file)
37
51
  end
38
52
 
39
- def files(pathes)
40
- Array(pathes).map do |path|
41
- if Dir.exist?(path)
53
+ def files(paths)
54
+ Array(paths).map do |path|
55
+ if File.exist?(path) && !File.directory?(path)
56
+ path
57
+ elsif Dir.exist?(path)
42
58
  Dir.glob(File.join(path, '**', '*_spec.rb'))
43
59
  else
44
60
  Dir.glob(path)
@@ -4,7 +4,7 @@ require 'thor'
4
4
 
5
5
  module R2M
6
6
  # Process input RSpec and convert it to minitest
7
- class Processor
7
+ class SpecConvector # rubocop:todo Metrics/ClassLength
8
8
  def initialize(command)
9
9
  @command = command
10
10
  end
@@ -76,18 +76,23 @@ module R2M
76
76
  @command.gsub_file(file, /\bhelper\./, '') if located_in_helpers?(file)
77
77
  end
78
78
 
79
- def convert_declarations(file)
79
+ # rubocop:todo Metrics/MethodLength
80
+ def convert_declarations(file) # rubocop:todo Metrics/AbcSize
80
81
  @command.gsub_file(file, /RSpec\.describe (['"])(.*?)\1 do\b/) do |match|
81
82
  title = match[/RSpec\.describe (['"])(.*?)\1 do/, 2]
82
83
 
84
+ # rubocop:todo Naming/VariableName
83
85
  camelCasedTitle = title.split('::').map do |title_part|
84
86
  title_part
85
87
  .split
86
88
  .reject(&:empty?)
87
89
  .map { |part| part[0].upcase + part[1..-1] }.join
88
90
  end.join('::')
91
+ # rubocop:enable Naming/VariableName
89
92
 
93
+ # rubocop:todo Naming/VariableName
90
94
  "RSpec.describe '#{camelCasedTitle}' do"
95
+ # rubocop:enable Naming/VariableName
91
96
  end
92
97
 
93
98
  @command.gsub_file(
@@ -129,6 +134,7 @@ module R2M
129
134
  'class \1Test < ActiveSupport::TestCase'
130
135
  )
131
136
  end
137
+ # rubocop:enable Metrics/MethodLength
132
138
 
133
139
  MANUAL_AROUND_PROCESS = "skip 'TODO: Remove this skip when `around` will be migrated manually by replacing `run` with `call`'"
134
140
  def convert_around(file)
@@ -148,7 +154,7 @@ module R2M
148
154
  end
149
155
 
150
156
  def located_in?(file, sub_folder)
151
- file =~ /(test|spec)\/#{sub_folder}\//
157
+ file =~ %r{(test|spec)/#{sub_folder}/}
152
158
  end
153
159
  end
154
160
  end
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'rake/file_utils'
4
+
5
+ class SpecMigration # rubocop:todo Style/Documentation
6
+ def initialize(basedir)
7
+ @basedir = Pathname(basedir)
8
+ end
9
+
10
+ def migrate(spec_file) # rubocop:todo Metrics/AbcSize
11
+ move_and_rename_spec_to_test(spec_file)
12
+ end
13
+
14
+ def split_path(file)
15
+ spec_root = @basedir / 'spec'
16
+ dirname, basename = Pathname(file).split
17
+ relative_path = dirname.relative_path_from(spec_root)
18
+
19
+ [relative_path, basename]
20
+ end
21
+
22
+ def move_and_rename_spec_to_test(spec_file)
23
+ relative_path, spec_basename = split_path(spec_file)
24
+ test_root = @basedir / 'test'
25
+
26
+ test_dirname = test_root + relative_path
27
+ FileUtils.mkdir_p test_dirname
28
+
29
+ test_basename = spec_basename.sub(/_spec(?=\.rb)/, '_test')
30
+ test_file = test_dirname + test_basename
31
+ FileUtils.cp spec_file, test_file
32
+ end
33
+ end
data/lib/r2m/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module R2M
2
- VERSION = "0.2.3"
2
+ VERSION = '0.2.4'.freeze
3
3
  end
data/lib/r2m.rb CHANGED
@@ -1,4 +1,4 @@
1
- require "r2m/version"
1
+ require 'r2m/version'
2
2
 
3
3
  module R2M
4
4
  class Error < StandardError; end
File without changes
File without changes
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: r2m
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.3
4
+ version: 0.2.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Paul Keen
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-05-02 00:00:00.000000000 Z
11
+ date: 2020-05-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor
@@ -50,9 +50,12 @@ files:
50
50
  - exe/rspec2minitest
51
51
  - lib/r2m.rb
52
52
  - lib/r2m/command.rb
53
- - lib/r2m/processor.rb
53
+ - lib/r2m/spec_convector.rb
54
+ - lib/r2m/spec_migration.rb
54
55
  - lib/r2m/version.rb
55
56
  - r2m.gemspec
57
+ - sample_app/test/example_spec/example_test.rb
58
+ - sample_app/test/example_test.rb
56
59
  homepage: https://github.com/jetthoughts/r2m
57
60
  licenses:
58
61
  - MIT