Sha256: 017b8fe6263d6e07fcbe43c794e68f520cf8f12f0fb112c67bdbd2b56b806f14

Contents?: true

Size: 1.83 KB

Versions: 2

Compression:

Stored size: 1.83 KB

Contents

require "rails/generators"

module Suspenders
  class TestingGenerator < Rails::Generators::Base
    source_root File.expand_path(
      File.join("..", "..", "..", "templates"),
      File.dirname(__FILE__),
    )

    def add_testing_gems
      gem "spring-commands-rspec", group: :development
      gem "rspec-rails", "~> 3.8", group: %i(development test)
      gem "shoulda-matchers", group: :test

      Bundler.with_clean_env { run "bundle install" }
    end

    def generate_rspec
      generate "rspec:install"
    end

    def configure_rspec
      remove_file "spec/rails_helper.rb"
      remove_file "spec/spec_helper.rb"
      copy_file "rails_helper.rb", "spec/rails_helper.rb"
      copy_file "spec_helper.rb", "spec/spec_helper.rb"
    end

    def provide_shoulda_matchers_config
      copy_file(
        "shoulda_matchers_config_rspec.rb",
        "spec/support/shoulda_matchers.rb",
      )
    end

    def configure_spec_support_features
      empty_directory_with_keep_file "spec/features"
      empty_directory_with_keep_file "spec/support/features"
    end

    def configure_i18n_for_test_environment
      copy_file "i18n.rb", "spec/support/i18n.rb"
    end

    def configure_action_mailer_in_specs
      copy_file "action_mailer.rb", "spec/support/action_mailer.rb"
    end

    def create_binstubs
      Bundler.with_clean_env { run "bundle binstubs rspec-core" }
    end

    def add_helpers_for_rspec
      copy_file 'queries_helper_rspec.rb', 'spec/support/queries_helper.rb'
    end

    def add_capybara_helper
      copy_file 'capybara_helpers.rb', 'spec/support/capybara_helpers.rb'
    end

    private

    def empty_directory_with_keep_file(destination)
      empty_directory(destination, {})
      keep_file(destination)
    end

    def keep_file(destination)
      create_file(File.join(destination, ".keep"))
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
welaika-suspenders-2.29.0.alpha.2 lib/suspenders/generators/testing_generator.rb
welaika-suspenders-2.29.0.alpha.1 lib/suspenders/generators/testing_generator.rb