Class: MSpecTag
- Inherits:
-
MSpecScript
- Object
- MSpecScript
- MSpecTag
- Defined in:
- lib/mspec/commands/mspec-tag.rb
Instance Method Summary collapse
-
#initialize ⇒ MSpecTag
constructor
A new instance of MSpecTag.
- #options(argv = ARGV) ⇒ Object
- #register ⇒ Object
- #run ⇒ Object
Methods inherited from MSpecScript
config, #config, #custom_options, #custom_register, #entries, #files, get, #load, #load_default, main, set, #signals
Constructor Details
#initialize ⇒ MSpecTag
Returns a new instance of MSpecTag.
9 10 11 12 13 14 15 16 |
# File 'lib/mspec/commands/mspec-tag.rb', line 9 def initialize super config[:tagger] = :add config[:tag] = 'fails:' config[:outcome] = :fail config[:ltags] = [] end |
Instance Method Details
#options(argv = ARGV) ⇒ Object
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 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/mspec/commands/mspec-tag.rb', line 18 def (argv=ARGV) = MSpecOptions.new "mspec tag [options] (FILE|DIRECTORY|GLOB)+", 30, config .doc " Ask yourself:" .doc " 1. What specs to run?" .doc " 2. How to modify the execution?" .doc " 3. How to display the output?" .doc " 4. What tag action to perform?" .doc " 5. When to perform it?" .doc "\n What specs to run" .filters .doc "\n How to modify the execution" .configure { |f| load f } .name .pretend .unguarded .interrupt .doc "\n How to display their output" .formatters .verbose .doc "\n What action to perform and when to perform it" .on("-N", "--add", "TAG", "Add TAG with format 'tag' or 'tag(comment)' (see -Q, -F, -L)") do |o| config[:tagger] = :add config[:tag] = "#{o}:" end .on("-R", "--del", "TAG", "Delete TAG (see -Q, -F, -L)") do |o| config[:tagger] = :del config[:tag] = "#{o}:" config[:outcome] = :pass end .on("-Q", "--pass", "Apply action to specs that pass (default for --del)") do config[:outcome] = :pass end .on("-F", "--fail", "Apply action to specs that fail (default for --add)") do config[:outcome] = :fail end .on("-L", "--all", "Apply action to all specs") do config[:outcome] = :all end .on("--list", "TAG", "Display descriptions of any specs tagged with TAG") do |t| config[:tagger] = :list config[:ltags] << t end .on("--list-all", "Display descriptions of any tagged specs") do config[:tagger] = :list_all end .on("--purge", "Remove all tags not matching any specs") do config[:tagger] = :purge end .doc "\n Help!" .version MSpec::VERSION .help .doc "\n Custom options" .doc "\n How might this work in the real world?" .doc "\n 1. To add the 'fails' tag to failing specs" .doc "\n $ mspec tag path/to/the_file_spec.rb" .doc "\n 2. To remove the 'fails' tag from passing specs" .doc "\n $ mspec tag --del fails path/to/the_file_spec.rb" .doc "\n 3. To display the descriptions for all specs tagged with 'fails'" .doc "\n $ mspec tag --list fails path/to/the/specs" .doc "" patterns = .parse argv if patterns.empty? puts puts "No files specified." exit 1 end @files = files patterns end |
#register ⇒ Object
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 |
# File 'lib/mspec/commands/mspec-tag.rb', line 99 def register case config[:tagger] when :add, :del tag = SpecTag.new config[:tag] tagger = TagAction.new(config[:tagger], config[:outcome], tag.tag, tag.comment, config[:atags], config[:astrings]) when :list, :list_all tagger = TagListAction.new config[:tagger] == :list_all ? nil : config[:ltags] MSpec.register_mode :pretend config[:formatter] = false when :purge tagger = TagPurgeAction.new MSpec.register_mode :pretend MSpec.register_mode :unguarded config[:formatter] = false else raise ArgumentError, "No recognized action given" end tagger.register super end |