Skip to content

Commit de67fae

Browse files
authored
RSpec util for exceptions (#119)
Motivated initially for testing pundit unauthorized exceptions, like: ``` it { is_expected_in_block.to raise_error(Pundit::NotAuthorizedError) } ``` Which matches well with typical `is_expected` cases, like: ``` it { is_expected.to permit_all_actions } ```
1 parent b6e1c86 commit de67fae

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

template/{{app_name}}/.rubocop.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,7 @@ RSpec/ExampleLength:
88
Enabled: false
99
RSpec/MultipleExpectations:
1010
Enabled: false
11+
RSpec/NoExpectationExample:
12+
AllowedPatterns:
13+
- assert_
14+
- is_expected_in_block

template/{{app_name}}/spec/spec_helper.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,10 @@
4646
# triggering implicit auto-inclusion in groups with matching metadata.
4747
config.shared_context_metadata_behavior = :apply_to_host_groups
4848

49+
# https://github.com/rspec/rspec-expectations/issues/805#issuecomment-1792552900
50+
# https://github.com/rspec/rspec/pull/150
51+
config.include(Module.new { def is_expected_in_block = expect { subject } })
52+
4953
# The settings below are suggested to provide a good initial experience
5054
# with RSpec, but feel free to customize to your heart's content.
5155
=begin

0 commit comments

Comments
 (0)