Class: Decko::Commands::RspecCommand::Parser
- Inherits:
-
OptionParser
- Object
- OptionParser
- Decko::Commands::RspecCommand::Parser
- Defined in:
- lib/decko/commands/rspec_command/parser.rb
Instance Method Summary collapse
- #find_spec_file(filename, base_dir) ⇒ Object
-
#initialize(opts) ⇒ Parser
constructor
A new instance of Parser.
Constructor Details
#initialize(opts) ⇒ Parser
Returns a new instance of Parser.
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/decko/commands/rspec_command/parser.rb', line 8 def initialize opts super() do |parser| parser. = "Usage: decko rspec [DECKO ARGS] -- [RSPEC ARGS]\n\n" \ "RSPEC ARGS" parser.separator "\n DECKO ARGS\n\n You don't have to give a full path for FILENAME, the basename is enough\n If FILENAME does not include '_spec' rspec searches for the\n corresponding spec file.\n The line number always referes to example in the (corresponding) spec\n file.\n\n EOT\n\n parser.on(\"-d\", \"--spec FILENAME(:LINE)\",\n \"Run spec for a Decko deck file\") do |file|\n opts[:files] = find_spec_file(file, \"\#{Decko.root}/mod\")\n end\n parser.on(\"-c\", \"--core-spec FILENAME(:LINE)\",\n \"Run spec for a Decko core file\") do |file|\n opts[:files] = find_spec_file(file, Cardio.gem_root)\n end\n parser.on(\"-m\", \"--mod MODNAME\",\n \"Run all specs for a mod or matching a mod\") do |file|\n opts[:files] =\n if File.exist?(\"mod/\#{file}\")\n \"\#{Cardio.gem_root}/mod/\#{file}\"\n elsif File.exist?(\"\#{Cardio.gem_root}/mod/\#{file}\")\n \"\#{Cardio.gem_root}/mod/\#{file}\"\n elsif (files = find_spec_file(file, \"mod\")) && files.present?\n files\n else\n find_spec_file(file, \"\#{Cardio.gem_root}/mod\")\n end\n end\n parser.on(\"-s\", \"--[no-]simplecov\", \"Run with simplecov\") do |s|\n opts[:simplecov] = s ? \"\" : \"COVERAGE=false\"\n end\n parser.on(\"--rescue\", \"Run with pry-rescue\") do\n if opts[:executer] == \"spring\"\n puts \"Disabled pry-rescue. Not compatible with spring.\"\n else\n opts[:rescue] = \"rescue \"\n end\n end\n parser.on(\"--[no-]spring\", \"Run with spring\") do |spring|\n if spring\n opts[:executer] = \"spring\"\n if opts[:rescue]\n opts[:rescue] = \"\"\n puts \"Disabled pry-rescue. Not compatible with spring.\"\n end\n else\n opts[:executer] = \"bundle exec\"\n end\n end\n parser.separator \"\\n\"\n end\nend\n" |
Instance Method Details
#find_spec_file(filename, base_dir) ⇒ Object
70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/decko/commands/rspec_command/parser.rb', line 70 def find_spec_file filename, base_dir file, line = filename.split(":") if file.include?("_spec.rb") && File.exist?(file) filename else file = File.basename(file, ".rb").sub(/_spec$/, "") Dir.glob("#{base_dir}/**/#{file}_spec.rb").flatten.map do |spec_file| line ? "#{spec_file}:#{line}" : file end.join(" ") end end |