spec/plugin/header_matchers_spec.rb in roda-2.29.0 vs spec/plugin/header_matchers_spec.rb in roda-3.0.0
- old
+ new
@@ -1,6 +1,6 @@
-require File.expand_path("spec_helper", File.dirname(File.dirname(__FILE__)))
+require_relative "../spec_helper"
describe "accept matcher" do
it "should accept mimetypes and set response Content-Type" do
app(:header_matchers) do |r|
r.on :accept=>"application/xml" do
@@ -12,14 +12,13 @@
status.must_equal 404
end
end
describe "header matcher" do
- # RODA3: undeprecate, and switch http-accept to accept
- deprecated "should match if header present" do
+ it "should match if header present" do
app(:header_matchers) do |r|
- r.on :header=>"http-accept" do
+ r.on :header=>"accept" do
"bar"
end
end
body("HTTP_ACCEPT" => "application/xml").must_equal "bar"
@@ -36,26 +35,10 @@
app.opts[:header_matcher_prefix] = true
body("HTTP_ACCEPT" => "application/xml").must_equal "bar-application/xml"
status.must_equal 404
end
-
- # RODA3: Remove
- it "should automatically use HTTP prefix for headers if :header_matcher_prefix is set" do
- app(:bare) do
- plugin :header_matchers
- opts[:header_matcher_prefix] = true
- route do |r|
- r.on :header=>"accept" do |v|
- "bar-#{v}"
- end
- end
- end
-
- body("HTTP_ACCEPT" => "application/xml").must_equal "bar-application/xml"
- status("ACCEPT"=>"application/xml").must_equal 404
- end
end
describe "host matcher" do
it "should match a host" do
app(:header_matchers) do |r|
@@ -66,12 +49,11 @@
body("HTTP_HOST" => "example.com").must_equal 'worked'
status("HTTP_HOST" => "foo.com").must_equal 404
end
- # RODA3: switch deprecated to it
- deprecated "should match a host with a regexp" do
+ it "should match a host with a regexp" do
app(:header_matchers) do |r|
r.on :host=>/example/ do
"worked"
end
end
@@ -88,42 +70,17 @@
end
body("HTTP_HOST" => "example.com").must_equal '0'
end
- deprecated "doesn't yield host if passed a regexp" do
- app(:header_matchers) do |r|
- r.on :host=>/\A(.*)\.example\.com\z/ do |*m|
- m.empty? ? '0' : m[0]
- end
- end
-
- body("HTTP_HOST" => "foo.example.com").must_equal '0'
- end
-
- # RODA3: Remove :host_matcher_captures setting
it "yields host if passed a regexp and opts[:host_matcher_captures] is set" do
app(:header_matchers) do |r|
r.on :host=>/\A(.*)\.example\.com\z/ do |*m|
m.empty? ? '0' : m[0]
end
end
- app.opts[:host_matcher_captures] = true
body("HTTP_HOST" => "foo.example.com").must_equal 'foo'
- end
-
- # RODA3: Remove
- it "doesn't yields host if passed a string and opts[:host_matcher_captures] is set" do
- app(:header_matchers) do |r|
- r.on :host=>'example.com' do |*m|
- m.empty? ? '0' : m[0]
- end
- end
-
- body("HTTP_HOST" => "example.com").must_equal '0'
- app.opts[:host_matcher_captures] = true
- body("HTTP_HOST" => "example.com").must_equal '0'
end
end
describe "user_agent matcher" do
it "should accept pattern and match against user-agent" do