Skip to content

Commit

Permalink
Merge pull request sinatra#128 from vipulnsward/fix-namespace-warnings
Browse files Browse the repository at this point in the history
Fix namespace warnings
  • Loading branch information
Zachary Scott committed May 22, 2015
2 parents 4837242 + 50fbf74 commit 908a140
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 37 deletions.
2 changes: 2 additions & 0 deletions sinatra-contrib/lib/sinatra/namespace.rb
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,8 @@ module Sinatra
module Namespace
def self.new(base, pattern, conditions = {}, &block)
Module.new do
#quelch uninitialized variable warnings, since these get used by compile method.
@pattern, @conditions = nil, nil
extend NamespacedMethods
include InstanceMethods
@base, @extensions, @errors = base, [], {}
Expand Down
74 changes: 37 additions & 37 deletions sinatra-contrib/spec/namespace_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def namespace(*args, &block)
it 'accepts the path as a regular expression' do
namespace('/foo') { send(verb, /\/\d\d/) { 'bar' }}
send(verb, '/foo/12').should be_ok
body.should == 'bar' unless verb == :head
body.should eq 'bar' unless verb == :head
send(verb, '/foo/123').should_not be_ok
end
end
Expand Down Expand Up @@ -478,24 +478,24 @@ def magic
namespace('/de') do
not_found { 'nicht gefunden' }
end
send(verb, '/foo').status.should == 404
last_response.body.should_not == 'nicht gefunden' unless verb == :head
get('/en/foo').status.should == 404
last_response.body.should_not == 'nicht gefunden' unless verb == :head
get('/de/foo').status.should == 404
last_response.body.should == 'nicht gefunden' unless verb == :head
send(verb, '/foo').status.should eq 404
last_response.body.should_not eq 'nicht gefunden' unless verb == :head
get('/en/foo').status.should eq 404
last_response.body.should_not eq 'nicht gefunden' unless verb == :head
get('/de/foo').status.should eq 404
last_response.body.should eq 'nicht gefunden' unless verb == :head
end

it 'can be customized for specific error codes' do
namespace('/de') do
error(404) { 'nicht gefunden' }
end
send(verb, '/foo').status.should == 404
last_response.body.should_not == 'nicht gefunden' unless verb == :head
get('/en/foo').status.should == 404
last_response.body.should_not == 'nicht gefunden' unless verb == :head
get('/de/foo').status.should == 404
last_response.body.should == 'nicht gefunden' unless verb == :head
send(verb, '/foo').status.should eq 404
last_response.body.should_not eq 'nicht gefunden' unless verb == :head
get('/en/foo').status.should eq 404
last_response.body.should_not eq 'nicht gefunden' unless verb == :head
get('/de/foo').status.should eq 404
last_response.body.should eq 'nicht gefunden' unless verb == :head
end

it 'falls back to the handler defined in the base app' do
Expand All @@ -507,12 +507,12 @@ def magic
error(404) { 'nicht gefunden' }
end
end
send(verb, '/foo').status.should == 404
last_response.body.should == 'not found...' unless verb == :head
get('/en/foo').status.should == 404
last_response.body.should == 'not found...' unless verb == :head
get('/de/foo').status.should == 404
last_response.body.should == 'nicht gefunden' unless verb == :head
send(verb, '/foo').status.should eq 404
last_response.body.should eq 'not found...' unless verb == :head
get('/en/foo').status.should eq 404
last_response.body.should eq 'not found...' unless verb == :head
get('/de/foo').status.should eq 404
last_response.body.should eq 'nicht gefunden' unless verb == :head
end

it 'can be customized for specific Exception classes' do
Expand Down Expand Up @@ -542,10 +542,10 @@ class BError < AError; end
end
end
end
get('/en/foo').status.should == 401
last_response.body.should == 'auth failed' unless verb == :head
get('/de/foo').status.should == 406
last_response.body.should == 'methode nicht erlaubt' unless verb == :head
get('/en/foo').status.should eq 401
last_response.body.should eq 'auth failed' unless verb == :head
get('/de/foo').status.should eq 406
last_response.body.should eq 'methode nicht erlaubt' unless verb == :head
end
end

Expand All @@ -560,8 +560,8 @@ class BError < AError; end
end
end

send(verb, '/').body.should == 'hi'
send(verb, '/foo').body.should == 'hi'
send(verb, '/').body.should eq 'hi'
send(verb, '/foo').body.should eq 'hi'
end

specify 'can be nested' do
Expand All @@ -574,8 +574,8 @@ class BError < AError; end
end
end

send(verb, '/').body.should == 'hi'
send(verb, '/foo').body.should == 'ho'
send(verb, '/').body.should eq 'hi'
send(verb, '/foo').body.should eq 'ho'
end

specify 'can use a custom views directory' do
Expand All @@ -588,8 +588,8 @@ class BError < AError; end
end
end

send(verb, '/').body.should == "hi\n"
send(verb, '/foo').body.should == "ho\n"
send(verb, '/').body.should eq "hi\n"
send(verb, '/foo').body.should eq "ho\n"
end

specify 'default to the base app\'s layout' do
Expand All @@ -603,8 +603,8 @@ class BError < AError; end
end
end

send(verb, '/').body.should == 'he said: hi'
send(verb, '/foo').body.should == 'he said: ho'
send(verb, '/').body.should eq 'he said: hi'
send(verb, '/foo').body.should eq 'he said: ho'
end

specify 'can define nested layouts' do
Expand All @@ -618,8 +618,8 @@ class BError < AError; end
end
end

send(verb, '/').body.should == 'Hello World!'
send(verb, '/foo').body.should == 'Hi World!'
send(verb, '/').body.should eq 'Hello World!'
send(verb, '/foo').body.should eq 'Hi World!'
end
end
end
Expand All @@ -633,7 +633,7 @@ class BError < AError; end
value = foo
end
end
value.should == 42
value.should eq 42
end

specify 'can be registered within a namespace' do
Expand All @@ -646,8 +646,8 @@ class BError < AError; end
end
b = views
end
a.should == 'CUSTOM!!!'
b.should_not == 'CUSTOM!!!'
a.should eq 'CUSTOM!!!'
b.should_not eq 'CUSTOM!!!'
end

specify 'trigger the route_added hook' do
Expand All @@ -663,7 +663,7 @@ class BError < AError; end
end
get('/bar') { }
end
route[1].should == '/foo'
route[1].should eq '/foo'
end

specify 'prevent app-global settings from being changed' do
Expand Down

0 comments on commit 908a140

Please sign in to comment.