Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use RSpec's when_first_matching_example_defined if available #1496

Merged
merged 2 commits into from
Jan 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ Changes since last non-beta release.

### Added
- Exposed `reactHydrateOrRender` utility via [PR 1481](https://github.com/shakacode/react_on_rails/pull/1481) by [vaukalak](https://github.com/vaukalak).
- Optimized `ReactOnRails::TestHelper`'s RSpec integration using
`when_first_matching_example_defined` via [PR 1496](https://github.com/shakacode/react_on_rails/pull/1496)

### [13.1.0] - 2022-08-20

Expand Down
11 changes: 10 additions & 1 deletion lib/react_on_rails/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,17 @@ module TestHelper
def self.configure_rspec_to_compile_assets(config, *metatags)
metatags = %i[js server_rendering controller] if metatags.empty?

# Supported since RSpec 3.5.0
supports_first_matching_example = config.respond_to?(:when_first_matching_example_defined)

metatags.each do |metatag|
config.before(:example, metatag) { ReactOnRails::TestHelper.ensure_assets_compiled }
if supports_first_matching_example
config.when_first_matching_example_defined(metatag) do
ReactOnRails::TestHelper.ensure_assets_compiled
end
else
config.before(:example, metatag) { ReactOnRails::TestHelper.ensure_assets_compiled }
end
end
end

Expand Down