Sha256: 210d24749121e8887b715f42d2e3051d9e7df2ec0ded6b8d0c6bd54ea067b07c

Contents?: true

Size: 1.67 KB

Versions: 10

Compression:

Stored size: 1.67 KB

Contents

require File.expand_path("helper", File.dirname(__FILE__))

test "executes on true" do
  Cuba.define do
    on true do
      res.write "+1"
    end
  end

  _, _, resp = Cuba.call({})

  assert_equal ["+1"], resp.body
end

test "executes on non-false" do
  Cuba.define do
    on "123" do
      res.write "+1"
    end
  end

  _, _, resp = Cuba.call({ "PATH_INFO" => "/123", "SCRIPT_NAME" => "/" })

  assert_equal ["+1"], resp.body
end

test "ensures SCRIPT_NAME and PATH_INFO are reverted" do
  Cuba.define do
    on lambda { env["SCRIPT_NAME"] = "/hello"; false } do
      res.write "Unreachable"
    end
  end

  env = { "SCRIPT_NAME" => "/", "PATH_INFO" => "/hello" }

  _, _, resp = Cuba.call(env)

  assert_equal "/", env["SCRIPT_NAME"]
  assert_equal "/hello", env["PATH_INFO"]
  assert_equal [], resp.body
end

test "skips consecutive matches" do
  Cuba.define do
    on true do
      env["foo"] = "foo"

      res.write "foo"
    end

    on true do
      env["bar"] = "bar"

      res.write "bar"
    end
  end

  env = {}

  _, _, resp = Cuba.call(env)

  assert_equal "foo", env["foo"]
  assert_equal ["foo"], resp.body

  assert ! env["bar"]
end

test "finds first match available" do
  Cuba.define do
    on false do
      res.write "foo"
    end

    on true do
      res.write "bar"
    end
  end

  _, _, resp = Cuba.call({})

  assert_equal ["bar"], resp.body
end

test "reverts a half-met matcher" do
  Cuba.define do
    on "post", false do
      res.write "Should be unmet"
    end
  end

  env = { "PATH_INFO" => "/post", "SCRIPT_NAME" => "/" }
  _, _, resp = Cuba.call(env)

  assert_equal [], resp.body
  assert_equal "/post", env["PATH_INFO"]
  assert_equal "/", env["SCRIPT_NAME"]
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
cuba-3.0.0.rc2 test/on.rb
cuba-3.0.0.rc1 test/on.rb
cuba-2.2.1 test/on.rb
cuba-2.2.0 test/on.rb
cuba-2.2.0.rc1 test/on.rb
cuba-2.1.0 test/on.rb
cuba-2.1.0.rc1 test/on.rb
cuba-2.0.1 test/on.rb
cuba-2.0.0 test/on.rb
cuba-2.0.0.rc3 test/on.rb