Skip to content

Commit ede9d8a

Browse files
authored
Merge pull request #14 from mocktools/develop
RSpec::Mock v0.4.0
2 parents 6925af9 + 2484a51 commit ede9d8a

File tree

14 files changed

+131
-136
lines changed

14 files changed

+131
-136
lines changed

.circleci/gemspecs/compatible

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ Gem::Specification.new do |spec|
1717
spec.require_paths = %w[lib]
1818

1919
spec.add_runtime_dependency 'colorize', '>= 0.8.1'
20+
spec.add_runtime_dependency 'rake', '~> 13.2', '>= 13.2.1'
2021
spec.add_runtime_dependency 'rspec-core', '~> 3.10'
2122
spec.add_runtime_dependency 'rspec-mocks', '~> 3.10'
2223
spec.add_runtime_dependency 'terminal-table', '~> 3.0'

.circleci/gemspecs/latest

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ Gem::Specification.new do |spec|
1717
spec.require_paths = %w[lib]
1818

1919
spec.add_runtime_dependency 'colorize', '>= 0.8.1'
20+
spec.add_runtime_dependency 'rake', '~> 13.2', '>= 13.2.1'
2021
spec.add_runtime_dependency 'rspec-core', '~> 3.10'
2122
spec.add_runtime_dependency 'rspec-mocks', '~> 3.10'
2223
spec.add_runtime_dependency 'terminal-table', '~> 3.0'

CHANGELOG.md

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,27 @@
22

33
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
44

5+
## [0.4.0] - 2024-11-09
6+
7+
### Added
8+
9+
- Added rake task to analyze Flexmock usage and track migration progress to RSpec mocks
10+
11+
### Removed
12+
13+
- Removed CLI
14+
515
## [0.3.1] - 2024-11-08
616

717
### Fixed
818

9-
- Fixed CLI broken import.
19+
- Fixed CLI broken import
1020

1121
## [0.3.0] - 2024-11-08
1222

1323
### Added
1424

15-
- Added CLI to analyze Flexmock usage and track migration progress to RSpec mocks.
25+
- Added CLI to analyze Flexmock usage and track migration progress to RSpec mocks
1626

1727
## [0.2.0] - 2024-11-04
1828

@@ -25,4 +35,4 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
2535

2636
### Added
2737

28-
- First release of `RSpec::Mock`.
38+
- First release of `RSpec::Mock`

README.md

Lines changed: 7 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -130,25 +130,18 @@ end
130130

131131
### Migration Analytics
132132

133-
You can create a Rake task to analyze Flexmock usage and track migration progress to RSpec mocks. Or use the CLI directly.
133+
This time implemented migration analytics for [Flexmock](https://github.com/doudou/flexmock) only. You can run Rake task to analyze Flexmock usage and track migration progress to RSpec mocks.
134134

135-
Example of the Rake task:
135+
For non-Rails applications to use the task, you need to load it:
136136

137137
```ruby
138-
namespace :rspec_mock do
139-
namespace :migration_analytics do
140-
desc 'Analyze Flexmock usage and track migration progress to RSpec mocks'
141-
task :flexmock do
142-
require 'rspec/mock/migration_analytics/cli'
143-
144-
path = ::ARGV[1] || 'spec'
145-
puts("\n🔍 Analyzing Flexmock usage in: #{path}")
146-
RSpec::Mock::MigrationAnalytics::Cli.verify_path(path)
147-
end
148-
end
149-
end
138+
require 'rspec/mock/task'
139+
140+
RSpec::Mock::Task.load
150141
```
151142

143+
For Rails applications it will be automatically loaded, so just run:
144+
152145
```bash
153146
# Analyze entire spec directory (default)
154147
rake rspec_mock:migration_analytics:flexmock
@@ -160,14 +153,6 @@ rake rspec_mock:migration_analytics:flexmock spec/services
160153
rake rspec_mock:migration_analytics:flexmock spec/services/sandbox_service_spec.rb
161154
```
162155

163-
Example of the CLI usage:
164-
165-
```bash
166-
ruby cli.rb spec
167-
ruby cli.rb spec/services
168-
ruby cli.rb spec/services/sandbox_service_spec.rb
169-
```
170-
171156
## Contributing
172157

173158
Bug reports and pull requests are welcome on GitHub at <https://github.com/mocktools/ruby-rspec-mock>. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct. Please check the [open tickets](https://github.com/mocktools/ruby-rspec-mock/issues). Be sure to follow Contributor Code of Conduct below and our [Contributing Guidelines](CONTRIBUTING.md).

lib/rspec/mock/core.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,15 @@ module Tracker
1313
end
1414

1515
require_relative 'migration_analytics/file_analyzer'
16-
require_relative 'migration_analytics/cli'
16+
require_relative 'migration_analytics/printer'
1717
end
1818

1919
require_relative 'configuration'
2020
require_relative 'context'
2121
require_relative 'methods'
2222
require_relative 'version'
23+
24+
require_relative(defined?(::Rails) ? 'railtie' : 'task')
2325
end
2426

2527
module Core

lib/rspec/mock/migration_analytics/cli.rb renamed to lib/rspec/mock/migration_analytics/printer.rb

Lines changed: 4 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
#!/usr/bin/env ruby
21
# frozen_string_literal: true
32

43
require 'colorize'
@@ -12,39 +11,16 @@
1211
module RSpec
1312
module Mock
1413
module MigrationAnalytics
15-
class Cli
14+
class Printer
1615
class << self
17-
def call
18-
if ::ARGV.empty?
19-
print_usage
20-
exit 1
21-
end
22-
23-
begin
24-
verify_path(::ARGV[0])
25-
rescue => error
26-
puts("\n❌ Error: #{error.message}".red)
27-
puts(error.backtrace) if ENV['DEBUG']
28-
end
29-
end
16+
def call(path)
17+
return verify_directory(path) if ::File.directory?(path)
3018

31-
def verify_path(path)
32-
case
33-
when ::File.directory?(path) then verify_directory(path)
34-
else verify_file(path)
35-
end
19+
verify_file(path)
3620
end
3721

3822
private
3923

40-
def print_usage
41-
puts('Usage: ruby cli.rb <path_to_spec_file_or_directory>'.yellow)
42-
puts("\nExamples:".blue)
43-
puts(' ruby cli.rb spec/models/user_spec.rb')
44-
puts(' ruby cli.rb spec/models/')
45-
puts(' ruby cli.rb spec/')
46-
end
47-
4824
def verify_directory(dir_path) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
4925
results = []
5026
stats = {
@@ -188,5 +164,3 @@ def create_file_row(result)
188164
end
189165
end
190166
end
191-
192-
RSpec::Mock::MigrationAnalytics::Cli.call if __FILE__.eql?($PROGRAM_NAME)

lib/rspec/mock/railtie.rb

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# frozen_string_literal: true
2+
3+
module RSpec
4+
module Mock
5+
class Railtie < ::Rails::Railtie
6+
rake_tasks do
7+
load(::File.join(::File.dirname(__FILE__), 'tasks', 'rspec_mock.rake'))
8+
end
9+
end
10+
end
11+
end

lib/rspec/mock/task.rb

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# frozen_string_literal: true
2+
3+
require 'rake'
4+
5+
module RSpec
6+
module Mock
7+
class Task
8+
def self.load
9+
::Kernel.load(::File.join(::File.dirname(__FILE__), 'tasks', 'rspec_mock.rake'))
10+
end
11+
end
12+
end
13+
end

lib/rspec/mock/tasks/rspec_mock.rake

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# frozen_string_literal: true
2+
3+
namespace :rspec_mock do
4+
namespace :migration_analytics do
5+
desc 'Analyze Flexmock usage and track migration progress to RSpec mocks'
6+
# :nocov:
7+
task :flexmock do
8+
require 'rspec/mock/migration_analytics/printer'
9+
10+
path = ::ARGV[1] || 'spec'
11+
puts("\n🔍 Analyzing Flexmock usage in: #{path}")
12+
RSpec::Mock::MigrationAnalytics::Printer.call(path)
13+
end
14+
# :nocov:
15+
end
16+
end

lib/rspec/mock/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22

33
module RSpec
44
module Mock
5-
VERSION = '0.3.1'
5+
VERSION = '0.4.0'
66
end
77
end

0 commit comments

Comments
 (0)