rspec-api-blueprint-formatter
rspec-api-blueprint-formatter copied to clipboard
Rspec Documentation for Sinatra
Hi I have a rather simple service Sinatra, tested via Rspec, The Other API are Node applications and are using API Blueprints. I would like all of the documentation to match, so I found this little awesome gem you made.
the only issue I'm having is when I run rspec spec --tag apidoc -f ApiBlueprint --out spec/apispec.md
in the console I get an empty spec/apispec.md
file.
my spec_helper.rb there is no rails_helper.rb as this is sinatra could that be a problem?
require 'rack/test'
require 'rspec'
require "pry"
ENV['RACK_ENV'] = 'test'
Dir["#{Dir.pwd}/spec/support/**/*.rb"].sort.each { |file| require file }
require File.expand_path '../../app.rb', __FILE__
module Requests
include ResponseHelpers
end
module RSpecMixin
include Rack::Test::Methods
include Requests
def app() API end
end
# For RSpec 2.x and 3.x
RSpec.configure do |config|
config.include RSpecMixin
config.around(:each) do |example|
DB.transaction(:rollback=>:always, :auto_savepoint=>true){example.run}
end
end
UPDATE
digging into this a little bit in ApiBlueprint#example_passed
the following line is rasing an error
@example_group_instance = notification.example.example_group_instance
notification is undefined.
Chris, thank you for opening this issue. I unfortunately am not really familiar with Sinatra, my guess would be that the gem is assuming certain fields to be accessible that come from the Rails request cycle. There is nothing inherent that requires it to be like that, I imagine we could make it Rack compliant, so definitely feel free to open a PR if end up going down that route.
@nambrot I have updated my comment, with a possible issue I'm not familiar with implementing plugins for Rspec. Any documentation you can point me to would be awesome.
Thanks for the quick response!
It's not a super complex gem, the main logic is in https://github.com/nambrot/rspec-api-blueprint-formatter/blob/master/lib/api_blueprint/example_formatter.rb
Basically at the end of a test, we just look for metadata on it, and if it matches we print it out