You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Is your feature request related to a problem? Please describe.
The current tests utilize let(:using_webpacker) { false } at the beginning and then override this condition within specific tests to true when needed. This approach, while flexible, can lead to confusion as the override happens in the middle of the test file, making it harder to track which condition applies to which set of tests.
Describe the solution you'd like
I propose that we reorganize these tests using RSpec's context blocks to group related tests under clear conditions. Each context will have its let and before blocks, making it immediately apparent which setup applies to which group of tests. This structure not only improves readability but also aligns with best practices by clearly separating different testing scenarios.
Describe alternatives you've considered
1- Use of Contexts: Define two main contexts: context "when not using webpacker" and context "when using webpacker". This distinction will group tests based on whether webpacker is being used, making the test conditions clearer.
2- Specific Setup per Context: Move the let(:using_webpacker) and related before blocks into their respective contexts. This ensures that each test group has its setup, avoiding the need for mid-file overrides.
Additional context
Benefits:
Clarity: It will be easier for developers to understand at a glance which conditions apply to which tests.
Maintainability: New tests can be added to the appropriate context without worrying about affecting unrelated tests.
Best Practices: Adheres to RSpec's intended use of context for organizing tests under specific conditions.
Example Refactoring:
moduleReactOnRailsRSpec.describeConfigurationdolet(:existing_path){Pathname.new(Dir.mktmpdir)}let(:not_existing_path){"/path/to/#{SecureRandom.hex(4)}"}beforedoReactOnRails.instance_variable_set(:@configuration,nil)endafterdoReactOnRails.instance_variable_set(:@configuration,nil)end# Use contexts to separate tests with different conditionscontext"when not using webpacker"dolet(:using_webpacker){false}beforedoallow(ReactOnRails::WebpackerUtils).toreceive(:using_webpacker?).and_return(using_webpacker)end# Place tests that operate under the condition `using_webpacker` is falseendcontext"when using webpacker"dolet(:using_webpacker){true}let(:webpacker_public_output_path){File.expand_path(File.join(Rails.root,"public/webpack/dev"))}beforedoallow(ReactOnRails::WebpackerUtils).toreceive(:using_webpacker?).and_return(using_webpacker)allow(Rails).toreceive(:root).and_return(File.expand_path("."))allow(Webpacker).toreceive_message_chain("config.public_output_path").and_return(webpacker_public_output_path)enddescribe"generated_assets_dir"doit"does not throw if the generated assets dir is blank with webpacker"doexpectdoReactOnRails.configuredo |config|
config.generated_assets_dir=""endend.not_toraise_errorendit"does not throw if the webpacker_public_output_path does match the generated assets dir"doexpectdoReactOnRails.configuredo |config|
config.generated_assets_dir="public/webpack/dev"endend.not_toraise_errorendit"does throw if the webpacker_public_output_path does not match the generated assets dir"doexpectdoReactOnRails.configuredo |config|
config.generated_assets_dir="public/webpack/other"endend.toraise_error(ReactOnRails::Error,/does not match the value for public_output_path/)endend# Add additional "when using webpacker" tests hereend# Add any additional contexts or tests hereendend
The text was updated successfully, but these errors were encountered:
While reviewing and checking on the Configuration specs within the ReactOnRails module, I've identified an area where we can improve the readability and organization of the test conditions, particularly concerning the use of the let(:using_webpacker) setup.
https://github.com/shakacode/react_on_rails/blob/master/spec/react_on_rails/configuration_spec.rb#L1-L305
Is your feature request related to a problem? Please describe.
The current tests utilize let(:using_webpacker) { false } at the beginning and then override this condition within specific tests to true when needed. This approach, while flexible, can lead to confusion as the override happens in the middle of the test file, making it harder to track which condition applies to which set of tests.
Describe the solution you'd like
I propose that we reorganize these tests using RSpec's context blocks to group related tests under clear conditions. Each context will have its let and before blocks, making it immediately apparent which setup applies to which group of tests. This structure not only improves readability but also aligns with best practices by clearly separating different testing scenarios.
Describe alternatives you've considered
1- Use of Contexts: Define two main contexts: context "when not using webpacker" and context "when using webpacker". This distinction will group tests based on whether webpacker is being used, making the test conditions clearer.
2- Specific Setup per Context: Move the let(:using_webpacker) and related before blocks into their respective contexts. This ensures that each test group has its setup, avoiding the need for mid-file overrides.
Additional context
Benefits:
Example Refactoring:
The text was updated successfully, but these errors were encountered: