Sha256: 3d95004fce88c6bcfd5093ea7b5c364dd3f5bb3c98fc9733139bf8304abad78e

Contents?: true

Size: 1.39 KB

Versions: 4

Compression:

Stored size: 1.39 KB

Contents

require_relative "../lib/tynn/hmote"

setup do
  Tynn.helpers(Tynn::HMote, views: File.expand_path("./test/views"))

  Tynn::Test.new
end

test "partial" do |app|
  Tynn.define do
    on "partial" do
      res.write(partial("partial", name: "mote"))
    end
  end

  app.get("/partial")

  assert_equal "mote", app.res.body.strip
end

test "view" do |app|
  Tynn.define do
    on "view" do
      res.write(view("view", title: "tynn", name: "mote"))
    end
  end

  app.get("/view")

  assert_equal "tynn / mote", app.res.body.strip
end

test "render" do |app|
  Tynn.define do
    on "render" do
      render("view", title: "tynn", name: "mote")
    end
  end

  app.get("/render")

  assert_equal 200, app.res.status
  assert_equal "text/html", app.res.headers["Content-Type"]
  assert_equal "tynn / mote", app.res.body.strip
end

test "404" do |app|
  Tynn.define do
    on "404" do
      res.status = 404

      render("view", title: "tynn", name: "mote")
    end
  end

  app.get("/404")

  assert_equal 404, app.res.status
  assert_equal "text/html", app.res.headers["Content-Type"]
  assert_equal "tynn / mote", app.res.body.strip
end

test "custom layout" do
  class App < Tynn
    layout("custom_layout")
  end

  App.define do
    root do
      render("view", title: "tynn", name: "mote")
    end
  end

  app = Tynn::Test.new(App)
  app.get("/")

  assert_equal "custom / tynn / mote", app.res.body.strip
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
tynn-1.0.0.rc1 test/hmote_test.rb
tynn-0.0.4 test/hmote_test.rb
tynn-0.0.3 test/hmote_test.rb
tynn-0.0.2 test/hmote.rb