Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/r7kamura/yardspec
Run YARD as RSpec.
https://github.com/r7kamura/yardspec
Last synced: about 2 months ago
JSON representation
Run YARD as RSpec.
- Host: GitHub
- URL: https://github.com/r7kamura/yardspec
- Owner: r7kamura
- License: mit
- Created: 2022-08-03T23:27:45.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2022-08-28T03:41:57.000Z (over 2 years ago)
- Last Synced: 2024-05-01T23:22:09.284Z (8 months ago)
- Language: Ruby
- Homepage:
- Size: 25.4 KB
- Stars: 15
- Watchers: 3
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE.txt
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
- awesome-rspec - yardspec
README
# Yardspec
[![test](https://github.com/r7kamura/yardspec/actions/workflows/test.yml/badge.svg)](https://github.com/r7kamura/yardspec/actions/workflows/test.yml)
Run YARD as RSpec.
```ruby
module Foo
class Bar
# @example returns "baz"
# expect(Foo::Bar.new.baz).to eq('baz')
#
# @example returns "bazbaz" for count 2
# expect(Foo::Bar.new.baz(count: 2)).to eq('bazbaz')
#
# @return [String]
def baz(count: 1)
'baz' * count
end
end
end
```The code above is interpreted as follows:
```
$ bundle exec rspecFoo::Bar#baz
returns "baz"
returns "bazbaz" for count 2Finished in 0.00129 seconds (files took 0.087 seconds to load)
2 examples, 0 failures
```## Installation
Install the gem and add to the application's Gemfile by executing:
```
bundle add yardspec
```If bundler is not being used to manage dependencies, install the gem by executing:
```
gem install yardspec
```## Usage
Require `"yardspec"` and call `Yardspec.define_examples` as follows:
```ruby
# spec/yard_spec.rb
require 'yardspec'Yardspec.define_examples
```then run entire test suite:
```
bundle exec rspec
```or run this test file:
```
bundle exec rspec spec/yard_spec.rb
```### Path glob
`Yardspec.define_examples` takes optional path glob as an argument.
If nothing is specified, the [default value of YARD](https://github.com/lsegal/yard/blob/0a550939f9b422f1bc4f46481749405284546ef9/lib/yard/parser/source_parser.rb#L69-L71) is used.
```ruby
Yardspec.define_examples(["{lib,app}/**/*.rb", "ext/**/*.{c,cc,cxx,cpp,rb}"])
```