Sha256: 59e43294d49fb30eff5aba3084e9fc560b13052d6b22b83684a0a1d382cc53f9

Contents?: true

Size: 1.83 KB

Versions: 1

Compression:

Stored size: 1.83 KB

Contents

require "spec_helper"
require "rack/test"

module Mado
  describe App do
    include Rack::Test::Methods

    let(:app) do
      described_class
    end

    describe "GET /" do
      it "should show the root page" do
        get "/"
        expect(last_response).to be_ok
      end
    end

    describe "GET /<image>" do
      let(:base_dir) do
        fixture_path("example")
      end

      let(:other_dir) do
        fixture_path("other")
      end

      before do
        Dir.chdir(base_dir)
      end

      context "with existed image" do
        context "in the same directory" do
          before do
            described_class.set :markdown_path, File.join(base_dir, "sample.md")
          end

          it "should return the specified image" do
            get "/example.png"
            expect(last_response).to be_ok
          end
        end

        context "in the different directory" do
          before do
            described_class.set :markdown_path, File.join(other_dir, "other.md")
          end

          it "should return the specified image" do
            get "/other.png"
            expect(last_response).to be_ok
          end
        end
      end

      context "with non-existed image" do
        it "should return 404" do
          get "/notfound.png"
          expect(last_response).to be_not_found
        end
      end
    end

    describe "GET /emoji/*" do
      let(:emoji_name) do
        "octocat.png"
      end

      context "when given emoji exists" do
        it "should return the image of given emoji" do
          get "/emoji/#{emoji_name}"
          expect(last_response).to be_ok
        end
      end

      context "when given emoji does not exist" do
        it "should return 404" do
          get "/emoji/#{emoji_name}.notfound"
          expect(last_response).to be_not_found
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
mado-0.2.0 spec/mado/app_spec.rb