Sha256: 9558c1188b4fea2647db787fbfff9290a2950b76fc9005f3de6ab437801fe373

Contents?: true

Size: 1.4 KB

Versions: 1

Compression:

Stored size: 1.4 KB

Contents

module RSpec
  module Generators
    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
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
myrails-7.0.0 lib/myrails/modules/rspec_generators.rb