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

Ability to add custom reloaders to run before running all specs. #43

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

sumitmah
Copy link

This ability will give us resolve issues related to missing constants, loading/requiring files.

@sumitmah sumitmah changed the title Ability to add custom reloaders to run be running all specs. Ability to add custom reloaders to run before running all specs. Apr 19, 2016
@nilbus
Copy link
Collaborator

nilbus commented Apr 19, 2016

Hi @sumitmah, thanks for this! Before we get this ready to merge, could you help us understand the scenario in which you want to have special reloaders associated with run_all but not normal runs?

Gemfile.lock
.idea/
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd rather not see .idea in the project .gitignore, as it's specific to your editor. Instead, this belongs in your global gitignore file. See https://help.github.com/articles/ignoring-files/ for setting this up.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure.

@sumitmah
Copy link
Author

sumitmah commented Apr 19, 2016

@nilbus As it is mentioned in readme,

Since JRuby cannot fork, guard-jruby-rspec reloads code with load on each changed path, which can potentially cause weird side side effects or errors.

I was also facing similar issues with my Rails project. e.g. for shared specs(I saw similar issue already posted for this gem) "context not found". This was happening because of following code.

def unload_previous_examples
  ::RSpec.configuration.reset
  ::RSpec.world.reset
end

::RSpec.world.reset will remove shared example groups. Following is definition of reset method. I had to reload these examples explicitly in the custom reloader for run all on rerun. Since following method clears the example groups.

def reset
  example_groups.clear
  @shared_example_group_registry = nil
end

Here is example from my guardfile

    reload_shared_specs = lambda do 
    if Object.const_defined?('Rails')
      $LOADED_FEATURES.reject! { |path| path =~ /\/spec\/support\//}
      ActiveSupport::Dependencies.loaded.reject! { |path| path =~ /\/spec\/support\//}.inspect

      ActiveSupport::Dependencies.autoloaded_constants.each {|c|   ActiveSupport::Dependencies.loaded.reject! { |path| path =~ /#{c.to_s.underscore}/} }
      ActiveSupport::Dependencies.autoloaded_constants.each {|c| $LOADED_FEATURES.reject! { |path| path =~ /#{c.to_s.underscore}/} }

      ActiveSupport::Dependencies.explicitly_unloadable_constants.each {|c| ActiveSupport::Dependencies.loaded.reject! { |path| path =~ /#{c.to_s.underscore}/} }
      ActiveSupport::Dependencies.explicitly_unloadable_constants.each {|c| $LOADED_FEATURES.reject! { |path| path =~ /#{c.to_s.underscore}/} }

      Dir[::Rails.root.join('spec/support/**/*.rb')].each { |f| ::RSpec.world.shared_example_group_registry.require_or_load(f) }
      end
    end

@sumitmah
Copy link
Author

sumitmah commented Apr 20, 2016

@nilbus @jkutner any thoughts on this?

@nilbus
Copy link
Collaborator

nilbus commented May 8, 2016

Thanks for the background information, and sorry for the delay @sumitmah. I'm trying to connect the code changes with that background story. Is the Guardfile code you provided what you're running inside a custom_reloaders_for_run_all block?

@sumitmah
Copy link
Author

sumitmah commented May 9, 2016

@nilbus Yes

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants