Sha256: 366e844e7fd3a642b4dce67125caefa5edf90d61f5e2dd2be72e041a384cdb05

Contents?: true

Size: 928 Bytes

Versions: 18

Compression:

Stored size: 928 Bytes

Contents

require 'rails/generators'

module Twirp
  class RspecGenerator < Rails::Generators::Base
    desc 'Install twirp rspec helpers into rails_helper.rb'
    def inject_rspec_helper
      in_root do
        unless File.exist?('spec/rails_helper.rb')
          log :inject_rspec, 'spec/rails_helper.rb is not found'
          return
        end

        require_sentinel = %r{require 'rspec/rails'\s*\n}m
        include_sentinel = /RSpec\.configure\s*do\s*\|config\|\s*\n/m

        inject_into_file 'spec/rails_helper.rb',
                         "require 'twirp_rails/rspec/helper'\n",
                         after: require_sentinel, verbose: true, force: false
        inject_into_file 'spec/rails_helper.rb',
                         "  config.include TwirpRails::RSpec::Helper, type: :rpc, file_path: %r{spec/rpc}\n",
                         after: include_sentinel, verbose: true, force: false
      end
    end
  end
end

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
twirp_rails-0.4.11 lib/twirp_rails/generators/twirp/twirp_rspec_generator.rb
twirp_rails-0.4.10 lib/twirp_rails/generators/twirp/twirp_rspec_generator.rb
twirp_rails-0.4.9 lib/twirp_rails/generators/twirp/twirp_rspec_generator.rb
twirp_rails-0.4.8 lib/twirp_rails/generators/twirp/twirp_rspec_generator.rb
twirp_rails-0.4.7 lib/twirp_rails/generators/twirp/twirp_rspec_generator.rb
twirp_rails-0.4.6 lib/twirp_rails/generators/twirp/twirp_rspec_generator.rb
twirp_rails-0.4.5 lib/twirp_rails/generators/twirp/twirp_rspec_generator.rb
twirp_rails-0.4.4 lib/twirp_rails/generators/twirp/twirp_rspec_generator.rb
twirp_rails-0.4.3 lib/twirp_rails/generators/twirp/twirp_rspec_generator.rb
twirp_rails-0.4.2 lib/twirp_rails/generators/twirp/twirp_rspec_generator.rb
twirp_rails-0.4.1 lib/twirp_rails/generators/twirp/twirp_rspec_generator.rb
twirp_rails-0.4.0 lib/twirp_rails/generators/twirp/twirp_rspec_generator.rb
twirp_rails-0.3.2 lib/twirp_rails/generators/twirp/twirp_rspec_generator.rb
twirp_rails-0.3.1 lib/twirp_rails/generators/twirp/twirp_rspec_generator.rb
twirp_rails-0.3.0 lib/twirp_rails/generators/twirp/twirp_rspec_generator.rb
twirp_rails-0.2.1 lib/twirp_rails/generators/twirp/twirp_rspec_generator.rb
twirp_rails-0.2.0 lib/twirp_rails/generators/twirp/twirp_rspec_generator.rb
twirp_rails-0.1.7 lib/twirp_rails/generators/twirp/twirp_rspec_generator.rb