Skip to content

Instantly share code, notes, and snippets.

@hemalvarambhia
Created November 7, 2014 16:45
Show Gist options
  • Select an option

  • Save hemalvarambhia/45f6a8db55b0f597c8f5 to your computer and use it in GitHub Desktop.

Select an option

Save hemalvarambhia/45f6a8db55b0f597c8f5 to your computer and use it in GitHub Desktop.
An RSpec matcher to check a user is allowed to connect to a database using TCP/IP connections unconditionally.
module PostgresqlMatchers
RSpec::Matchers.define :permit_user do |user|
match do |content|
!(content=~/host #{@database} #{user} 127\.0\.0\.1\/32 trust/).nil?
end
chain :to_connect_to do |database|
@database = database
end
failure_message_for_should do |content|
"expected user #{user} to be permitted to connect to database #{@database}"
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment