Module: RSpec::Generators

Included in:
Myrails::Myrails
Defined in:
lib/myrails/modules/rspec_generators.rb

Class Method Summary collapse

Class Method Details

.included(thor) ⇒ Object



3
4
5
6
7
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
# File 'lib/myrails/modules/rspec_generators.rb', line 3

def self.included(thor)
  thor.class_eval do
    
    desc 'spec <OPTION> <NAME>', 'Execute without options to see HELP. Generate a rspec template with a given name'
    def spec(*opts)
      item, @param = opts
      
      option = {
        example: 'Generate RSpec shared example temlate. Prompts for name and context',
        feature: 'Generate RSpec feature template',
        helper: 'Generates an RSpec helper in support/helpers for extracting reusable code',
        request: 'Generate RSpec request template'
      }
      
      unless item
        say 'ERROR: "myrails spec" was called with no arguments'
        say 'Usage: "myrails spec <OPTION> <NAME>"'
        say "Available Options:\n"
        option.each{|k,v| say "* #{k}: #{v}"}
        exit
      end
      
      raise ArgumentError, "NAME must be specified for #{item} option. Ex: `myrails spec <OPTION> <NAME>`" unless @param
      
      case item
      when 'example'
        shared_example
      when 'feature'
        feature
      when 'helper'
        helper
      when 'request'
        request
      else
        say "Unknown Action! #{@param}"
      end
    end

    desc 's', 'spec shortcut'
    alias_method :s, :spec
    
  end
end