Module: RspecStarter::Help
- Included in:
- Runner
- Defined in:
- lib/rspec_starter/help.rb
Instance Method Summary collapse
-
#calling_file_name ⇒ Object
This is ugly, but it gives us some added flexibility.
- #should_show_help? ⇒ Boolean
- #show_help ⇒ Object
Instance Method Details
#calling_file_name ⇒ Object
This is ugly, but it gives us some added flexibility. Users can invoke the rspec_starter method from any script or executable. This method attempts to find out the name of the script/exectuable. “caller” returns the method stack, and because of the location of this file in the gem, we happen to be the 4 item in the the array (hence “caller” below).
This method may not return a pretty result in all cases, but it’s decent if the user has defined a script in their project (possibly in the bin folder, or root of the project).
31 32 33 |
# File 'lib/rspec_starter/help.rb', line 31 def calling_file_name caller[3].split(":")[0] end |
#should_show_help? ⇒ Boolean
3 4 5 |
# File 'lib/rspec_starter/help.rb', line 3 def should_show_help? ARGV.any? { |option| option.include? "--help" } end |
#show_help ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/rspec_starter/help.rb', line 7 def show_help # Figure out the name of the file that invoked the rspec_starter helper. This is the name of the script; it be called anything. script_name = calling_file_name puts "Usage: #{script_name.rs_yellow} #{'[options] [options for RSpec]'.rs_yellow}\n" puts " #{script_name} will look for its own options first then pass any remaining options to rspec" puts "\nOptions: (run 'rspec --help' to see RSpec's options)" puts " #{'--no-xvfb'.rs_yellow} DO NOT run XVFB (this can speed up RSpec when running tests that don't need XVFB)" puts " #{'--no-prep'.rs_yellow} DO NOT prepare the test database (can speed up testing if you know the DB is clean)" puts "\nExamples:" puts " #{script_name.rs_yellow} #{'spec/features'.rs_yellow} (only run specs in the specs/features folder)" puts " #{script_name.rs_yellow} #{'spec/features/some_spec:53'.rs_yellow} (run the spec on line 53 of the spec/features_some_spec.rb file)" puts " #{script_name.rs_yellow} #{'--no-xvfb'.rs_yellow} #{'spec/requests/some_spec'.rs_yellow} (don't start XVFB since it's not needed for request specs)" puts " SIMPLECOV_FORMATTER=rcov #{script_name.rs_yellow} (use with environment variables)\n" end |