Sha256: ee4b19a0050cf23efcd3c3d3dd6925304f33c6000058fe2c9284d157bca7d547

Contents?: true

Size: 1.98 KB

Versions: 30

Compression:

Stored size: 1.98 KB

Contents

require_relative "../spec_helper"

describe "multi_run plugin" do 
  it "adds Roda.run method for setting up prefix delegations to other rack apps" do
    app(:multi_run) do |r|
      r.multi_run
      "c"
    end

    app.run "a", Class.new(Roda).class_eval{route{"a1"}; app}

    body("/a").must_equal 'a1'
    body("/b").must_equal 'c'
    body("/b/a").must_equal 'c'
    body.must_equal 'c'

    app.run "b", Class.new(Roda).class_eval{route{"b1"}; app}

    body("/a").must_equal 'a1'
    body("/b").must_equal 'b1'
    body("/b/a").must_equal 'b1'
    body.must_equal 'c'

    app.run "b/a", Class.new(Roda).class_eval{route{"b2"}; app}

    body("/a").must_equal 'a1'
    body("/b").must_equal 'b1'
    body("/b/a").must_equal 'b2'
    body.must_equal 'c'
  end

  it "works when freezing the app" do
    app(:multi_run) do |r|
      r.multi_run
      "c"
    end

    app.run "a", Class.new(Roda).class_eval{route{"a1"}; app}
    app.run "b", Class.new(Roda).class_eval{route{"b1"}; app}
    app.run "b/a", Class.new(Roda).class_eval{route{"b2"}; app}
    app.freeze

    body("/a").must_equal 'a1'
    body("/b").must_equal 'b1'
    body("/b/a").must_equal 'b2'
    body.must_equal 'c'

    proc{app.run "a", Class.new(Roda).class_eval{route{"a1"}; app}}.must_raise
  end

  it "works when subclassing" do
    app(:multi_run) do |r|
      r.multi_run
      "c"
    end

    app.run "a", Class.new(Roda).class_eval{route{"a1"}; app}
    body("/a").must_equal 'a1'

    a = app
    @app = Class.new(a)

    a.run "b", Class.new(Roda).class_eval{route{"b2"}; app}
    app.run "b", Class.new(Roda).class_eval{route{"b1"}; app}

    body("/a").must_equal 'a1'
    body("/b").must_equal 'b1'

    @app = a
    body("/b").must_equal 'b2'
  end

  it "yields prefix" do
    yielded = false

    app(:multi_run) do |r|
      r.multi_run do |prefix|
        yielded = prefix
      end
    end

    app.run "a", Class.new(Roda).class_eval{route{"a1"}; app}

    body("/a").must_equal "a1"
    yielded.must_equal "a"
  end
end

Version data entries

30 entries across 30 versions & 1 rubygems

Version Path
roda-3.9.0 spec/plugin/multi_run_spec.rb
roda-3.8.0 spec/plugin/multi_run_spec.rb
roda-3.7.0 spec/plugin/multi_run_spec.rb
roda-3.6.0 spec/plugin/multi_run_spec.rb
roda-3.5.0 spec/plugin/multi_run_spec.rb
roda-3.4.0 spec/plugin/multi_run_spec.rb
roda-3.3.0 spec/plugin/multi_run_spec.rb
roda-3.2.0 spec/plugin/multi_run_spec.rb
roda-3.1.0 spec/plugin/multi_run_spec.rb
roda-3.0.0 spec/plugin/multi_run_spec.rb