Sha256: 0ab4b293d945942df78740bb7e280a5b8cda90eb540919aa7f19446da7596b3d

Contents?: true

Size: 1.71 KB

Versions: 68

Compression:

Stored size: 1.71 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/#{singularized_class_name}_manager"
      FileUtils.mkdir_p(file_dir) unless Dir.exist?(file_dir)
      file_path = "#{file_dir}/#{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: {
                    argument: "argument test!"
                  }) {
                      response
                    }
                  }
                )
              end

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

              it "return User response" 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(eq("success!"))
              end
            end
          end
        TEXT
      end
      SOULs::Painter.create_file(file_path.to_s)
      file_path
    end
  end
end

Version data entries

68 entries across 68 versions & 1 rubygems

Version Path
souls-4.1.2 lib/souls/cli/generate/rspec_manager.rb
souls-4.1.1 lib/souls/cli/generate/rspec_manager.rb
souls-4.1.0 lib/souls/cli/generate/rspec_manager.rb
souls-4.0.3 lib/souls/cli/generate/rspec_manager.rb
souls-4.0.2 lib/souls/cli/generate/rspec_manager.rb
souls-4.0.1 lib/souls/cli/generate/rspec_manager.rb
souls-4.0.0 lib/souls/cli/generate/rspec_manager.rb
souls-3.0.8 lib/souls/cli/generate/rspec_manager.rb
souls-3.0.7 lib/souls/cli/generate/rspec_manager.rb
souls-3.0.6 lib/souls/cli/generate/rspec_manager.rb
souls-3.0.5 lib/souls/cli/generate/rspec_manager.rb
souls-3.0.4 lib/souls/cli/generate/rspec_manager.rb
souls-3.0.3 lib/souls/cli/generate/rspec_manager.rb
souls-3.0.2 lib/souls/cli/generate/rspec_manager.rb
souls-3.0.1 lib/souls/cli/generate/rspec_manager.rb
souls-3.0.0 lib/souls/cli/generate/rspec_manager.rb
souls-2.0.4 lib/souls/cli/generate/rspec_manager.rb
souls-2.0.3 lib/souls/cli/generate/rspec_manager.rb
souls-2.0.2 lib/souls/cli/generate/rspec_manager.rb
souls-2.0.1 lib/souls/cli/generate/rspec_manager.rb