RSpec::RfcHelper
RSpec RFC Helper is a RSpec module to help tracking implementation of big specifications, when having only comments in
code or tests becomes too tedious to maintain and follow.
Installation
Add the gem to your Gemfile:
gem 'rspec-rfc-helper'
Usage
- Write the specs: read the RFC/specifications that needs to be implemented and extract everything that has to be implemented. This is tedious.
- Use the gem in Rspec
- Sprinkle your tests to reference the specs
- Run the tests
- Open the report
Writing specs
...in a YAML file
Specs in a YAML file can be loaded easily when integrated in RSpec; the format is simple:
name:
url:
specs:
- section: 1
id:
url:
specs:
- id:
text: It [[MUST]] work
For more example, there is a fixture in spec/fixtures/rfc.yaml
, and the example spec file in spec/rfc.yaml
.
...programmatically
Declaring specs programmatically can be interesting if you manage somehow to process the original specification
automatically.
specs = RSpec::RfcHelper::Specs.new name: 'The easy thing RFC', url: 'https://somewhere'
spec.add_section number: '1.1', title: 'Implementation', id: :implementation
spec.add section: '1.1', text: 'It [[MUST]] do something', id: :do_something
spec.add section: '1.1', text: <<~TXT, id: :do_something
Some long text, but the context is important to understand
what you [[MUST]] implement, how you SHOULD do it
and what you MAY do if you feel like it
TXT
Usage in RSpec
...with the spec file: use the module
require 'rspec/rfc-helper'
RSpec.configure do |config|
config.before(:suite) do
RSpec::RfcHelper.start_from_file 'path/to/your/spec.yaml'
end
config.after do |example|
RSpec::RfcHelper.add_example example
end
config.after( :suite) do
RSpec::RfcHelper.save_markdown_report 'path/to/report.md'
end
end
...programmatically: use the classes
require 'rspec-rfc-helper'
RSpec.configure do |config|
rfc_helper = RSpec::RfcHelper::Spec.new name: 'Plumbus management', url: 'https://somewhere'
rfc_helper.add_section
rfc_helper.add
rfc_helper = RSpec::RfcHelper::Spec.new_from_file 'path_to_file'
config.after do |example|
rfc_helper.add_example example
end
config.after( :suite) do
rfc_helper.save_markdown_report 'path/to/report.md'
end
end
Reference the specs in your suite
RFC Helper uses the RSpec tagging system to track and assign examples to specs.
RSpec.describe 'Something' do
it 'works', rfc: :section1__spec_id do
end
it 'works', rfc: [:section1__spec_id, :other_section__other_spec_id] do
end
end
Development
After checking out the repo, run bundle install
to install dependencies. Then, run bundle exec rspec
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 the created tag, and push the .gem
file to rubygems.org.
Tools
Well, we use RSpec for testing.
Also, we use Rubocop for code style.
Contributing
All contributions, ideas and discussions are welcome. Feel free to open issues and feature requests on the
bug tracker.
You also can join the ExperimentsLabs Matrix chatroom
to discuss of the project.