Sha256: f25d1c5d2491f207f75a616d39a1c07c8b954aa347946cbbf51639ef298f2c08

Contents?: true

Size: 1.24 KB

Versions: 24

Compression:

Stored size: 1.24 KB

Contents

# frozen_string_literal: true

require "refinements/structs"

module Gemsmith
  module Builders
    module RSpec
      # Builds RSpec spec helper for project skeleton.
      class Helper
        using Refinements::Structs

        def self.call(...) = new(...).call

        def initialize configuration, builder: Rubysmith::Builder
          @configuration = configuration
          @builder = builder
        end

        def call
          return configuration unless configuration.build_rspec && configuration.build_cli

          update_spec_helper
          render_shared_example
          configuration
        end

        private

        attr_reader :configuration, :builder

        def update_spec_helper
          builder.call(configuration.merge(template_path: "%project_name%/spec/spec_helper.rb.erb"))
                 .touch
                 .insert_after(
                   %r(support/shared_contexts),
                   %(Pathname.require_tree __dir__, "support/shared_examples/**/*.rb"\n)
                 )
        end

        def render_shared_example
          path = "%project_name%/spec/support/shared_examples/a_parser.rb.erb"
          builder.call(configuration.merge(template_path: path)).render
        end
      end
    end
  end
end

Version data entries

24 entries across 24 versions & 1 rubygems

Version Path
gemsmith-19.5.0 lib/gemsmith/builders/rspec/helper.rb
gemsmith-19.4.0 lib/gemsmith/builders/rspec/helper.rb
gemsmith-19.3.0 lib/gemsmith/builders/rspec/helper.rb
gemsmith-19.2.0 lib/gemsmith/builders/rspec/helper.rb
gemsmith-19.1.0 lib/gemsmith/builders/rspec/helper.rb
gemsmith-19.0.0 lib/gemsmith/builders/rspec/helper.rb
gemsmith-18.9.0 lib/gemsmith/builders/rspec/helper.rb
gemsmith-18.8.0 lib/gemsmith/builders/rspec/helper.rb
gemsmith-18.7.0 lib/gemsmith/builders/rspec/helper.rb
gemsmith-18.6.0 lib/gemsmith/builders/rspec/helper.rb
gemsmith-18.5.0 lib/gemsmith/builders/rspec/helper.rb
gemsmith-18.4.0 lib/gemsmith/builders/rspec/helper.rb
gemsmith-18.3.0 lib/gemsmith/builders/rspec/helper.rb
gemsmith-18.2.0 lib/gemsmith/builders/rspec/helper.rb
gemsmith-18.1.1 lib/gemsmith/builders/rspec/helper.rb
gemsmith-18.1.0 lib/gemsmith/builders/rspec/helper.rb
gemsmith-18.0.2 lib/gemsmith/builders/rspec/helper.rb
gemsmith-18.0.1 lib/gemsmith/builders/rspec/helper.rb
gemsmith-18.0.0 lib/gemsmith/builders/rspec/helper.rb
gemsmith-17.0.1 lib/gemsmith/builders/rspec/helper.rb