Security, how to temporarily track a specific file?

I am using Guard gem

At some point in development, I need to track only a specific file or several files, but not the entire project.

Is there a convenient way to temporarily track a specific file?

I know that this can be done by changing the protection file, but I do not think this is a neat solution.

+7
source share
4 answers

In fact, you can simply use focus: true in the it statement for example:

In your Spec file.

 it "needs to focus on this!", focus: true do #test written here. end 

Then in spec / spec_helper you need to add the config option.

 RSpec.configure do |config| config.treat_symbols_as_metadata_keys_with_true_values = true config.filter_run :focus => true config.run_all_when_everything_filtered = true end 

Then Guard will automatically pick up the test that is focused and run it. In addition, config.run_all_when_everything_filtered = true tells the guard to run all tests when nothing is filtered, even if the name sounds misleading.

I believe Ryan Bate's rails are very useful for Guard and Spork .

+12
source

Perhaps groups will work for you?

 # In your Guardfile group :focus do guard :ruby do watch('file_to_focus_on.rb') end end # Run it with guard -g focus 

I know that you mentioned that you do not want to change the Guardfile, but you need to add a group just once, not every time you switch from viewing a project to a focused set and vice versa.

Of course, if you need to focus on the changes in the fileset, you will need to change the arguments to watch (and possibly add more observers), but I suppose you will need to specify them somewhere, and this seems like a good place like any .

Alternatively, if you really do not want to list the files that you need to focus on in Guard File, you can get: a focus group read in the list of files from a separate file or environment variable, as suggested by David above . Guardfile is just ruby ​​(with access to the security DSL), so it's easy to read a file or ENV variable.

+3
source

If you are using guard-rspec . You can do it.

Modify the Guardfile rspec block to have something like this:

 guard 'rspec', :cli => ENV['RSPEC_e'].nil? ? "": "-e #{ENV['RSPEC_e']}") do # ... regular rspec-rails stuff goes here ... end 

Launch the Guard. And set RSPEC_e . So ...

 RSPEC_e=here guard 

Then whenever you change something, only those specifications that contain the text "here" (specified by RSPEC_e) in their description will be re-displayed.

+1
source

You can permanently modify the protection file to check the environment variable of your choice and behave differently if present. For example, refer to the variable ENV ['FILE']. Then you can add a command to start protection with FILE=foo.rb whenever you want.

0
source

All Articles