Skip to content
This repository has been archived by the owner on Feb 17, 2023. It is now read-only.

More sugar for HashDef#[] and HashDef#[]= #4

Open
nicolasdespres opened this issue May 21, 2013 · 0 comments
Open

More sugar for HashDef#[] and HashDef#[]= #4

nicolasdespres opened this issue May 21, 2013 · 0 comments

Comments

@nicolasdespres
Copy link
Owner

Users should be able to write something like that:

# Check "HTTP_VERSION" is "HTTP/1.1".
h["HTTP_VERSION"] = "HTTP/1.1"
# Check "rack.version" is an array equal to [ 1, 1 ].
h["rack.version"] = [ 1, 1 ]
# Check "HTTP_USER_AGENT" matches /^Mozilla/.
h["HTTP_USER_AGENT"] =~ /^Mozilla/
# Check "rack.run_once" is boolean equal to false.
h["rack.run_once"] = false
# Check "action_dispatch.parameter_filter" is an array including :password.
h["action_dispatch.parameter_filter"].include_item :password
# Check "rack.session" is a hash containing a "session_id" key with a string value of minimum length 16.
h["rack.session"].has_property("session_id").string(min_length: 16)
# Check "rack.session" is a hash containing a _csrf_token" key with a string value of minimum length 44.
h["rack.session"].has_property("_csrf_token").string(min_length: 44)
# Check "rack.session.options" is a hash with the given hash schema.
h["rack.session.options"].object strict: false do |s|
  # A "secret" key with a string value of minimum lenght 60.
  s.string "secret", min_length: 60
  # A "httponly" key with a boolean value equal to true
  s.boolean "httponly", equal_to: true
  # A "rack.request.cookie_hash" hash with the following schema.
  s.headers "rack.request.cookie_hash" do |h|
    h["_blog_session"].string min_length: 218
  end
end
# Check "action_controller.instance" value is a ActionController::Base instance.
# This check won't be documented.
h["action_controller.instance"].is_a ActionController::Base, doc: false
# Check "__internal__" is a string equal to "foo" and won't be documented.
h["__internal__"].must_be("foo", doc: false)
# Check "REQUEST_URI" is string formatted as a URI.
h.uri "REQUEST_URI"

This would be useful for headers specification.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

1 participant