Class: RspecStarter::Helpers
- Inherits:
-
Object
- Object
- RspecStarter::Helpers
- Defined in:
- lib/rspec_starter/helpers.rb
Overview
A class that provides helper methods that can be used anywhere in RspecStarter.
Instance Method Summary collapse
- #class_for_task_name(string_or_symbol) ⇒ Object
- #is_linux? ⇒ Boolean
- #is_mac? ⇒ Boolean
- #operating_system_name ⇒ Object
- #project_has_lib_dir? ⇒ Boolean
- #project_is_rails_app? ⇒ Boolean
- #project_is_rails_engine? ⇒ Boolean
-
#starter_script_file_name ⇒ Object
This is ugly, but it gives us some added flexibility.
- #xvfb_installed? ⇒ Boolean
- #xvfb_not_installed? ⇒ Boolean
Instance Method Details
#class_for_task_name(string_or_symbol) ⇒ Object
9 10 11 |
# File 'lib/rspec_starter/helpers.rb', line 9 def class_for_task_name(string_or_symbol) string_or_symbol.to_s.camelize.constantize end |
#is_linux? ⇒ Boolean
49 50 51 |
# File 'lib/rspec_starter/helpers.rb', line 49 def is_linux? == :linux end |
#is_mac? ⇒ Boolean
53 54 55 |
# File 'lib/rspec_starter/helpers.rb', line 53 def is_mac? == :maxosx end |
#operating_system_name ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/rspec_starter/helpers.rb', line 31 def @operating_system_name ||= begin host_os = RbConfig::CONFIG['host_os'] case host_os when /mswin|msys|mingw|cygwin|bccwin|wince|emc/ :windows when /darwin|mac os/ :macosx when /linux/ :linux when /solaris|bsd/ :unix else :unknown end end end |
#project_has_lib_dir? ⇒ Boolean
26 27 28 |
# File 'lib/rspec_starter/helpers.rb', line 26 def project_has_lib_dir? @project_has_lib_dir ||= Dir.exist?("#{Dir.pwd}/lib") end |
#project_is_rails_app? ⇒ Boolean
13 14 15 |
# File 'lib/rspec_starter/helpers.rb', line 13 def project_is_rails_app? @project_is_rails_app ||= File.file?(File.join(Dir.pwd, 'config', 'application.rb')) end |
#project_is_rails_engine? ⇒ Boolean
17 18 19 20 21 22 23 24 |
# File 'lib/rspec_starter/helpers.rb', line 17 def project_is_rails_engine? return false unless project_has_lib_dir? Dir["#{Dir.pwd}/lib/**/*.rb"].each do |file| return true if File.readlines(file).detect { |line| line.match(/\s*class\s+.*<\s+::Rails::Engine/) } end false end |
#starter_script_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 file name of the script/exectuable.
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).
70 71 72 |
# File 'lib/rspec_starter/helpers.rb', line 70 def starter_script_file_name caller.last.split(":")[0] end |
#xvfb_installed? ⇒ Boolean
57 58 59 |
# File 'lib/rspec_starter/helpers.rb', line 57 def xvfb_installed? @xvfb_installed ||= RspecStarter.which("xvfb-run") end |
#xvfb_not_installed? ⇒ Boolean
61 62 63 |
# File 'lib/rspec_starter/helpers.rb', line 61 def xvfb_not_installed? !xvfb_installed? end |