From 64cfcf5ee6eb1cd957ae726f2d6e7df20ace9894 Mon Sep 17 00:00:00 2001 From: Kevin Jalbert Date: Wed, 14 Oct 2015 09:54:44 -0400 Subject: [PATCH] Allow Class Resources, call `#to_s` for defined resource_name If using a class as the resource: resource Order do end The resource_name will be a class, which causes issues when sorting for sections. By calling `#to_s` on the `args.first` when first dealing with the resource we can ensure that we are always working with a string for the resource_name. --- lib/rspec_api_documentation/dsl.rb | 4 ++-- spec/dsl_spec.rb | 7 +++++++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/lib/rspec_api_documentation/dsl.rb b/lib/rspec_api_documentation/dsl.rb index 646337ab..e8f8478d 100644 --- a/lib/rspec_api_documentation/dsl.rb +++ b/lib/rspec_api_documentation/dsl.rb @@ -18,9 +18,9 @@ module DSL # +block+:: Block to pass into describe # def resource(*args, &block) - options = if args.last.is_a?(Hash) then args.pop else {} end + options = args.last.is_a?(Hash) ? args.pop : {} options[:api_doc_dsl] = :resource - options[:resource_name] = args.first + options[:resource_name] = args.first.to_s options[:document] ||= :all args.push(options) describe(*args, &block) diff --git a/spec/dsl_spec.rb b/spec/dsl_spec.rb index a03ed1c4..57102dfa 100644 --- a/spec/dsl_spec.rb +++ b/spec/dsl_spec.rb @@ -583,3 +583,10 @@ expect(example.metadata[:document]).to eq(:not_all) end end + +class Order; end +resource Order do + it 'should have a string resource_name' do |example| + expect(example.metadata[:resource_name]).to eq(Order.to_s) + end +end