Skip to content

Instantly share code, notes, and snippets.

@benlinton
Created May 4, 2017 14:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save benlinton/7fc551b4572e3a81efbc23abd340cad2 to your computer and use it in GitHub Desktop.
Save benlinton/7fc551b4572e3a81efbc23abd340cad2 to your computer and use it in GitHub Desktop.
Rails Test Helper
# Only outputs block if preceeded by `=` in rails views
# Preferred.
def testify(value = nil, &block)
return unless Rails.env.development? || Rails.env.test?
block_given? ? capture(&block) : value
end
# Outputs block for both `-` and `=` in rails views
def testify(value = nil, &block)
return unless Rails.env.development? || Rails.env.test?
if block_given?
block.call
nil
else
value
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment