Sha256: d7537a5f24b5034f216761c66b826adaca90416cb73d4652b57f44b5b1b13b94

Contents?: true

Size: 1.84 KB

Versions: 9

Compression:

Stored size: 1.84 KB

Contents

# frozen_string_literal: true

require "json"
require "rack/test"

RSpec.describe "Web / Welcome view", :app_integration do
  include Rack::Test::Methods

  let(:app) { Hanami.app }

  before do
    with_directory(@dir = make_tmp_directory) do
      write "config/app.rb", <<~RUBY
        require "hanami"

        module TestApp
          class App < Hanami::App
            config.logger.stream = File::NULL
          end
        end
      RUBY

      write "config/routes.rb", <<~RUBY
        module TestApp
          class Routes < Hanami::Routes
          end
        end
      RUBY

      before_prepare if respond_to?(:before_prepare)
      require "hanami/prepare"
    end
  end

  context "no routes defined" do
    it "renders the welcome page" do
      get "/"

      body = last_response.body.strip
      expect(body).to include "<h1>Welcome to Hanami</h1>"
      expect(body).to include "Hanami version: #{Hanami::VERSION}"
      expect(body).to include "Ruby version: #{RUBY_DESCRIPTION}"

      expect(last_response.status).to eq 200
    end
  end

  context "routes defined" do
    def before_prepare
      write "config/routes.rb", <<~RUBY
        module TestApp
          class Routes < Hanami::Routes
            root to: -> * { [200, {}, "Hello from a route"] }
          end
        end
      RUBY
    end

    it "does not render the welcome page" do
      get "/"

      expect(last_response.body).to eq "Hello from a route"
      expect(last_response.status).to eq 200
    end
  end

  context "non-development env" do
    def before_prepare
      @hanami_env = ENV["HANAMI_ENV"]
      ENV["HANAMI_ENV"] = "production"
    end

    after do
      ENV["HANAMI_ENV"] = @hanami_env
    end

    it "does not render the welcome page" do
      get "/"

      expect(last_response.body).to eq "Not Found"
      expect(last_response.status).to eq 404
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
hanami-2.2.1 spec/integration/web/welcome_view_spec.rb
hanami-2.2.0 spec/integration/web/welcome_view_spec.rb
hanami-2.2.0.rc1 spec/integration/web/welcome_view_spec.rb
hanami-2.2.0.beta2 spec/integration/web/welcome_view_spec.rb
hanami-2.2.0.beta1 spec/integration/web/welcome_view_spec.rb
hanami-2.1.0 spec/integration/web/welcome_view_spec.rb
hanami-2.1.0.rc3 spec/integration/web/welcome_view_spec.rb
hanami-2.1.0.rc2 spec/integration/web/welcome_view_spec.rb
hanami-2.1.0.rc1 spec/integration/web/welcome_view_spec.rb