spec/configuration_spec.rb in safe_cookies-0.1.4 vs spec/configuration_spec.rb in safe_cookies-0.1.5
- old
+ new
@@ -24,56 +24,33 @@
expect(®istration_with_domain).to raise_error(NotImplementedError)
end
describe 'register_cookie' do
- context 'cookie name formatting' do
-
- let(:set_cookie) do
- # These tests for the Configuration module require an integration with
- # the middleware itself. Therefore, we need to actually use it.
-
- app = stub('app')
- env = { 'HTTPS' => 'on' }
- stub_app_call(app, :application_cookies => 'cookie_name=value')
-
- middleware = described_class.new(app)
- code, headers, response = middleware.call(env)
- headers['Set-Cookie']
- end
-
- it 'understands cookies registered as symbol' do
+ it 'raises an error if a cookie is registered without passing its expiry' do
+ registration_without_expiry = lambda do
SafeCookies.configure do |config|
- config.register_cookie(:cookie_name, :expire_after => nil)
+ config.register_cookie('filter', :some => :option)
end
-
- set_cookie.should =~ /cookie_name=value;.* secure; HttpOnly/
end
- it 'understands cookies registered as string' do
- SafeCookies.configure do |config|
- config.register_cookie('cookie_name', :expire_after => nil)
- end
-
- set_cookie.should =~ /cookie_name=value;.* secure; HttpOnly/
- end
-
+ expect(®istration_without_expiry).to raise_error(SafeCookies::MissingOptionError)
end
- it 'raises an error if a cookie is registered without passing its expiry' do
- registration_without_expiry = lambda do
+ it 'raises an error if the cookie name is not a String, because the middleware’s logic depends on strings' do
+ registration_as_symbol = lambda do
SafeCookies.configure do |config|
config.register_cookie(:filter, :some => :option)
end
end
- expect(®istration_without_expiry).to raise_error(SafeCookies::MissingOptionError)
+ expect(®istration_as_symbol).to raise_error(RuntimeError, /must be a string/i)
end
it 'allows nil as expiry (means session cookie)' do
registration_with_nil_expiry = lambda do
SafeCookies.configure do |config|
- config.register_cookie(:filter, :expire_after => nil)
+ config.register_cookie('filter', :expire_after => nil)
end
end
expect(®istration_with_nil_expiry).to_not raise_error(SafeCookies::MissingOptionError)
end