Sha256: 3286bbe95f0254566001ae8fa8a866c0d179104d33ac11227ae096991b150a60

Contents?: true

Size: 1.78 KB

Versions: 110

Compression:

Stored size: 1.78 KB

Contents

module Souls
  class Generate < Thor
    desc "rspec_manager [CLASS_NAME]", "Generate Rspec Manager Test Template"
    method_option :mutation, aliases: "--mutation", required: true, desc: "Mutation File Name"
    def rspec_manager(class_name)
      singularized_class_name = class_name.underscore.singularize
      file_dir = "./spec/managers/"
      FileUtils.mkdir_p(file_dir) unless Dir.exist?(file_dir)
      file_path = "./spec/mutations/managers/#{singularized_class_name}/#{options[:mutation]}_spec.rb"
      return "RspecManager already exist! #{file_path}" if File.exist?(file_path)

      File.open(file_path, "w") do |f|
        f.write(<<~TEXT)
          RSpec.describe("#{options[:mutation].singularize.camelize}") do
            describe "Define #{options[:mutation].singularize.camelize}" do

              let(:mutation) do
                %(mutation {
                  #{options[:mutation].singularize.camelize(:lower)}(input: {}) {
                      response
                    }
                  }
                )
              end

              subject(:result) do
                SoulsApiSchema.execute(mutation).as_json
              end

              it "return StockSheet Data" do
                begin
                  a1 = result.dig("data", "#{options[:mutation].singularize.camelize(:lower)}", "response")
                  raise unless a1.present?
                rescue StandardError
                  raise(StandardError, result)
                end
                expect(a1).to(include("response" => be_a(String)))
              end
            end
          end
        TEXT
      end
      puts(Paint % ["Created file! : %{white_text}", :green, { white_text: [file_path.to_s, :white] }])
      file_path
    rescue Thor::Error => e
      raise(Thor::Error, e)
    end
  end
end

Version data entries

110 entries across 110 versions & 1 rubygems

Version Path
souls-1.6.3 lib/souls/cli/generate/rspec_manager.rb
souls-1.6.2 lib/souls/cli/generate/rspec_manager.rb
souls-1.6.1 lib/souls/cli/generate/rspec_manager.rb
souls-1.6.0 lib/souls/cli/generate/rspec_manager.rb
souls-1.5.7 lib/souls/cli/generate/rspec_manager.rb
souls-1.5.6 lib/souls/cli/generate/rspec_manager.rb
souls-1.5.5 lib/souls/cli/generate/rspec_manager.rb
souls-1.5.4 lib/souls/cli/generate/rspec_manager.rb
souls-1.5.3 lib/souls/cli/generate/rspec_manager.rb
souls-1.5.2 lib/souls/cli/generate/rspec_manager.rb
souls-1.5.1 lib/souls/cli/generate/rspec_manager.rb
souls-1.5.0 lib/souls/cli/generate/rspec_manager.rb
souls-1.4.12 lib/souls/cli/generate/rspec_manager.rb
souls-1.4.11 lib/souls/cli/generate/rspec_manager.rb
souls-1.4.10 lib/souls/cli/generate/rspec_manager.rb
souls-1.4.9 lib/souls/cli/generate/rspec_manager.rb
souls-1.4.8 lib/souls/cli/generate/rspec_manager.rb
souls-1.4.7 lib/souls/cli/generate/rspec_manager.rb
souls-1.4.6 lib/souls/cli/generate/rspec_manager.rb
souls-1.4.5 lib/souls/cli/generate/rspec_manager.rb