Sha256: ecf5c2c945731183a8e6a44b2a29f1e39968b77ba0935b391249bf8a5b7145a6

Contents?: true

Size: 1.49 KB

Versions: 3

Compression:

Stored size: 1.49 KB

Contents

# frozen_string_literal: true

RSpec.describe "Rake: default task", type: :integration do
  context "with RSpec" do
    it "runs tests" do
      with_project("bookshelf", test: "rspec") do
        setup_model

        prepare_development_database
        generate_development_data

        prepare_test_database

        generate "mailer bookshelf"

        write "spec/bookshelf/repositories/book_repository_spec.rb", <<~EOF
          RSpec.describe BookRepository do
            before do
              described_class.new.clear
            end

            it 'finds all the records' do
              expect(described_class.new.all.to_a).to eq([])
            end
          end
        EOF

        bundle_exec "rake"

        # The default mailer_spec fails on purpose so you set the correct delivery information.
        expect(out).to include("3 examples, 1 failure")

        assert_development_data
      end
    end
  end

  private

  def prepare_development_database
    prepare_database
  end

  def prepare_test_database
    prepare_database env: "test"
  end

  def generate_development_data
    migrate

    console do |input, _, _|
      input.puts("BookRepository.new.create(title: 'Learn Hanami')")
      input.puts("exit")
    end
  end

  def assert_development_data
    console do |input, _, _|
      input.puts("BookRepository.new.all.to_a.count")
      input.puts("exit")
    end

    expect(out).to include("\n1")
  end

  def prepare_database(env: nil)
    hanami "db prepare", env: env
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
hanami-2.0.0.beta2 spec/integration/rake/with_rspec_spec.rb
hanami-2.0.0.beta1.1 spec/integration/rake/with_rspec_spec.rb
hanami-2.0.0.beta1 spec/integration/rake/with_rspec_spec.rb