Sha256: e043fa0c4c662b8a1e82a29a0dcf0f87878160afb63c660bdd3c1b6f00ec36d7

Contents?: true

Size: 1.74 KB

Versions: 4

Compression:

Stored size: 1.74 KB

Contents

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

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").should == 'a1'
    body("/b").should == 'c'
    body("/b/a").should == 'c'
    body.should == 'c'

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

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

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

    body("/a").should == 'a1'
    body("/b").should == 'b1'
    body("/b/a").should == 'b2'
    body.should == '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").should == 'a1'
    body("/b").should == 'b1'
    body("/b/a").should == 'b2'
    body.should == 'c'

    proc{app.run "a", Class.new(Roda).class_eval{route{"a1"}; app}}.should raise_error
  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").should == '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").should == 'a1'
    body("/b").should == 'b1'

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

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
roda-2.2.0 spec/plugin/multi_run_spec.rb
roda-2.1.0 spec/plugin/multi_run_spec.rb
roda-2.0.0 spec/plugin/multi_run_spec.rb
roda-1.3.0 spec/plugin/multi_run_spec.rb