https://github.com/andyw8/mocha_to_rspec
A set of RuboCop cops to help migrate from Mocha to rspec-mocks
https://github.com/andyw8/mocha_to_rspec
Last synced: about 1 month ago
JSON representation
A set of RuboCop cops to help migrate from Mocha to rspec-mocks
- Host: GitHub
- URL: https://github.com/andyw8/mocha_to_rspec
- Owner: andyw8
- License: mit
- Created: 2019-01-26T20:06:39.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2022-05-11T11:11:45.000Z (about 3 years ago)
- Last Synced: 2025-03-29T05:51:12.607Z (about 2 months ago)
- Language: Ruby
- Size: 57.6 KB
- Stars: 4
- Watchers: 1
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# mocha_to_rspec
This gem is to help migrating from [mocha] to [rspec-mocks].
It uses RuboCop to perform the conversion.
It converts the syntax, for example:
```ruby
widget.stubs(:foo).returns(bar)
```to
```ruby
allow(widget).to receive(:foo).and_return(bar)
```It does not handle _every_ conversion, but should get you most of the way there.
You might find it useful to use this alongside [rspec-multi-mock]
The gem's structure is based on [rubocop-github].
[mocha]: https://github.com/freerange/mocha
[rspec-mocks]: https://github.com/rspec/rspec-mocks
[rspec-multi-mock]: https://github.com/endeepak/rspec-multi-mock
[rubocop-github]: https://github.com/github/rubocop-github## Known Limitations
* `.yields`
* `.at_least_once` (and similar count-based checks)## Installation
Add this line to your application's Gemfile:
```ruby
gem 'mocha_to_rspec'
```And then execute:
$ bundle
Or install it yourself as:
$ gem install mocha_to_rspec
## Usage
The individual cops can be run through RuboCop, and you can pass the
`--auto-correct` flag. However, it really only makes sense to run all the cops
together, so a single command is provided:```ruby
mocha_to_rspec [path]
```## Development
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
## Contributing
I wrote this for use on one particular project so I probably won't be doing any
further work on it, but pull requests are welcome if accompanied by tests.## License
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).