Sha256: f12253ae4289fbe8da9d8387263596c377d0b4d82430494244ebc5b7255e5879

Contents?: true

Size: 1.32 KB

Versions: 11

Compression:

Stored size: 1.32 KB

Contents

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

describe "params_capturing plugin" do 
  it "should add captures to r.params" do
    app(:params_capturing) do |r|
      r.on('foo/:y/:z', :w) do |y, z, w|
        (r.params.values_at('y', 'z', 'w') + [y, z, w, r[:captures].length]).join('-')
      end

      r.on("bar/:foo") do |foo|
        "b-#{foo}-#{r[:foo]}-#{r[:captures].length}"
      end

      r.on(/(quux)/, /(foo)(bar)/) do |q, foo, bar|
        "y-#{r[:captures].join}-#{q}-#{foo}-#{bar}"
      end

      r.on(/(quux)/, :y) do |q, y|
        r.on(:x) do |x|
          "y-#{r[:y]}-#{r[:x]}-#{q}-#{y}-#{x}-#{r[:captures].length}"
        end

        "y-#{r[:y]}-#{q}-#{y}-#{r[:captures].length}"
      end

      r.on(:x) do |x|
        "x-#{x}-#{r[:x]}-#{r[:captures].length}"
      end
    end

    body('/blarg', 'rack.input'=>StringIO.new).must_equal 'x-blarg-blarg-1'
    body('/foo/1/2/3', 'rack.input'=>StringIO.new).must_equal '1-2-3-1-2-3-3'
    body('/bar/banana', 'rack.input'=>StringIO.new).must_equal 'b-banana-banana-1'
    body('/quux/foobar', 'rack.input'=>StringIO.new).must_equal 'y-quuxfoobar-quux-foo-bar'
    body('/quux/asdf', 'rack.input'=>StringIO.new).must_equal 'y--quux-asdf-2'
    body('/quux/asdf/890', 'rack.input'=>StringIO.new).must_equal 'y--890-quux-asdf-890-3'
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
roda-2.21.0 spec/plugin/params_capturing_spec.rb
roda-2.20.0 spec/plugin/params_capturing_spec.rb
roda-2.19.0 spec/plugin/params_capturing_spec.rb
roda-2.18.0 spec/plugin/params_capturing_spec.rb
roda-2.17.0 spec/plugin/params_capturing_spec.rb
roda-2.16.0 spec/plugin/params_capturing_spec.rb
roda-2.15.0 spec/plugin/params_capturing_spec.rb
roda-2.14.0 spec/plugin/params_capturing_spec.rb
roda-2.13.0 spec/plugin/params_capturing_spec.rb
roda-2.12.0 spec/plugin/params_capturing_spec.rb
roda-2.11.0 spec/plugin/params_capturing_spec.rb