Skip to content

Commit

Permalink
Merge pull request #23 from pocke/Clarify_error_message_when_a_test_c…
Browse files Browse the repository at this point in the history
…ase_is_in_incorrect__describe_

Clarify error message when a test case is in incorrect `describe`
  • Loading branch information
r7kamura authored Mar 28, 2024
2 parents 69e4b16 + cca2346 commit 2dd893a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
7 changes: 6 additions & 1 deletion lib/rspec/request_describer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

module RSpec
module RequestDescriber
class IncorrectDescribe < StandardError; end

RESERVED_HEADER_NAMES = %w[
content-type
host
Expand Down Expand Up @@ -62,7 +64,10 @@ def included(base)

let(:endpoint_segments) do
current_example = ::RSpec.respond_to?(:current_example) ? ::RSpec.current_example : example
current_example.full_description.match(/(#{::Regexp.union(SUPPORTED_METHODS)}) (\S+)/).to_a
match = current_example.full_description.match(/(#{::Regexp.union(SUPPORTED_METHODS)}) (\S+)/)
raise IncorrectDescribe, 'Please use the format "METHOD /path" for the describe' unless match

match.to_a
end

# @return [String] e.g. `"get"`
Expand Down
6 changes: 6 additions & 0 deletions spec/rspec/request_describer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -138,4 +138,10 @@ def get(*args)
)
end
end

context 'when the test case is under the top-level describe unexpectedly' do
it 'handles the error' do
expect { subject }.to raise_error(RSpec::RequestDescriber::IncorrectDescribe)
end
end
end

0 comments on commit 2dd893a

Please sign in to comment.